S1434 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

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?

Name it

The prior

A Gaussian process f∼𝒢𝒫(0,k) says that for any inputs x1,…,xN the values f(xn) are jointly Gaussian with zero mean and covariance Knm=k(xn,xm). The squared-exponential kernel

k(x,x′)=σf2exp⁡(−(x−x′)22ℓ2)

gives smooth functions of typical size σf that vary over a distance ℓ: values a distance d apart have correlation e−d2/2ℓ2, falling to r at d=ℓ−2ln⁡r.

The posterior

Observations tn=f(xn)+ϵn with noise variance σn2 have covariance C=K+σn2I. At a new input with covariances 𝐤* to the data,

μ(x)=𝐤*TC−1𝐭,σ2(x)=k(x,x)−𝐤*TC−1𝐤*

For one observation: μ=k(x,x1)t1/(σf2+σn2) and σ2=σf2−k(x,x1)2/(σf2+σn2). The mean is exactly kernel ridge regression with λ=σn2.

Hyperparameters

ℓ, σf and σn are chosen by maximizing the marginal likelihood of the data,

ln⁡p(𝐭)=−12𝐭TC−1𝐭−12ln⁡|C|−N2ln⁡2π

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 N3/3 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
  1. At x = 0. σ2=1−12/1.1=0.0909 so σ = 0.302, below the noise's 0.316, because it describes f itself; a new noisy reading would add the noise variance back.
  2. At x = 1. σ2=1−0.3679/1.1=0.666 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 σf2 = 1).

Show the solution
  1. Noise variance 0.1. With C = 1.1: ln⁡p=−1/2.2−12ln⁡1.1−12ln⁡2π=−0.4545−0.0477−0.9189=−1.421
  2. Noise variance 1. With C = 2: ln⁡p=−0.250−0.347−0.919=−1.516
  3. 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 σf = 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
  1. Kernel values. k(0,2)=e−2=0.135k(1,0)=k(1,2)=e−1/2=0.607
  2. Mean. By symmetry the two observations get equal weight 1/(1.01+0.135), so μ=2×0.607/1.145=1.06 a little above both observations: the two together are evidence for a function staying near 1 throughout.
  3. Variance. Since 0.6072=e−1: σ2=1−2e−11.01+e−2=0.358 a standard deviation of 0.60.
  4. 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 σf = 2 and ℓ = 0.5. What's the covariance of two function values 2 apart?

Check

A Gaussian process with σf = 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 (σf = 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 (σf = 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 σf = 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°.

Explain why

How does a Gaussian process decide how confident to be at a new input?

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.