Posterior equations, the marginal likelihood and Cholesky.
The GP posterior fits on one line, but using it well takes more: a proof of where it comes from, a numerically stable algorithm, gradients for the hyperparameters, a way past the cubic cost, and a precise meaning for the error bars. This lesson supplies all five, and ends with a result from 1996 that still shapes deep learning theory: infinitely wide neural networks are Gaussian processes.
What you’ll learn
Prove the Gaussian conditioning formula with a Schur complement, and show that the weight-space view (Bayesian linear regression) gives the same posterior.
Implement GP regression with a Cholesky factorization (Rasmussen & Williams' Algorithm 2.1), and explain its costs and numerical pitfalls.
Derive the gradient of the log marginal likelihood, and prove that the posterior standard deviation is a worst-case error over the RKHS unit ball.
Explain sparse variational GPs with inducing points, and derive the Gaussian-process limit of infinitely wide neural networks.
Conditioning, proved two ways
DerivationProof by decorrelation
r=b−C⊤A−1a,Cov(r,a)=C⊤−C⊤A−1A=0
Subtract from b its best linear predictor from a. The remainder r is uncorrelated with a:
(r,a) is a linear image of a Gaussian vector, hence jointly Gaussian, and for jointly Gaussian vectors uncorrelated means independent. So observing a leaves the distribution of r unchanged, with
Given a, b=r+C⊤A−1a is r shifted by a known vector, which proves the theorem. With a=y, A=K+σn2I, C=k∗ and zero means, it gives the GP posterior:
The same answer comes from parameters instead of functions. Take f(x)=φ(x)⊤w with prior w∼N(0,Σp); then f is a GP with kernel k(x,x′)=φ(x)⊤Σpφ(x′). Bayesian linear regression (Bayesian Linear Regression) gives the weight posterior N(σn−2A−1Φ⊤y,A−1) with A=σn−2Φ⊤Φ+Σp−1, and two matrix identities turn it into the function-space formulas:
Push-through (multiply both sides by A on the left and by ΦΣpΦ⊤+σn2I on the right to check it). With K=ΦΣpΦ⊤ and k∗=ΦΣpφ(x∗) the predictive mean φ(x∗)⊤wˉ becomes:
Weight space costs O(D3) for D features, function space O(n3) for n data points: the same trade as primal against dual in The Kernel Trick. Function space is the only option when D=∞.
Cholesky in practice
text
GP-REGRESSION(X, y, kernel k, noise variance sn2, test input x*) # Rasmussen & Williams, Algorithm 2.1
L = cholesky(K + sn2 * I) # K = k(X, X); n^3/6 multiply-adds
alpha = L^T \ (L \ y) # two triangular solves, O(n^2)
mean = k*^T alpha # k* = k(X, x*); O(n) per test input
v = L \ k* # O(n^2) per test input
var = k(x*, x*) - v^T v # posterior variance of f(x*)
logp = -0.5 * y^T alpha - sum_i log L[i,i] - (n/2) log(2 pi)
return mean, var, logp
The last line uses logdet(K+σn2I)=2∑ilogLii, so the factorization pays for the marginal likelihood too.
Practical rules:
Never form (K+σn2I)−1. Triangular solves with L are cheaper and far more stable.
Add jitter. With little or no noise, or a long length scale, K is numerically singular: the RBF Gram matrix of nearby points has eigenvalues that decay faster than any power. Adding 10−6σf2 to the diagonal (the widget's choice) keeps the factorization alive.
Optimize in log space.ℓ, σf and σn are positive and range over orders of magnitude.
Sample by updating prior samples. Exact posterior samples follow from prior samples by Matheron's rule: fpost(⋅)=f(⋅)+k(⋅,X)(K+σn2I)−1(y−f(X)−ε) with ε∼N(0,σn2I), which lets prior samples be drawn cheaply, for instance from random features, and then conditioned on the data (Wilson et al., 2020).
Predict before you look
Factorizing the 5,000×5,000 matrix K+σn2I takes 1 second on some machine. About how many seconds does the same step take for 20,000 points?
Show the answer
64 s
Cholesky costs about n3/6 operations, so four times the data costs 43=64 times the time, while memory grows sixteenfold, to about 3.2 GB in double precision. Every hyperparameter step repeats it, which is why exact GPs stall in the tens of thousands of points without the methods of Scaling Kernel Methods.
Gradients, and what the error bar means
DerivationThe gradient of the log marginal likelihood
Differentiate logp=−21y⊤Ky−1y−21logdetKy−2nlog2π and collect both terms in one trace, with α=Ky−1y (Rasmussen & Williams, eq. 5.9):
∂ℓ∂k(x,x′)=k(x,x′)ℓ3∥x−x′∥2
For the RBF length scale the matrix derivative is explicit. Computing Ky−1 from the Cholesky factor costs O(n3) once; each hyperparameter then costs O(n2), since the trace of a product needs only the elementwise products of the two matrices.
Predict before you look
With the 8 starting points at the defaults, the widget reports data fit −3.61 and complexity 1.96. What is logp(y∣X)?
Show the answer
-9
−3.61+1.96−28log2π=−3.61+1.96−7.35=−9.00, the value the widget shows. The constant −2nlog2π never changes with the hyperparameters, so the fit trades only the first two terms.
Consequence: if the true function has ∥f∥H≤B, the noise-free posterior mean is within Bσ(x) of it everywhere, with no probability involved. Noisy versions of this bound drive the regret analysis of GP-UCB in Bayesian Optimization.
Beyond the cubic cost: inducing points
Choose m≪ninducing inputsZ and let u=f(Z) summarize the function. Early approximations (subset of regressors, FITC; Snelson & Ghahramani, 2006) changed the prior so that the training and test values of f interact only through u, and Quiñonero-Candela & Rasmussen (2005) unified them as different such modifications. Titsias (2009) kept the exact prior and approximated the posterior instead, with q(f,u)=p(f∣u)q(u). Optimizing q(u) analytically leaves a collapsed lower bound on the log marginal likelihood:
The first term is the marginal likelihood of a Nyström-approximated GP and costs O(nm2). The trace is the total prior variance of f at the data that u fails to explain, so it penalizes poorly placed inducing points. The inducing inputs are variational parameters: optimizing them can only tighten the bound, bringing the approximation closer to the exact posterior, so they cannot overfit the way extra model hyperparameters can.
Hensman, Fusi & Lawrence (2013) went further and kept q(u)=N(m,S) explicit. The bound then becomes a sum over data points,
L=i=1∑nEq(fi)[logp(yi∣fi)]−DKL(q(u)∥p(u)),
which mini-batch stochastic optimization handles at O(m3) per step: GPs on millions of points, and with non-Gaussian likelihoods (classification, counts) as a bonus, since only one-dimensional expectations of logp(yi∣fi) are needed.
Infinitely wide networks are Gaussian processes
Take a network with one hidden layer of H units, f(x)=b+H1∑j=1Hvjϕ(uj⊤x+aj), and put independent priors on all the weights, with Evj=0, Varvj=σv2 and b∼N(0,σb2). Neal (1996) asked what this prior over functions becomes as H→∞.
At any input the hidden terms vjϕ(uj⊤x+aj) are i.i.d. across j with mean zero. The covariance between two inputs does not depend on H:
fH→∞GP(0,k)
For any finite set of inputs, (f(x1),…,f(xm)) is b plus a normalized sum of H i.i.d. random vectors, so the multivariate central limit theorem makes it Gaussian as H→∞: the prior becomes GP(0,k).
Deep networks compose the argument layer by layer (Lee et al., 2018; Matthews et al., 2018): with weight variance σw2/(width), the kernel of layer l+1 is an expectation over the Gaussian pre-activations of layer l. For ReLU and erf activations the expectation has a closed form.
Exact Bayesian inference in an infinitely wide network is therefore GP regression with this kernel. The limit has a price: no single hidden unit matters, so the data cannot reshape the hidden layer, and the infinitely wide network learns no features. Training a wide network by gradient descent leads to a different kernel, the neural tangent kernel (Jacot, Gabriel & Hongler, 2018); both limits, and the feature-learning regimes beyond them, are the subject of Infinite Width: NTK & Mean-Field Limits.
Key takeaways
Conditioning a Gaussian subtracts the best linear predictor: b∣a has mean μb+C⊤A−1(a−μa) and Schur-complement covariance B−C⊤A−1C. The weight-space view of Bayesian linear regression gives the same posterior through the push-through and Woodbury identities.
In practice: one Cholesky factorization (n3/6), two triangular solves, logdet=2∑ilogLii, a little jitter, hyperparameters in log space.
∂logp/∂θj=21tr((αα⊤−Ky−1)∂Ky/∂θj). Noise-free, the posterior standard deviation is the worst-case interpolation error over the RKHS unit ball, so ∣f−μ∣≤∥f∥Hσ.
Sparse variational GPs replace O(n3) by O(nm2) (Titsias) or O(m3) per mini-batch step (Hensman et al.); for the squared-exponential kernel with Gaussian inputs, O((logn)d) inducing points suffice. Infinitely wide Bayesian networks are GPs whose kernel is computed layer by layer.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
Question 1
In the proof of the conditioning formula, why is r=b−C⊤A−1a independent of a?
Because a and b are independent
Because r and a are uncorrelated and jointly Gaussian, and for jointly Gaussian vectors that implies independence
Because A is invertible
Because r has mean zero
Show the answer
B. Because r and a are uncorrelated and jointly Gaussian, and for jointly Gaussian vectors that implies independence
Cov(r,a)=C⊤−C⊤A−1A=0, and (r,a) is a linear transformation of a Gaussian vector. Zero correlation implies independence only in this jointly Gaussian case, which is why the posterior of a GP is again Gaussian.
Question 2
After the Cholesky factor L and the weights α are computed, what does each additional test input cost?
O(n3) for the mean and the variance, since the factorization must be redone
O(1) for both
O(n2) for the mean and O(n3) for the variance
O(n) for the mean (k∗⊤α) and O(n2) for the variance (the solve L\k∗)
Show the answer
D.O(n) for the mean (k∗⊤α) and O(n2) for the variance (the solve L\k∗)
The mean is a dot product of k∗ with the precomputed α. The variance needs v=L\k∗, a triangular solve costing O(n2). The O(n3) factorization is shared by all test inputs.
Question 3
A function has RKHS norm at most 2 for some kernel. A noise-free GP with that kernel, conditioned on its values at some points, has posterior standard deviation 0.1 at x. What can you guarantee?
∣f(x)−μ(x)∣≤0.2, with certainty
∣f(x)−μ(x)∣≤0.2 with probability about 95%
∣f(x)−μ(x)∣≤0.1, with certainty
Nothing, since f was not drawn from the GP
Show the answer
A.∣f(x)−μ(x)∣≤0.2, with certainty
∣f(x)−μ(x)∣=∣⟨f,hx⟩∣≤∥f∥H∥hx∥H=2×0.1. The worst-case reading of the posterior standard deviation needs no probabilistic assumption about f at all.
Question 4
Why can the inducing inputs Z of a sparse variational GP be optimized freely without overfitting?
Because there are fewer of them than data points
Because they are variational parameters: improving them tightens a lower bound on the marginal likelihood and moves the approximation toward the exact posterior, rather than changing the model
Because they are fixed at a random subset of the inputs
They do overfit, so they must be chosen on held-out data
Show the answer
B. Because they are variational parameters: improving them tightens a lower bound on the marginal likelihood and moves the approximation toward the exact posterior, rather than changing the model
In Titsias's formulation the prior is the exact GP; Z only parameterizes the approximating posterior. Maximizing the bound minimizes the KL divergence to the true posterior, so a better Z means a better approximation of a fixed model, not a more flexible model.
Further reading
C. E. Rasmussen & C. K. I. Williams, Gaussian Processes for Machine Learning (MIT Press, 2006), chapters 2, 5 and 8.
M. K. Titsias, "Variational learning of inducing variables in sparse Gaussian processes," Proceedings of AISTATS, PMLR 5, 567–574 (2009).
J. Hensman, N. Fusi & N. D. Lawrence, "Gaussian processes for big data," Proceedings of the Conference on Uncertainty in Artificial Intelligence (UAI) (2013).
R. M. Neal, Bayesian Learning for Neural Networks (Springer, 1996).
J. Lee, Y. Bahri, R. Novak, S. S. Schoenholz, J. Pennington & J. Sohl-Dickstein, "Deep neural networks as Gaussian processes," ICLR (2018).