01 / 22
AI for Materials Science  ·  Lecture 04 (Complete Beginner-to-Research Edition)

Bayesian Optimization & Active Experimental Design:
Gaussian Processes, Uncertainty Quantification & Self-Driving Labs

Zesheng Liu
Laboratory of Organic Electronics, Linköping University
Modules 04a–04b  |  AqSolDB (N = 9,482) & Buchwald–Hartwig Coupling Reactions (N = 3,955)
Linköping University Laboratory of Organic Electronics

Lecture 04 roadmap: from uncertainty to autonomous labs

Closing the loop between machine learning predictions and physical synthesis across Notebooks 04a–04b
PART 1 · MODULE 04a

Gaussian Process Regression

Why small data demands uncertainty σ(x), multivariate Gaussian conditioning, RBF & Matérn kernels, 10-line NumPy GP posterior, WhiteKernel noise estimation, and Tanimoto molecular kernels.

PART 2 · MODULE 04b

Acquisition & Process BO

The 4-step active learning loop, balancing Exploitation vs. Exploration, Greedy vs. UCB vs. Expected Improvement (EI), and escaping local optima in 1D & 2D process windows.

PART 3 · MODULE 04b

Buchwald–Hartwig Case

Optimizing 3,955 Pd-catalyzed C–N coupling reactions (Science 2018): reaching >95% yield in ~25 experiments (<0.7% of space), Morgan FP + PCA generalization, and Batch BO.

Bayesian Optimization couples a probabilistic surrogate (GPR) with an acquisition function to find global optima in dozens—not thousands—of experiments.
Linköping University Laboratory of Organic Electronics

Why expensive materials experiments need a new paradigm

Grid search suffers exponential curse of dimensionality; sequential Bayesian Optimization learns from every single run
BRUTE-FORCE GRID / RANDOM

Combinatorial Explosion

  • 4 synthesis variables × 10 levels = 10,000 experiments.
  • At 10 reactions/day, a full grid takes nearly 3 years.
  • Wastes reagents and time in clearly poor regions of parameter space.
BAYESIAN OPTIMIZATION (BO)

Self-Driving Lab Engine

  • Start with just 3–5 initial experiments.
  • Fit a surrogate model that predicts both mean μ(x) and uncertainty σ(x).
  • Pick the single next experiment most likely to beat the current record—or resolve a blind spot.
When each experiment costs hours of synthesis or DFT time, sequential active learning replaces brute-force grids with targeted uncertainty-guided queries.
Linköping University Laboratory of Organic Electronics

Why prediction uncertainty σ(x) is essential in small data

Standard ML models give a single confident curve everywhere—even across huge unexplored gaps
Why prediction uncertainty σ(<i>x</i>) is essential in small data
Gaussian Process Regression outputs a full probability distribution at every point: tight confidence near data, wide error bars in unexplored gaps.
Linköping University Laboratory of Organic Electronics

From 1D Normal to Multivariate Correlated Gaussians

How observing y(x1) mathematically pulls the mean and shrinks the variance of its neighbor y(x2)
From 1D Normal to Multivariate Correlated Gaussians
A Gaussian Process is simply a multivariate Gaussian over infinitely many points—conditioning on observed experiments updates all nearby predictions.
Linköping University Laboratory of Organic Electronics

Kernel functions k(x, x′): encoding physical smoothness

Before seeing any data, the kernel specifies how fast a material property can change with composition or temperature
Kernel functions <i>k</i>(<i>x</i>, <i>x</i>′): encoding physical smoothness
RBF assumes infinite smoothness; Matérn (ν = 1.5 / 2.5) captures realistic physical roughness; length-scale ℓ controls correlation range.
Linköping University Laboratory of Organic Electronics

GP Posterior in 10 lines of NumPy: exact analytical inference

No gradient descent needed for inference—matrix conditioning gives exact μ* and Σ*
1
K = rbf(X_tr, X_tr) + noise * I
Training covariance matrix; L = np.linalg.cholesky(K) factorizes it stably.
2
mu_star = K_s.T @ solve(K, y_tr)
Posterior mean: weighted linear combination of training labels by kernel similarity.
3
var_star = diag(K_ss) - sum(v**2)
Posterior variance: prior variance minus uncertainty explained away by nearby data.
SCIKIT-LEARN EQUIVALENT

3-Line Production API

