Bayesian Optimization
Part III: Bayesian Optimization
中文

The Bayesian Optimization Loop

Section 1.3 named the two ingredients of Bayesian optimization: a model of the objective that knows what it does not know, and a rule that turns that knowledge into the next experiment. Part II built the first ingredient. A Gaussian process, conditioned on the evaluations made so far, gives a posterior mean that says what the function probably looks like and a posterior standard deviation that says how unsure the model is at every input (Chapter 8). This chapter puts that model inside a loop.

The loop itself is short enough to fit on an index card: fit the model, pick the input where one more evaluation looks most worthwhile, evaluate it, add the result to the data, and repeat. Most of the ideas in the rest of the book are refinements of one of those four steps. What makes the loop interesting is the second step, because "most worthwhile" has no single right answer. An input can be worth evaluating because the model expects a high value there, or because the model knows little about it and a high value might be hiding there. Every rule for choosing the next input strikes some balance between those two reasons, and this chapter lets you feel what happens when the balance is wrong in either direction.

We start by stating the problem precisely, then write the loop as an algorithm and watch it run on the book's running example. The middle of the chapter is about the trade-off between exploring and exploiting. It ends with two practical questions, how to choose the first few points before the model has anything to go on, and where the method came from. Chapter 12 then derives the rules for choosing the next input one by one.

11.1 The problem #

Let ff be a function from an input domain X\X to the real numbers. We want an input where ff is largest:

x⋆∈arg max⁡x∈Xf(x).\vx^\star \in \argmax_{\vx \in \X} f(\vx).
(11.1)

Written this way, the problem looks like any other optimization problem. What sets Bayesian optimization apart are the conditions under which it is meant to work, which Frazier (2018) lists explicitly.

  • Each evaluation is expensive. Evaluating ff at one input takes minutes or hours, costs money, or asks something of a person. The number of evaluations is limited, typically to at most a few hundred. We call the allowed number the budget and write it NN.
  • The function is a black box. We can evaluate ff wherever we like, but we have no formula for it and no known structure such as convexity or linearity that a specialized method could exploit.
  • There are no derivatives. An evaluation returns a value and nothing else, so gradient descent and its relatives are unavailable.
  • The domain is simple and not too large. Usually X\X is a box, a range for each of dd inputs, which we rescale to [0,1]d[0, 1]^d. Most successful applications have d≤20d \le 20 (Frazier, 2018); Section 14.6 discusses what changes beyond that.
  • The function is reasonably smooth. Nearby inputs tend to give similar values. This is the assumption the Gaussian process prior encodes, and without it no finite number of evaluations would say anything about the inputs between them.

Two published problems show what these conditions look like in practice. Snoek et al. (2012) tuned nine hyperparameters of a convolutional neural network for image classification, among them the learning rate, the number of training epochs, and four weight penalties. Each evaluation was a full training run, and the best setting found reached a test error of 14.98% on the CIFAR-10 benchmark, against 18% for the setting a human expert had tuned. Shields et al. (2021) optimized chemical reactions, where each evaluation is an experiment in the laboratory. In a benchmark run as an online game against expert chemists and engineers, the optimizer needed fewer experiments on average, and its results depended less on the data it started from. Chapter 22 and Chapter 23 work through problems of these two kinds end to end.

Evaluations may also be noisy. Training a neural network twice with different random seeds gives two different accuracies; a person rating the same coffee twice gives two different scores. We then observe y=f(x)+εy = f(\vx) + \varepsilon with noise ε\varepsilon, the model of Section 8.3, and the task is still to maximize ff, not the noisy yy.

Because the budget is finite, the method does not have to find x⋆\vx^\star exactly. After NN evaluations it must return a single recommendation x^N\hat\vx_N, and it is judged by how close f(x^N)f(\hat\vx_N) comes to the best achievable value f⋆=f(x⋆)f^\star = f(\vx^\star). The gap f⋆−f(x^N)f^\star - f(\hat\vx_N) is called the simple regret; Section 13.1 defines it and its relatives carefully. Here it is enough that the gap is what we want small, and that evaluations which teach us a lot but score badly are not wasted if they lead to a better recommendation.

The figures in this part of the book use one running objective on [0,1][0, 1], drawn as a dashed aqua curve. It has a broad bump near x=0.23x = 0.23 that reaches about 0.530.53 and a narrower, taller bump near x=0.73x = 0.73 that reaches 0.820.82, on a gently falling, slightly wavy baseline. The shape is chosen to be a trap: a search that finds the broad bump first can easily settle there and never discover the taller one. The figures can show the dashed curve because they know the formula. The loop never sees it. It sees only the values at the inputs it chooses to evaluate.

Sources cited in Section 11.1 3
  1. Frazier (2018) A Tutorial on Bayesian Optimization
  2. Snoek et al. (2012) Practical Bayesian Optimization of Machine Learning Algorithms
  3. Shields et al. (2021) Bayesian reaction optimization as a tool for chemical synthesis

11.2 The loop #

The central idea of Bayesian optimization is to trade one hard problem for a sequence of easy ones. Maximizing ff directly is hard because every evaluation is expensive. Instead, at each step, the method builds a cheap function from the model and maximizes that. The cheap function scores every candidate input by how useful it would be to evaluate ff there next. Finding its maximum may take thousands of evaluations, but each costs microseconds, not hours.

