2.6.14 · D3Model Evaluation & Selection

Worked examples — Bayesian hyperparameter optimization

3,013 words14 min readBack to topic

This page is the drill hall for Bayesian hyperparameter optimization. The parent note built the machinery: a Gaussian Process surrogate that gives us a mean and an uncertainty at every hyperparameter , plus an acquisition function that turns those two numbers into a single "how worth trying is this point?" score.

Here we do nothing new theoretically — we just hit every case the Expected Improvement (EI) and Upper Confidence Bound (UCB) formulas can throw at you, until no scenario surprises you.

Let us re-anchor the four symbols so nothing is assumed.

We will use the standard-normal reference values (memorise these three, they cover most hand calculations):

(Note is symmetric: , and .)


The scenario matrix

Every worked example below is tagged with the cell it covers. Together they fill the grid.

Cell What makes it special Which case of /
A. Exploit wins high mean, low uncertainty, large
B. Explore wins low mean but huge uncertainty , but big
C. The tie / crossover two points with nearly equal EI compare vs
D. Zero-uncertainty (degenerate) at an already-sampled point
E. Predicted-worse but positive EI yet EI ,
F. UCB vs EI disagree same two points, different acquisition tradeoff
G. Limiting behaviour and asymptotics of EI
H. The knife-edge predicted mean exactly equals the best ,
I. Real-world word problem log-scale learning rate, cost budget end-to-end loop
J. Exam twist minimisation problem disguised as maximisation sign flip of

Worked examples

Example 1 — Cell A: exploitation dominates

Forecast: the mean already beats the best by a comfortable and there's barely any doubt. Guess: EI is roughly the raw improvement , dominated by the first term.

  1. Compute . . Why this step? tells us the predicted improvement is uncertainty-steps above the current best — deep into "almost certainly better" territory.
  2. Look up normal values. , . Why this step? means ~99% of plausible outcomes beat ; the tiny says almost no probability sits at the threshold.
  3. Plug into EI. Why this step? Exploitation term swamps exploration term — exactly Cell A.

Verify: EI () is essentially the raw improvement , as forecast. Sanity: since is large positive, , which is what we got.


Example 2 — Cell B: exploration dominates

Forecast: the mean is below the best — pure exploitation would say "skip it". But is enormous. Guess: EI is still sizeable, maybe even competitive.

  1. Compute . . Why this step? Negative = we predict worse than best on average. But only uncertainty-steps below — the bell curve still pokes well above .
  2. Normal values. , . Why this step? says ~36% chance of beating despite the low mean; is near its peak, so exploration term will be large.
  3. Plug in. Why this step? The first (exploitation) term is negative — it penalises the low mean — but the exploration term from high rescues it.

