liveBook · Manning

Sampling

As explained in Build AI Drug Discovery Pipelines

Random sampling is the selection of items uniformly at random from an available population or pool.

Random sampling selects items uniformly at random from an available pool. In molecular docking, it can initialize an active-learning loop before any labeled data exists. section 9.2.4

For an initial set of molecular candidates, random sampling:

  • Provides a simple, low-overhead selection that reflects the starting library’s distribution. section 9.2.4
  • Can reproduce library imbalances, overrepresenting some scaffolds or functional groups while leaving parts of chemical space unexplored. section 9.2.4
  • Serves as a virtual-screening baseline: in a dataset with 10% actives, a random top 1% selection is expected to contain one active per ten compounds screened. section 8.1.3
Listing 9.7 Initial Sampling – Random or Diverse
def initialize_samples(
    X_pool, initialization: str, n_samples: int
) -> np.ndarray:
    """Initialize samples either randomly or using diversity picking."""
    if initialization == 'random':
        print("Selecting initial samples randomly...")
        return np.random.choice(len(X_pool), size=n_samples, replace=False)
    elif initialization == 'diverse':
        print("Selecting initial samples following MaxMin diversity...")
        picker = rdSimDivPickers.MaxMinPicker()    #A
        fps_for_diversity = [
            list(fp) for fp in X_pool
        ]    #B
        picked = list(picker.LazyBitVectorPick(    #C
            fps_for_diversity, 
            len(fps_for_diversity),
            n_samples
        ))
        return np.array(picked)
    else:
        raise ValueError(f"Unknown initialization method: {initialization}")

Compare the NumPy random-selection branch with an optional RDKit MaxMin diversity-selection branch. section 9.2.4

How Build AI Drug Discovery Pipelines covers it

How deep it goes
Defines uniform selection, provides a NumPy implementation, and notes library-imbalance drawbacks.
Examples
Uses molecular-pool initialization and a 1,000-compound screening example with 100 known actives.
What you can do after
Apply it via NumPy to select an initial subset of molecular candidates without replacement.
How it connects
Connects random sampling to active learning, molecular docking, diversity-based sampling, chemical space, and virtual screening.

Also explained in

Compare how 31 books explain 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.