kernel = C(1.0) * RBF(1.0)
gp = GaussianProcessRegressor(kernel)
gp.fit(X_train, y_train)
mu, std = gp.predict(X_test, return_std=True)

Posterior variance σ2(x*) depends only on input geometry X and kernel k—uncertainty drops to zero right at observed points.
Linköping University Laboratory of Organic Electronics

How adding experiments collapses posterior uncertainty

Tracking N = 3 → 5 → 8 observations as new measurements pin down the true curve
How adding experiments collapses posterior uncertainty
Each new measurement pins down μ(x) locally and shrinks σ(x) across its neighborhood—automatically guiding where to sample next.
Linköping University Laboratory of Organic Electronics

Automatic hyperparameter tuning & WhiteKernel noise

Maximizing log-marginal likelihood learns ℓ and separates true experimental noise from signal
Automatic hyperparameter tuning & <code>WhiteKernel</code> noise
Without WhiteKernel, GPR tries to interpolate noisy lab measurements (overfitting); adding WhiteKernel recovers the smooth trend + σnoise.
Linköping University Laboratory of Organic Electronics

Discrete molecular GPR: Tanimoto kernel & built-in AD

Replacing Euclidean RBF with Tanimoto similarity on 2,048-bit Morgan fingerprints (AqSolDB)
Discrete molecular GPR: Tanimoto kernel & built-in AD
Tanimoto-kernel GPR turns Lecture 03's Applicability Domain check into a continuous uncertainty σ(x)—flagging C8-BTBT and rubrene automatically.
Linköping University Laboratory of Organic Electronics

The 4-step Bayesian Optimization loop

Balancing Exploitation (high predicted mean μ) and Exploration (high uncertainty σ)
1
Fit GP Surrogate on Current Dataset D = {(xi, yi)}
Predict posterior mean μ(x) and uncertainty σ(x) across all untested candidates.
2
Evaluate Acquisition Function α(x) = f(μ(x), σ(x))
Score every candidate by combining predicted performance (Exploitation) and uncertainty (Exploration).
3
Run Single Expensive Experiment at xnext = argmax α(x)
Synthesize the molecule, run the DFT calculation, or anneal the film at xnext to measure true ynext.
4
Update D ← D ∪ {(xnext, ynext)} and Repeat
Re-fit the GP with the new measurement and iterate until target performance or budget is reached.
BO never optimizes the expensive lab directly—it optimizes a cheap Acquisition Function α(x) over the GP surrogate to pick the next test.
Linköping University Laboratory of Organic Electronics

Three classic Acquisition Functions: Greedy, UCB, and EI

Translating (μ(x), σ(x)) into a single actionable decision score α(x)
Three classic Acquisition Functions: Greedy, UCB, and EI
Greedy (μ) gets trapped near existing peaks; UCB (μ + κσ) and Expected Improvement (EI) actively probe high-uncertainty regions for better optima.
Linköping University Laboratory of Organic Electronics

1D process optimization: escaping a local optimum in 6 steps

Expected Improvement (EI) probes the unexplored right-hand region and discovers the global peak
1D process optimization: escaping a local optimum in 6 steps
Starting with only 3 points near a local trap, EI automatically balances exploration and exploitation to lock onto the global optimum within 6 iterations.
Linköping University Laboratory of Organic Electronics

How UCB exploration weight κ controls the search

αUCB(x) = μ(x) + κσ(x) — tuning the risk appetite of your optimizer
How UCB exploration weight κ controls the search
Tiny κ (0.1) traps the search in a local optimum; huge κ (10) wastes budget space-filling; balanced κ ≈ 2.0 reliably finds the global peak.
Linköping University Laboratory of Organic Electronics

2D process window: annealing temperature T × concentration c

Starting from 4 random recipes, 10 BO steps map and lock onto the high-efficiency processing island
2D process window: annealing temperature <i>T</i> × concentration <i>c</i>
BO simultaneously maps the global trend (μ) and concentrates samples around the optimal 2D process window—using only 14 total experiments.
Linköping University Laboratory of Organic Electronics

Real-world synthesis: Buchwald–Hartwig coupling (N = 3,955)

Ahneman et al., Science 360, 186 (2018) — 15 aryl halides × 4 Pd ligands × 3 bases × 22 additives
Real-world synthesis: Buchwald–Hartwig coupling (<i>N</i> = 3,955)
Only a small fraction of the 3,955 reaction recipes achieve >95% yield—making brute-force screening prohibitively expensive.
Linköping University Laboratory of Organic Electronics