Write Dn={(x1,y1),…,(xn,yn)}\D_n = \{(\vx_1, y_1), \dots, (\vx_n, y_n)\} for the data after nn evaluations, and μn(x)\mu_n(\vx) and σn(x)\sigma_n(\vx) for the posterior mean and standard deviation of f(x)f(\vx) given Dn\D_n, computed with Equation (8.6). Here the subscript nn counts evaluations, and σn(x)\sigma_n(\vx) is always written with its argument. It is not the noise standard deviation σn\sigma_n of Section 8.3, which has no argument and whose subscript stands for noise.

Definition 11.1 Acquisition function

An acquisition function is a function an:X→Ra_n : \X \to \R, computed from the posterior given Dn\D_n, that scores how useful it would be to evaluate ff at each input next. The loop evaluates ff where the acquisition function is largest:

xn+1∈arg max⁡x∈Xan(x).\vx_{n+1} \in \argmax_{\vx \in \X} a_n(\vx).
(11.2)

Most acquisition functions depend on x\vx only through μn(x)\mu_n(\vx) and σn(x)\sigma_n(\vx), sometimes with the best value observed so far, so they can be evaluated anywhere at the cost of one posterior prediction. With the two ingredients in place, the whole method is one loop.

Algorithm 11.1 Bayesian optimization

Input: domain X\X, budget NN, a Gaussian process prior (kernel and mean), an acquisition function aa, an initial design size n0<Nn_0 < N.

  1. Initial design. Choose x1,…,xn0\vx_1, \dots, \vx_{n_0} without the model (Section 11.4), evaluate ff at each, and collect Dn0\D_{n_0}.
  2. For n=n0,n0+1,…,N−1n = n_0, n_0 + 1, \dots, N - 1:
    1. Fit. Condition the Gaussian process on Dn\D_n to get μn(x)\mu_n(\vx) and σn(x)\sigma_n(\vx), refitting the kernel's hyperparameters if desired (Section 9.4).
    2. Decide. Find xn+1∈arg max⁡xan(x)\vx_{n+1} \in \argmax_{\vx} a_n(\vx) with an ordinary numerical optimizer (Section 12.9).
    3. Query. Evaluate the objective at xn+1\vx_{n+1}.
    4. Answer. Receive yn+1=f(xn+1)+εn+1y_{n+1} = f(\vx_{n+1}) + \varepsilon_{n+1}.
    5. Update. Set Dn+1=Dn∪{(xn+1,yn+1)}\D_{n+1} = \D_n \cup \{(\vx_{n+1}, y_{n+1})\}.
  3. Return a recommendation x^N\hat\vx_N (Section 11.2.3).

This is the structure of Algorithm 1 of Frazier (2018) and Algorithm 1.1 of Garnett (2023).

The algorithm separates query, answer, and update into three steps even though here they are one function call. Keeping them apart pays off later. In preferential Bayesian optimization (PBO, Chapter 19) the query becomes a pair of inputs shown to a person, the answer becomes a single bit saying which one they preferred, and the update can no longer use the closed-form Gaussian process formulas, because a comparison is not a noisy value (Chapter 18). The loop around those steps stays the same.

The three kinds of work inside the loop have very different costs, and the design of the method follows from that. Evaluating ff is the expensive step, which is the reason for everything else. Fitting the model costs O(n3)O(n^3) for the Cholesky factorization (Section 8.4), which for the few hundred observations of a typical run takes well under a second. Maximizing the acquisition function needs many evaluations of μn(x)\mu_n(\vx) and σn(x)\sigma_n(\vx), each costing O(n2)O(n^2) after the factorization. All of this computation is negligible next to an evaluation that takes an hour, so it is worth spending a great deal of arithmetic to choose each evaluation well.

11.2.1 A first acquisition function #

To run the loop we need one concrete acquisition function. Chapter 12 derives the standard ones; here a single, transparent rule is enough. Score each input by an optimistic estimate of its value, the posterior mean plus a multiple of the posterior standard deviation:

an(x)=μn(x)+β1/2 σn(x),a_n(\vx) = \mu_n(\vx) + \beta^{1/2}\, \sigma_n(\vx),
(11.3)

where β≥0\beta \ge 0 is a constant we choose. With β1/2=2\beta^{1/2} = 2, the score is close to the top edge of the 95% credible band that the figures draw (the band extends 1.961.96 standard deviations above the mean), so the rule picks the input whose plausible best case is highest. The rule is called the upper confidence bound, UCB for short, and Section 12.4 returns to it, including the theory that tells how β\beta should grow over time.

The two terms of Equation (11.3) pull in different directions, which is the subject of Section 11.3. The mean term favors inputs the model already believes are good. The standard deviation term favors inputs the model knows little about. The weight β1/2\beta^{1/2} sets the exchange rate between them: how many units of expected value one unit of uncertainty is worth.

11.2.2 The loop on the running example #

Figure 11.1 runs Algorithm 11.1 on the running objective with Equation (11.3) and β1/2=2\beta^{1/2} = 2. The run starts from two random inputs. One of them happens to land on top of the broad bump, at x≈0.23x \approx 0.23, so the loop starts in exactly the trap the objective was designed to set.

hidden objectiveposterior mean95% bandnext query−1.0−0.50.00.51.01.5f(x)best so far 0.53, true max 0.82010.00.20.40.60.81.0input xacquisition: UCB
hidden objectiveposterior mean95% bandnext query−1.0−0.50.00.51.01.5f(x)best so far 0.53, true max 0.82010.00.20.40.60.81.0input xacquisition: UCB
Figure 11.1 Bayesian optimization on the running objective. Each step of the timeline is one iteration of Algorithm 11.1. Top: the hidden objective (dashed), the posterior mean and 95% band given the evaluations so far (dots, the newest ringed), and the next query (orange line). Bottom: the acquisition function and its maximum. The figure opens on the upper confidence bound of Equation (11.3); its UCB weight √β slider sets the multiplier of the standard deviation, β1/2\beta^{1/2}. The other choices are derived in Chapter 12. The kernel and its lengthscale are fixed, not fitted, so the pictures stay comparable.

