Foundations to Frontier
Tests
A. Mathematical Foundations › A6 Optimization › Advanced

Bayesian Optimization

When each evaluation costs minutes of simulation, hours of training or a real hardware trial, you can afford only a few dozen. Bayesian optimization builds a probabilistic surrogate (usually a Gaussian process) of the objective from the evaluations so far, then chooses the next point by an acquisition function that trades off exploiting the predicted best region against exploring uncertain ones. You will implement GP regression, expected improvement, lower-confidence bounds and probability of improvement, and beat random search on a deceptive test function and on controller tuning.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Drilling for oil with a small budget

You can afford ten test wells. After each, you update your map of where oil probably is: near good wells the map is confident, far from any well it’s a guess. Where next? Either drill near the best well so far (exploit), or in a big unexplored area that might be better (explore). Bayesian optimization makes that choice with a principled score.

Spend each expensive evaluation wisely: Bayesian optimization
acquisition (expected improvement): next point at its maximum
3 evaluations · best found f = -0.657 at x = 0.100 · true minimum -6.021
Green: the GP's guess of the hidden function (mean ± 2σ band), fitted to the dots. The acquisition function balances exploitation (low predicted mean) and exploration (high uncertainty). Each click spends one evaluation where it's most worthwhile. The Forrester function has a deceptive local minimum near x ≈ 0.14; BO typically finds the global one near 0.76 within a handful of evaluations. Too long a length scale makes the GP overconfident; too short makes it explore everywhere.
Why engineers care

Tuning a legged robot’s gait on hardware, a flight controller in a costly simulator, or a neural network’s hyperparameters each needs a sample-efficient optimizer. Bayesian optimization routinely finds good settings in tens of trials where grid or random search would need hundreds.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Bayesian optimization is designed for objectives that are…
  2. 2. Drilling where the map is most uncertain is…
  3. 3. BO keeps a map (model) of the objective called a…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

The loop

  1. Evaluate a few initial points (random or space-filling).
  2. Fit a surrogate: a Gaussian process gives a mean μ(x)\mu(x) and uncertainty σ(x)\sigma(x) everywhere (A4.4-6).
  3. Maximize an acquisition function a(x)a(x). This is cheap, since it only involves the surrogate.
  4. Evaluate ff there, add the point to the data, and repeat.

Acquisition functions (minimization, best value so far f+f^+)

  • Probability of improvement: PI(x)=Φ(f+−μσ)\mathrm{PI}(x) = \Phi\big(\frac{f^+ - \mu}\sigma\big). It’s greedy.
  • Expected improvement: EI(x)=(f+−μ)Φ(z)+σφ(z)\mathrm{EI}(x) = (f^+ - \mu)\Phi(z) + \sigma\varphi(z) with z=(f+−μ)/σz = (f^+ - \mu)/\sigma. The first term exploits and the second explores.
  • Lower confidence bound: minimize μ(x)−βσ(x)\mu(x) - \beta\sigma(x), which is optimism in the face of uncertainty (GP-UCB).
📝 Quick check (Level 1)
0/3 answered
  1. 1. EI at a point with μ = f⁺ and σ = 1 equals…
  2. 2. Maximizing the acquisition function is cheap because…
  3. 3. The LCB rule picks the point minimizing…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 45 minUndergraduate students and practising engineers.

Gaussian process surrogate

With kernel k(x,x′)=σf2exp⁡(−∥x−x′∥2/(2ℓ2))k(x, x') = \sigma_f^2\exp(-\|x - x'\|^2/(2\ell^2)) and noise σn2\sigma_n^2:

μ(x)=m0+kx⊤(K+σn2I)−1(y−m0),σ2(x)=k(x,x)−kx⊤(K+σn2I)−1kx\mu(x) = m_0 + k_x^\top(K + \sigma_n^2I)^{-1}(y - m_0),\qquad\sigma^2(x) = k(x, x) - k_x^\top(K + \sigma_n^2I)^{-1}k_x

Hyperparameters (ℓ,σf,σn\ell, \sigma_f, \sigma_n) are fit by maximizing the marginal likelihood (A5.2-5). The cost is O(n3)O(n^3) in the number of evaluations, which is negligible when evaluations are expensive.

Practical notes

  • Normalize inputs to [0,1]d[0, 1]^d and standardize outputs.
  • Optimize the acquisition with many random candidates plus local refinement. It’s multimodal.
  • Dimension: standard BO works best for d≲20d\lesssim20. Beyond that, use additive or embedded structure (REMBO, TuRBO; Eriksson et al., 2019).
  • Noise and constraints: noisy EI, constrained BO, and safe BO that never evaluates points likely to violate safety (SafeOpt; Berkenkamp et al., 2016).
  • Batches: q-EI or Thompson sampling for parallel evaluations.
🐍 Exercise 1: GP + EI on a deceptive function
Implement the RBF kernel, GP posterior, expected improvement and a BO loop. On the Forrester function, compare median regret after 12 evaluations with random search over 8 seeds.
📝 Quick check (Level 2)
0/3 answered
  1. 1. GP regression costs … in the number of observations
  2. 2. Standard BO scales well up to about…
  3. 3. SafeOpt-style BO…

Level 3: Advanced

★★★★☆ Advanced⏱ 40 minGraduate level, with full derivations and proofs.

Deriving expected improvement

