liveBook · Manning

Uncertainty sampling

As explained in Build AI Drug Discovery Pipelines

Uncertainty sampling is an active-learning acquisition strategy that selects examples for which the current model is most uncertain.

Uncertainty sampling is an active-learning strategy that selects unlabeled examples whose predictions are most uncertain. In virtual screening, it directs expensive docking evaluations toward molecules with novel structures or predictions near the active–inactive boundary. section 9.2.5

Estimate uncertainty according to the predictive model:

  • Use predictive variance with probabilistic models such as Gaussian processes. section 9.2.5
  • Measure ensemble disagreement across multiple model predictions. section 9.2.5
  • Apply Monte Carlo dropout during inference to approximate an implicit ensemble. section 9.2.5
  • Select classification points closest to the decision boundary. section 9.2.5

A practical loop begins with an initial molecular sample, evaluates selected compounds by docking, trains a surrogate model on the resulting scores, and predicts the unlabeled pool. The acquisition function then selects the next batch; repeating this cycle expands the labeled pool and generally reduces uncertainty. Combining uncertainty with representativeness or diversity helps explore chemical space rather than repeatedly sampling one molecular family. section 9.2.1 section 9.4

Listing 9.8 Greedy Acquisition and Uncertainty Sampling
def greedy_acquisition(model, X_pool, device, batch_size=1):
    predictions = model.predict(X_pool, device)
    best_indices = np.argsort(predictions)[:batch_size]
    return best_indices
 
def uncertainty_sampling(
    model, X_pool, device, batch_size=1, n_samples=100
):
    model.train()    #A
    all_predictions = np.zeros((n_samples, len(X_pool)))
    
    for i in range(n_samples):    #B
        inputs = torch.tensor(X_pool, dtype=torch.float32).to(device)
        
        with torch.no_grad():    #C
            outputs = model(inputs)            
        all_predictions[i, :] = outputs.cpu().numpy().flatten()
    
    uncertainties = np.std(all_predictions, axis=0)    #D
    best_indices = np.argsort(
        uncertainties
    )[::-1][:batch_size]    #E
    return best_indices
 
def select_next_molecule(
    model, X_pool, smiles_pool, device, best_score, batch_size=1, 
    acquisition_function="greedy", xi=0.01
):    #F
    if acquisition_function == "greedy":
        best_indices = greedy_acquisition(model, X_pool, device, batch_size)
    elif acquisition_function == "uncertainty":
        best_indices = uncertainty_sampling(model, X_pool, device)
    elif acquisition_function == "pi":
        best_indices = probability_of_improvement(
            model, X_pool, device, best_score, xi
        )
    elif acquisition_function == "ei":
        best_indices = expected_improvement(
            model, X_pool, device, best_score, xi
        )
    else:
        raise ValueError(f"Unknown acquisition function: {acquisition_function}")
 
    best_smiles = [smiles_pool[i] for i in best_indices]
    return best_indices, best_smiles

The implementation samples model predictions repeatedly, computes each pool molecule's prediction standard deviation, and returns the highest-uncertainty indices for the next batch. section 9.2.5

Progressive docking

For VEGFR-2 structure 4AG8, an active-learning run started with 5,000 molecules and added 250 per iteration. After 10 iterations, it evaluated 7,500 molecules and captured 73 of the top 100 docking candidates, while the best reported score reached approximately −20.66 kcal/mol. section 9.4

How Build AI Drug Discovery Pipelines covers it

How deep it goes
Explains uncertainty measures, iterative acquisition, diversity trade-offs, and a PyTorch implementation, while deferring model-specific theory.
Examples
Demonstrates prediction standard deviation, 4AG8 docking, PCA chemical-space plots, TensorBoard metrics, and top-100 molecule capture.
What it assumes
Assumes molecular representations, model predictions, docking scores, and labeled versus unlabeled pools; introduces the selection rationale incrementally.
What you can do after
Apply it via a surrogate model to select informative molecules and monitor candidate recovery across active-learning iterations.
How it connects
Connects active learning with surrogate models, molecular docking, representativeness, diversity sampling, exploration–exploitation, and virtual screening.

Also explained in

Compare how 3 books explain uncertainty sampling →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build AI Drug Discovery Pipelines. The section links point to the parts of the book it draws on.