Stepping through the timeline shows the pattern most runs follow.

The first queries go where the band is widest. With only two observations the standard deviation term dominates Equation (11.3) almost everywhere, so the loop spends its first steps on inputs far from both observations, including the two ends of the domain. These evaluations are not wasted. Each one collapses the band near it and rules out a region.

Optimism finds the tall bump. Around the fifth or sixth step, the remaining wide part of the band sits over the tall bump, and an evaluation there returns a value well above anything seen so far. The mean jumps up, and from then on the mean term pulls the queries back to that region.

The end of the run refines. Once the band is narrow everywhere except near the best region, the queries cluster around x≈0.72x \approx 0.72, the best value found approaches the true maximum, and the acquisition function becomes a narrow spike.

Try another rule and another start. Switch the acquisition to EI (expected improvement), PI (probability of improvement), or Thompson sampling, three rules derived in Chapter 12, and press New run for different initial points. The details change; the pattern of broad search followed by refinement does not. Switch back to UCB, set the UCB weight √β slider to 0, and the loop never leaves the broad bump.

The same loop in three dimensions. Nothing in Algorithm 11.1 depends on the input being a single number. The figure below runs it on the Hartmann function, a standard three-dimensional test problem with one global maximum and a few local ones. A curve can no longer show the posterior, so the figure shows the evaluated points inside the unit cube (drag it to rotate) and three slices of the model through the best point found so far, one along each input.

x₁x₂x₃25 evaluations · best 3.76 at (0.33, 0.51, 0.85)024slice along x1024slice along x2024slice along x30.00.20.40.60.81.0510152025evaluations024true max 3.86best value found
x₁x₂x₃25 evaluations · best 3.76 at (0.33, 0.51, 0.85)024slice along x1024slice along x2024slice along x30.00.20.40.60.81.0510152025evaluations024true max 3.86best value found
Figure 11.2 The loop on the three-dimensional Hartmann function: 5 initial points, then expected improvement, 25 evaluations in all. Left: evaluated points in the unit cube, larger and more opaque for higher values, with drop lines to the floor for depth; the newest point is ringed, the best is orange, and the star is the true maximizer. Right: slices of the model through the best point, one per input, with the posterior mean and 95% band (blue) and the true function along the same line (dashed). Below: the best value found. Step through the run, rotate the cube, and press New run for other initial designs.

Two things are worth looking for. Early points spread through the cube, and later ones cluster, the same broad-then-narrow pattern as in one dimension. And the default run stalls for most of its budget: from the ninth evaluation to the twenty-third, the best point is (0.83,0.56,0.87)(0.83, 0.56, 0.87), with value 3.59 against a maximum of 3.86. Step back to evaluation 23, and the slice along x1x_1 shows the true function climbing toward x1≈0.1x_1 \approx 0.1, exactly where the model's band is still wide. Evaluation 24 goes that way and reaches 3.76 at (0.33,0.51,0.85)(0.33, 0.51, 0.85), still short of the maximizer at x1=0.11x_1 = 0.11. A longer budget, a different start, or a more exploratory rule finds the global maximum; a slice is often the quickest way to see that a run has not.

11.2.3 What the loop returns #

When the budget runs out, the loop must name one input. Two choices are common: the evaluated input with the best observed value, or the input with the highest posterior mean (Frazier, 2018). When evaluations are exact, the first is safe: its value has been measured and is not in doubt.

With noisy evaluations the best observed value is a biased guide. Among many noisy measurements, the largest tends to be one whose noise happened to be positive, so the input that produced it is probably not as good as its measurement suggests. Recommending the input with the highest posterior mean, either among the evaluated inputs or over the whole domain, uses all the evaluations near an input instead of a single lucky one. Section 14.2 returns to this choice, and Section 12.6 shows that it changes which acquisition function is the principled one.

In code NumPy
import numpy as np
# rbf() and gp_posterior() from the Gaussian process chapter

def f(x):  # the running objective; pretend each call takes an hour
    return (0.62 * np.exp(-(x - 0.25) ** 2 / (2 * 0.1**2))
            + np.exp(-(x - 0.73) ** 2 / (2 * 0.055**2))
            + 0.1 * np.sin(11 * x + 0.6) - 0.35 * x)

rng = np.random.default_rng(0)
grid = np.linspace(0, 1, 501)      # candidates for the inner search
X = rng.uniform(0, 1, size=2)      # initial design
Y = f(X)
for n in range(10):
    m = Y.mean()                   # constant prior mean
    mean, var = gp_posterior(X, Y - m, grid, ell=0.08)
    sd = np.sqrt(np.maximum(var, 0.0))
    acq = mean + m + 2.0 * sd      # mean + sqrt(beta) * sd
    x_next = grid[np.argmax(acq)]  # decide
    X = np.append(X, x_next)       # query ...
    Y = np.append(Y, f(x_next))    # ... answer, and update

print("recommend x =", X[np.argmax(Y)], "with f =", Y.max())

The function gp_posterior is the one from Section 8.4. Maximizing over a grid works in one dimension; Section 12.9 explains what replaces it in more. With this seed the loop finds the tall bump on its ninth query and recommends x=0.72x = 0.72, where f≈0.81f \approx 0.81. Appendix C extends this sketch to expected improvement.

