Bayesian Optimization: Learning Where to Evaluate Next

On this page

A validation score, simulator output, or experimental measurement may require an expensive evaluation each time we change its inputs. Bayesian optimization uses the evaluations already collected to model the unknown objective and choose the next input. We derive the Gaussian-process update and expected improvement, then prove a regret bound for a separate acquisition rule, GP-UCB.

Recap: Conditioning a Gaussian model

As in Bayesian linear regression, jointly Gaussian unknowns UU and observations VV satisfy

E[U∣V=v]=mU+CUVCVV−1(v−mV).\mathbb E[U\mid V=v] =m_U+C_{UV}C_{VV}^{-1}(v-m_V).

Here mU,mVm_U,m_V are means, CUVC_{UV} is cross-covariance, and CVVC_{VV} is an invertible observation covariance. The conditional mean averages over uncertainty in UU with vv fixed. For a Gaussian process, the unknowns are function values; Section 2 derives the corresponding mean and variance.

1. The objective and the observation model

Let X⊂Rd\mathcal X\subset\mathbb R^d be the feasible set and f:X→Rf:\mathcal X\to\mathbb R the unknown objective. Throughout, larger values are better; minimize a loss ℓ\ell by setting f=−ℓf=-\ell. After tt evaluations, write

Dt={(xi,yi):1≤i≤t},x∗∈arg max⁡x∈Xf(x).\mathcal D_t=\{(x_i,y_i):1\le i\le t\},\qquad x^*\in\operatorname*{arg\,max}_{x\in\mathcal X}f(x).

Assume the maximum exists. A query xtx_t is chosen using only the preceding data. In the noisy model,

Yt=f(xt)+εt,εt∼iidN(0,τ2),Y_t=f(x_t)+\varepsilon_t,\qquad \varepsilon_t\overset{\mathrm{iid}}\sim N(0,\tau^2),

with future noise independent of ff and past data. Thus, conditional on f,Dt−1f,\mathcal D_{t-1} and the selected xtx_t,

Yt∣f,Dt−1,xt∼N(f(xt),τ2).Y_t\mid f,\mathcal D_{t-1},x_t\sim N(f(x_t),\tau^2).

The observed lowercase yty_t is a realization. We can assess optimization of a fixed unknown ff while using a working prior for inference. The regret theorem below makes the stronger assumption that ff was actually drawn from that prior.

An acquisition function at:X→Ra_t:\mathcal X\to\mathbb R, computed from Dt\mathcal D_t, selects

xt+1∈arg max⁡x∈Xat(x).x_{t+1}\in\operatorname*{arg\,max}_{x\in\mathcal X}a_t(x).

Evaluating ata_t uses the fitted model, not a new evaluation of ff. This separates the expensive outer experiment from the usually cheaper inner optimization. See Frazier (2018), Sections 2–4 for the sequential-design formulation.

Original Frazier tutorial Figure 1: three noise-free observations appear in the upper panel with a Gaussian-process posterior mean and dashed pointwise credible limits. The lower panel shows expected improvement, with a cross marking the next input selected at its maximum.
Figure 1. A posterior model and its acquisition function. Original figure from Frazier (2018), A Tutorial on Bayesian Optimization, Figure 1. The source's dashed bands are pointwise posterior credible intervals. The lower curve is expected improvement; it is not the GP-UCB confidence rule used in our theorem. Full resolution ↗Figure excerpt for discussion; copyright remains with the author/rightsholder.

2. Deriving the Gaussian-process posterior

A Gaussian process (GP) prior is specified by a mean mm and a positive-semidefinite covariance kernel kk:

f∼GP⁡(m,k)⟺(f(u1),…,f(un))⊤∼N(m(U),K(U,U))f\sim\operatorname{GP}(m,k) \quad\Longleftrightarrow\quad (f(u_1),\ldots,f(u_n))^\top\sim N(m(U),K(U,U))

for every finite, fixed input collection U=(u1,…,un)U=(u_1,\ldots,u_n), where K(U,U)ij=k(ui,uj)K(U,U)_{ij}=k(u_i,u_j). For example, the squared-exponential kernel is

k(x,x′)=α2exp⁡ ⁣(−12∑j=1d(xj−xj′)2ℓj2),α,ℓj>0.k(x,x')=\alpha^2\exp\!\left(-\frac12\sum_{j=1}^d \frac{(x_j-x'_j)^2}{\ell_j^2}\right),\qquad \alpha,\ell_j>0.

