Explanation of the Gaussian Process and Bayesian Optimization Simulator — What the Prediction Line, the Confidence Width, and Auto-Pick’s Choice Compute

This page explains, in the order words → formulas → calculation procedure, which quantities of Gaussian process regression and Bayesian optimization correspond to the “prediction line,” the “confidence width,” and the rule by which “Auto-pick” chooses the amount to measure next, as seen in the simulator, and by what formulas they are computed. The procedure for the detailed view, the conditions of the calculation, and questions for checking are also collected here.

1. About this page

The Gaussian Process and Bayesian Optimization Simulator is a device for watching how we predict, from measured points, “the values where we have not measured” and their uncertainty, and how we use that prediction to decide “where to measure next.” It covers Gaussian process regression in Chapter 12 (Gaussian Process Regression) and Bayesian optimization in Chapter 13 (Bayesian Optimization and Experimental Design). In both, the function studied is Data C, “Dopant Amount and Ionic Conductivity,” of Chapter 12 (synthetic data for teaching purposes).

The simulator has two views.

Scene A of the simple view performs the same computation as ① of the detailed view, and Scene B the same as ② and ③. We recommend reading in this order: try the simple view, check what it really shows in Section 2, read the formulas in Section 3, and operate the detailed view with the procedure in Section 4.

2. What the simple view really shows

The “prediction line” in the simple view is the predictive mean μ*(x) of Gaussian process regression, and the “confidence width” band is, at a dopant amount x not yet measured, the width of the predictive distribution for the true function value f(x) (the latent function), μ* ± 2σ* (about 95 %). σ* is the predictive standard deviation and expresses “how much we do not know” (Section 13.2 of the text). Where the band is narrow, the value is well known; where it is wide, the value is not yet well known. This is the same as the “latent-function band” of ① in the detailed view; the “observation band” (Section 12.6), which also includes the scatter of the observed value at the next measurement, is not drawn in the simple view.

The vertical axis, “Performance (pts),” is the value y of Data C (the logarithm of the ionic conductivity) converted into a score by the following linear formula.

performance (pts)=62.5×(y+5),y=log10(σion/S cm−1)

The global maximum of the true function, y = −3.4 (7.0 mol%), corresponds to 100 pts, y = −5.0 to 0 pts, and the local maximum y ≈ −4.0 (2.2 mol%) to 62.5 pts. Because the formula is linear, the shape of the band and the point chosen by the acquisition function do not change (the band width is read in points, multiplied by 62.5). The observed values carry noise (standard deviation 0.05, about 3 pts), so a measured performance can be slightly above 100 pts or slightly below 0 pts.

2.1 Scene A: Can we predict the performance where we have not measured?

Choose an amount of additive x, make a sample, and measure its performance y (“▶ Make a sample and measure” or a click on the figure). Each time you measure, Gaussian process regression is redone from all the observations so far, and the prediction line and band are redrawn. The edges of the band from before the button was pressed are left as faint dashed lines.

Table 1: Words on the screen in Scene A and the corresponding terms and symbols
Words on the screenTermSymbol or formula
Amount of additive (horizontal axis)Inputx (mol%)
Performance (vertical axis, pts)Target value (Data C)y (on screen, 62.5(y + 5) pts)
Measured performance (●)Observed valueyn = f(xn) + εn, εn ~ 𝒩(0, 0.052)
Prediction linePredictive meanμ*(x)
Confidence width (band), band width ±Latent-function band (about 95 %)μ* ± 2σ*
Where to measure ▼, Prediction at ▼Test input and the prediction therex*, μ*(x*) ± 2σ*(x*)
Where the band is widestInput with the largest predictive standard deviationargmax σ*(x) (on the grid of 201 points)
Smoothness of the prediction line (assumption)Length scale of the RBF kernelℓ
  Bumpy / Medium / Gentle ℓ = 0.3, 1, 10 mol%
Small curve on each choiceSample from the prior (one)f ~ 𝒢𝒫(0, k)
Hidden true curve (Check the answer)True function of Data Cy(x) = −5.0 + 1.0 exp[…] + 1.6 exp[…]

