Technopedia

The technologist’s encyclopedia

Gaussian processes

A Gaussian process is a stochastic process (Xt)t∈T(X_t)_{t \in T} in which every finite subfamily is jointly Gaussian. It is the “Gaussian” way to put a probability distribution on an entire function: instead of a random variable taking values in R\mathbb{R}, you get a random function f:T→Rf : T \to \mathbb{R}, and the only ingredients you must supply are a mean function m(t)=E[Xt]m(t) = \mathbb{E}[X_t] and a covariance kernel k(s,t)=Cov(Xs,Xt)k(s,t) = \mathrm{Cov}(X_s, X_t).

Gaussian processes are relevant whenever you want a distribution over functions with honest uncertainty: interpolating sparse spatial measurements (geostatistics / kriging), fitting a regression model that reports a calibrated error bar at every input (machine learning), or searching for the optimum of an expensive black-box function (Bayesian optimization). They are the natural tool whenever the answer you want is a curve or a field, not a single number.

Authoritative sources

Definition (cheatsheet)

The covariance kernel and positive-definiteness

Definition. A function k:T×T→Rk : T \times T \to \mathbb{R} is a valid covariance kernel if it is symmetric and positive semi-definite (PSD): for every nn, every choice of points t1,…,tn∈Tt_1,\dots,t_n \in T, and every real vector (ci)(c_i),

∑i=1n∑j=1nci cj k(ti,tj)  ≥  0.\sum_{i=1}^{n}\sum_{j=1}^{n} c_i\, c_j\, k(t_i, t_j) \;\geq\; 0.

PSD is exactly the condition that makes (k(ti,tj))(k(t_i,t_j)) a legitimate covariance matrix for every finite set of points, so that a Gaussian process with that kernel actually exists.

Details

Why PSD is the right condition. A covariance matrix KK of any random vector must satisfy Var(∑iciXi)=∑i,jcicjKij≥0\mathrm{Var}\big(\sum_i c_i X_i\big) = \sum_{i,j} c_i c_j K_{ij} \geq 0, because a variance is never negative. So PSD is not an extra assumption — it is precisely the requirement that kk can be the covariance of some Gaussian vector at every finite set of points. Conversely, if kk is PSD, the Kolmogorov extension theorem guarantees a Gaussian process with that kernel.

Worked check — a kernel that passes. Take k(s,t)=min⁡(s,t)k(s,t) = \min(s,t) on [0,∞)[0,\infty) (the Brownian kernel). For ordered points 0≤t1<⋯<tn0 \le t_1 < \cdots < t_n, the matrix Kij=min⁡(ti,tj)K_{ij} = \min(t_i,t_j) is exactly the covariance matrix of the vector (Wt1,…,Wtn)(W_{t_1},\dots,W_{t_n}) of a Brownian motion, so it is PSD by construction. Concretely, for two points s<ts<t, K=(ssst)K = \begin{pmatrix} s & s \\ s & t \end{pmatrix} has determinant st−s2=s(t−s)≥0st - s^2 = s(t-s) \geq 0 and positive trace, hence PSD.

Worked check — a candidate that fails. Consider the tempting candidate k(s,t)=s2+t2k(s,t) = s^2 + t^2. At the two points s=1,t=2s=1, t=2 it gives the matrix

K=(12+1212+2212+2222+22)=(2558),K = \begin{pmatrix} 1^2+1^2 & 1^2+2^2 \\ 1^2+2^2 & 2^2+2^2 \end{pmatrix} = \begin{pmatrix} 2 & 5 \\ 5 & 8 \end{pmatrix},

whose determinant is 2⋅8−52=16−25=−9<02\cdot 8 - 5^2 = 16 - 25 = -9 < 0. A 2×22\times 2 symmetric matrix with negative determinant has a negative eigenvalue, so it is not PSD. Indeed, with c=(−1.77, 1)c = (-1.77,\, 1) one gets c⊤Kc≈−3.4<0c^{\top} K c \approx -3.4 < 0. The candidate s2+t2s^2+t^2 is therefore not a valid kernel: it cannot be the covariance of any random process. (The fix is to use a product s ts\,t, which is rank-one and PSD, since ∑i,jcicjsitj=(∑icisi)2≥0\sum_{i,j} c_i c_j s_i t_j = \big(\sum_i c_i s_i\big)^2 \geq 0.)

Example problem

Is k(s,t)=1+stk(s,t) = 1 + s t a valid kernel on R\mathbb{R}?

