Bayesian Optimization
Acquisition functions, GP-UCB and optimizing expensive black boxes.
Tuning a network's hyperparameters, choosing a molecule to synthesize, calibrating a slow simulator: each evaluation costs hours or money, returns no gradient, and you can afford a few dozen. Bayesian optimization spends cheap computation to save expensive evaluations. It fits a Gaussian process to everything seen so far and asks the posterior where the next evaluation is most worth making, trading exploitation of promising regions against exploration of uncertain ones, and for GP-UCB that trade comes with a no-regret guarantee.
What you’ll learn
- Describe the Bayesian optimization loop (surrogate, acquisition, evaluation, update) and the problems it suits.
- Derive the probability of improvement and the closed form of expected improvement, and compare EI, UCB, Thompson sampling and information-based acquisitions.
- State the GP-UCB regret bound in terms of the maximum information gain, prove it for finite domains, and quote the information-gain rates and lower bounds for common kernels.
- Handle practice: hyperparameters during the search (and why estimated priors can break EI), evaluation costs, parallel queries and high dimensions.
Optimizing what you can barely afford to evaluate
The task is on a box of modest dimension, where is a black box: each evaluation is expensive, possibly noisy, and returns no gradient. The budget is tens to hundreds of evaluations, so any computation that saves one evaluation is worth it. The loop:
BAYESIAN-OPTIMIZATION(f, domain X, budget T)
evaluate f at a few initial points (random or space-filling)
for t = 1, 2, ..., T:
fit a GP to all evaluations so far # refit hyperparameters now and then
x_t = argmax over x in X of acquisition(x) # cheap: uses only the posterior
y_t = f(x_t) + noise # the expensive step
return the best point evaluated (or the maximizer of the posterior mean)The acquisition function scores each candidate from the posterior mean and standard deviation . Maximizing it is itself a nonconvex problem, but a cheap one: multistart gradient ascent, or a dense grid in low dimension.
The widget evaluates on a grid of 401 points, and 13 of them count as finding the maximum. If you instead queried grid points uniformly at random (with replacement), how many queries would you need on average to hit one?
Show the answer
31 queries
Each query succeeds with probability , so the number of queries is geometric with mean (the median is about 22, since the distribution has a long tail). Expected improvement needed 6: the surrogate turns every evaluation into information about where the maximum is not.
Acquisition functions
Let be the best value observed so far and the posterior mean and standard deviation at a candidate . The oldest criterion, Kushner's (1964) probability of improvement, is . It ignores how much improvement is on offer, so with it happily picks near-certain, tiny gains. Expected improvement (Močkus, 1975), the criterion of the EGO algorithm of Jones, Schonlau & Welch (1998), weighs size and probability together.
The improvement is , and under the posterior :
Substitute and write ; the lower limit becomes :
Use and , since :
The first term rewards a mean above the incumbent (exploitation), the second rewards uncertainty (exploration), and EI is zero only where and . A small margin (the widget uses 0.01) replaces by to discourage dithering around the incumbent.
At a candidate whose posterior mean equals the incumbent, , with posterior standard deviation , what is the expected improvement?
Show the answer
0.2
, so . A point that is merely as good as the incumbent on average still has value, purely from its uncertainty: that is the exploration term at work.
| Acquisition | Rule | Character |
|---|---|---|
| Probability of improvement | greedy; needs a margin to explore | |
| Expected improvement | the classic default; closed form, no tuning | |
| GP-UCB | optimism under uncertainty; a schedule for gives regret guarantees | |
| Thompson sampling | maximize one posterior sample | randomized, so batches of different queries come naturally (Thompson, 1933, for bandits) |
| Entropy search family | expected reduction in uncertainty about or | information-greedy; needs approximations (Hennig & Schuler, 2012; Hernández-Lobato, Hoffman & Ghahramani, 2014; Wang & Jegelka, 2017) |
| Knowledge gradient | expected gain in the best posterior mean after one more evaluation | values information for the final recommendation (Frazier, Powell & Dayanik, 2009) |
No regret: the GP-UCB guarantee
Measure a strategy by its cumulative regret . A strategy has no regret if ; then the best point found also converges, because . The difficulty of a problem enters through the maximum information gain, the most that noisy evaluations can reveal about under the prior:
Confidence. At each and , given the data is Gaussian, and for a standard normal . A union bound over points and all , using , gives with probability at least :
Regret per step. maximizes the upper bound, which at is at least , while is at least the lower bound at :
Information. The information the chosen queries reveal is . Since and on that interval, and is nondecreasing:
Cauchy–Schwarz finishes it. The bound is sublinear exactly when grows slower than .
| Kernel | Maximum information gain | Regret lower bound (RKHS setting) |
|---|---|---|
| Linear, inputs | — | |
| Squared exponential | ||
| Matérn- | (Vakili, Khezeli & Picheny, 2021) |
What does a no-regret guarantee, , say about the optimization?
- The algorithm evaluates exactly after finitely many steps
- The best value found so far approaches , since the smallest instantaneous regret is at most the average
- Every query after some time is within any of the optimum
- The posterior variance vanishes everywhere
Show the answer
B. The best value found so far approaches , since the smallest instantaneous regret is at most the average
, so the best evaluated point is asymptotically optimal. It does not mean every late query is good (exploration continues), nor that itself is hit.
Practice: hyperparameters, costs and dimension
The guarantees above assume a known kernel. In practice the hyperparameters are re-estimated as evaluations arrive, and that is where things can go wrong:
- Estimated priors can break convergence. For noise-free evaluations, Bull (2011) gave convergence rates for expected improvement with a fixed GP prior on any function in the prior's RKHS (optimal for rough functions), but showed that when the prior parameters are re-estimated from the data by standard estimators the procedure may never find the optimum of some such functions; modified estimators keep the rates.
- Too few points, degenerate fits. In the widget, fitting on the two starting evaluations alone gives a degenerate model ( at its floor of 0.1), after which EI wanders; fitting after a few queries usually works. Snoek, Larochelle & Adams (2012) sidestep point estimates by averaging the acquisition over hyperparameters drawn by MCMC, and use an ARD Matérn 5/2 kernel rather than the overly smooth RBF.
Other practicalities:
- Cost and parallelism. Evaluations differ in cost, so Snoek et al. (2012) maximize expected improvement per second; with several machines, batch acquisitions choose many points at once (Thompson sampling parallelizes naturally). For hyperparameter tuning, multi-fidelity methods that stop bad configurations early, such as Hyperband, compete with and complement BO (Hyperparameter Optimization).
- Dimension. A GP needs many points to model a function on a high-dimensional box, and grows with . Standard BO is usually applied to up to about 10–20 inputs. Beyond that, methods assume structure: a low effective dimension, exploited by searching a random low-dimensional embedding (Wang, Hutter, Zoghi, Matheson & de Freitas, 2016), an additive decomposition (Kandasamy, Schneider & Póczos, 2015), or local trust regions (Eriksson et al., 2019). Hvarfner, Hellsten & Nardi (2024) reported that simply scaling the length-scale prior with the dimension makes standard BO competitive in high dimensions; how far that observation extends is still being assessed as of the mid-2020s.
Key takeaways
- Bayesian optimization fits a GP to all evaluations and queries the maximizer of a cheap acquisition function; it pays off when evaluations are expensive, gradient-free and few, in modest dimension.
- with balances exploitation and exploration in closed form; PI is greedier, UCB optimistic, Thompson sampling randomized, entropy search information-greedy.
- GP-UCB with has with probability at least ; the proof chains a confidence band, , the information gain and Cauchy–Schwarz. is polylogarithmic for the RBF kernel and polynomial for Matérn kernels.
- In practice: refit or average the hyperparameters (estimated priors can break EI's convergence, as Bull showed), account for costs and batches, and expect standard BO to struggle beyond roughly 10–20 dimensions unless structure or dimension-aware priors help.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
At a candidate, and . Using and , what is the expected improvement?
- about 0.30
- about 0.25
- about 0.07
- about 0.33
Show the answer
D. about 0.33
, so . EI exceeds the mean gain because the improvement is truncated at zero: bad outcomes cost nothing, good ones count in full.
What happens to GP-UCB if ?
- It queries the maximizer of the posterior mean, pure exploitation, and can lock onto a suboptimal region forever
- It becomes expected improvement
- It explores uniformly at random
- Nothing changes, because only affects the regret bound
Show the answer
A. It queries the maximizer of the posterior mean, pure exploitation, and can lock onto a suboptimal region forever
With the rule maximizes alone. Nothing rewards uncertainty, so a region where the model is pessimistic but wrong is never visited again; the confidence step of the regret proof fails. The widget's too-smooth model, stuck on the decoy hill, shows the same failure from a different cause.
Why is the GP-UCB regret bound sublinear for the squared-exponential kernel?
- Because decreases with
- Because the posterior variance is zero after queries
- Because the squared-exponential kernel makes linear
- Because grows only polylogarithmically, so
Show the answer
D. Because grows only polylogarithmically, so
The bound is sublinear whenever . For a finite domain grows like , and the smooth kernel's fast eigenvalue decay keeps polylogarithmic, so the regret is up to logarithmic factors.
You plan to tune 200 continuous hyperparameters with 100 evaluations, using BO with an isotropic RBF kernel and default priors. What is the main concern?
- The acquisition function cannot be computed in 200 dimensions
- A GP cannot model a generic function of 200 inputs from 100 points, so the surrogate is nearly uninformative unless structure is assumed (low effective dimension, additivity) or the priors are adapted to the dimension
- Expected improvement is undefined when
- Gaussian processes only accept one-dimensional inputs
Show the answer
B. A GP cannot model a generic function of 200 inputs from 100 points, so the surrogate is nearly uninformative unless structure is assumed (low effective dimension, additivity) or the priors are adapted to the dimension
With far more inputs than evaluations, a generic smooth function is underdetermined, and the information gain grows quickly with . Practical high-dimensional BO bets on structure (random embeddings, additive models, trust regions) or, following Hvarfner et al. (2024), on length-scale priors scaled to the dimension.
Further reading
- D. R. Jones, M. Schonlau & W. J. Welch, "Efficient global optimization of expensive black-box functions," Journal of Global Optimization 13(4), 455–492 (1998).
- N. Srinivas, A. Krause, S. M. Kakade & M. W. Seeger, "Information-theoretic regret bounds for Gaussian process optimization in the bandit setting," IEEE Transactions on Information Theory 58(5), 3250–3265 (2012); conference version at ICML 2010.
- J. Snoek, H. Larochelle & R. P. Adams, "Practical Bayesian optimization of machine learning algorithms," Advances in Neural Information Processing Systems 25 (2012).
- P. I. Frazier, "A tutorial on Bayesian optimization," arXiv:1807.02811 (2018).
- R. Garnett, Bayesian Optimization (Cambridge University Press, 2023).