When the page opens, three places, 1.6, 5.2, and 8.2 mol%, have already been measured. Right on the measured places the band narrows, and about 2 mol% (twice ℓ) away from them the band returns to nearly its width with nothing measured (±2σf = ±1.6, or ±100 pts). At the initial position of ▼, 3.4 mol%, the prediction is 39 pts and the band width is ±96 pts.

Numbers for “Try it”:

Where the analogy fits and where it does not

Where it fits: the prediction line and band are computed with the same settings as the defaults of ① in the detailed view (RBF kernel, σf = 0.80, model noise σ = 0.050, the mean of the observed values ȳ as the mean function m) and with the same functions (gpFit and gpPredict in gp-bo.model.js). “Medium” is the default of ① in the detailed view, ℓ = 1.00 mol%. The measured performance is the true value of Data C plus noise with standard deviation 0.05.

Where it does not fit: the performance curve is synthetic data for teaching purposes, not the values of a real material. In real experiments on materials, the input usually has many dimensions, such as composition, temperature, and time, and the size of the noise is usually unknown. Also, the band is the width “if the assumptions, such as the smoothness of the prediction line (ℓ), are correct.” As in the “Gentle” example, if the assumption does not fit, the band is narrow but wrong. A method of choosing ℓ from the data (the log marginal likelihood) can be tried in ① of the detailed view.

2.2 Scene B: Can we find the best with only a few experiments?

With the same Data C, we search for the dopant amount with the highest performance in 20 experiments. “Auto-pick” is Bayesian optimization. From the observations so far, it makes the same prediction line and band as in Scene A, and next measures where the acquisition function EI (expected improvement) is largest. “Random pick” is random search, which chooses an amount from 0–10 mol% with a uniform random number. The first 3 tries have no clues, so both choose with uniform random numbers (initial points; since the random-number seeds differ, the 3 places differ between Auto-pick and Random pick). When the page opens, it draws the state after these first 3 tries (3 / 20 tries). Each press of “▶ Auto-pick the next experiment” advances both by one experiment. The first press is the 4th experiment, the first point that Auto-pick chooses from the prediction line and band.

Table 2: Words on the screen in Scene B and the corresponding terms and symbols
Words on the screenTermSymbol or formula
Auto-pickBayesian optimization (surrogate model: Gaussian process; acquisition function: EI)ξ = 0, ℓ = 1 mol% (“Medium”)
Random pickRandom searchx ~ uniform distribution [0, 10]
Experiments (/ 20 tries)Number of evaluations and budgetn, B = 20
First 3 tries (■)Initial points (uniform random; already done when the page opens)n0 = 3
Points chosen by Auto-pick (●)Point that maximizes the acquisition functionxn+1 = argmax EI(x)
Next here (▼)Next candidateargmax on the grid of 401 points (spacing 0.025 mol%)
Worth measuring (peaks in the lower strip)Acquisition function EIEI(x) (the height is drawn divided by the maximum; when the maximum is less than 0.01 pts, the screen says “almost 0 everywhere”)
Best (◆)Recommended point (the point with the largest observed value)x̂n
Gap from the true bestSimple regret (in pts)62.5 × rn, rn = ymax − y(x̂n)
Match resultComparison of the simple regret with the same budgetthe one with the smaller r20 at the 20th try wins
Rematch with a new startAdvance the repetition number r of ③ by oneseed assignment in Section 5.2

The match shown when the page opens is the same as repetition r = 2 among the default 200 repetitions of ③ in the detailed view (seed 20261114 for Bayesian optimization, seed 20361114 for random search). In ② of the detailed view, if you set the seed to 20261114 and keep pressing “Observe next point,” you get the same sequence as Auto-pick.

Numbers for “Try it”:

Where the analogy fits and where it does not

