2.6.14 · D4Model Evaluation & Selection

Exercises — Bayesian hyperparameter optimization

2,301 words10 min readBack to topic

Before we start, one shared picture of the whole machine. Every exercise is a slice of this diagram.

Figure — Bayesian hyperparameter optimization

How to read Figure s01. The three coloured boxes are the three moving parts you will reason about below. The lavender box (left) is the surrogate; the coral box (middle) is the acquisition function; the mint box (right) is the expensive evaluation. The straight arrows show one pass left-to-right; the curved butter arrow at the bottom is the refit step that closes the loop. Level-1 Exercise 1.1 asks you to match names to these boxes; Level-4 Exercise 4.2 redraws this same loop as a flowchart. Keep this picture in mind — every exercise is a slice of it.

The three moving parts you will reason about:

  • the surrogate — a Gaussian Process that gives, at every candidate , a mean (best guess of performance) and a standard deviation (how unsure we are).
  • the acquisition function — a cheap score that turns into "how worth-it is this point?".
  • the loop — pick the argmax of , pay for one real evaluation, refit, repeat.

Level 1 — Recognition

Exercise 1.1

Match each name to its job: (a) surrogate model, (b) acquisition function, (c) . Jobs: (i) the current best observed score, (ii) approximates the expensive function with uncertainty, (iii) scores which point to try next.

Recall Solution

(a)→(ii), (b)→(iii), (c)→(i). These are exactly the three boxes of Figure s01: (a) is the lavender surrogate box, (b) is the coral acquisition box, (c) is the "bar to beat" that both refer to. The surrogate is the map, the acquisition function is the compass, and is the bar you're trying to clear.

Exercise 1.2

In the RBF kernel , where is the output-scale, the length-scale, and the Euclidean distance, what happens to when ? What does that value mean?

Recall Solution

When the Euclidean distance is , so the exponent is and . Thus . This is the variance of at a single point — the most a point can be correlated with is itself. The length-scale plays no role here (distance is ); it only controls how fast decays once .

Exercise 1.3

Bayesian optimization beats grid search mainly because it (choose one): (A) trains faster per model, (B) uses past evaluations to choose the next point, (C) needs no validation set.

Recall Solution

(B). Each real evaluation costs the same (a full training run), but Bayesian optimization spends those evaluations wisely by learning from every result. Compare 2.6.11-Grid-Search and 2.6.12-Random-Search, which choose points without looking at earlier outcomes.


Level 2 — Application

Exercise 2.1

Given , , current best . Compute .

Recall Solution

. Positive means the mean already sits above the bar — exploitation looks promising here.

Exercise 2.2

Using the same numbers (), compute Expected Improvement: Use and .

Recall Solution

First term: . Second term: . . Notice both terms are positive: exploitation () and exploration () contribute.

Exercise 2.3

Compute UCB at that point with : .

Recall Solution

. Why weight linearly by a constant ? A Gaussian posterior at has mean and spread . Moving standard deviations above the mean gives an optimistic high-quantile of the score: for a normal, is roughly the "best plausible value" at confidence set by (e.g. covers about the upper tail). Because the uncertainty of a Gaussian scales linearly with , the honest optimistic bound is plus a linear multiple of — that is the entire justification for the simple sum. UCB literally reads as "mean plus slices of the doubt."


Level 3 — Analysis

Exercise 3.1

Two candidate points after fitting the GP:

  • Point A:
  • Point B:

Current best . Which does EI prefer, and what does that reveal about exploration vs exploitation? Use values: for A, ; for B, .

Recall Solution

Point A: . . Point B: . . B wins (). Even though B's mean is below the current best, its large means it could still surprise us upward — EI values that gamble. This is exploration overruling exploitation.

