← Explainer Library

Interactive Explainer

Bayesian Optimization, Step by Step

A live 1-D Gaussian-process surrogate plus an acquisition function decides where to evaluate a hidden expensive function next. Click to acquire, watch the band shrink, and race four acquisition strategies on a convergence plot.

Prelude

The expensive-function problem

Tuning hyperparameters of a model that takes 8 hours to train. Picking the next concentration in a wet-lab experiment. Choosing where to deploy the next air-quality sensor. The function $f$ you're optimising is expensive, black-box, and possibly noisy. Random search burns a lot of calls; grid search burns even more. You want every evaluation to tell you the most.

The slogan. Fit a cheap surrogate to your observations; use it to predict with uncertainty; query the next point where the predicted-improvement is largest. Repeat.
Step 1

The two ingredients

Where $\Phi$ and $\phi$ are the standard normal CDF and PDF, and $z = (\mu(x) - f^* - \xi) / \sigma(x)$ for the current best $f^*$. UCB picks the upper-confidence bound; PI picks the probability of any improvement; EI picks the expected improvement (often the default).

Step 2

Run it

A hidden function (you'll see the true curve only after acquiring points). Press Acquire next to evaluate $f$ at $\arg\max a(x)$. The GP mean and 2σ band update; the acquisition function below reshapes; the convergence plot keeps score across all four acquisition strategies on the same hidden function.

queries = 3 best-so-far =
GP surrogate (μ ± 2σ) over hidden f
Acquisition function a(x)
Best-so-far convergence (4 strategies)
What to watch for. Early on, EI and UCB explore widely (the band is fat everywhere). After ~5 acquisitions they zoom into the best neighbourhood. PI gets stuck more often (it finds a near-optimum and stops exploring). Thompson sampling is a surprisingly strong baseline that's almost trivial to implement: draw a sample from the posterior and pick its arg-max.
Step 3

Why Bayesian optimisation, not grid search

Step 4

The traps in real BO

Step 5

Where Bayesian optimisation is the right tool

Final takeaway. Bayesian optimisation is the go-to whenever a single evaluation is expensive enough to make you think twice. It asks a simple question every step — "what's the most informative thing I could try next?" — and answers it using the same posterior machinery from the Bayesian playground article.
Step 6

Acquisition function deep dive

The four most-used acquisitions, with their closed forms and trade-offs:

Step 7

Batch and async BO

Real BO loops rarely evaluate one point at a time — you have $B$ parallel workers (GPUs, lab benches, simulator instances). Batch BO picks $B$ points per round.

Step 8

Reading list