Foundations to Frontier
Tests

Kernels and kernel design

The kernel is where a Gaussian process gets its assumptions: how smooth the function is, over what length scales it varies, whether it repeats, trends or has several additive parts. This page is a working catalogue: stationary kernels (RBF, the Matérn family, rational quadratic), periodic and linear kernels, and how smoothness shows up in the spectral density (Bochner's theorem). It then covers the algebra for building new kernels: sums for independent additive components, products for interactions and modulation, scaling, input warping and ARD lengthscales. It also covers how to choose among candidate kernels with the marginal likelihood, automatic kernel search and spectral-mixture kernels. In the exercise, six kernels are fitted to 8 years of a synthetic monthly vegetation index (trend, a multi-year cycle and a season whose amplitude drifts) and asked to forecast 3 more years. A lone RBF reverted to the mean (forecast RMSE 0.246). Adding a periodic part raised the log evidence from 75 to 102. Letting the season drift (RBF × periodic) raised it to 113, and the full designed kernel, linear + RBF + locally periodic, reached 115 with the best forecast (RMSE 0.101). On one of three seeds, though, the highest-evidence kernel forecast worse than a simpler one.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Telling the model what kind of curve to expect

A Gaussian process will fit almost anything, but what it does between and beyond the data depends entirely on its kernel: the rule for how strongly two points are related. A smooth kernel expects gentle curves, a rough one expects jagged ones, a periodic one expects the pattern to repeat. Real signals mix these: a crop’s greenness has a yearly cycle, a slow trend and noise. You build a kernel for that by adding and multiplying simple ones, like building a sentence from words. Choose kernels and combinations in the demo and look at what curves each one believes in.

Uncertainty lab
Three draws from a zero-mean GP with the RBF + periodic kernel (ℓ = 1, period = 2). Sums add structure (trend plus season); products modulate it (a seasonal pattern whose shape drifts on a longer scale).
Why engineers care

Kernel design is how you put physics and domain knowledge into a GP: known periods (orbits, seasons, rotation), known smoothness (Matérn for rough terrain), known additive structure (trend + cycle + noise). Good kernels make 3-year forecasts of satellite time series, poor ones revert to the mean after a few months.

📝 Quick check (Level 0)
0/3 answered
  1. 1. A periodic kernel expects functions that…
  2. 2. Adding two kernels models…
  3. 3. An RBF kernel far beyond the data predicts…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

A kernel catalogue

  • Stationary kernels depend only on r = |x − x′|:
    • RBF / squared exponential: σ² exp(−r²/2ℓ²). Infinitely smooth samples; correlation e^(−1/2) = 0.607 at r = ℓ.
    • Matérn ν: ν = 1/2 gives σ² exp(−r/ℓ) (rough, Ornstein–Uhlenbeck; 0.368 at r = ℓ); ν = 3/2 and 5/2 give once and twice differentiable samples; ν → ∞ gives the RBF. Stein (1999) recommends Matérn for physical data.
    • Rational quadratic: σ²(1 + r²/2αℓ²)^(−α), a scale mixture of RBFs with many lengthscales.
  • Periodic (MacKay, 1998): σ² exp(−2 sin²(πr/p)/ℓ²). Points a whole period apart are perfectly correlated.
  • Linear: σ²(x − c)(x′ − c): Bayesian linear regression; its samples are straight lines. (xᵀx′ + 1)^p is the polynomial kernel with C(d + p, p) features (176851 for d = 100, p = 3).
  • Building kernels:
    • k₁ + k₂: sum of independent functions (trend + season + noise).
    • k₁ × k₂: interactions; periodic × RBF is locally periodic: correlation 0.980 one period apart but 0.607 five periods apart when the decay scale is 5 periods.
    • c·k, k(g(x), g(x′)) for any warping g, and ARD: exp(−½ Σ_d (x_d − x′_d)²/ℓ_d²). A huge ℓ_d switches input d off.
  • Spectral view (Bochner): a stationary kernel is the Fourier transform of a non-negative spectral density S(ω). For the RBF, S(ω) ∝ exp(−ω²ℓ²/2), down to 1.1% of its peak at ω = 3/ℓ; Matérn spectra decay only polynomially, so their samples are rougher.
  • Not kernels: tanh(a xᵀx′ + c) (the “sigmoid kernel”) for many a, c; a negative distance −|x − x′|. Always check positive semidefiniteness.
📝 Quick check (Level 1)
0/3 answered
  1. 1. The Matérn-1/2 kernel gives samples that are…
  2. 2. A product of a periodic and an RBF kernel gives…
  3. 3. Bochner's theorem links a stationary kernel to…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

Designing and checking kernels

Exercise 1.

  • RBF, Matérn-5/2 and periodic kernels.
  • A positive-semidefiniteness check for sums, products and two non-kernels.
  • Random Fourier features that approximate the RBF by Bochner’s theorem.

Practice.

  • Start from structure you know: periods (day, year, orbit), trends, smoothness, which inputs interact. Write it as a sum of products.
  • Default to Matérn-5/2 with ARD for physical inputs and as the BO surrogate (Snoek et al., 2012); RBF when you know the function is very smooth.
  • Compare candidates by log marginal likelihood (I2-3), then check forecasts or held-out NLPD; inspect posterior decompositions of each additive part.
  • For unknown structure: spectral mixture kernels (Wilson and Adams, 2013), compositional kernel search (Duvenaud et al., 2013), or deep kernel learning (Wilson et al., 2016) when inputs are images or high-dimensional.
  • In GPyTorch: ScaleKernel(RBFKernel()) + ScaleKernel(PeriodicKernel() * RBFKernel()); in scikit-learn: kernel operators +, * and ExpSineSquared.
import gpytorch as gp
class NDVIModel(gp.models.ExactGP):            # trend + smooth cycle + drifting season
    def __init__(s, x, y, lik):
        super().__init__(x, y, lik); s.mean = gp.means.ConstantMean()
        s.cov = (gp.kernels.ScaleKernel(gp.kernels.LinearKernel())
                 + gp.kernels.ScaleKernel(gp.kernels.RBFKernel())
                 + gp.kernels.ScaleKernel(gp.kernels.PeriodicKernel() * gp.kernels.RBFKernel()))
        s.cov.kernels[2].base_kernel.kernels[0].period_length = 1.0    # one year, then learn or fix
    def forward(s, x): return gp.distributions.MultivariateNormal(s.mean(x), s.cov(x))
🐍 Exercise 1: kernels, PSD checks and random features
Implement RBF, Matérn-5/2 and periodic kernels, check which combinations are positive semidefinite, and approximate the RBF with random Fourier features.
📝 Quick check (Level 2)
0/3 answered
  1. 1. A good default kernel for physical inputs is…
  2. 2. To combine a known yearly cycle with a trend, use…
  3. 3. Spectral mixture kernels are useful when…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Why the algebra works. If K₁ and K₂ are PSD, then cᵀ(K₁ + K₂)c ≥ 0, and K₁ ∘ K₂ (elementwise product) is PSD by the Schur product theorem. Probabilistically, k₁ + k₂ is the covariance of f₁ + f₂ and k₁k₂ of f₁f₂ for independent zero-mean processes. Warping and positive scaling preserve PSD trivially.

Smoothness and spectra. Mean-square differentiability of a stationary GP is set by the tail of S(ω): k times differentiable iff ∫ω^(2k) S(ω) dω is finite. The Matérn-ν spectrum decays like (2ν/ℓ² + ω²)^(−ν − 1/2), so samples are ⌈ν⌉ − 1 times differentiable; the RBF’s Gaussian spectrum makes samples infinitely differentiable, which is often unrealistically smooth (Stein, 1999).

Random features. By Bochner, k(x − x′) = E_ω[cos(ωᵀ(x − x′))] for ω drawn from the normalized spectral density, so D random cosines give an unbiased approximation with error O(1/√D) (Rahimi and Recht, 2007). This turns a GP into Bayesian linear regression with D features, at cost O(nD²).

Choosing kernels by evidence. The marginal likelihood p(y | kernel) automatically trades fit against complexity and is the standard criterion for kernel search (the Automatic Statistician, Lloyd et al., 2014). But it measures how well the kernel explains the training data, not how it extrapolates; a kernel can win on evidence by explaining in-sample wiggles with a flexible component that then misbehaves outside. Check forecasts on held-out periods.

📝 Quick check (Level 3)
0/3 answered
  1. 1. The elementwise product of two PSD matrices is PSD by…
  2. 2. A heavier spectral tail means samples are…
  3. 3. Random Fourier feature error decays like…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

Which kernel structure forecasts a seasonal satellite time series, and does the marginal likelihood pick it?

History.

  • D. MacKay, “Introduction to Gaussian processes” (1998): the periodic kernel.
  • M. Stein, Interpolation of Spatial Data: Some Theory for Kriging (1999): the case for Matérn.
  • A. Rahimi and B. Recht, “Random features for large-scale kernel machines” (2007).
  • A. Wilson and R. Adams, “Gaussian process kernels for pattern discovery and extrapolation” (2013); D. Duvenaud et al., “Structure discovery in nonparametric regression through compositional kernel search” (2013).

Exercise 2. A synthetic monthly vegetation index (NDVI-like) over 11 years: a linear trend, a 7-year cycle, and a seasonal cycle with an asymmetric shape whose amplitude drifts over 9 years; noise sd 0.05.

  • Train on the first 8 years (96 points), forecast the next 3 (36 points).
  • Kernels (period fixed at one year, every other hyperparameter and the noise learned by maximizing the log marginal likelihood with 120 random starts and a pattern search): RBF; periodic; linear + periodic; RBF + periodic; RBF + locally periodic (RBF × periodic); linear + RBF + locally periodic.
kernel log evidence forecast RMSE forecast NLPD 95% coverage learned noise sd (true 0.05)
RBF 75.1 0.246 0.04 1.0 0.044
periodic 22.8 0.222 −0.03 1.0 0.174
linear + periodic 75.7 0.163 −0.05 0.75 0.094
RBF + periodic 101.7 0.212 −0.13 0.86 0.049
RBF + locally periodic 112.5 0.110 −0.63 0.94 0.063
linear + RBF + locally periodic 114.6 0.101 −0.67 0.94 0.059
  • Structure matters more than tuning: a lone RBF fits the past well but forecasts the mean; a lone periodic kernel blames everything else on noise (sd 0.174).
  • Products earn their keep: letting the season drift added 10.8 nats of evidence over a fixed season and halved the forecast error.
  • Evidence and forecasting agreed here, but not always. On seed 1 the two locally periodic kernels tied on evidence (122.0) and forecast best (0.084 and 0.108), while RBF + periodic covered only 11% of the forecast points. On seed 2 the highest-evidence kernel (linear + RBF + locally periodic, 108.5) forecast poorly (RMSE 0.299, coverage 0.69) and the simple linear + periodic kernel was best (0.133): evidence measures in-sample explanation, not extrapolation. Negative result: the highest-evidence kernel forecast best in 2 of 3 seeds.
🐍 Exercise 2 (research): which kernel structure forecasts a seasonal satellite time series, and does the marginal likelihood pick it?
Fit six composite kernels to 8 years of a seasonal vegetation index by maximizing the marginal likelihood, and compare evidence with 3-year forecast accuracy.

Kernel design in AI, robotics and aerospace

  • Earth observation: composite periodic kernels gap-fill and forecast NDVI, land-surface temperature and soil-moisture time series, separating trend from season.
  • Orbits and attitude: periodic kernels at the orbital period model eclipse-driven thermal and power telemetry; deviations flag anomalies.
  • Robotics: Matérn kernels on terrain elevation; product kernels over (position, time) for changing environments; ARD kernels identify which state variables drive a learned dynamics residual.
  • Bayesian optimization: Matérn-5/2 ARD is the default surrogate in BoTorch and most hyperparameter tuners.

References

  1. D. J. C. MacKay (1998). “Introduction to Gaussian processes.” In Neural Networks and Machine Learning, NATO ASI Series.
  2. M. L. Stein (1999). Interpolation of Spatial Data: Some Theory for Kriging. Springer.
  3. A. Rahimi and B. Recht (2007). “Random features for large-scale kernel machines.” NeurIPS.
  4. J. Snoek, H. Larochelle and R. Adams (2012). “Practical Bayesian optimization of machine learning algorithms.” NeurIPS.
  5. A. G. Wilson and R. P. Adams (2013). “Gaussian process kernels for pattern discovery and extrapolation.” ICML.
  6. D. Duvenaud, J. R. Lloyd, R. Grosse, J. B. Tenenbaum and Z. Ghahramani (2013). “Structure discovery in nonparametric regression through compositional kernel search.” ICML.
  7. J. R. Lloyd, D. Duvenaud, R. Grosse, J. Tenenbaum and Z. Ghahramani (2014). “Automatic construction and natural-language description of nonparametric regression models.” AAAI.
  8. A. G. Wilson, Z. Hu, R. Salakhutdinov and E. P. Xing (2016). “Deep kernel learning.” AISTATS.