Sources cited in Section 11.2 2
  1. Frazier (2018) A Tutorial on Bayesian Optimization
  2. Garnett (2023) Bayesian Optimization

11.3 Exploration and exploitation #

Every acquisition function must answer the question from the opening of the chapter: is an input worth evaluating because the model expects a high value there, or because the model does not know? The two answers have names. Exploitation means evaluating where the posterior mean is high, to refine what already looks good. Exploration means evaluating where the posterior standard deviation is high, to learn about regions the model knows little about. The terms come from the study of bandit problems (Section 13.2), where a gambler must choose between the slot machine that has paid best so far and one that has been tried too rarely to judge.

Neither pure strategy works, and the running objective shows why.

Pure exploitation gets stuck. Set β=0\beta = 0 in Equation (11.3), so the loop always evaluates where the posterior mean is highest. Suppose the first evaluations land on the broad bump. The mean is then highest near the best of them, so the next evaluation lands nearby, confirms that the region is good, and raises the mean there further. The loop climbs the broad bump, reaches its top at about 0.530.53, and stays. Nothing in its rule ever sends it to the right half of the domain, where the mean is lower only because nothing has been observed there. With exact observations it can even evaluate the same input again and again, learning nothing each time (Exercise 11.2).

Pure exploration never settles. Make β\beta very large, so the standard deviation term dominates. The loop then evaluates wherever the model is most uncertain, which on an interval means filling the largest gap between previous evaluations. The result is close to a grid built one point at a time. It eventually lands near the tall bump, but it gives the region no more attention than the poor region at the right end, so the best value it finds is limited by how fine its grid has become when the budget runs out.

Pure exploration also scales badly with dimension. Suppose one evaluation makes the model confident within a distance of 0.20.2 of it, roughly one lengthscale. A ball of radius 0.20.2 covers 40% of the unit interval, 13% of the unit square, and 3.4% of the unit cube, but only 0.033% of the six-dimensional unit cube. Covering six dimensions this way would take at least 3,000 evaluations, and covering the nine dimensions of the network tuned by Snoek et al. (2012) at least 590,000. The true numbers are larger, since the balls overlap and stick out of the cube. No budget allows this. In more than a few dimensions, exploration has to be selective: it can only afford to reduce uncertainty where a high value is still plausible.

Between these extremes lies a range of weights that do well. How wide is that range, and how badly do the extremes fail? Figure 11.3 answers by running the loop many times.

hidden objectivefinal posterior meanchosen by the rule95% bandone run, weight √β = 0.00: best 0.53, true max 0.82−1.0−0.50.00.51.01.5f(x)0.00.20.40.60.81.0input xbest value so far, this run−0.50.00.51.014681012evaluationinitial designtrue maxaverage gap after 12 evaluations, 32 starts0.000.050.100.150.2002468exploration weight √β12 of 32 starts within 0.05 of the max
hidden objectivefinal posterior meanchosen by the rule95% bandone run, weight √β = 0.00: best 0.53, true max 0.82−1.0−0.50.00.51.01.5f(x)0.00.20.40.60.81.0input xbest value so far, this run−0.50.00.51.014812evaluationinitial designtrue maxaverage gap after 12 evaluations, 32 starts0.000.050.100.150.2002468exploration weight √β12 of 32 starts within 0.05 of the max
Figure 11.3 The exploration weight β1/2\beta^{1/2} of Equation (11.3), set by the slider. Top: one run of twelve evaluations (two random initial points, hollow, then ten chosen by the rule) and the posterior at the end; the best value found is ringed. Lower left: the best value found after each evaluation in that run. Lower right: the same experiment repeated from 32 random initial designs for each weight from 0 to 8, showing the average gap between the true maximum and the best value found; the orange marker is the current weight. The figure opens on the greedy rule, β=0\beta = 0. The objective, kernel, and budget are illustrative; the shape of the curve, not its numbers, is the point.

Four experiments with the figure make the trade-off concrete.

Start greedy. At weight 0 the run in the top panel climbs the broad bump and stops at 0.530.53. Over the 32 starts, only 12 come within 0.050.05 of the maximum; the others never leave the bump they started on, and the average gap is 0.180.18.

Add a little optimism. At weights between 1 and 2, all 32 starts come within 0.050.05 of the maximum and the average gap is at most 0.0030.003. Even weight 0.50.5 helps a lot: 24 of 32 starts succeed.

Overdo it. At weight 8 the top panel shows evaluations spread almost evenly across the domain, and the run's best value is 0.620.62. Over the 32 starts the average gap rises to about 0.070.07. The explorer does find the tall bump's neighborhood, but with its budget spent everywhere, it rarely has an evaluation close to the peak itself.

Change the start. Press Another start a few times. For some initial designs even the greedy rule succeeds, because one of the two random points happens to land on the tall bump's slope. Luck in the initial design can make any rule look good on a single run, which is why comparisons of optimizers average over many runs (Section 31.4).

The lower right panel has the shape that recurs throughout the subject: a valley between two failure modes. On this problem the valley is wide, so the weight need not be tuned finely, but the extremes cost a great deal. The location of the valley depends on the budget. Exploration pays only if there are evaluations left to exploit what it finds, so a short budget favors a smaller weight and a long one tolerates a larger weight (inference).

Key idea An acquisition function prices uncertainty

Every acquisition function trades expected value against uncertainty. UCB does it with an explicit exchange rate β1/2\beta^{1/2}; the rules of Chapter 12 derive the rate from a model of what an evaluation is for.