Solution

Yes. Write k(s,t)=1+st=1⋅1+s⋅tk(s,t) = 1 + s t = 1\cdot 1 + s\cdot t, a sum of two rank-one PSD kernels: the constant kernel 11 (PSD because ∑i,jcicj=(∑ici)2≥0\sum_{i,j} c_i c_j = (\sum_i c_i)^2 \geq 0) and the product kernel sts t (PSD as shown above). A non-negative linear combination of PSD kernels is PSD, so 1+st1 + st is a valid kernel.

Why the kernel is everything: Gaussianity collapses the specification

Definition. A general stochastic process is specified by all of its finite-dimensional distributions (infinitely many objects). A Gaussian process is specified by only two functions — the mean mm and the kernel kk — because a multivariate normal distribution is completely determined by its mean vector and covariance matrix.

Details

The global idea. For an arbitrary process, knowing the law of (Xt1,Xt2)(X_{t_1}, X_{t_2}) tells you nothing about the law of (Xt1,Xt2,Xt3)(X_{t_1}, X_{t_2}, X_{t_3}); you must specify each finite-dimensional distribution separately, and they must all be mutually consistent. For a Gaussian process this burden vanishes: the joint law of any finite subfamily is a multivariate normal, and a multivariate normal N(μ,Σ)\mathcal{N}(\mu, \Sigma) has no free parameters beyond μ\mu and Σ\Sigma. So once you fix mm and kk, every finite-dimensional distribution is forced, and consistency is automatic.

Concrete example. Suppose T={1,2,3}T = \{1, 2, 3\}. To fully specify a general process on these three points you would need: three one-dimensional laws, three two-dimensional joint laws, and one three-dimensional joint law, all consistent with each other. To specify a Gaussian process on the same three points you need only 33 numbers (the means m(1),m(2),m(3)m(1),m(2),m(3)) and a 3×33\times 3 symmetric PSD matrix (the kernel values k(i,j)k(i,j)). That is the entire specification.

The payoff. Because the whole law is pinned down by mm and kk, every question about the process — its conditional distributions, its sample-path smoothness, its predictions — reduces to manipulating the single function kk. The next two sections are the two most important consequences: conditioning (GP regression) and regularity.

Example problem

A Gaussian process on T={a,b}T=\{a,b\} has m(a)=m(b)=0m(a)=m(b)=0, Var(Xa)=Var(Xb)=1\mathrm{Var}(X_a)=\mathrm{Var}(X_b)=1, and Cov(Xa,Xb)=ρ\mathrm{Cov}(X_a,X_b)=\rho. What is the joint density of (Xa,Xb)(X_a, X_b), and for which ρ\rho is it a valid Gaussian process?

Solution

The joint law is the bivariate normal N(0,(1ρρ1))\mathcal{N}\big(\mathbf{0}, \begin{pmatrix} 1 & \rho \\ \rho & 1 \end{pmatrix}\big), with density

f(x,y)=12π1−ρ2exp⁡ ⁣(−x2−2ρxy+y22(1−ρ2)).f(x,y) = \frac{1}{2\pi\sqrt{1-\rho^2}} \exp\!\left( -\frac{x^2 - 2\rho x y + y^2}{2(1-\rho^2)} \right).

It is a valid Gaussian process exactly when the covariance matrix is PSD, i.e. when its determinant 1−ρ2≥01-\rho^2 \geq 0, so ∣ρ∣≤1|\rho| \leq 1. This is the two-point shadow of the PSD condition from the previous section.

Common kernels

Definition. A small family of kernels generates most applications. Each is controlled by an amplitude σ2\sigma^2 and a length-scale ℓ>0\ell > 0 that sets the distance over which values stay correlated:

KernelFormula k(s,t)Sample paths
Brownian (random walk)σ² min(s,t)continuous, nowhere differentiable
Ornstein–Uhlenbeckσ² e−|s−t|/ℓcontinuous, nowhere differentiable
Matérn (ν)(σ²/Γ(ν)) · (√2·|s−t|/ℓ)ν · Kν(√2·|s−t|/ℓ)ν−1 times differentiable
Squared-exponential (RBF)σ² e−(s−t)²/2ℓ²infinitely differentiable

The length-scale ℓ\ell is the single most important knob: a small ℓ\ell makes the kernel decay fast, so values far apart are nearly independent and the function looks wiggly; a large ℓ\ell keeps values correlated over long distances, so the function looks smooth.

