Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Where the GP formulas come from
A Gaussian process says: before seeing data, any handful of function values is jointly Gaussian, with correlations set by how close the inputs are. Seeing some values then simply narrows the bell curve over the others, exactly as knowing one sensor’s reading narrows your guess of a correlated sensor. All of GP regression is one formula for that narrowing. The same answer also comes out if you think of the function as a weighted sum of many bumps with random weights and do ordinary Bayesian regression on the weights. In the demo, click to add points and watch the band shrink near them and return to the prior far away.
Knowing the derivation tells you what the error bars mean: they are honest exactly when the kernel and noise are right. That is the difference between a terrain map you can plan on and one that drives a rover into soft sand.
- 1. GP regression is, at heart,…
- 2. The weight-space view treats a GP as…
- 3. Far from the data the predictive band…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.Two derivations
- Weight space. f(x) = φ(x)ᵀw with prior w ~ N(0, Σ_p) and noise y = f + ε, ε ~ N(0, σ²).
- Posterior: w | y ~ N(A⁻¹Φᵀy/σ², A⁻¹) with A = ΦᵀΦ/σ² + Σ_p⁻¹ (rows of Φ are φ(x_i)ᵀ).
- Prediction: f* | y ~ N(φᵀA⁻¹Φᵀy/σ², φᵀA⁻¹φ*).
- Only inner products φ(x)ᵀΣ_pφ(x′) = k(x, x′) appear after the matrix inversion lemma, so any positive-definite kernel can replace the features (Mercer).
- Function space. Prior f ~ GP(0, k). Then [y; f*] ~ N(0, [[K + σ²I, K*], [K*ᵀ, K**]]).
- Gaussian conditioning (Schur complement): f̄ = Kᵀ(K + σ²I)⁻¹y** and cov(f) = K* − Kᵀ(K + σ²I)⁻¹K**.
- A noisy test output y* has variance cov(f*) + σ².
- One observation, by hand. RBF kernel, ℓ = 1, σ_f = 1, σ² = 0.01, y = 2 at x = 0. At x* = 1, k* = e^(−1/2) = 0.607:
- mean = 0.607 / 1.01 × 2 = 1.201; variance = 1 − 0.607² / 1.01 = 0.636 (sd 0.797).
- At the observation the sd is 0.10; five lengthscales away it is back to 1.
- Properties you can read off:
- The mean is a linear smoother: f̄ = Hy with H = K(K + σ²I)⁻¹, and α = (K + σ²I)⁻¹y gives f̄(x) = Σ α_i k(x, x_i).
- The variance never depends on y, only on where you measured.
- Effective degrees of freedom tr(H) = Σ λ_i / (λ_i + σ²): 5 independent unit-variance points with σ² = 1 use 2.5.
- Leave-one-out for free: with C = K + σ²I, μ₋ᵢ = y_i − [C⁻¹y]_i / [C⁻¹]_ii and σ²₋ᵢ = 1/[C⁻¹]_ii (Rasmussen and Williams, 2006, §5.4.2).
- 1. The GP posterior mean is…
- 2. The predictive variance of a noisy test output adds…
- 3. Leave-one-out predictions need…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Computing it stably
Exercise 1.
- Prediction from kernel blocks with one Cholesky factor.
- The weight-space prediction, checked equal to the function-space one when k = φᵀΣφ.
- Closed-form leave-one-out predictions, checked against refitting.
Practice.
- Never form (K + σ²I)⁻¹: factor L = chol(K + σ²I), then α = solve(Lᵀ, solve(L, y)) and v = solve(L, K*) with triangular solves; mean K*ᵀα, variance k** − vᵀv.
- log|K + σ²I| = 2 Σ log L_ii; never compute det() directly.
- Add jitter (1e-6 times the signal variance) when σ² is tiny or inputs repeat; work in float64.
- Standardize y (subtract the mean, divide by the sd) or use a constant mean; scale inputs so lengthscales are order 1.
- Report noisy predictive intervals for future measurements and latent ones for the underlying field.
- Libraries: GPyTorch (2018), GPflow, scikit-learn’s GaussianProcessRegressor, BoTorch for Bayesian optimization.
import numpy as np
from scipy.linalg import cho_factor, cho_solve, solve_triangular
def gp_predict(X, y, Xs, k, sn2):
L = np.linalg.cholesky(k(X, X) + sn2 * np.eye(len(X)))
alpha = cho_solve((L, True), y)
Ks = k(X, Xs); v = solve_triangular(L, Ks, lower=True)
mean = Ks.T @ alpha
var_f = np.diag(k(Xs, Xs)) - np.sum(v ** 2, 0) # latent function
return mean, var_f, var_f + sn2 # noisy observation
# scikit-learn: GaussianProcessRegressor(kernel=RBF(1.0) + WhiteKernel(0.01), normalize_y=True)- 1. log|K + σ²I| is computed as…
- 2. Jitter is added to…
- 3. Before fitting, y is usually…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Conditioning (Schur complement). If [a; b] ~ N(0, [[A, C], [Cᵀ, B]]) then b | a ~ N(CᵀA⁻¹a, B − CᵀA⁻¹C). Proof: the vector b − CᵀA⁻¹a is uncorrelated with a (cov = Cᵀ − CᵀA⁻¹A = 0), hence independent since they are jointly Gaussian; its covariance is B − CᵀA⁻¹C. With a = y, A = K + σ²I, C = K*, B = K** this is the GP predictive.
Weight space equals function space. The matrix inversion lemma gives A⁻¹Φᵀ/σ² = Σ_pΦᵀ(ΦΣ_pΦᵀ + σ²I)⁻¹. So the weight-space mean is φᵀΣ_pΦᵀ(K + σ²I)⁻¹y = Kᵀ(K + σ²I)⁻¹y with K = ΦΣ_pΦᵀ; the covariance identity follows the same way. The function-space form costs O(n³) instead of O(D³) in the number of features, which is what makes infinitely many features usable.
Leave-one-out. Partition C⁻¹ by the block inverse formula: the predictive precision of y_i given the rest is [C⁻¹]_ii, and its mean is y_i − [C⁻¹y]_i / [C⁻¹]_ii. All n LOO predictions come from one inverse (O(n³)), as for kernel ridge regression.
In what sense the error bars are right. If f really is drawn from the GP prior and the noise is right, then y* | y has exactly the predictive distribution, so z = (y* − μ*)/σ* is N(0, 1) when averaged over functions and noise. For one fixed function there is no such guarantee; frequentist coverage of GP credible sets holds only under conditions on the function’s smoothness relative to the kernel (Szabó, van der Vaart and van Zanten, 2015). Exercise 2 shows the failure modes: too smooth a prior (long ℓ, RBF for rough data) is overconfident, too rough a prior is underconfident.
- 1. b − CᵀA⁻¹a is independent of a because…
- 2. The weight-space and function-space forms agree by…
- 3. GP error bars are exactly calibrated when…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.How calibrated are GP error bars when the kernel or its lengthscale is wrong?
History.
- D. Krige (1951) and G. Matheron (1963): kriging, GP prediction for mining and geostatistics.
- A. O’Hagan, “Curve fitting and optimal design for prediction” (1978).
- C. Williams and C. Rasmussen, “Gaussian processes for regression” (1996); R. Neal, Bayesian Learning for Neural Networks (1996).
- C. Rasmussen and C. Williams, Gaussian Processes for Machine Learning (2006).
Exercise 2. 30 inputs uniform on [0, 10]; 500 functions drawn from a true GP with lengthscale 1 (either RBF, smooth, or Matérn-1/2, rough), noise sd 0.1. Each is fitted with an RBF model with ℓ = 0.3, 1 or 3 and with a Matérn-1/2 model with ℓ = 1 (σ_f and σ_n always correct). Measures on 100 test points inside [0, 10] and 20 extrapolation points in [10, 12]: coverage of 95% predictive intervals, mean z² (1 if calibrated), RMSE and NLPD.
| truth | model | coverage inside | coverage outside | mean z² inside | RMSE inside | NLPD inside |
|---|---|---|---|---|---|---|
| RBF | RBF, ℓ = 0.3 | 0.985 | 0.964 | 0.57 | 0.293 | 0.008 |
| RBF | RBF, ℓ = 1 (correct) | 0.950 | 0.961 | 0.99 | 0.127 | −0.654 |
| RBF | RBF, ℓ = 3 | 0.471 | 0.256 | 11.05 | 0.366 | 4.233 |
| RBF | Matérn-1/2, ℓ = 1 | 0.999 | 0.978 | 0.19 | 0.176 | 0.113 |
| Matérn-1/2 | RBF, ℓ = 0.3 | 0.783 | 0.929 | 2.83 | 0.554 | 1.135 |
| Matérn-1/2 | RBF, ℓ = 1 | 0.395 | 0.593 | 16.66 | 0.533 | 7.178 |
| Matérn-1/2 | RBF, ℓ = 3 | 0.277 | 0.2 | 34.07 | 0.641 | 15.743 |
| Matérn-1/2 | Matérn-1/2, ℓ = 1 (correct) | 0.950 | 0.946 | 1.0 | 0.47 | 0.521 |
- Correct assumptions give exact calibration, as the derivation promises: 0.950 coverage and mean z² ≈ 1 for both truths, and the best RMSE and NLPD.
- Too smooth is dangerous: a lengthscale 3 times too long, or an RBF kernel on rough functions, gives intervals covering 20–47% of points, worst when extrapolating; the model is confidently wrong.
- Too rough is safe but wasteful: ℓ = 0.3 or a Matérn-1/2 kernel on smooth functions over-cover (98.5–99.9%) and lose accuracy (RMSE 0.293 and 0.176 vs 0.127).
- Seeds 1 and 2: correct models covered 0.95 inside in all cases; RBF with ℓ = 3 covered 0.457 and 0.477; RBF ℓ = 1 on Matérn-1/2 functions covered 0.402 and 0.405.
- Caveat: hyperparameters were fixed, not learned; I2-3 shows how marginal likelihood picks them.
GP regression in AI, robotics and aerospace
- Geostatistics and earth observation: kriging is the standard for interpolating soil, ore, air-quality and ocean measurements, and for gap-filling satellite products with uncertainty.
- Terrain and field mapping: rovers and UAVs map elevation, radio signal and gas concentration with GPs and plan where to sample next.
- Surrogates for simulation: design and analysis of computer experiments (Sacks et al., 1989) replace expensive CFD or thermal simulations with GP emulators.
- Learning-based control: GP residual dynamics models with calibrated variance feed robust and safe MPC.
References
- A. O’Hagan (1978). “Curve fitting and optimal design for prediction.” JRSS B, 40.
- J. Sacks, W. Welch, T. Mitchell and H. Wynn (1989). “Design and analysis of computer experiments.” Statistical Science, 4.
- C. K. I. Williams and C. E. Rasmussen (1996). “Gaussian processes for regression.” NeurIPS.
- C. E. Rasmussen and C. K. I. Williams (2006). Gaussian Processes for Machine Learning. MIT Press.
- B. Szabó, A. W. van der Vaart and J. H. van Zanten (2015). “Frequentist coverage of adaptive nonparametric Bayesian credible sets.” Annals of Statistics, 43.
- J. Gardner, G. Pleiss, D. Bindel, K. Weinberger and A. Wilson (2018). “GPyTorch: blackbox matrix-matrix Gaussian process inference with GPU acceleration.” NeurIPS.
- M. Kanagawa, P. Hennig, D. Sejdinovic and B. Sriperumbudur (2018). “Gaussian processes and kernel methods: a review on connections and equivalences.” arXiv.