With Y∼N(μ,σ2)Y\sim\mathcal N(\mu, \sigma^2), let I=max⁡(f+−Y,0)I = \max(f^+ - Y, 0) and Y=μ+σZY = \mu + \sigma Z. Then

E[I]=∫−∞z(f+−μ−σt)φ(t) dt=(f+−μ)Φ(z)+σφ(z)\mathbb E[I] = \int_{-\infty}^{z}(f^+ - \mu - \sigma t)\varphi(t)\,dt = (f^+ - \mu)\Phi(z) + \sigma\varphi(z)

using ∫−∞ztφ(t) dt=−φ(z)\int_{-\infty}^zt\varphi(t)\,dt = -\varphi(z). ∎ EI is increasing in σ\sigma (exploration) and decreasing in μ\mu (exploitation).

Zero variance at observations

For noiseless data, take x=xix = x_i. Then kx=Keik_x = Ke_i, so kx⊤K−1kx=ei⊤Kei=k(xi,xi)k_x^\top K^{-1}k_x = e_i^\top Ke_i = k(x_i, x_i), and σ2(xi)=0\sigma^2(x_i) = 0. The surrogate interpolates. ∎

Regret guarantees

GP-UCB with suitable βt\beta_t has cumulative regret O(TγTβT)O(\sqrt{T\gamma_T\beta_T}), where γT\gamma_T is the maximum information gain. For the RBF kernel, γT=O((log⁡T)d+1)\gamma_T = O((\log T)^{d + 1}), which is sublinear: BO provably homes in on the optimum (Srinivas et al., 2010).

Exercise 3.1: EI at μ = 1, σ = 1, f⁺ = 0

z=−1z = -1: −1⋅Φ(−1)+φ(−1)=−0.1587+0.2420=0.0833-1\cdot\Phi(-1) + \varphi(-1) = -0.1587 + 0.2420 = 0.0833. It’s still positive: a point predicted worse than the best can still be worth trying if it’s uncertain.

📝 Quick check (Level 3)
0/3 answered
  1. 1. EI's derivation uses ∫ t φ(t) dt from −∞ to z =
  2. 2. At a noiseless observation, the GP posterior variance is…
  3. 3. GP-UCB's cumulative regret is…

Level 4: Expert

★★★★★ Expert⏱ 40 minResearchers: original papers and open problems.

Tuning a PD controller in 20 simulations

Two gains, Kp∈[0,15]K_p\in[0, 15] and Kd∈[0,6]K_d\in[0, 6], control a lightly damped plant with actuator saturation. The cost (tracking error, overshoot and effort) comes from a simulation, so it’s a black box. With 5 random points and 15 EI-guided evaluations, BO reaches the same cost (≈ 0.553) on every seed. Random search with the same 20 simulations is sometimes as good and sometimes noticeably worse. BO’s advantage is reliability with a tiny budget, and it grows as evaluations get more expensive and the space gets larger.

🐍 Exercise 2 (research): BO for controller tuning
Use your BO loop (GP + EI) to tune two PD gains of a saturated plant from simulations, and compare best-found cost with random search at equal budget over several seeds.

Bayesian optimization in AI, robotics and aerospace

  • Robot learning on hardware: gait tuning for bipeds and quadrupeds (Calandra et al., 2016) and safe controller tuning on quadrotors (Berkenkamp, Schoellig and Krause, 2016).
  • Hyperparameter optimization: Spearmint, BoTorch and Optuna’s GP/TPE samplers (Snoek, Larochelle and Adams, 2012; Balandat et al., 2020).
  • Aerospace design: airfoil and trajectory design with expensive CFD or mission simulators (Forrester, Sóbester and Keane, 2008).
  • Materials and experiments: closed-loop autonomous labs choose the next experiment by BO.

References

  1. J. Mockus (1975). “On Bayesian methods for seeking the extremum.” Optimization Techniques IFIP.
  2. D. Jones, M. Schonlau, W. Welch (1998). “Efficient global optimization of expensive black-box functions.” Journal of Global Optimization, 13.
  3. N. Srinivas, A. Krause, S. Kakade, M. Seeger (2010). “Gaussian process optimization in the bandit setting: no regret and experimental design.” ICML.
  4. J. Snoek, H. Larochelle, R. Adams (2012). “Practical Bayesian optimization of machine learning algorithms.” NeurIPS.
  5. B. Shahriari, K. Swersky, Z. Wang, R. Adams, N. de Freitas (2016). “Taking the human out of the loop: a review of Bayesian optimization.” Proceedings of the IEEE, 104(1).
  6. F. Berkenkamp, A. Schoellig, A. Krause (2016). “Safe controller optimization for quadrotors with Gaussian processes.” ICRA.
  7. R. Calandra, A. Seyfarth, J. Peters, M. Deisenroth (2016). “Bayesian optimization for learning gaits under uncertainty.” Annals of Mathematics and Artificial Intelligence, 76.
  8. D. Eriksson et al. (2019). “Scalable global optimization via local Bayesian optimization.” NeurIPS (TuRBO).
  9. M. Balandat et al. (2020). “BoTorch: a framework for efficient Monte-Carlo Bayesian optimization.” NeurIPS.
  10. A. Forrester, A. Sóbester, A. Keane (2008). Engineering Design via Surrogate Modelling. Wiley.