Where it fits: Auto-pick uses the same settings as the defaults of ② in the detailed view (maximization, EI, ξ = 0, fbest is the best observed value, 3 initial points, budget 20, ℓ = 1.00 mol%, σf = 0.80, σ = 0.050) and the same functions (boCreate, boStep, boModel). Random pick uses the same function as the random search of ③ (randomRun), and the match is judged by the same simple regret as in ③.

Where it does not fit: “Auto-pick” is not a mechanism that knows everything; it merely chooses the next amount by one fixed rule called EI. Besides EI there are other rules, such as UCB and PI, and the chosen point changes with the rule (② of the detailed view). Also, the “gap from the true best” and the “match result” can be computed only because we know the answer (the true function); in real experiments they are unknown. The win or loss of a single match changes with how it starts (the random numbers), so methods are compared by the distribution over many repetitions (③ of the detailed view).

3. How it works

3.1 Placing a distribution on functions — narrow near measured places, wide far from them

A Gaussian process places a probability distribution on the function f(x) itself. The distribution of functions is fixed by the property that, whatever finite set of inputs x1, …, xN is chosen, the set of function values there follows a multivariate Gaussian distribution (Section 12.1 of the text). The distribution is determined by the mean function m and the covariance function (kernel) k, and the kernel expresses “how similar the values at two inputs are.” With the RBF kernel, if the distance between two inputs is much shorter than the length scale ℓ, the values are almost the same, and if the inputs are several times ℓ apart, the values are unrelated (Section 12.2 of the text). The “Smoothness of the prediction line” in the simple view is the choice of this ℓ.

When there are observations, the predictive distribution at unmeasured places is obtained by applying the formula for the conditional distribution to the joint distribution with the observed values (Section 12.4 of the text). With only one observation (x1, y1), it becomes the following short formula (Section 13.3 of the text; σf2 is the signal variance and σ2 is the noise variance).

μ*=m+ρg(y1−m),σ*2=σf2(1−ρ2g)ρ=exp(−(x−x1)22ℓ2),g=σf2σf2+σ2

Near the observation point (ρ ≈ 1), the predictive mean is pulled toward the observed value y1 and the variance becomes small. Far away (ρ ≈ 0), the predictive mean returns to m and the standard deviation to σf. Even with more observations, this property, “pulled in and narrow nearby, back to the prior and wide far away,” does not change. This is why, in Scene A of the simple view, the band narrows at measured places and swells away from them. The predictive variance does not depend on the data values; it only decreases from the prior variance (summary in Section 12.13 of the text).

3.2 Formulas for the predictive distribution and the marginal likelihood

For the Gaussian process f ~ 𝒢𝒫(m, k), the covariance function is the RBF (Gaussian) kernel, with length scale ℓ and signal variance σf2. The mean function m is a constant.

k(x,x′)=σf2exp(−(x−x′)22ℓ2),yn=f(xn)+εn,εn∼𝒩(0,σ2)

From N observations y and Ky ≡ K + σ2I (K ∈ ℝN×N is the Gram matrix), at the test input x*, the latent function f* has the predictive distribution 𝒩(f* | μ*, σ*2), and the observation y* has the predictive variance

μ*=m+k*TKy−1(y−m1),σ*2=k(x*,x*)−k*TKy−1k*Var[y*]=σ*2+σ2lnp(y∣θ)=−12(y−m1)TKy−1(y−m1)⏟data fit−12ln|Ky|⏟complexity penalty−N2ln2π⏟constant

Here, k* = (k(x1, x*), …, k(xN, x*))T, θ = (ℓ, σf, σ). No matrix inverse is formed. The Cholesky decomposition Ky = LLT is computed only once, and forward and backward substitution give a = LT\(L\(y − m1)) and v = L\k*; then μ* = m + k*Ta, σ*2 = k(x*, x*) − vTv, and ln |Ky| = 2 Σi ln Lii (the same procedure as Algorithm 2.1 in the textbook by Rasmussen and Williams). If the decomposition fails, a small value (jitter) is added to the diagonal and the decomposition is retried; the amount added is shown on screen. If rounding makes σ*2 negative, it is clipped to 0 and the number clipped is shown.

3.3 Bayesian optimization — where the prediction is high, or where the band is wide