Details

Reading smoothness off the decay. The figure below plots k(0,t)k(0,t) (correlation with the origin) against distance tt for three kernels with the same ℓ=0.5\ell = 0.5. The squared-exponential curve leaves the origin flat (its derivative at t=0t=0 is 00), the Matérn curve leaves with a corner, and the Ornstein–Uhlenbeck curve falls off as a pure exponential. That difference in local shape is exactly what shows up in the sample paths: flat departure gives smooth paths, a corner gives continuous-but-rough paths.

t 1 0 correlation k(0,t) vs distance t, ℓ = 0.5 squared-exponential Matérn (ν = 3/2) Ornstein–Uhlenbeck

The Matérn family as a dial. The Matérn kernel interpolates between the two extremes: for ν=1/2\nu = 1/2 it reduces exactly to the Ornstein–Uhlenbeck kernel σ2e−∣s−t∣/ℓ\sigma^2 e^{-|s-t|/\ell}, for ν=3/2\nu = 3/2 to σ2(1+∣s−t∣/ℓ) e−∣s−t∣/ℓ\sigma^2(1 + |s-t|/\ell)\, e^{-|s-t|/\ell}, and as ν→∞\nu \to \infty it approaches the squared-exponential kernel. The parameter ν\nu controls the number of continuous derivatives of the sample paths (see the regularity section).

Example problem

Two models of a temperature field use the same amplitude but length-scales ℓ=1\ell = 1 km and ℓ=10\ell = 10 km (squared-exponential kernel). Which model predicts that two stations 5 km apart are more strongly correlated, and why?

Solution

The ℓ=10\ell = 10 km model. The squared-exponential correlation at distance dd is e−d2/2ℓ2e^{-d^2/2\ell^2}. At d=5d = 5 km this is e−25/2e^{-25/2} for ℓ=1\ell = 1 (≈ 3×10−63\times 10^{-6}, essentially uncorrelated) but e−25/200e^{-25/200} for ℓ=10\ell = 10 (≈ 0.880.88, strongly correlated). A larger length-scale stretches the correlation over longer distances, so nearby stations stay correlated.

GP regression (kriging)

Definition. Given a GP prior f∼GP(m,k)f \sim \mathcal{GP}(m, k) and noiseless observations yi=f(ti)y_i = f(t_i) at points t1,…,tnt_1,\dots,t_n, the posterior at a new point t0t_0 is again Gaussian. Writing Kij=k(ti,tj)K_{ij} = k(t_i,t_j), k∗=(k(t0,t1),…,k(t0,tn))⊤k_* = (k(t_0,t_1),\dots,k(t_0,t_n))^{\top}, y=(y1,…,yn)⊤y = (y_1,\dots,y_n)^{\top} and m=(m(t1),…,m(tn))⊤m = (m(t_1),\dots,m(t_n))^{\top}, the posterior mean and posterior variance are

m∗(t0)  =  m(t0)+k∗⊤ K−1(y−m),σ∗2(t0)  =  k(t0,t0)−k∗⊤ K−1 k∗.m_*(t_0) \;=\; m(t_0) + k_*^{\top}\, K^{-1}\big(y - m\big), \qquad \sigma_*^2(t_0) \;=\; k(t_0,t_0) - k_*^{\top}\, K^{-1}\, k_* .

With independent observation noise of variance σn2\sigma_n^2, replace KK by K+σn2IK + \sigma_n^2 I in both formulas. This is kriging in geostatistics and Gaussian-process regression in machine learning.

Details

The global idea. Conditioning a multivariate normal is pure linear algebra: the conditional distribution of one component given the others is Gaussian, with mean and covariance given by block-matrix formulas. Because a GP is just a (possibly infinite) multivariate normal, conditioning the function ff on its values at the observed points is the same computation, and the answer is again a GP — the posterior GP — whose mean and kernel are the two formulas above. The posterior mean is a weighted average of the observations (the weights are k∗⊤K−1k_*^{\top}K^{-1}), and the posterior variance is the prior variance k(t0,t0)k(t_0,t_0) minus the information the observations carry about t0t_0.

Why the variance shrinks near the data. The term k∗⊤K−1k∗k_*^{\top}K^{-1}k_* measures how correlated t0t_0 is with the observed points. If t0t_0 coincides with an observed point, k∗k_* is a row of KK and the variance becomes exactly 00 (noiseless case): you already know the value there. Far from the data, k∗k_* is small and the variance returns to the prior k(t0,t0)k(t_0,t_0). This “tighten around the data, relax away from it” behavior is the whole point of the method.