BO vs. Random Search: >95% yield in 25 experiments (<0.7% of space)

Starting from 5 random reactions + 20 sequential GP-BO steps (averaged across 5 random seeds)
BO vs. Random Search: >95% yield in 25 experiments (<0.7% of space)
Both EI and UCB find >95% yield recipes in ~25 total experiments—saving >99% of the experimental budget compared to exhaustive screening.
Linköping University Laboratory of Organic Electronics

From One-Hot IDs to chemistry: Morgan FP + PCA(30)

Bridging Lectures 01, 03, and 04: chemical descriptors let GPR generalize across unseen ligands & halides
From One-Hot IDs to chemistry: Morgan FP + <code>PCA(30)</code>
One-Hot encoding treats every ligand/additive as an isolated island; Morgan FP + PCA(30) transfers structure–reactivity knowledge across molecules.
Linköping University Laboratory of Organic Electronics

Engineering boundaries of BO & Batch BO for parallel labs

Knowing when standard GP-BO struggles—and how modern Self-Driving Labs scale to 24/96-well plates
LIMIT 1 · CURSE OF DIMENSIONALITY

Standard GP-BO Struggles Above d > 20

In high dimensions, Euclidean distances concentrate. Compress molecular fingerprints via PCA (or VAE latent spaces in Lecture 09) before fitting GPR.

LIMIT 2 · CUBIC SCALING O(N3)

Exact GPR Slows Down Past N > 2,000

Cholesky inversion scales as O(N3). For large datasets, switch to Deep Ensembles, MC-Dropout, or Random Forest variance surrogates.

LIMIT 3 · NON-STATIONARY CLIFFS

Activity Cliffs & Mixed Variables

Phase transitions or Activity Cliffs violate constant length-scale assumptions; use Matérn kernels, warped inputs, or tree-based BO (TPE/SMAC).

SOLUTION · PARALLEL WET LABS

Batch BO (q-EI / Kriging Believer)

Real synthesis runs 8, 24, or 96 wells in parallel! Batch BO selects a diverse batch of q experiments per round instead of 1 at a time.

Standard GP-BO excels for ≤20 dimensions and small budgets; high-D spaces need PCA/VAE compression, and parallel plates use Batch BO.
Linköping University Laboratory of Organic Electronics

Practical cheat-sheet: GP kernels & acquisition functions

Quick-reference guide for designing active experimental campaigns in materials & chemistry
Component Choice Key Behavior When to Use in Materials Science
Kernel RBF Infinitely differentiable (very smooth) Smooth thermodynamic / optical response surfaces
Kernel Matern(nu=1.5 / 2.5) Finite differentiability (realistic roughness) Default choice for real experimental process landscapes
Noise Term + WhiteKernel() Learns experimental noise floor σnoise Mandatory whenever measurements have lab/assay noise
Molecular Kernel Tanimoto Similarity on binary/count fingerprints Discrete molecular screening with built-in AD uncertainty
Acquisition EI / UCB EI: parameter-free; UCB: tunable κ EI as default; UCB when you want explicit exploration control
Default starting recipe: C() * Matern(nu=2.5) + WhiteKernel() with normalize_y=True and Expected Improvement (EI).
Linköping University Laboratory of Organic Electronics

Summary (Take home notes)

  • Predict distributions, not just points: Gaussian Process Regression outputs both μ(x) and uncertainty σ(x), turning data gaps into quantifiable confidence bands.
  • Encode physics in the kernel: Use Matérn/RBF for continuous process parameters, add WhiteKernel for noisy lab measurements, and use Tanimoto kernels for discrete molecular fingerprints.
  • Balance Exploitation & Exploration: Expected Improvement (EI) and UCB (μ + κσ) escape local optima where greedy optimization gets trapped.
  • Massive lab savings: On 3,955 Buchwald–Hartwig coupling reactions, GP-BO consistently reaches >95% yield in ~25 experiments (<0.7% of the search space).
  • Representations still rule: Pairing Morgan fingerprints + PCA(30) lets BO transfer reactivity knowledge across chemical structures rather than treating IDs as isolated islands.
Linköping University Laboratory of Organic Electronics

Thanks for your listening

Zesheng Liu  ·  zesheng.liu@liu.se
AI for Materials Science  ·  Lecture 04  |  Next: Hands-on Practice in 04c_exercises.ipynb
Linköping University Laboratory of Organic Electronics