Bayesian optimization repeats the following: from the predictive mean μ*(x) and the predictive standard deviation σ*(x) given by the surrogate model (here a Gaussian process), it builds an acquisition function that turns “the value of measuring x next” into a single number, and next measures where that function is largest (Section 13.2 of the text). Measuring where the predictive mean is high is exploitation, and measuring where the band is wide is exploration (Section 13.3 of the text). EI combines both in one formula.

EI(x)=dΦ(z)⏟part from the height of the prediction+σ*𝒩(z∣0,1)⏟part from the band width,d=μ*−fbest−ξ,z=d/σ*

The first term is the part determined by the improvement d (how much the prediction exceeds fbest), and the second term is the part that grows as σ* grows (the wider the band). At the 4th try in Scene B of the simple view, 10.0 mol% was chosen even though its prediction is below fbest (d < 0), because the band there is wide; this is mainly due to the second term.

In Bayesian optimization (tabs ② and ③), taking the best observed value fbest as the reference, the acquisition function is evaluated on a grid of 401 points (spacing 0.025 mol%) and the best point is observed next. z = (μ* − fbest − ξ)/σ*, and Φ is the cumulative distribution function of the standard Gaussian distribution.

EI(x)=𝔼[max(f*−fbest−ξ,0)]=(μ*−fbest−ξ)Φ(z)+σ*𝒩(z∣0,1)σ*→0impliesEI→max(μ*−fbest−ξ,0)PI(x)=Φ(z),UCB(x)=μ*+κσ*

Sign conventions for maximization and minimization (switchable in tab ②; as the minimization example, we solve the same problem rewritten as the minimization of g(x) = −y(x)):

Maximization (default in the text)Minimization
fbestmaximum so farminimum so far
Improvementμ* − fbest − ξfbest − μ* − ξ
EI(improvement) Φ(z) + σ* 𝒩(z | 0, 1), z = improvement / σ* (in both cases the point with the maximum is chosen)
PIΦ(z) (the point with the maximum is chosen)
Confidence boundUCB = μ* + κσ* is maximizedLCB = μ* − κσ* is minimized

fbest can be switched between “the best observed value” and “the best posterior mean μ*(xn) over the observed points.” The simple regret is rn = ymax − y(x̂n), where x̂n is the point with the largest observed value up to evaluation n (the recommended point), y(x̂n) is the true function value at that point, and ymax = −3.400 (at x = 7.000 mol%) is the true maximum value.

3.4 Calculation procedure

  1. Decide the kernel hyperparameters (ℓ, σf, σ) and the mean function m (by default, the mean of the observed values ȳ).
  2. Form Ky = K + σ2I and perform the Cholesky decomposition Ky = LLT once (if it fails, add jitter and retry).
  3. At each grid point x*, obtain μ* and σ*2 by forward and backward substitution, and draw the prediction line and the band μ* ± 2σ* (the curves use 201 points).
  4. In Bayesian optimization, compute EI on the grid of 401 points and observe the point xn+1 where it is largest (the 3 initial points are uniform random). Add the observation, return to step 2, and repeat until the budget of B evaluations is used up.
  5. Take the recommended point to be the point x̂n with the largest observed value, and compute the simple regret rn with the true function. Random search is compared with the same budget and the same recommendation rule.

The simple view calls the same functions as the detailed view (gpFit, gpPredict, gpPredictOne, observeC, boCreate, boStep, boModel, randomRun, recommend, regretCurve, compareSeeds, sampleFunctions in gp-bo.model.js). The only computations added for the simple view are the conversion to points, the fraction of the curve sticking out of the band, the try on which a place within 0.5 mol% is first measured, the judging of the match, the check of whether “Worth measuring” is almost 0 (maximum less than 0.01 pts), and the small curves on the choices (gp-bo.easy.js).

4. How to use the detailed view

The detailed view has three tabs: “① Gaussian Process Regression,” “② Bayesian Optimization,” and “③ Comparison with Random Search.” Each has the figures and the “Putting the current numbers into the formula” box on the left, and the controls and readout on the right.