Numeric example (Brownian kernel). Let m≡0m \equiv 0 and k(s,t)=min⁡(s,t)k(s,t) = \min(s,t). Observe y1=1y_1 = 1 at t1=1t_1 = 1 and y2=3y_2 = 3 at t2=4t_2 = 4, and predict at t0=2t_0 = 2.

K=(1114),k∗=(12),k(t0,t0)=2,K−1=13(4−1−11).K = \begin{pmatrix} 1 & 1 \\ 1 & 4 \end{pmatrix},\quad k_* = \begin{pmatrix} 1 \\ 2 \end{pmatrix},\quad k(t_0,t_0) = 2,\quad K^{-1} = \tfrac{1}{3}\begin{pmatrix} 4 & -1 \\ -1 & 1 \end{pmatrix}.

Then K−1y=13(1,2)⊤K^{-1}y = \tfrac{1}{3}(1, 2)^{\top}, so

m∗(2)=k∗⊤K−1y=(1,2)⋅13(1,2)⊤=13+43=53≈1.67,m_*(2) = k_*^{\top}K^{-1}y = (1,2)\cdot\tfrac{1}{3}(1,2)^{\top} = \tfrac{1}{3} + \tfrac{4}{3} = \tfrac{5}{3} \approx 1.67, σ∗2(2)=2−k∗⊤K−1k∗=2−(1,2)⋅13(1,2)⊤=2−53=13≈0.33.\sigma_*^2(2) = 2 - k_*^{\top}K^{-1}k_* = 2 - (1,2)\cdot\tfrac{1}{3}(1,2)^{\top} = 2 - \tfrac{5}{3} = \tfrac{1}{3} \approx 0.33.

So the model predicts f(2)≈1.67f(2) \approx 1.67 with standard deviation 1/3≈0.58\sqrt{1/3} \approx 0.58. As a sanity check, predicting at the observed point t0=1t_0 = 1 gives k∗=(1,1)⊤k_* = (1,1)^{\top} and σ∗2(1)=1−(1,1)⋅13(3,0)⊤=1−1=0\sigma_*^2(1) = 1 - (1,1)\cdot\tfrac{1}{3}(3,0)^{\top} = 1 - 1 = 0, exactly as it must.

The interactive simulation below shows this in action: a hidden smooth function is sampled from a GP, a few points are observed, and the posterior mean with its ±2σ∗\pm 2\sigma_* confidence band is drawn. Add observations to watch the band tighten around the data and relax between them.

Example problem

A noiseless GP has zero mean and kernel k(s,t)=min⁡(s,t)k(s,t) = \min(s,t). You observe f(1)=2f(1) = 2. What is the posterior mean and variance of f(4)f(4)?

Solution

With a single observation, K=[1]K = [1], k∗=[min⁡(4,1)]=[1]k_* = [\min(4,1)] = [1], k(4,4)=4k(4,4) = 4, and y=[2]y = [2]. The posterior mean is m∗(4)=k∗K−1y=1⋅1⋅2=2m_*(4) = k_* K^{-1} y = 1 \cdot 1 \cdot 2 = 2, and the posterior variance is σ∗2(4)=4−k∗K−1k∗=4−1=3\sigma_*^2(4) = 4 - k_* K^{-1} k_* = 4 - 1 = 3. Intuitively, f(4)=f(1)+(f(4)−f(1))f(4) = f(1) + (f(4)-f(1)) with an independent increment of variance 4−1=34-1 = 3, so the prediction is the observed value plus an uncertainty of 3\sqrt{3}.

Sample-path regularity

Definition. The smoothness of a GP’s sample paths is read off the kernel through the Kolmogorov continuity criterion: if there exist constants α>0\alpha > 0, β>0\beta > 0, C<∞C < \infty such that

E[ ∣Xt−Xs∣α]  ≤  C ∣t−s∣1+βfor all s,t,\mathbb{E}\big[\,|X_t - X_s|^{\alpha}\big] \;\leq\; C\,|t - s|^{1+\beta} \qquad \text{for all } s, t,

then the process admits a continuous modification. For a GP with Var(Xt)=σ2\mathrm{Var}(X_t) = \sigma^2 constant, take α=2\alpha = 2 and the left side is Var(Xt−Xs)=2(σ2−k(s,t))\mathrm{Var}(X_t - X_s) = 2\big(\sigma^2 - k(s,t)\big), so continuity follows from how fast σ2−k(s,t)\sigma^2 - k(s,t) shrinks as s→ts \to t.