Here α2\alpha^2 is the prior marginal variance; the length scales ℓj\ell_j control how quickly correlation decreases. Fix these parameters during the following derivation. As in Bayesian linear regression, conditioning updates a Gaussian prior, but here the Gaussian vector consists of function values.

Gaussian conditioning from an independent residual

First consider fixed evaluation inputs Xt=(x1,…,xt)X_t=(x_1,\ldots,x_t). Set

Kt=[k(xi,xj)]i,j≤t,At=Kt+τ2It,mt=(m(x1),…,m(xt))⊤,kt(x)=(k(x1,x),…,k(xt,x))⊤.\begin{aligned} K_t&=[k(x_i,x_j)]_{i,j\le t},& A_t&=K_t+\tau^2I_t,\\ \boldsymbol m_t&=(m(x_1),\ldots,m(x_t))^\top,& \boldsymbol k_t(x)&=(k(x_1,x),\ldots,k(x_t,x))^\top. \end{aligned}

Suppose AtA_t is invertible. This holds for τ2>0\tau^2>0, or for a nonsingular noiseless kernel matrix. Independent Gaussian noise gives the joint law

(Ytf(x))∼N ⁣[(mtm(x)),(Atkt(x)kt(x)⊤k(x,x))].\begin{pmatrix}\boldsymbol Y_t\\ f(x)\end{pmatrix} \sim N\!\left[ \begin{pmatrix}\boldsymbol m_t\\m(x)\end{pmatrix}, \begin{pmatrix} A_t&\boldsymbol k_t(x)\\ \boldsymbol k_t(x)^\top&k(x,x) \end{pmatrix}\right].

Define the residual

Ux=f(x)−m(x)−kt(x)⊤At−1(Yt−mt).U_x=f(x)-m(x)-\boldsymbol k_t(x)^\top A_t^{-1}(\boldsymbol Y_t-\boldsymbol m_t).

Its covariance with the observed vector vanishes:

Cov⁡(Ux,Yt)=kt(x)⊤−kt(x)⊤At−1At=0.\operatorname{Cov}(U_x,\boldsymbol Y_t) =\boldsymbol k_t(x)^\top-\boldsymbol k_t(x)^\top A_t^{-1}A_t=0.

Because (Ux,Yt)(U_x,\boldsymbol Y_t) is jointly Gaussian, zero covariance implies independence. Expanding the residual variance gives

Var⁡(Ux)=k(x,x)−2kt(x)⊤At−1kt(x)+kt(x)⊤At−1AtAt−1kt(x)=k(x,x)−kt(x)⊤At−1kt(x).\begin{aligned} \operatorname{Var}(U_x) &=k(x,x)-2\boldsymbol k_t(x)^\top A_t^{-1}\boldsymbol k_t(x)\\ &\quad+\boldsymbol k_t(x)^\top A_t^{-1}A_tA_t^{-1}\boldsymbol k_t(x)\\ &=k(x,x)-\boldsymbol k_t(x)^\top A_t^{-1}\boldsymbol k_t(x). \end{aligned}

Consequently, conditioning on the realized observations yields

f(x)∣Dt∼N(μt(x),st2(x)),μt(x)=m(x)+kt(x)⊤At−1(yt−mt),st2(x)=k(x,x)−kt(x)⊤At−1kt(x).\boxed{ \begin{aligned} f(x)\mid\mathcal D_t&\sim N(\mu_t(x),s_t^2(x)),\\ \mu_t(x)&=m(x)+\boldsymbol k_t(x)^\top A_t^{-1} (\boldsymbol y_t-\boldsymbol m_t),\\ s_t^2(x)&=k(x,x)-\boldsymbol k_t(x)^\top A_t^{-1}\boldsymbol k_t(x). \end{aligned}}

These are the predictive equations in Rasmussen and Williams, Chapter 2, equations (2.22)–(2.24). More generally, the posterior covariance between two latent values is