4.1 Procedure and what to observe

  1. In tab ①, press “Place the example 8 points.” What to look for: near the observation points, the latent-function band ±2σ* (filled) becomes narrow and widens between 6.4 and 8.2 mol%, where there are no observations. The observation band ±2√(σ*2 + σ2) (dashed) never becomes narrower than ±2σ = ±0.1, even right on an observation point.
  2. Read the values with the “Query point x*” left at its default 7.0 (where there is no observation point), then move it to 6.4, which is on an observation point (keep the example 8 points). What to look for: in “Putting the current numbers into the formula,” for σ*2 = σf2 − vTv, the subtracted term vTv increases from 0.556 at 7.0 to 0.638 at 6.4 and σ* decreases from 0.290 to 0.050. Return x* to 7.0, then set ℓ to 0.2. At x* = 7.0, vTv ≈ 0, so σ*2 returns to the prior variance σf2 = 0.64 and μ* returns to near the mean function m = −4.469 (−4.459) (far from the data, the prediction simply reverts to the mean function).
  3. Set the length scale ℓ to 0.2 and then to 5. What to look for: when ℓ is small, the mean drops back to m between observation points and the band balloons; when it is large, the two peaks cannot be represented and the fit is poor. In the lower figure, the data-fit term goes down as ℓ is increased, while the complexity-penalty term goes up (the penalty gets lighter).
  4. Press “Grid search: maximize ℓ” and “Grid search: maximize ℓ, σf, σ.” What to look for: the ℓ that maximizes the log marginal likelihood, and the values of the three terms there. With little data, the maximum is flat and the selected value cannot be trusted.
  5. Display “Samples from the prior” and “Samples from the posterior,” and vary ℓ. What to look for: how fine the waves of the prior samples are is determined by ℓ. Near the observation points the posterior samples pass close to the observed values; farther away they scatter like the prior samples.
  6. In tab ②, press “Observe next point” repeatedly (default: EI, ξ = 0, 3 initial points). What to look for: the acquisition function (lower figure) becomes large both “where the predictive mean is high” and “where the band is wide,” and the observations gather near the global maximum (about 7.0 mol%) rather than the local maximum (about 2.2 mol%). Also look at the history table and the simple regret.
  7. In tab ②, switch to “Minimize −y,” press “Restart,” and advance the same number of steps. What to look for: minimization uses LCB and an EI adapted to the sign convention, but since this merely flips the sign of the objective function, with the same seed the sequence of observed points matches that of maximization exactly.
  8. In tab ③, press “Run” (default: 200 repetitions, budget 20). Then press “BO loses (ℓ = 10 fixed, B = 30)” and run it. What to look for: the median and interquartile range (band) of the simple regret. By default, the median for Bayesian optimization is nearly an order of magnitude smaller than that for random search. If the length scale is fixed at 10 mol%, the median becomes larger than that of random search (BO loses).

With the keyboard, move to buttons and sliders with Tab, press with Enter (or Space), and move sliders with the arrow keys. Tabs can be switched with ←→. Clicking the figure in tab ① can also be done with “Dopant amount to observe x” and “Observe at this x” in the right-hand column.

5. Conditions of the calculation

5.1 Data and random-number conditions

5.2 Conditions fixed in the simple view

5.3 Simplifications

5.4 Conditions under which results become unstable

6. Questions for checking