Verify: , essentially tied with . So a confident +0.05 improvement and a wild guess with big uncertainty are worth almost the same — that is Bayesian optimization refusing to be greedy. Sanity: EI always (improvement can't be negative), and indeed . ✓


Example 3 — Cell C & the crossover figure

Forecast: since is already almost tied at , a slightly bigger uncertainty should tip it over.

  1. Restate the target line. From Example 1, has the fixed value . We treat this as a constant to beat. Why this step? So the reader need not flip back — the crossover is "when does the varying EI reach ?"
  2. Set EI as a function of . With fixed, , so Why this step? We freeze the mean and let only uncertainty grow — isolating the exploration effect.
  3. Read the crossover. Numerically, near ; the figure below shows rising through the flat line. Why this step? Locating the intersection gives the exact uncertainty at which the "explore" pull overtakes a confident improvement — the whole point of Cell C is to quantify that tipping point, not just assert it exists.

The red curve is the explore point's EI as its uncertainty grows; the dashed black line is the fixed exploit EI of . Where red rises above black, exploration wins.

Figure — Bayesian hyperparameter optimization

Verify: at we computed ; at , , , , giving . So the crossover lies between and — consistent with the red curve piercing the black line in the figure. ✓


Example 4 — Cell D: the degenerate zero-uncertainty point

Forecast: we already know the answer there — there's nothing to learn. Guess: EI .

  1. Find . For a noiseless GP, the posterior variance at an observed input is : . Why this step? The GP interpolates its own data exactly, so it has zero doubt where it has measured.
  2. Apply the definition. The EI formula's second branch is whenever . Why this step? If there's no uncertainty, there is no random upside to expect — improvement is fully determined (, so improvement is exactly ).

Verify: , and with there's no distribution to average over, so . This is why Bayesian optimization never re-samples an exact known point — a crucial safety property. ✓


Example 5 — Cell E: predicted-worse yet still worth trying (the parent's Example 1 finished properly)

Forecast: both means are below , so both — pure Cell E. The one with more uncertainty should score higher.

  1. Point : . . , . Why this step? Small uncertainty ⇒ small exploration reward; net EI is modest.
  2. Point : . . , . Why this step? Double the uncertainty ⇒ the exploration term dominates, lifting EI above point 1.

Verify: vs match the parent's and (tiny rounding). The higher-EI point is chosen — exactly the parent's conclusion that "exploration wins" even though . ✓


Example 6 — Cell F: UCB and EI can disagree

Recall — a linear mix, no bell-curve mathematics.

Forecast: UCB weights by a fixed ; the point has more , so it may win here too — but let's check whether the mean gap flips it.

  1. UCB at : . Why this step? UCB asks "optimistically, how high could this be?" — mean plus two std-devs.
  2. UCB at : . Why this step? Same optimism rule; the bigger inflates the ceiling more.
  3. Compare. ⇒ UCB also picks . Agreement with EI here. Why this step? The acquisition rule is "pick the highest score", so comparing the two UCB values is the decision — and with the extra uncertainty of outweighs its lower mean, matching EI's choice.

Now the twist — set (a cautious explorer):

  • UCB; UCB. Now wins — UCB flips!

Verify: EI is fixed and always preferred ; UCB's choice depends on . This is the key lesson of Cell F: the acquisition function is a design choice, and UCB's tradeoff is tunable and explicit where EI's is baked in. ✓


Example 7 — Cell G: limiting behaviour of EI

Forecast: with a positive mean gap, tiny uncertainty should give EI (we're sure it's better by 0.03); huge uncertainty should make EI grow without bound.

  1. As : , so , . Why this step? Perfect certainty of a improvement gives EI exactly — no randomness left.
  2. As : , , . Why this step? Infinite uncertainty ⇒ infinite upside potential; EI grows linearly in (slope ).

The red curve is EI against uncertainty for a fixed predicted advantage of ; the dotted line marks the left-hand floor , and the dashed line is the right-hand linear growth with slope .

Figure — Bayesian hyperparameter optimization

Verify: At : , , ; EI ✓. At : , EI — enormous, confirming the divergence. The red curve in the figure flattens to on the left and rises linearly on the right. ✓


Example 8 — Cell H: the knife-edge

Forecast: the exploitation term vanishes (mean gap is ), so only the exploration term survives. Guess: EI is small but strictly positive, driven entirely by uncertainty.

  1. Compute . . Why this step? At the knife-edge the predicted improvement is exactly zero uncertainty-steps — the bell curve is centred right on , so exactly half its mass lies above.
  2. Normal values at . , (the peak of the bell curve). Why this step? says "50% chance of beating the best"; is the maximum possible height, so the exploration term is as large as it can be for this .
  3. Plug into EI. Why this step? The first (exploitation) term is exactly — the mean gives no help at the knife-edge — leaving pure exploration . This gives the clean closed form whenever .

Verify: EI — even a point predicted to just tie the best is worth trying, because half its uncertainty band lies above . Sanity check the closed form: ✓, matching the full plug-in. ✓


Example 9 — Cell I: the real-world word problem (full loop)

Forecast: we did exactly these EI numbers in Example 5 — the edge point wins.

  1. Work in , not . Best so far . Why this step? Learning rates span five orders of magnitude; on a linear axis the RBF kernel's Euclidean distance would treat and as "almost equal", crushing the low end. Taking spaces them evenly so the kernel's smoothness assumption is meaningful — see 3.4.2-Gaussian-Processes.
  2. EI at : identical to Example 5 point . Why this step? Acquisition only ever needs ; the physical units of drop out.
  3. EI at : identical to Example 5 point . Why this step? Same formula, higher uncertainty — exploration lifts this candidate.
  4. Decide. Higher EI ⇒ train at , i.e. . Why this step? We spend our single expensive run where the model expects to learn the most.

Verify: ✓, matching the parent's that then scored (new best). Contrast with 2.6.11-Grid-Search/2.6.12-Random-Search, which would have spent that run blindly. ✓


Example 10 — Cell J: the exam twist (minimisation in disguise)

Forecast: we must flip the sign so "improvement" means "lower loss". Guess: define and everything else follows.

  1. Negate the objective. Let ; maximising = minimising loss. Why this step? Our EI formula rewards increasing ; feeding it makes it reward decreasing loss.
  2. Best in -space. Best observed loss , so . Candidate mean in -space , (unchanged — variance is sign-blind). Why this step? measures spread; negating a variable doesn't change its spread.
  3. Compute and EI. . , . Why this step? Standard EI in the negated space; the negative first term reflects the predicted loss being worse than the best.

Verify: EI : even though predicted loss is above the best , the uncertainty leaves room to beat it — a legitimate exploration candidate. If you had forgotten the sign flip you'd have maximised loss and chased the worst configs. Sanity: because the mean loss exceeds the best, exactly as expected. ✓


Recall

Every cell of the matrix, in one line each. When does EI reduce to the raw mean gap? ::: When with : (Cell G / Ex 1). Why is EI exactly at an already-sampled noiseless point? ::: there, and the formula's second branch sets (Cell D / Ex 4). Can a point with mean below still be chosen? ::: Yes — if its is large enough the exploration term outweighs the negative exploitation term (Cell B/E). What is EI at the knife-edge ? ::: Exactly — pure exploration, strictly positive (Cell H / Ex 8). How do EI and UCB differ in their explore/exploit control? ::: EI bakes the tradeoff into ; UCB exposes it as a tunable (Cell F). How do you use maximisation-EI for a minimisation objective? ::: Optimise ; then and is unchanged (Cell J).


Where to go next: the same surrogate-plus-acquisition loop, applied to whole network structures, is 2.6.15-Neural-Architecture-Search.