S14 · Lesson 34 · Gaussian processes
A prior placed directly on functions, the squared-exponential covariance and its length scale, the posterior mean and variance after noisy observations, choosing hyperparameters by the marginal likelihood, and the link to kernel ridge and Bayesian regression
Lesson 10 put a Gaussian prior on a model's weights and got error bars on its predictions. A Gaussian process skips the weights and puts the prior directly on the function: any finite set of function values is jointly Gaussian, with a covariance given by a kernel. Conditioning on data then uses nothing but lesson 8's Gaussian conditioning. The result is a flexible regression method that says how sure it is everywhere, and it's the engine behind Bayesian optimization, which tunes everything from circuit parameters to neural network hyperparameters with as few expensive evaluations as possible.
- A Gaussian process with a squared-exponential kernel (length scale ℓ, prior variance 1) conditioned on two noisy observations, at x = −1 and x = 1.5.
- Near the data the band narrows to about the noise; far away it relaxes to the prior's ±2.
- Short length scales let the function wiggle and forget the data quickly; long ones tie the two points together into one smooth curve.
Predict
A Gaussian process with prior variance 1, length scale 1 and noise variance 0.1 observes f(0) = 1. What's its posterior mean at x = 1?
The covariance between f(1) and the observation is = 0.607, and the observation's variance is 1 + 0.1. Gaussian conditioning gives a mean of 0.607 × 1/1.1 = 0.551. At x = 0 itself the mean is 1/1.1 = 0.909, pulled slightly toward the prior's 0 by the noise.
Name it
The prior
A Gaussian process says that for any inputs the values are jointly Gaussian with zero mean and covariance . The squared-exponential kernel
gives smooth functions of typical size that vary over a distance ℓ: values a distance d apart have correlation , falling to r at .
The posterior
Observations with noise variance have covariance . At a new input with covariances to the data,
For one observation: and . The mean is exactly kernel ridge regression with .
Hyperparameters
ℓ, and are chosen by maximizing the marginal likelihood of the data,
whose first term rewards fitting the data and second penalizes a flexible model, an automatic Occam's razor.
Cost
Training needs a solve with the N × N matrix C, about operations by Cholesky factorization, which limits exact Gaussian processes to tens of thousands of points.
Worked example
For the predict question's setup, find the posterior standard deviation at x = 0 and at x = 1.
Show the solution
- At x = 0. so σ = 0.302, below the noise's 0.316, because it describes f itself; a new noisy reading would add the noise variance back.
- At x = 1. so σ = 0.816, most of the way back to the prior's 1.
Answer the posterior standard deviation is 0.302 at x = 0 and 0.816 at x = 1.
Worked example
Compare the log marginal likelihood of the single observation t = 1 under noise variances 0.1 and 1 (with = 1).
Show the solution
- Noise variance 0.1. With C = 1.1:
- Noise variance 1. With C = 2:
- Compare. The quieter model explains the data slightly better; with more data the comparison sharpens.
Answer the log marginal likelihood is −1.421 with noise variance 0.1 and −1.516 with noise variance 1, so the quieter model fits slightly better.
Worked example
A Gaussian process with = 1, ℓ = 1 and noise variance 0.01 observes t = 1 at x = 0 and at x = 2. What does it predict at x = 1, halfway between?
Show the solution
- Kernel values.
- Mean. By symmetry the two observations get equal weight , so a little above both observations: the two together are evidence for a function staying near 1 throughout.
- Variance. Since : a standard deviation of 0.60.
- Why it's wide. It's far larger than at the observations because one length scale away the correlation has fallen to 0.6.
Answer at x = 1 it predicts a mean of 1.06 with a standard deviation of 0.60.
Check
A squared-exponential kernel has = 2 and ℓ = 0.5. What's the covariance of two function values 2 apart?
Check
A Gaussian process with = 1, length scale 2 and noise variance 0.5 observes 0.5 at one point. What's its posterior mean 0.5 away?
Check
For that process ( = 1, ℓ = 1, noise variance 0.5, one observation), what's the posterior variance 0.5 away?
Check
A process with prior variance 1² observes a point with noise variance 0.1. What's the posterior variance of f at that same point?
Check
A single observation 0.5 has total variance C = 0.5 under a model. What's its log marginal likelihood?
Check
A squared-exponential process has length scale 2. At what separation does the correlation between function values fall to 0.1?
Check
A Gaussian process ( = 1, length scale 0.5, noise variance 0.1) observes the same value 2 at x = 0 and x = 2.
(a)
What mean does it predict halfway between?
(b)
What standard deviation?
Check
A Gaussian process with = 1, length scale ℓ and noise variance σ² has one observation t; predict at distance d from it.
Step 1
What is the prior correlation between the two points' function values?
Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.
Step 2
What is the predictive mean?
Step 3
What is the predictive variance of the function value?
Explain why
How does a Gaussian process decide how confident to be at a new input?
The process treats the unknown function's values at the new input and at the training inputs as jointly Gaussian, with covariances set by the kernel according to how far apart the inputs are. Conditioning on the observed values removes the part of the new value's variance that the observations can explain. If the new input is close to training points, its value is strongly correlated with theirs, so most of the prior variance is explained and the posterior is narrow; if it's far away, the correlations are weak, little variance is removed, and the band relaxes to the prior's. The noise level limits how much any single observation can explain, so even at a training point some uncertainty remains.
Practice
Keep practicing
10 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.