Questions 1 and 2 can be answered with the simple view alone. Questions 3–6 use the detailed view.

  1. In Scene A of the simple view, after pressing “What if we measure at 8 places?”, how does the “confidence width” change when you move ▼ from 6.4 mol% to 7.0 mol%? Why?
    Sample answer

    It widens from ±6 pts to ±36 pts, about 6 times. 6.4 mol% is a measured place, so the prediction line is pulled toward the observed value there and the band narrows to about the size of the noise. 7.0 mol% lies in the gap between the measured 6.4 mol% and 8.2 mol%, 0.6 mol% and 1.2 mol% away from the observation points on both sides, so the information from the observations reaches it less and the band stays wide (Section 3.1).

  2. At the 4th try in Scene B of the simple view, why did Auto-pick choose 10.0 mol%, where the prediction is low? How is it different from Random pick?
    Sample answer

    10.0 mol% is a place not yet measured, where the band is as wide as the prior and the real value might be higher. EI becomes large not only where the prediction is high but also where the band is wide (the second term in Section 3.3). Random pick chooses amounts without using the prediction or the band, so it may measure the same place many times or measure places already known to be low. Once Auto-pick has checked a wide-band place and found a high peak, it then concentrates on places where the prediction is high.

  1. In tab ①, after pressing “Place the example 8 points” (default seed), at x* = 7.0 mol%, what are σ* and √(σ*2 + σ2)? What about exactly on an observation point (x* = 6.4)? Why does the observation band never become narrower than ±2σ?
    Sample answer

    With the defaults (ℓ = 1.00 mol%, σf = 0.80, σ = 0.050, m = ȳ = −4.469), at x* = 7.0 we get σ* = 0.290 and √(σ*2 + σ2) = 0.294, so the two bands have almost the same width (the point is far from the observation points, σ* ≫ σ). On an observation point, x* = 6.4, σ* narrows to 0.0499, but √(σ*2 + σ2) = 0.0706. The variance of the next observed value is σ*2 + σ2 ≥ σ2, so no matter how accurately f is known, the part due to observation noise cannot be predicted.

  2. What does the formula for EI become when σ* → 0? Why is EI almost 0 on an observation point?
    Sample answer

    z = (μ* − fbest − ξ)/σ* goes to +∞ if the improvement is positive and to −∞ if it is negative, so Φ(z) → 1 or 0, 𝒩(z | 0, 1) → 0, and EI → max(μ* − fbest − ξ, 0) (the improvement of a value known with certainty). On an observation point, σ* is small and μ* is near the observed value at that point, which is at most fbest, so almost no expected improvement remains.

  3. In tab ②, if you run maximization and minimization (minimizing −y) with the same seed and the same number of steps, what happens to the sequence of observation points? Why?
    Sample answer

    They match exactly. Flipping the sign of the objective function flips the sign of the posterior mean (μ* is linear in y) and leaves the posterior variance unchanged. fbest also flips sign, so the improvement in minimization fbest − μ* − ξ has the same value as the improvement in maximization; EI and PI take the same values, and LCB is UCB with the sign flipped.

  4. With the defaults of tab ③ (budget 20, 200 repetitions), what are the medians of the simple regret at evaluation 20 for Bayesian optimization and for random search? What happens in “BO loses”? Why does it lose?
    Sample answer

    With seed 20261112 and 200 repetitions, the median [interquartile range] of the simple regret at evaluation 20 is 0.0037 [0.00041, 0.010] for Bayesian optimization and 0.031 [0.0053, 0.088] for random search (0.041 for the equally spaced grid). Comparing paired repetitions, Bayesian optimization was smaller in 81.5 % of them, so it does not always win. In “BO loses” (ℓ = 10 mol% fixed, budget 30), the medians are 0.049 [0.012, 0.13] for Bayesian optimization and 0.019 [0.0032, 0.054] for random search, so Bayesian optimization loses (the fraction of repetitions in which Bayesian optimization was smaller is 36.5 %). If ℓ is too long compared with the peak widths (0.7 mol% and 1.1 mol%), the surrogate model is too smooth to represent the peak positions correctly and, moreover, underestimates σ*, so it measures only near the wrong place and stops exploring. If the surrogate model is wrong, the search is wrong too (in tab ①, when ℓ = 5 is applied to the example 8 points, the log marginal likelihood is −230, far smaller than −6.5 for ℓ = 1, which shows that the data do not support this ℓ).

7. Corresponding sections of the text and references

References (from the end of Chapters 12 and 13):

Back to the Gaussian Process and Bayesian Optimization Simulator | Machine Learning — From Probability to GPT (Contents) | Equations are typeset with the browser’s built-in MathML (no external library).