The weighted sum in Equation (11.3) already does something a fixed schedule cannot. A schedule such as "explore at random for the first half of the budget, then exploit" spends its exploration everywhere, including regions the model already knows to be poor. The upper confidence bound explores only where uncertainty and a plausible high value coincide: an input whose mean plus two standard deviations is still below the best value seen is never chosen, however uncertain it is. Not all uncertainty is worth reducing, only the uncertainty that could change which input we end up recommending. That observation is the starting point of the more principled acquisition functions in Chapter 12, which ask directly how much an evaluation is expected to improve the outcome.

Sources cited in Section 11.3 1
  1. Snoek et al. (2012) Practical Bayesian Optimization of Machine Learning Algorithms

11.4 Starting the loop #

The loop needs data before its model can say anything useful, and there are two reasons not to let the acquisition function choose the very first points (Garnett, 2023, sec. 9.3).

The first reason is that the acquisition function has nothing to go on. Before any data, a Gaussian process with a constant prior mean and a stationary kernel, one whose covariance depends only on the distance between inputs, gives the same mean and the same standard deviation at every input. Every acquisition function built from them is then constant, and its maximum is anywhere (Exercise 11.1).

The second reason is the model's hyperparameters. The lengthscale, the signal amplitude, and the noise level are usually fitted to the data (Section 9.4), and two or three points cannot pin them down. A badly fitted lengthscale makes the model either overconfident between points or uninformative everywhere, and the early decisions made with it can send the search in the wrong direction. A handful of points chosen without the model gives the fit something to work with.

So the loop begins with an initial design of n0n_0 points chosen by a rule that ignores the objective. The goal is coverage: the points should spread over the domain so that no large region is left unexamined. There are four common ways to place them.

A grid takes kk values of each input and evaluates every combination, so kdk^d points in dd dimensions. Grids are easy to describe and wasteful in a specific way: they use only kk distinct values of each input. When the objective turns out to depend mainly on one input, which is common, the grid has spent kdk^d evaluations to learn about kk values of that input. The count itself grows quickly: in six dimensions, a grid with only three values per input needs 36=7293^6 = 729 evaluations, and in the nine dimensions of the network tuned by Snoek et al. (2012) it needs 39=19,6833^9 = 19{,}683. Bergstra and Bengio (2012) found that for most of the data sets they studied, only a few of a learning algorithm's hyperparameters really mattered, and that different ones mattered on different data sets, which makes grids a poor default.

Uniform random sampling gives every point a distinct value of every input, and needs no planning. Its weakness is clumping. Some points land close together and leave gaps elsewhere. Cut one input's range into nn equal bins, and nn random points leave on average a fraction (1−1/n)n(1 - 1/n)^n of the bins empty, about 37% for large nn.

A Latin hypercube fixes the clumping along every axis at once (McKay et al., 1979). Cut each input's range into nn equal bins. Place the nn points so that every bin of every input contains exactly one point: for each input independently, randomly permute the bins and assign the ii-th point to the ii-th bin of the permutation, at a random position inside it. The name comes from the Latin square, a grid in which each symbol appears once in every row and column. A Latin hypercube guarantees coverage of each input separately, but not of the space as a whole: the points could all sit on the diagonal and still satisfy the definition. One remedy is to draw many Latin hypercubes and keep the one whose two closest points are farthest apart.