Details

The global idea. The criterion says: if the expected size of an increment over a small gap ∣t−s∣|t-s| is smaller than the gap itself (raised to a power >1> 1), the paths must be continuous. For a Gaussian process the increment Xt−XsX_t - X_s is Gaussian, so its typical size is its standard deviation Var(Xt−Xs)\sqrt{\mathrm{Var}(X_t-X_s)}. The question “are the paths continuous?” becomes “does Var(Xt−Xs)\mathrm{Var}(X_t - X_s) go to zero faster than ∣t−s∣|t-s|?”

Concrete examples, from the kernel table.

The figure below shows one sample path of a smooth GP (squared-exponential kernel): a single continuous, differentiable random curve.

t f(t) one sample path, squared-exponential kernel (smooth, differentiable)
Example problem

A GP has constant variance σ2=1\sigma^2 = 1 and, near the diagonal, 1−k(s,t)≈∣t−s∣3/21 - k(s,t) \approx |t-s|^{3/2}. Are its sample paths continuous? Differentiable?

Solution

The increment variance is Var(Xt−Xs)=2(1−k(s,t))≈2∣t−s∣3/2\mathrm{Var}(X_t - X_s) = 2(1 - k(s,t)) \approx 2|t-s|^{3/2}. With α=2\alpha = 2 the Kolmogorov criterion needs E∣Xt−Xs∣2≤C∣t−s∣1+β\mathbb{E}|X_t-X_s|^2 \le C|t-s|^{1+\beta}; here the exponent is 3/2=1+1/23/2 = 1 + 1/2, so β=1/2>0\beta = 1/2 > 0 and the paths are continuous. For differentiability the increment would need to shrink faster than ∣t−s∣|t-s| in a stronger sense (roughly 1−k∼∣t−s∣2+β1-k \sim |t-s|^{2+\beta}); since 3/2<23/2 < 2, the paths are not differentiable. This is the same borderline logic as Brownian motion, which has 1−k∼∣t−s∣1-k \sim |t-s|.

Applications

Quizz

Example problem

A noiseless Gaussian process has zero mean and the squared-exponential kernel k(s,t)=e−(s−t)2/2k(s,t) = e^{-(s-t)^2/2} (so ℓ=1\ell = 1). You observe f(0)=1f(0) = 1 and f(2)=1f(2) = 1.

  1. Write down the 2×22\times 2 kernel matrix KK and the vector k∗k_* for predicting at t0=1t_0 = 1.
  2. Explain, without computing, whether the posterior variance at t0=1t_0 = 1 is larger or smaller than the posterior variance at t0=10t_0 = 10, and why.
How to solve it

Part 1. The kernel values are k(0,0)=k(2,2)=e0=1k(0,0) = k(2,2) = e^0 = 1 and k(0,2)=k(2,0)=e−4/2=e−2k(0,2) = k(2,0) = e^{-4/2} = e^{-2}. So

K=(1e−2e−21),k∗=(k(1,0)k(1,2))=(e−1/2e−1/2).K = \begin{pmatrix} 1 & e^{-2} \\ e^{-2} & 1 \end{pmatrix}, \qquad k_* = \begin{pmatrix} k(1,0) \\ k(1,2) \end{pmatrix} = \begin{pmatrix} e^{-1/2} \\ e^{-1/2} \end{pmatrix}.

Part 2. The posterior variance is σ∗2(t0)=k(t0,t0)−k∗⊤K−1k∗=1−k∗⊤K−1k∗\sigma_*^2(t_0) = k(t_0,t_0) - k_*^{\top}K^{-1}k_* = 1 - k_*^{\top}K^{-1}k_*. The subtracted term measures how correlated t0t_0 is with the observed points. At t0=1t_0 = 1 the point sits exactly halfway between the two observations, so k∗k_* has large entries (e−1/2≈0.61e^{-1/2} \approx 0.61) and the variance is reduced a lot. At t0=10t_0 = 10 the point is far from both observations, so k∗k_* has tiny entries (e−20e^{-20}) and almost nothing is subtracted — the variance is close to the prior value 11. Therefore the posterior variance at t0=1t_0 = 1 is smaller than at t0=10t_0 = 10: the confidence band is tight where the data are and wide where they are not.