kt(x,x′)=k(x,x′)−kt(x)⊤At−1kt(x′).k_t(x,x')=k(x,x')-\boldsymbol k_t(x)^\top A_t^{-1}\boldsymbol k_t(x').

Inputs are adaptive when we choose them using earlier observations. Before conditioning on that history, the observation vector need not be Gaussian. The posterior formulas still apply because each choice is determined by the recorded past data. Once we condition on that history, the choice adds no further likelihood factor involving ff. The sequential likelihood is proportional to ∏ip(yi∣f(xi))\prod_i p(y_i\mid f(x_i)). If the query rule also uses independent randomization, we can include it in the recorded history.

What the uncertainty measures

With xx and Dt\mathcal D_t fixed, st2(x)=Var⁡f∣Dt(f(x))s_t^2(x)=\operatorname{Var}_{f\mid\mathcal D_t}(f(x)) measures posterior uncertainty about the underlying function, not variation across new training datasets. A fresh noisy observation also includes independent measurement noise:

Ynew(x)∣Dt∼N(μt(x),st2(x)+τ2).Y_{\rm new}(x)\mid\mathcal D_t\sim N(\mu_t(x),s_t^2(x)+\tau^2).

Use the latent standard deviation sts_t, not the noisy predictive standard deviation, in the acquisition rules derived here. When observations are noiseless and KtK_t is invertible, μt(xi)=yi\mu_t(x_i)=y_i and st(xi)=0s_t(x_i)=0.

Numerically, solve linear systems. If At=LL⊤A_t=LL^\top is a Cholesky factorization, solve Lv=kt(x)L\boldsymbol v=\boldsymbol k_t(x) and Atb=yt−mtA_t\boldsymbol b=\boldsymbol y_t-\boldsymbol m_t. Then

μt(x)=m(x)+kt(x)⊤b,st2(x)=k(x,x)−∥v∥22.\mu_t(x)=m(x)+\boldsymbol k_t(x)^\top\boldsymbol b,\qquad s_t^2(x)=k(x,x)-\|\boldsymbol v\|_2^2.

A tiny diagonal jitter stabilizes this computation. It is a numerical approximation, not evidence of physical observation noise.

3. Expected improvement, derived explicitly

For this section use noiseless evaluations and at least one observed point. The incumbent is the best known function value,

bt=max⁡i≤tf(xi)=max⁡i≤tyi.b_t=\max_{i\le t}f(x_i)=\max_{i\le t}y_i.

If only one evaluation remained and the final recommendation had to be an evaluated point, observing f(x)f(x) would improve the incumbent by (f(x)−bt)+(f(x)-b_t)_+, where u+=max⁡(u,0)u_+=\max(u,0). Expected improvement (EI) is its posterior average:

EI⁡t(x)=EFx∼N(μt(x),st2(x))[(Fx−bt)+],Fx≡f(x)∣Dt.\operatorname{EI}_t(x) =\mathbb E_{F_x\sim N(\mu_t(x),s_t^2(x))} [(F_x-b_t)_+],\qquad F_x\equiv f(x)\mid\mathcal D_t.

The data, candidate xx, and incumbent stay fixed inside this expectation. Let Δ=μt(x)−bt\Delta=\mu_t(x)-b_t, s=st(x)>0s=s_t(x)>0, and Z∼N(0,1)Z\sim N(0,1). Writing Fx=μt(x)+sZF_x=\mu_t(x)+sZ, with z=Δ/sz=\Delta/s, gives

EI⁡t(x)=∫−z∞(Δ+su)ϕ(u) du=Δ{1−Φ(−z)}+s∫−z∞uϕ(u) du=ΔΦ(z)+sϕ(z).\begin{aligned} \operatorname{EI}_t(x) &=\int_{-z}^{\infty}(\Delta+su)\phi(u)\,du\\ &=\Delta\{1-\Phi(-z)\}+s\int_{-z}^{\infty}u\phi(u)\,du\\ &=\Delta\Phi(z)+s\phi(z). \end{aligned}

Here ϕ\phi and Φ\Phi are the standard-normal density and distribution function. The final equality uses symmetry and ϕ′(u)=−uϕ(u)\phi'(u)=-u\phi(u), so ∫c∞uϕ(u) du=ϕ(c)\int_c^\infty u\phi(u)\,du=\phi(c). Thus

EI⁡t(x)={(μt(x)−bt)Φ(z)+st(x)ϕ(z),st(x)>0,(μt(x)−bt)+,st(x)=0.\boxed{\operatorname{EI}_t(x)= \begin{cases} (\mu_t(x)-b_t)\Phi(z)+s_t(x)\phi(z),&s_t(x)>0,\\ (\mu_t(x)-b_t)_+,&s_t(x)=0. \end{cases}}

The zero-variance case is a deterministic improvement, not automatically zero. At an already evaluated noiseless point it is zero because f(xi)≤btf(x_i)\le b_t.

Holding the incumbent fixed, differentiation also makes the tradeoff precise:

∂EI⁡∂μ=Φ(z),∂EI⁡∂s=ϕ(z)>0.\frac{\partial\operatorname{EI}}{\partial\mu}=\Phi(z),\qquad \frac{\partial\operatorname{EI}}{\partial s}=\phi(z)>0.

For example, ∂z/∂s=−Δ/s2\partial z/\partial s=-\Delta/s^2 and ϕ′(z)=−zϕ(z)\phi'(z)=-z\phi(z) cancel the extra terms when differentiating with respect to ss. EI favors a larger predicted value and greater uncertainty. This is a one-evaluation decision calculation; repeatedly applying it is not a proof of optimal allocation over an arbitrary remaining budget. The noiseless decision argument is developed in Frazier, Section 4.1.

With noisy observations, max⁡iyi\max_i y_i is not the best known latent value. Simply substituting it into this formula does not produce a noise-aware decision-theoretic EI rule. One must specify the terminal recommendation and account for uncertainty in its value; see Frazier, Section 5.1.

4. GP-UCB and a finite-domain regret guarantee

EI quantifies improvement over an incumbent. Gaussian-process upper confidence bound (GP-UCB) instead evaluates an optimistic prediction:

xt∈arg max⁡x∈X{μt−1(x)+βt st−1(x)}.x_t\in\operatorname*{arg\,max}_{x\in\mathcal X} \{\mu_{t-1}(x)+\sqrt{\beta_t}\,s_{t-1}(x)\}.

The exploration schedule βt\beta_t determines how much uncertainty to include. Unlike a fixed pointwise 95% posterior interval, the schedule below controls all inputs and all rounds simultaneously. All logarithms below are natural.

Assumptions and the information quantity

Specialize to a finite nonempty set X\mathcal X with MM points. Assume:

  • f∼GP⁡(0,k)f\sim\operatorname{GP}(0,k) with a known, fixed kernel satisfying k(x,x)≤1k(x,x)\le1.
  • εt∼iidN(0,τ2)\varepsilon_t\overset{\mathrm{iid}}\sim N(0,\tau^2), τ2>0\tau^2>0, independently of ff; the posterior uses this known noise variance.
  • Queries depend only on previous observations; GP-UCB maximization is exact, with a fixed tie-breaking rule. Before any data, μ0=0\mu_0=0 and s02(x)=k(x,x)s_0^2(x)=k(x,x).

The probability law Pf,ε\mathbb P_{f,\varepsilon} below averages over both the prior draw of ff and observation noise. It is not a uniform guarantee for every fixed function.

For a fixed design U=(u1,…,uT)∈XTU=(u_1,\ldots,u_T)\in\mathcal X^T, including repeated locations, define

I(U)=12log⁡det⁡(IT+τ−2K(U,U)),γT=max⁡U∈XTI(U).\mathcal I(U)=\frac12\log\det(I_T+\tau^{-2}K(U,U)),\qquad \gamma_T=\max_{U\in\mathcal X^T}\mathcal I(U).

Why information? For this fixed design let FU∼N(0,K(U,U))\boldsymbol F_U\sim N(0,K(U,U)) and E∼N(0,τ2I)\boldsymbol E\sim N(0,\tau^2I) independently, and put YU=FU+E\boldsymbol Y_U=\boldsymbol F_U+\boldsymbol E. The Gaussian entropy formula gives

I(FU;YU)=h(YU)−h(YU∣FU)=12log⁡det⁡(K(U,U)+τ2I)−12log⁡det⁡(τ2I)=I(U).\begin{aligned} I(\boldsymbol F_U;\boldsymbol Y_U) &=h(\boldsymbol Y_U)-h(\boldsymbol Y_U\mid\boldsymbol F_U)\\ &=\tfrac12\log\det(K(U,U)+\tau^2I) -\tfrac12\log\det(\tau^2I)\\ &=\mathcal I(U). \end{aligned}

The observation covariance is invertible even when the covariance of the underlying function values is singular. Below, we evaluate the log-determinant expression I\mathcal I at the query locations selected by the algorithm. This use of the expression does not require a Gaussian law conditional only on those adaptive locations; the Gaussian calculation above assumes fixed locations.

Theorem: cumulative regret of GP-UCB

Let δ∈(0,1)\delta\in(0,1) and

βt=2log⁡ ⁣(Mπ2t26δ),rt=f(x∗)−f(xt),RT=∑t=1Trt.\beta_t=2\log\!\left(\frac{M\pi^2t^2}{6\delta}\right),\qquad r_t=f(x^*)-f(x_t),\qquad R_T=\sum_{t=1}^T r_t.

Under the assumptions above,

Pf,ε ⁣{RT≤8TβTγTlog⁡(1+τ−2) for every T≥1}≥1−δ.\boxed{\mathbb P_{f,\varepsilon}\!\left\{ R_T\le \sqrt{\frac{8T\beta_T\gamma_T}{\log(1+\tau^{-2})}} \ \text{for every }T\ge1\right\}\ge1-\delta.}

This is the finite-decision-set GP-prior result of Srinivas et al. (2010), Theorem 1 and Appendix A.1, with the information maximum written over query sequences so repeats are explicit.

Uniform posterior control

First fix tt and xx, and condition on Dt−1\mathcal D_{t-1}. If st−1(x)>0s_{t-1}(x)>0,

f(x)−μt−1(x)st−1(x) ∣ Dt−1∼N(0,1).\frac{f(x)-\mu_{t-1}(x)}{s_{t-1}(x)} \,\bigg|\,\mathcal D_{t-1}\sim N(0,1).

For Z∼N(0,1)Z\sim N(0,1) and c≥0c\ge0, symmetry and a shifted normal integral give

P(∣Z∣>c)=2∫0∞ϕ(v+c) dv=2e−c2/2∫0∞e−cvϕ(v) dv≤e−c2/2.\begin{aligned} \mathbb P(|Z|>c) &=2\int_0^\infty\phi(v+c)\,dv\\ &=2e^{-c^2/2}\int_0^\infty e^{-cv}\phi(v)\,dv \le e^{-c^2/2}. \end{aligned}

The failure probability for a particular (t,x)(t,x) is therefore at most e−βt/2e^{-\beta_t/2}. This bound also holds unconditionally by the tower property. If the variance is zero, f(x)=μt−1(x)f(x)=\mu_{t-1}(x) conditionally almost surely, so no failure occurs. A union bound over the finite input set and all positive integers yields

Pf,ε ⁣(∃t,x: ∣f(x)−μt−1(x)∣>βtst−1(x))≤∑t=1∞Me−βt/2=6δπ2∑t=1∞t−2=δ.\begin{aligned} \mathbb P_{f,\varepsilon}\!\left( \exists t,x:\ |f(x)-\mu_{t-1}(x)|> \sqrt{\beta_t}s_{t-1}(x)\right) &\le\sum_{t=1}^\infty M e^{-\beta_t/2}\\ &=\frac{6\delta}{\pi^2}\sum_{t=1}^\infty t^{-2} =\delta. \end{aligned}

Call the complementary event E\mathcal E. It holds simultaneously at the random optimizer x∗x^* and the adaptively selected xtx_t because it holds at every input.

Optimism bounds one-round regret

On E\mathcal E, the UCB at x∗x^* is at least f(x∗)f(x^*). Since xtx_t maximizes UCB,

f(x∗)≤μt−1(x∗)+βtst−1(x∗)≤μt−1(xt)+βtst−1(xt).\begin{aligned} f(x^*)&\le\mu_{t-1}(x^*)+\sqrt{\beta_t}s_{t-1}(x^*)\\ &\le\mu_{t-1}(x_t)+\sqrt{\beta_t}s_{t-1}(x_t). \end{aligned}

Also f(xt)≥μt−1(xt)−βtst−1(xt)f(x_t)\ge\mu_{t-1}(x_t)-\sqrt{\beta_t}s_{t-1}(x_t). Subtracting gives

0≤rt≤2βt st−1(xt).\boxed{0\le r_t\le2\sqrt{\beta_t}\,s_{t-1}(x_t).}

The one-round regret is therefore bounded by uncertainty at the selected input. To control cumulative regret, we next bound the sum of these posterior uncertainties.

Posterior variances and the log determinant

For any realized query sequence, set vt=st−12(xt)v_t=s_{t-1}^2(x_t). The Schur-complement determinant identity, a block-matrix calculation related to the identities in Linear Algebra Essentials, gives

det⁡(Kt+τ2It)=det⁡(Kt−1+τ2It−1)(τ2+vt).\det(K_t+\tau^2I_t) =\det(K_{t-1}+\tau^2I_{t-1})(\tau^2+v_t).

Dividing by τ2t\tau^{2t} and iterating from the empty design establishes the pathwise identity

12∑t=1Tlog⁡(1+τ−2vt)=12log⁡det⁡(IT+τ−2KT)≤γT.\frac12\sum_{t=1}^T\log(1+\tau^{-2}v_t) =\frac12\log\det(I_T+\tau^{-2}K_T) \le\gamma_T.

No independence of the selected inputs is used in this matrix identity. Moreover, 0≤vt≤k(xt,xt)≤10\le v_t\le k(x_t,x_t)\le1. Concavity of u↦log⁡(1+τ−2u)u\mapsto\log(1+\tau^{-2}u) places it above the chord between 0 and 1:

log⁡(1+τ−2u)≥ulog⁡(1+τ−2),0≤u≤1.\log(1+\tau^{-2}u)\ge u\log(1+\tau^{-2}), \qquad 0\le u\le1.

Consequently,

∑t=1Tvt≤2γTlog⁡(1+τ−2).\sum_{t=1}^T v_t\le \frac{2\gamma_T}{\log(1+\tau^{-2})}.

Finally, Cauchy–Schwarz and the nondecreasing schedule βt\beta_t imply, on the same event E\mathcal E,

RT2≤T∑t=1Trt2≤4TβT∑t=1Tvt≤8TβTγTlog⁡(1+τ−2).\begin{aligned} R_T^2 &\le T\sum_{t=1}^T r_t^2 \le4T\beta_T\sum_{t=1}^T v_t\\ &\le\frac{8T\beta_T\gamma_T}{\log(1+\tau^{-2})}. \end{aligned}

This proves the stated bound for every TT simultaneously. The UCB comparison bounds regret by posterior standard deviations, while the log-determinant identity controls their accumulated squares.

Why the bound implies learning on a fixed finite domain

A direct bound makes the asymptotic conclusion explicit. Since KTK_T has rank at most MM, write its nonzero eigenvalues as λ1,…,λr\lambda_1,\ldots,\lambda_r, padding with zeros to MM terms. They satisfy λj≥0\lambda_j\ge0 and ∑jλj=tr⁡(KT)≤T\sum_j\lambda_j=\operatorname{tr}(K_T)\le T. Jensen's inequality for the concave logarithm gives, for every length-TT design UU,

I(U)=12∑j=1Mlog⁡(1+τ−2λj)≤M2log⁡ ⁣(1+∑jλjMτ2)≤M2log⁡ ⁣(1+TMτ2).\begin{aligned} \mathcal I(U) &=\frac12\sum_{j=1}^M\log(1+\tau^{-2}\lambda_j)\\ &\le\frac M2\log\!\left(1+\frac{\sum_j\lambda_j}{M\tau^2}\right) \le\frac M2\log\!\left(1+\frac{T}{M\tau^2}\right). \end{aligned}

Maximizing over UU preserves the bound:

γT≤M2log⁡ ⁣(1+TMτ2).\gamma_T\le\frac M2\log\!\left(1+\frac{T}{M\tau^2}\right).

For fixed M,δ,τ2M,\delta,\tau^2, therefore,

RTT≤8βTγTTlog⁡(1+τ−2)⟶0.\frac{R_T}{T} \le\sqrt{\frac{8\beta_T\gamma_T}{T\log(1+\tau^{-2})}} \longrightarrow0.

Also min⁡t≤Trt≤RT/T\min_{t\le T}r_t\le R_T/T: at least one queried point has small latent regret. Identifying that point from noisy yty_t requires a recommendation rule; maximizing the noisy observations is not justified by this inequality. The result does not prove the same bound for EI, a continuous domain without additional analysis, an approximate acquisition maximizer, or an empirically retuned kernel.

5. The sequential algorithm

Algorithm 1 Sequential GP-based Bayesian optimization

Input: budget BB, initial design of size 1≤n0≤B1\le n_0\le B, fixed prior and noise model, acquisition rule, feasible set, and tie-breaking rule.

Output: collected observations and a final recommendation.

  1. Evaluate the initial design and form Dn0\mathcal D_{n_0}.
  2. For t=n0,…,B−1t=n_0,\ldots,B-1:
  3. Compute the posterior μt,st\mu_t,s_t from Dt\mathcal D_t.
  4. Set at=EI⁡ta_t=\operatorname{EI}_t in the noiseless setting, or at(x)=μt(x)+βt+1st(x)a_t(x)=\mu_t(x)+\sqrt{\beta_{t+1}}s_t(x) for GP-UCB.
  5. Choose xt+1∈arg max⁡x∈Xat(x)x_{t+1}\in\operatorname*{arg\,max}_{x\in\mathcal X}a_t(x).
  6. Evaluate ff with the stated observation model and append (xt+1,yt+1)(x_{t+1},y_{t+1}).
  7. End for.
  8. Return the observations; in the noiseless case recommend the best evaluated point. With noise, specify a posterior-based recommendation or independent confirmation evaluations.

The theorem above starts GP-UCB at round 1. A separately chosen initial design is a practical variation, not literally that theorem's algorithm; its initial regret must be accounted for in a corresponding guarantee.

6. A one-dimensional Python example

Consider the fixed, noiseless function

f(x)=0.7sin⁡(9x)+0.3cos⁡(17x)+0.5x,x∈[0,1].f(x)=0.7\sin(9x)+0.3\cos(17x)+0.5x,\qquad x\in[0,1].

Use initial inputs 0.05,0.45,0.900.05,0.45,0.90, a zero-mean unit-variance squared-exponential GP with length scale 0.180.18, and EI on a 1,001-point grid. The true curve is plotted only for explanation; the selection rule receives only queried values. This illustrative fixed function is not an experiment sampled from the theorem's GP prior.

The complete Python companion implements the posterior with Cholesky solves. Its acquisition calculation includes the zero-variance limit:

import numpy as np
from scipy.special import ndtr

def expected_improvement(mu, sd, best):
    mu, sd = np.broadcast_arrays(np.asarray(mu, float),
                                 np.asarray(sd, float))
    delta = mu - best
    z = np.divide(delta, sd, out=np.zeros_like(delta), where=sd > 0)
    phi = np.exp(-0.5 * z * z) / np.sqrt(2 * np.pi)
    return np.where(sd > 0, delta * ndtr(z) + sd * phi,
                    np.maximum(delta, 0.0))

Each iteration computes the model on cheap grid points, masks previously evaluated inputs, and spends exactly one new function evaluation:

grid = np.linspace(0, 1, 1001)[:, None]
x = np.array([[0.05], [0.45], [0.90]])
y = objective(x[:, 0])
for _ in range(6):
    mu, sd = posterior(x, y, grid)
    ei = expected_improvement(mu, sd, y.max())
    available = np.min(np.abs(grid - x[:, 0]), axis=1) > 1e-8
    index = np.argmax(np.where(available, ei, -np.inf))
    x = np.vstack([x, grid[index]])
    y = np.append(y, objective(grid[index, 0]))

Here objective and posterior are defined in the companion. The 10−1010^{-10} jitter is numerical regularization; no measurement noise is simulated. Maximizing EI over a grid is an approximation to continuous-domain acquisition optimization.

Computed noiseless Bayesian-optimization example after three and six evaluations. Each posterior panel shows the true function, fitted mean, 95 percent pointwise posterior interval and observed values. The panel below plots expected improvement and marks its selected next query.
Figure 2. Posterior updates and EI selections. Computed by the linked Python companion, with fixed inputs and kernel. Shading is a 95% pointwise posterior interval for the latent function under the working GP, not a simultaneous frequentist confidence band. Scroll sideways on small screens; click for the full-resolution vector figure.

7. Hyperparameter tuning with a fixed budget

For an RBF support-vector classifier, let x=(x1,x2)∈[0,1]2x=(x_1,x_2)\in[0,1]^2 encode

C=10−3+6x1,η=10−3+6x2,C=10^{-3+6x_1},\qquad \eta=10^{-3+6x_2},

where η\eta is the classifier's RBF kernel parameter, called gamma by scikit-learn. It is unrelated to the information quantity γT\gamma_T. Let V1,V2,V3V_1,V_2,V_3 be fixed validation folds within the training partition, and let g^x,−j\widehat g_{x,-j} fit the scaling pipeline and classifier using the other folds. The expensive objective is

f(x)=13∑j=131∣Vj∣∑i∈Vj1{g^x,−j(Zi)=Li},f(x)=\frac13\sum_{j=1}^3\frac1{|V_j|} \sum_{i\in V_j}\mathbf1\{\widehat g_{x,-j}(Z_i)=L_i\},

where ZiZ_i and LiL_i are features and labels. Conditional on the generated dataset and these folds, this objective is deterministic. The remaining search randomness comes from the seeded candidate pool and random-search ordering, not independent Gaussian observation noise.

The companion generates 500 noisy two-moons observations, reserves 25% as a test set, and compares EI with uniform random search over the same 800-point candidate pool. Before search, pool points Uj∼iidUnif⁡([0,1]2)U_j\overset{\mathrm{iid}}\sim\operatorname{Unif}([0,1]^2) are generated independently of the dataset. Random search follows an independent uniform permutation of the pool indices, without replacement; EI chooses among the remaining pool points. Both use the same five initial configurations and a budget of 20 objective evaluations, including initialization. Each objective evaluation comprises three classifier fits. Scaling is fitted inside each fold, preventing preprocessing leakage.

For EI, we center and scale the observed cross-validation (CV) scores at each round. The working GP uses a fixed length scale 0.250.25 on the normalized inputs. These choices and the nonsmooth accuracy objective differ from the GP-UCB theorem's assumptions.

Snoek, Larochelle and Adams (2012) study hyperparameter optimization with GP models of the objective. We compare with random search because it is itself an effective tuning method in relevant settings (Bergstra and Bengio, 2012).

Best observed three-fold cross-validation accuracy plotted against a budget of twenty objective evaluations, comparing expected improvement with random search. Both methods share the first five configurations. This is one seeded synthetic-data illustration, not a repeated-run benchmark.
Figure 3. Equal-budget tuning comparison. One seeded run on synthetic two-moons data; curves show the running best CV score, not test accuracy. They are not averages or uncertainty intervals across seeds. Full queried scores and selected parameters are available in the run record.

Each optimizer chooses its final configuration by CV score, refits on the full training partition, and evaluates it once on the untouched test partition. The test results are descriptive checks of the selected models, not criteria for choosing the optimizer or changing its settings. A single seed cannot establish that either method is generally better. Repeated independent runs with matched budgets would be needed for that comparison.

Search ruleObjective evaluationsBest CV accuracyFinal test accuracy
EI2092.00%96.80%
Random search2091.47%95.20%

These are the saved run's values, with package versions and seeds in the JSON record. Test accuracy is based on 125 held-out observations; no repeated-sample uncertainty interval is reported for this one-run illustration.

Run both examples and the numerical checks locally:

python -m pip install numpy scipy matplotlib scikit-learn
python bayesian_optimization.py --output-dir bo-output

The companion checks EI against numerical integration, its zero-variance limit, GP posterior moments against direct solves, and the variance/log-determinant identity. It exports both vector figures and a JSON record. Use --check-only to run just these mathematical checks. Download the companion first; the commands do not require a running website or external dataset.

8. What can fail in practice

  • Kernel misspecification. Posterior uncertainty reflects the assumed kernel and noise model. A narrow interval is not evidence that the true function obeys them. Estimating kernel parameters adds uncertainty that plug-in predictions omit.
  • Large dimension or large budgets. Acquisition search becomes harder in large spaces; an exact GP factorization costs O(t3)O(t^3) time and O(t2)O(t^2) storage at round tt. Sparse or structured alternatives change that calculation.
  • Noisy incumbents. The largest noisy outcome can be a lucky measurement. Use an acquisition and recommendation rule designed for the actual observation model.
  • Numerical and optimization error. Cholesky solves, input scaling and carefully chosen jitter help conditioning. Finite candidate searches or local acquisition maxima do not automatically satisfy an exact-maximization theorem.
  • Constraints and costs. If feasibility is unknown or evaluations have different costs, improving ff alone is not the entire decision problem.
  • Adaptive validation overfitting. BO repeatedly uses the same validation evidence. Keep a test set untouched until final selection and account for the full evaluation budget.

The central distinction is between modeling the objective and choosing an experiment. GP conditioning addresses the first; an acquisition rule addresses the second. The regret proof connects them only under its stated assumptions.

References

  1. Frazier, P. I. (2018). A Tutorial on Bayesian Optimization. Sections 3–5: GP models, acquisition functions and noisy observations.
  2. Rasmussen, C. E., and Williams, C. K. I. (2006). Gaussian Processes for Machine Learning, Chapter 2. Gaussian conditioning and stable posterior computation.
  3. Srinivas, N., Krause, A., Kakade, S. M., and Seeger, M. (2010). Gaussian Process Optimization in the Bandit Setting: No Regret and Experimental Design. Theorem 1 and Appendix A.1.
  4. Snoek, J., Larochelle, H., and Adams, R. P. (2012). Practical Bayesian Optimization of Machine Learning Algorithms. GP-based hyperparameter optimization.
  5. Bergstra, J., and Bengio, Y. (2012). Random Search for Hyper-Parameter Optimization. Random-search methodology and comparisons.