A Sobol sequence is deterministic (Sobol', 1967). It is built so that each new point falls into the largest gaps left by the earlier ones, a property called low discrepancy: every box in the domain contains close to its fair share of points. In the two-dimensional version in the figure below, the first 2k2^k points of the sequence put exactly one point in each of the 2k2^k bins of each input, like a Latin hypercube. Unlike a Latin hypercube, a sequence can be extended. Adding points to a Latin hypercube breaks its one-point-per-bin property, but adding the next points of a Sobol sequence restores it at the next power of two.

0.00.51.0first input0.00.51.0second input16 pointsempty bins, first input: 6 of 16empty bins, second input: 5 of 16closest pair: 0.077 apartempty binclosest pair
0.00.51.0first input0.00.51.0second input16 pointsempty bins, first input: 6 of 16empty bins, second input: 5 of 16closest pair: 0.077 apartempty binclosest pair
Figure 11.4 Initial designs in the unit square. The strips along the bottom and the left show each point projected onto one input, with the input's range cut into as many equal bins as there are points; shaded bins received no point. The orange segment joins the two closest points. Switch between designs, change the number of points, and press New draw for another random instance.

The projection strips in Figure 11.4 carry the main lesson.

Grid. At 16 points, the grid is a 4×44 \times 4 array, and 12 of the 16 bins of each input are empty. If only the first input mattered, these 16 evaluations would amount to 4.

Random. The 16 random points typically leave five or six bins of each input empty, close to the 37% predicted above, and the closest pair is often much closer than any pair in the other designs. Press New draw to see how much the picture varies.

Latin hypercube. No bin is ever empty, by construction. The closest pair is usually farther apart than for random points, but not always: press New draw until two points nearly touch.

Sobol. With 16 or 32 points no bin is empty. Move the slider to 20 and four bins of the second input empty out; of the counts between 16 and 32, only 24 fills every bin. This is why Sobol designs are usually drawn in powers of two.

How many initial points to use is a trade-off of its own, since every point in the design is a point not chosen by the model. A common rule in the design of computer experiments, used by Jones et al. (1998), is ten points per input dimension; Loeppky et al. (2009) gave reasons and evidence for it. Their criterion is how accurately the Gaussian process predicts the function everywhere, which is more than optimization needs, since an optimizer only has to be right near the top. With a budget of 30 evaluations in five dimensions, the rule would ask for 50, so small budgets need smaller designs, leaving the rest of the exploration to the acquisition function (inference). The figures in this chapter, in one dimension, start from two random points.

Sources cited in Section 11.4 7
  1. Garnett (2023) Bayesian Optimization
  2. Snoek et al. (2012) Practical Bayesian Optimization of Machine Learning Algorithms
  3. Bergstra and Bengio (2012) Random Search for Hyper-Parameter Optimization
  4. McKay et al. (1979) A Comparison of Three Methods for Selecting Values of Input Variables in the Analysis of Output from a Computer Code
  5. Sobol' (1967) On the Distribution of Points in a Cube and the Approximate Evaluation of Integrals
  6. Jones et al. (1998) Efficient Global Optimization of Expensive Black-Box Functions
  7. Loeppky et al. (2009) Choosing the Sample Size of a Computer Experiment: A Practical Guide

11.5 A short history #

Bayesian optimization is older than its name suggests. Its ideas come from statistics, operations research, and engineering design, and several of them were invented more than once.

A model and a decision rule (1960s). Statisticians had studied how to design experiments sequentially, each one chosen in light of the last, since the 1940s (Garnett, 2023, sec. 12.2). Kushner (1964) applied the idea to finding the maximum of a one-dimensional function observed with noise. He modeled the function with a Wiener process, a Gaussian process whose sample paths look like the trace of a random walk, continuous everywhere and smooth nowhere. Early work favored such processes because their updates were cheap enough for the computers of the time (Garnett, 2023, sec. 12.3). Kushner set aside the optimal sequential policy as impractical to compute and proposed simpler rules instead, including maximizing the probability of improving on the best value so far (Section 12.2). His papers also discussed how a human expert could adjust that rule's improvement threshold during the search (Garnett, 2023, sec. 12.3), an early person in the loop, a theme that returns in Part IV.

One-step lookahead (1970s). A line of work in the Soviet Union developed acquisition functions that look exactly one evaluation ahead. Expected improvement (Section 12.3) is usually credited to Močkus and his colleagues (Močkus, 1975; Jones et al., 1998; Frazier, 2018; Brochu et al., 2010). Garnett's history traces an explicit formula for it to Šaltenis in 1971, and reads Močkus's one-step criterion, which values an evaluation by how much it raises the best expected value anywhere, as what is now called the knowledge gradient (Section 12.6); for the Wiener process the two criteria coincide (Garnett, 2023, sec. 12.3). Either way, both one-step criteria were in print by the early 1970s.

Kriging and computer experiments (1950s to 1990s). Independently, the estimation of ore grades in mines had produced Gaussian process regression under the name kriging (Krige, 1951; Matheron, 1963). Sacks et al. (1989) brought it to the design and analysis of computer experiments, where an expensive simulation stands in for a physical experiment. Jones et al. (1998) combined such a model with expected improvement in its closed form, together with a careful treatment of model validation and a branch-and-bound method for maximizing the acquisition function, and called the result Efficient Global Optimization, or EGO. EGO brought the method to wide attention, first in engineering design (Frazier, 2018).

Guarantees from bandits (2010). The upper confidence bound of Equation (11.3) was proposed by Kushner and rediscovered several times (Garnett, 2023, sec. 12.5). Srinivas et al. (2010) connected it to the multi-armed bandit literature and proved how fast it converges for Gaussian process models, the analysis that Section 13.4 explains.

Machine learning (2012 onward). Snoek et al. (2012) showed that with careful choices of the prior and of how its hyperparameters are handled, Bayesian optimization could tune machine learning algorithms, including convolutional neural networks, as well as or better than human experts. The paper set off a surge of interest in machine learning: more than half of the works cited in Garnett's 2023 textbook appeared after 2012 (Garnett, 2023, sec. 12.4), and software frameworks such as BoTorch followed (Balandat et al., 2020). In the same years, a separate line of work developed information-theoretic acquisition functions, first proposed by Villemonteix and colleagues and named entropy search by Hennig and Schuler (2012) (Garnett, 2023, sec. 12.4), then refined by Hernández-Lobato et al. (2014) and Wang and Jegelka (2017) (Section 12.7).

Preferences (2007 onward). Brochu et al. (2007) used the same machinery with a person choosing between options instead of reporting numbers, for designing the appearance of rendered materials. That line of work, PBO, is the subject of Part IV.

Table 11.1 Milestones in the development of Bayesian optimization.
Year Work Contribution
1933 Thompson (1933) Allocate treatments by the posterior probability that each is better; the origin of Thompson sampling (Section 12.5)
1964 Kushner (1964) One-dimensional optimization with a Wiener process model; probability of improvement
1975 Močkus (1975) One-step lookahead in the Bayesian approach; usually credited with expected improvement
1989 Sacks et al. (1989) Gaussian process models for expensive computer simulations
1998 Jones et al. (1998) EGO: expected improvement in closed form with a fitted Gaussian process
2009 Frazier et al. (2009) Knowledge gradient for correlated beliefs
2010 Srinivas et al. (2010) GP-UCB and its regret bounds
2012 Hennig and Schuler (2012) Entropy search: choose evaluations by information about the maximizer
2012 Snoek et al. (2012) Hyperparameter tuning of machine learning algorithms
2020 Balandat et al. (2020) BoTorch: Monte Carlo acquisition functions with automatic differentiation
Sources cited in Section 11.5 18
  1. Garnett (2023) Bayesian Optimization
  2. Kushner (1964) A New Method of Locating the Maximum Point of an Arbitrary Multipeak Curve in the Presence of Noise
  3. Močkus (1975) On Bayesian Methods for Seeking the Extremum
  4. Jones et al. (1998) Efficient Global Optimization of Expensive Black-Box Functions
  5. Frazier (2018) A Tutorial on Bayesian Optimization
  6. Brochu et al. (2010) A Tutorial on Bayesian Optimization of Expensive Cost Functions, with Application to Active User Modeling and Hierarchical Reinforcement Learning
  7. Krige (1951) A Statistical Approach to Some Basic Mine Valuation Problems on the Witwatersrand
  8. Matheron (1963) Principles of Geostatistics
  9. Sacks et al. (1989) Design and Analysis of Computer Experiments
  10. Srinivas et al. (2010) Gaussian Process Optimization in the Bandit Setting: No Regret and Experimental Design
  11. Snoek et al. (2012) Practical Bayesian Optimization of Machine Learning Algorithms
  12. Balandat et al. (2020) BoTorch: A Framework for Efficient Monte-Carlo Bayesian Optimization
  13. Hennig and Schuler (2012) Entropy Search for Information-Efficient Global Optimization
  14. Hernández-Lobato et al. (2014) Predictive Entropy Search for Efficient Global Optimization of Black-box Functions
  15. Wang and Jegelka (2017) Max-value Entropy Search for Efficient Bayesian Optimization
  16. Brochu et al. (2007) Active Preference Learning with Discrete Choice Data
  17. Thompson (1933) On the Likelihood that One Unknown Probability Exceeds Another in View of the Evidence of Two Samples
  18. Frazier et al. (2009) The Knowledge-Gradient Policy for Correlated Normal Beliefs

11.6 Exercises #

Exercise 11.1

Consider a Gaussian process prior with constant mean mm and a stationary kernel, k(x,x′)=κ(x−x′)k(\vx, \vx') = \kappa(\vx - \vx') for some function κ\kappa. Show that before any data, μ0(x)\mu_0(\vx) and σ0(x)\sigma_0(\vx) do not depend on x\vx. What does this imply for any acquisition function that depends on x\vx only through μ0(x)\mu_0(\vx) and σ0(x)\sigma_0(\vx)?

Solution

With no data, the posterior is the prior, so μ0(x)=m\mu_0(\vx) = m and σ02(x)=k(x,x)=κ(0)\sigma_0^2(\vx) = k(\vx, \vx) = \kappa(\mathbf{0}), the same at every input. An acquisition function of the form a0(x)=h(μ0(x),σ0(x))a_0(\vx) = h(\mu_0(\vx), \sigma_0(\vx)) is then a constant, and every input maximizes it. The first query is arbitrary, which is one reason to choose the first points with a design rule.

Exercise 11.2

With exact observations, suppose the greedy rule an(x)=μn(x)a_n(\vx) = \mu_n(\vx) selects an input xi\vx_i that has already been evaluated. Show that evaluating it again leaves the posterior unchanged, so the loop will select the same input forever.

Solution

With exact observations the posterior variance at an evaluated input is zero and its posterior mean equals the observed value: σn(xi)=0\sigma_n(\vx_i) = 0 and μn(xi)=yi\mu_n(\vx_i) = y_i (Section 8.2). A new evaluation at xi\vx_i returns yiy_i again, a value the model already predicted with certainty. Conditioning on an event that had probability one does not change a distribution, so μn+1(x)=μn(x)\mu_{n+1}(\vx) = \mu_n(\vx) and σn+1(x)=σn(x)\sigma_{n+1}(\vx) = \sigma_n(\vx) at every x\vx. The greedy rule therefore chooses xi\vx_i again, and so on until the budget is spent. (In floating point the repeated input makes the kernel matrix singular; the small jitter of Section 8.4 keeps the factorization working and changes the posterior only negligibly.)

Exercise 11.3

Random search draws nn inputs uniformly from the domain. Let pp be the fraction of the domain's volume where ff is within some tolerance of its maximum. Show that the probability that at least one of the nn inputs lands in that region is 1−(1−p)n1 - (1 - p)^n, and find the smallest nn that makes this probability at least 0.950.95 when p=0.05p = 0.05. Why does this number not depend on the dimension dd, and why is that less reassuring than it sounds?

Solution

Each input misses the region independently with probability 1−p1 - p, so all nn miss with probability (1−p)n(1 - p)^n and at least one hits with probability 1−(1−p)n1 - (1 - p)^n. Setting 1−0.95n≥0.951 - 0.95^n \ge 0.95 gives n≥log⁡0.05/log⁡0.95≈58.4n \ge \log 0.05 / \log 0.95 \approx 58.4, so n=59n = 59. The calculation uses only the volume fraction pp, not dd. But in dd dimensions a region that spans a fraction qq of each input's range has volume fraction p=qdp = q^d. With q=0.5q = 0.5 and d=10d = 10, p≈0.001p \approx 0.001, and the required nn grows to about 3,000. Random search is a strong baseline when only a few inputs matter (Bergstra and Bengio, 2012), because then pp is set by those few inputs alone.

Sources cited in Section 11.6 1
  1. Bergstra and Bengio (2012) Random Search for Hyper-Parameter Optimization

Further reading #

  • Frazier (2018) is a short tutorial that covers the loop, expected improvement, the knowledge gradient, and entropy search, and surveys the problem variants of Chapter 14.
  • Garnett (2023) is the textbook of the field. Chapters 5 to 7 derive the loop from Bayesian decision theory, its chapter 9 covers initial designs and stopping, and its chapter 12 is the history summarized here.
  • Shahriari et al. (2016) is a broad review with a large bibliography of applications, written as Bayesian optimization was spreading through machine learning.
  • Brochu et al. (2010) is an accessible tutorial that also introduces preference learning, the bridge to Part IV.
  • Jones et al. (1998) remains readable, and shows the method as engineers met it: a fitted Gaussian process, expected improvement, and diagnostics for the model.
  • Snoek et al. (2012) is the paper that brought the method to machine learning, with practical advice on priors and hyperparameters that still applies.

References

  1. Balandat, M., Karrer, B., Jiang, D. R., Daulton, S., Letham, B., Wilson, A. G., and Bakshy, E. (2020). BoTorch: A Framework for Efficient Monte-Carlo Bayesian Optimization. Advances in Neural Information Processing Systems 33 (NeurIPS 2020). Cited in §11.5
  2. Bergstra, J., and Bengio, Y. (2012). Random Search for Hyper-Parameter Optimization. Journal of Machine Learning Research. Cited in §11.4 §11.6
  3. Brochu, E., de Freitas, N., and Ghosh, A. (2007). Active Preference Learning with Discrete Choice Data. Advances in Neural Information Processing Systems. Cited in §11.5
  4. Brochu, E., Cora, V. M., and de Freitas, N. (2010). A Tutorial on Bayesian Optimization of Expensive Cost Functions, with Application to Active User Modeling and Hierarchical Reinforcement Learning. arXiv preprint. preprint Cited in §11.5
  5. Frazier, P. I. (2018). A Tutorial on Bayesian Optimization. arXiv. preprint Cited in §11.1 §11.2 §11.5
  6. Frazier, P., Powell, W., and Dayanik, S. (2009). The Knowledge-Gradient Policy for Correlated Normal Beliefs. INFORMS Journal on Computing. Cited in §11.5
  7. Garnett, R. (2023). Bayesian Optimization. Cambridge University Press. Cited in §11.2 §11.4 §11.5
  8. Hennig, P., and Schuler, C. J. (2012). Entropy Search for Information-Efficient Global Optimization. Journal of Machine Learning Research. Cited in §11.5
  9. Hernández-Lobato, J. M., Hoffman, M. W., and Ghahramani, Z. (2014). Predictive Entropy Search for Efficient Global Optimization of Black-box Functions. Advances in Neural Information Processing Systems 27 (NeurIPS 2014). Cited in §11.5
  10. Jones, D. R., Schonlau, M., and Welch, W. J. (1998). Efficient Global Optimization of Expensive Black-Box Functions. Journal of Global Optimization. Cited in §11.4 §11.5
  11. Krige, D. G. (1951). A Statistical Approach to Some Basic Mine Valuation Problems on the Witwatersrand. Journal of the Southern African Institute of Mining and Metallurgy. Cited in §11.5
  12. Kushner, H. J. (1964). A New Method of Locating the Maximum Point of an Arbitrary Multipeak Curve in the Presence of Noise. Journal of Basic Engineering. Cited in §11.5
  13. Loeppky, J. L., Sacks, J., and Welch, W. J. (2009). Choosing the Sample Size of a Computer Experiment: A Practical Guide. Technometrics. Cited in §11.4
  14. Matheron, G. (1963). Principles of Geostatistics. Economic Geology. Cited in §11.5
  15. McKay, M. D., Beckman, R. J., and Conover, W. J. (1979). A Comparison of Three Methods for Selecting Values of Input Variables in the Analysis of Output from a Computer Code. Technometrics. Cited in §11.4
  16. Močkus, J. (1975). On Bayesian Methods for Seeking the Extremum. Optimization Techniques IFIP Technical Conference. Cited in §11.5
  17. Sacks, J., Welch, W. J., Mitchell, T. J., and Wynn, H. P. (1989). Design and Analysis of Computer Experiments. Statistical Science. Cited in §11.5
  18. Shahriari, B., Swersky, K., Wang, Z., Adams, R. P., and de Freitas, N. (2016). Taking the Human Out of the Loop: A Review of Bayesian Optimization. Proceedings of the IEEE.
  19. Shields, B. J., Stevens, J., Li, J., Parasram, M., Damani, F., Alvarado, J. I. M., … Doyle, A. G. (2021). Bayesian reaction optimization as a tool for chemical synthesis. Nature. Cited in §11.1
  20. Snoek, J., Larochelle, H., and Adams, R. P. (2012). Practical Bayesian Optimization of Machine Learning Algorithms. Advances in Neural Information Processing Systems 25 (NeurIPS 2012). Cited in §11.1 §11.3 §11.4 §11.5
  21. Sobol', I. M. (1967). On the Distribution of Points in a Cube and the Approximate Evaluation of Integrals. USSR Computational Mathematics and Mathematical Physics. Cited in §11.4
  22. Srinivas, N., Krause, A., Kakade, S. M., and Seeger, M. (2010). Gaussian Process Optimization in the Bandit Setting: No Regret and Experimental Design. ICML 2010. Cited in §11.5
  23. Thompson, W. R. (1933). On the Likelihood that One Unknown Probability Exceeds Another in View of the Evidence of Two Samples. Biometrika. Cited in §11.5
  24. Wang, Z., and Jegelka, S. (2017). Max-value Entropy Search for Efficient Bayesian Optimization. Proceedings of the 34th International Conference on Machine Learning (ICML 2017). Cited in §11.5