How to read Figure s02. The lavender curve is the GP mean ; the shaded lavender band is the uncertainty (wide where we haven't sampled). The dashed slate line is the current best . Point A (coral dot) is a tall-mean, thin-band candidate; point B (mint square) is a lower-mean but tall-band candidate. The figure shows visually why B's band pokes far above the dashed line — that upside is exactly the EI gap you computed.

Figure — Bayesian hyperparameter optimization

Exercise 3.2

Explain, using the EI formula, what happens to EI as in both cases: (i) a point whose mean is below the best, and (ii) a point whose mean is above the best.

Recall Solution

Case (i): below-best mean (). The second term . And (numerator negative, denominator ), so , killing the first term too. Therefore : a known point that isn't better is worthless to re-sample. Case (ii): above-best mean (). Again . But now (numerator positive), so , and the first term . Therefore : a point we're certain about but that beats the bar is worth exactly its guaranteed improvement. This is the sensible limit — no uncertainty, so the improvement is just the deterministic gap. Together these two limits are why the piecewise definition sets at : zero in case (i), the plain gap in case (ii).


Level 4 — Synthesis

Exercise 4.1

You run 3 initial evaluations: , , . Then the GP proposes two candidates with:

  • Candidate P:
  • Candidate Q:

Using EI, decide which to evaluate next. Then state what changes in the GP after you evaluate it. (: for P ; for Q .)

Recall Solution

Current best . Candidate P: . . Candidate Q: . . Evaluate Q (): higher uncertainty makes the bigger bet worthwhile. After evaluating Q: the GP refits with the new point; collapses toward 0 near Q (we now know it), while the mean bends toward the observed . If , updates and the whole landscape re-scores.

Exercise 4.2

Write the Bayesian optimization loop in a Mermaid flowchart and label which step is "expensive."

Recall Solution
flowchart TD
  A["Init random points"] --> B["Fit GP get mu and sigma"]
  B --> C["Maximize acquisition alpha"]
  C --> D["Evaluate f at new point EXPENSIVE"]
  D --> E["Add point to data"]
  E --> F{"Budget left"}
  F -->|yes| B
  F -->|no| G["Return best lambda"]

Only step D pays a real training cost. Steps B and C are cheap math on the surrogate — that is exactly why we can afford to be clever about choosing D. This flowchart is Figure s01's loop drawn in boxes: B is the lavender surrogate, C the coral acquisition, D the mint evaluation, and the yes edge is the butter refit arrow.


Level 5 — Mastery

Exercise 5.1

A student claims: "UCB with large and EI early in the search behave similarly — both explore heavily." Argue for or against, using the formulas, and give the limiting behaviour of UCB as and .

Recall Solution

The claim is broadly correct, and here's the mechanism. . As , UCB : pure exploitation (pick highest predicted mean, ignore doubt). As , UCB is dominated by : pure exploration (pick the most uncertain point regardless of mean). EI's second term is its built-in exploration bonus; early on, is large everywhere (few points sampled), so EI naturally spreads out — matching large- UCB. As data accumulates and collapses, both methods drift toward exploitation. Verdict: similar tendency early; but UCB's balance is a fixed knob , whereas EI's balance is automatic and data-driven via and .

Exercise 5.2 (Capstone)

Derive why EI's first term uses and the second uses , starting from with . Then confirm numerically for .

Recall Solution

Setup. Let , so with . We want . Substitute , so and . The lower limit maps to . First integral — why . Recall . Differentiate it: . So is an antiderivative of — that's the whole justification. Evaluating: . Why . The bell curve depends on only through (the exponent is ), and . So is an even function: reflecting the input sign leaves the height unchanged. Hence . Times gives the uncertainty term. Second integral: . Using the same evenness of , the CDF satisfies , so . Times gives the improvement term. Summing: . ∎ Numeric check: , . — matching Exercise 2.2. The derivation and the formula agree.

Recall

Quick self-test before you leave: EI's exploration term ::: EI's exploitation term ::: UCB as ::: pure exploitation, picks max EI as with ::: tends to (the deterministic gap) Why refit the GP each loop ::: so shrinks where sampled and the acquisition updates