Gaussian Processes
Function-space priors over regression functions: kernel-driven posteriors, marginal-likelihood hyperparameter learning, and three responses to the O(n^3) Cholesky bottleneck
Overview
A Gaussian process is a probability distribution over functions, specified by a mean and a kernel, with the property that every finite collection of function values is jointly multivariate Normal. The function-space view it makes possible — place the prior on the function, not on the parameters — is the canonical Bayesian regression model and the second pillar of the T5 Bayesian & Probabilistic ML track, building on the variational machinery of Variational Inference. Given a kernel, the posterior over function values at any test inputs is a closed-form multivariate Normal computable from kernel evaluations alone, with calibrated uncertainty for free in the conjugate-Gaussian-likelihood case.
This topic develops the substrate. §1 motivates the move from parametric Bayesian regression to function-space priors. §2 fixes the GP definition and verifies that positive-definite kernels yield internally consistent finite-dimensional joints. §3 derives the conjugate-Gaussian regression posterior in closed form via multivariate-Normal conditioning. §4 surveys the kernel zoo and the inductive bias each kernel encodes. §5 turns the kernel hyperparameters from quantities we set by hand into quantities we learn from the marginal likelihood. §6 closes with the Cholesky bottleneck and three structural responses — Nyström, sparse variational GPs, and random Fourier features — plus connections to the rest of formalML and forward-link topics on the T5 roadmap.
1. From parametric Bayes to function-space priors
Bayesian regression starts with a parametric model. Pick a fixed basis — polynomials, splines, RBFs at fixed centers — write the regression function as a linear combination , place a Gaussian prior on the weights , and the posterior is the standard conjugate-Gaussian update from formalStatistics: Bayesian Foundations . The procedure is clean and closed-form. Its weakness is structural: by committing to a fixed -dimensional basis up front, we have committed to a -dimensional family of regression functions, and no amount of data will let wander outside it.
Gaussian processes lift that commitment. Rather than choosing a basis and a prior over its coefficients, place the prior directly on the function — a probability distribution over a far richer space — and never name a basis at all. This section makes the move precise. §1.1 unpacks the parametric starting point and observes a fact that motivates everything that follows: parametric Bayesian regression already puts a Gaussian distribution on functions. §1.2 shows what’s wrong with that distribution — its covariance has a built-in low-rank constraint that the basis dimension cannot exceed. §1.3 reads the constraint as a permission slip: skip the basis, choose the covariance directly, and the function-space prior we get is exactly a Gaussian process.
1.1 Bayesian linear regression already puts a Gaussian prior on functions
Let denote an input — we will mostly take or in this topic — and let be a fixed feature map. Two running examples: the cubic polynomial map , and an RBF basis at fixed centers with width , . The Bayesian linear-regression model is with a Gaussian prior on the coefficients and Gaussian observation noise of variance . We use for noise throughout the topic and reserve for kernel signal variance once it appears in §2.
The prior on induces a prior on . Evaluating at any single input gives , a linear functional of the Gaussian random vector , so it is itself a Gaussian random variable with mean zero and variance . The same calculation applies jointly to any finite collection of inputs : stack the function values into and the feature evaluations into with rows . Then , a linear map of the Gaussian , jointly Gaussian: Reading the entries: and
This is the function-space view of parametric Bayes. The prior on — a distribution over a -dimensional weight vector — is equivalent to a particular distribution over functions, characterized by the property that the joint distribution of at any finite set of inputs is multivariate Normal with the covariance just displayed. We never had to leave the space of weight vectors to do calculations, but as a pure mathematical object, the prior over is what the model has put on the table.
1.2 The covariance is finite-rank by construction
The function-space prior we just wrote down has a structural property worth staring at. Define the bivariate function . For any finite collection of inputs , the implied covariance matrix factors as , where has rows . The rank of a product of matrices is bounded by the rank of any factor, so Whenever we evaluate at inputs, the implied -dimensional Gaussian over is degenerate — its support is a -dimensional affine subspace of , and at least of its eigenvalues are exactly zero. The function-space prior knows that all values of collapse onto a -dimensional surface no matter how many points we look at it from.
This is the structural cost of having committed to a finite basis. In a low-data regime (), we won’t notice — the covariance is full-rank on the points we have. In a moderate-data regime (), the model is right at the edge of capacity and is prone to interpolating noise. In a large-data regime (), the function class is too small to host the truth, and the posterior concentrates on the closest member of the -dimensional family no matter how badly that member misses. Adding basis functions is the obvious response, but it pushes the choice elsewhere: how many, where centered, of what width. The model designer pays in basis selection what they save in inference.
1.3 The function-space view: place the prior on directly
Reading §1.1–§1.2 more carefully, we notice something useful. The function-space prior on is fully characterized — for the purposes of any computation we will ever do — by the bivariate function and the mean function . We never store an entire function in memory; we only ever evaluate it at finitely many inputs. So the operational specification of a prior over functions only needs to provide, for any finite collection of inputs, a joint distribution over the function values. The Gaussian-process move drops the feature map.
A Gaussian process is a distribution over functions specified by a mean function and a kernel , with the property that for any finite collection of inputs , the joint distribution of is multivariate Normal with mean vector and covariance matrix . We will write and (throughout this topic, unless otherwise noted) take for simplicity. The -dimensional basis is gone. The kernel is the only thing we choose.
What changes? Two things, both consequential.
The kernel need not be finite-rank. The kernel from a parametric model is bilinear in a -dimensional feature representation, so as a kernel matrix on inputs its rank is capped at . Many natural kernels — the squared-exponential , the Matérn family, the periodic kernel — have no such cap. As kernel matrices on inputs they are generically full-rank, and the function-space prior they induce is correspondingly richer.
Validity now requires an argument. The parametric model gave us the function-space prior for free, because its construction (sample , plug into ) builds a single random function whose finite-dimensional marginals automatically agree. The GP construction goes the other way: it specifies the finite-dimensional marginals first and asks whether some random function has them as its marginals. Whether such a function exists, and whether the marginals are mutually consistent — for example, the marginal of the joint over obtained by integrating out must equal the directly-specified marginal of — is the content of the Kolmogorov extension theorem. §2 makes this precise and uses it to verify that any positive-definite kernel does in fact define a Gaussian process.
Figure 1 below shows what the move buys us. Reading the columns left to right is the structural lift the rest of this topic exploits.
Reading left to right is the structural lift §1 develops: the same plot conventions, increasing functional richness. The polynomial family is D-dimensional; the RBF family is K-dimensional; the GP family is infinite-dimensional. Drag the sliders to feel each axis.
The question §2 takes up is what it means, formally, to place a probability distribution on a space of functions in the first place — and which kernels qualify. §3 develops the closed-form posterior given data. §4 surveys the kernels that do most of the practical work. §5 turns the kernel hyperparameters from quantities we set by hand into quantities we learn from the marginal likelihood. §6 closes with the bottleneck that comes free with the construction and three responses to it.
2. Gaussian processes as priors over functions
§1 closed with a definition we have not yet earned: a Gaussian process is a distribution over functions specified by a mean and a kernel, with the property that every finite collection of function values is jointly Gaussian. Two questions are open. Which bivariate functions qualify as kernels? And, given a kernel, does an actual probability distribution over functions exist whose finite-dimensional marginals match the prescription? §2.1 fixes the formal definition. §2.2 identifies the answer to both questions — positive-definiteness — and proves that PD kernels yield internally consistent finite-dimensional joints, so by the Kolmogorov extension theorem a Gaussian process exists. §2.3 surveys three canonical kernels with prior-samples pictures, deferring the full design discussion to §4. §2.4 sketches the spectral / Mercer view that justifies §1.3’s “infinite-dimensional” claim.
2.1 The definition
Definition 1 (Gaussian process).
Let be a set, a function (the mean function), and a function (the kernel or covariance function). A real-valued stochastic process is a Gaussian process with mean and kernel , written , if for every finite collection of inputs , the random vector is multivariate Normal, with mean vector and kernel matrix .
The notation deserves explicit unpacking. The index set is whatever space the inputs live in — for time series, for tabular data, a graph or string set in more exotic applications. A stochastic process indexed by is, formally, a collection of real-valued random variables on a common probability space; informally, a single random function whose value at each input is a random variable. The Gaussian-process definition is a constraint on the family of finite-dimensional joint distributions of the process — the full distribution over functions is implied, not directly named. Whether the implied distribution actually exists for a given choice of and is the §2.2 question.
Throughout this topic — except in §5 where the mean function is briefly relevant for hyperparameter learning — we will take . The zero-mean simplification costs nothing in generality: any GP with non-zero mean function is the sum of a deterministic function and a centered GP with the same kernel, and most computations reduce to the centered case after subtracting .
2.2 Positive-definite kernels and consistency
For Definition 1 to make sense, the kernel matrix must be a valid covariance matrix — symmetric and positive semi-definite — for every finite . The condition on the kernel that achieves this has a name.
Definition 2 (Positive-definite kernel).
A function is a positive-definite kernel if it is symmetric — for all — and for every finite collection and every coefficient vector ,
This is exactly the condition that the kernel matrix is symmetric positive semi-definite for every finite , which is exactly the condition for to be a well-defined multivariate Normal distribution. The strict-PD case adds equality only at , which makes every strictly PD and is what we tacitly assume in §3 when we invert kernel matrices.
PD-ness of each individual matrix is necessary, but it is not obviously sufficient for a Gaussian process to exist — we also need the family of multivariate Normals defined across all finite to be internally consistent. Specifically, if and we write down the joint over both directly via the kernel and indirectly by marginalizing the joint over , the two answers must match. They do.
Proposition 1 (Consistency of finite-dimensional joints).
Let be a symmetric positive-definite kernel on and any mean function. The family of multivariate Normal distributions satisfies the two Kolmogorov consistency conditions:
- Permutation invariance. For any finite and any permutation of , the joint distribution of the permuted vector is the directly-specified joint over the relabeled inputs.
- Marginalization. For any finite and any input , the marginal of the joint over onto the components indexed by equals the directly-specified joint over .
Proof.
For (1), let be the permutation matrix with if and otherwise. The permuted random vector is , which is a linear function of the Gaussian and is therefore Gaussian itself. Its mean vector is , with -th entry — which is exactly . Its covariance matrix is , with entry equal to — which is exactly . So the relabeled vector has distribution .
For (2), assume without loss of generality that . Write the joint over in block form with the -block in the top position: The marginal density of is obtained by integrating out from the joint Gaussian density. A direct calculation — write the joint density, complete the square in , recognize the resulting integral as a univariate Gaussian normalizing constant, and collect the -dependent terms — gives The off-diagonal block and the diagonal entry both disappear from the marginal, leaving the -block of the covariance unchanged. The general fact — marginalizing a multivariate Normal onto a block of components yields a multivariate Normal whose covariance is the corresponding principal submatrix — is the standard Gaussian marginal/conditional formula and is the same fact we will reuse in §3. The resulting marginal matches the directly-specified joint over .
∎The Kolmogorov extension theorem now bridges from consistency to existence: any consistent family of finite-dimensional distributions extends uniquely to a probability measure on the path space . We will not prove the extension theorem itself — that’s measure-theoretic machinery rightly developed in formalStatistics: Random Variables — but we use its conclusion: a positive-definite kernel together with a mean function determines a Gaussian process.
The converse direction is immediate. Every kernel that arises from a Gaussian process is positive-definite, because the implied kernel matrix is the covariance matrix of a real-valued random vector and is therefore symmetric PSD. So PD kernels and centered Gaussian processes are in one-to-one correspondence — picking a kernel and picking a centered GP are the same act.
2.3 A first kernel zoo
We will not attempt a full kernel-design treatment here — that’s §4. But three kernels recur often enough to introduce now, both because §3’s derivation needs a concrete example to compute against and because the prior-samples picture they generate (Figure 2 below) drives home the point that the kernel choice is the main design knob in a GP model.
Squared-exponential (or RBF, or Gaussian) kernel. The most-used kernel in the GP literature, defined for by Two hyperparameters: the signal variance (the marginal variance ) and the lengthscale (the input-distance over which varies appreciably). Samples are infinitely differentiable.
Matérn- kernel. A one-parameter family parametrized by smoothness . The two practical instantiations have closed-form expressions; let and write Samples from a Matérn- GP are times mean-square differentiable; the limit recovers the squared-exponential. §4 develops the full Matérn family.
Periodic kernel. For one-dimensional inputs, the periodic kernel of MacKay 1998 is with an additional period hyperparameter . Samples are exactly -periodic.
Verifying that each is positive-definite uses Bochner’s theorem: a stationary kernel on is PD iff it is the inverse Fourier transform of a non-negative finite Borel measure (the spectral density of the kernel). For the squared-exponential the spectral density is itself Gaussian; for Matérn- it is Student’s--shaped; for the periodic kernel it is a discrete measure on integer multiples of . We invoke Bochner without proof and treat the three kernels’ positive-definiteness as established.
Smaller ν gives rougher samples (Matérn-1/2 is Brownian-motion-like; ν → ∞ gives the analytic SE limit). Lengthscale ℓ tunes the spatial correlation distance, independently of smoothness. Periodic samples agree exactly across one period; the kernel encodes that as inductive bias rather than a fitted property.
2.4 The infinite-dimensional view
§1.3 made an informal claim that GP priors are infinite-dimensional in a way the parametric model is not. The spectral / Mercer view of kernels makes the claim formal. Treat the kernel as the kernel of an integral operator acting on functions via for some reference measure on . Mercer’s theorem — the spectral theorem for compact self-adjoint operators applied here — says that under mild regularity conditions on and , the operator has a spectral decomposition with non-negative eigenvalues and orthonormal eigenfunctions , giving the kernel expansion The connection to the parametric model is then the Karhunen-Loève expansion: a centered GP with kernel has the equivalent series representation with the series converging in . Reading this carefully: the GP is a parametric Bayesian regression model — but one with countably infinitely many features and weight prior variances . The §1.2 finite-rank obstruction is gone exactly because there are infinitely many features with positive prior variance; the rank cap moves from to .
The Mercer expansion is also the spectral lens through which §6’s Nyström approximation works: truncating the eigenexpansion at the top eigenvalues produces a rank- kernel approximation, equivalent to the parametric model with features. The connection to formalML’s PCA and Low-Rank Approximation is direct: Nyström is principal-component analysis of the kernel matrix, with the truncation error controlled by the discarded tail .
This subsection is a sketch, not a proof. The full theorem is the spectral theorem for self-adjoint compact operators on a Hilbert space, which we point to via formalML’s Spectral Theorem topic. For our purposes the Mercer expansion is conceptual scaffolding: the right answer to “what does it mean for a GP to be infinite-dimensional?” is that the implied feature representation is the eigenbasis of the kernel operator, with countably infinitely many features.
3. Conjugate GP regression
§1 motivated the move to function-space priors; §2 verified that positive-definite kernels actually define such priors. Now we put a GP prior to work. Given a kernel , training inputs , noisy observations , and test inputs , what is the posterior distribution over at the test inputs? The answer is a closed-form multivariate Normal — the operational reason GPs are attractive — and the derivation is one careful application of the multivariate-Normal conditioning formula. §3.1 sets up the joint distribution. §3.2 proves the conditioning lemma in the form we need and reads the GP regression posterior off as a corollary. §3.3 unpacks what the formula is telling us. §3.4 runs it on a synthetic 1D problem. §3.5 closes with the Cholesky bottleneck that motivates §6.
3.1 The setup
The data are with inputs and noisy real-valued observations with the latent function . The noise is Gaussian — non-Gaussian likelihoods break conjugacy — and additive and homoscedastic.
Stack training inputs into the index set and observations into . The latent function values at training inputs are , related to by with . Test inputs have function values . Three kernel matrices appear: the training-kernel , the cross-kernel , and the test-kernel .
The §2 GP definition says the joint of is multivariate Normal; the observations inherit Gaussianity, and is independent of , so the joint of is Gaussian as well:
The posterior is the conditional of given in this joint. Because the joint is multivariate Normal, the conditional is multivariate Normal as well, with mean and covariance given by the standard Gaussian-conditioning formula.
3.2 The conditioning lemma and the GP regression posterior
Lemma 1 (Multivariate-Normal conditioning).
Let and be jointly multivariate Normal: with invertible. Then the conditional distribution of given is multivariate Normal:
Proof.
Centering eliminates the means: write and . Define a residual random vector by subtracting from its best linear predictor in : The pair is a linear function of the joint Gaussian , so it is jointly Gaussian. Compute the cross-covariance of with : The residual is uncorrelated with . For jointly Gaussian random vectors, uncorrelatedness implies independence (the joint density factors when the cross-covariance block is zero — see formalStatistics: Multivariate Distributions for the careful treatment). So is independent of .
Compute ‘s mean and covariance. The mean is zero (both inputs are centered). For the covariance, use the bilinearity of : where the last equality uses and simplifies the resulting expression. Thus and is independent of .
Express in terms of the residual: Conditioning on , the second term becomes a constant, and — independent of — has the same distribution as before conditioning. So Translating back to the original variables and adding to the conditional mean gives the claim.
∎The lemma’s mean formula is the classical linear minimum-mean-square-error predictor of given — the Wiener filter in time-series language, the kriging predictor in spatial statistics. The covariance formula is the Schur complement of in .
Specializing to GP regression is a substitution. Set , , both means zero, and read the covariance blocks off the joint .
Theorem 1 (GP regression posterior).
Under the GP-regression model of §3.1, the posterior distribution of the latent function values at test inputs given the training observations is multivariate Normal: with predictive mean and predictive covariance
Proof.
Apply Lemma 1 to the joint from §3.1. The hypothesis that is invertible holds for any : the matrix is symmetric positive definite because is positive semi-definite as a kernel matrix, and adding shifts every eigenvalue up by . Substituting , , , into the lemma gives the theorem.
∎A short corollary handles predictions of noisy observations at test inputs: if with , then — same mean, variance inflated by the irreducible noise.
3.3 Reading the formula
The closed-form posterior packs a lot into one line of algebra.
The predictive mean is a kernel-weighted combination of the training observations. Define . Then the predictive mean at any single test input is a linear combination of kernel evaluations between and each training input. Once is computed (one Cholesky), predictions at any new require only the -dimensional cross-kernel vector and one inner product. This is the representer-theorem flavor of GP regression: the posterior mean function lies in the span of kernel sections at the training inputs.
The predictive variance subtracts a “knowledge” term from the prior variance. At a single test input, The first term is the prior variance at . The second term is a quadratic form in a positive-definite matrix (non-negative) representing the variance reduction the data provide. In the no-data limit (), the second term vanishes. In the low-noise limit at a training point (), the two terms cancel and the predictive variance shrinks to zero — we have observed the function value exactly. In between, the predictive variance is small near the data and reverts to the prior variance as moves far from the training inputs.
The predictive variance does not depend on the observations . It depends only on the locations of the training inputs and the kernel. This is a feature of the conjugate-Gaussian-likelihood case (it breaks for non-Gaussian likelihoods) and it makes active learning with GPs clean: the next training input can be chosen at the location of maximum predictive variance, independently of any future observation. The geostatistics literature has developed this idea under the name kriging variance since the 1960s.
3.4 Worked example: 1D regression with the squared-exponential kernel
A synthetic 1D problem makes the formula visible. Take the truth on — a smooth function with two distinct frequency components. Observe at training inputs with Gaussian noise . Use the squared-exponential kernel with and — values chosen by hand here to match the truth’s roughest scale; §5 will turn into hyperparameters we learn.
Figure 3 shows three panels. Panel (a) — sparse data (): posterior mean (blue solid), band (light blue), truth (red dashed), training points (black markers). The band pinches to near- width at training points and widens dramatically in the gaps and outside the training range. The mean tracks the truth where data are present and reverts to zero where they are not. Panel (b) — same data with five posterior samples drawn jointly from . Each sample agrees with the others at training points (within noise) and diverges in the gaps by an amount calibrated by the band width. Panel (c) — dense data (): the credible band collapses uniformly to the irreducible -scale.
Panel (b) is the panel that makes the GP framing visceral. The posterior is not a band around a curve; it is a probability distribution over functions, and the band is a marginal summary of that distribution.
At n = 6 the band pinches near training points and reverts to the prior in the gaps; at n = 30 the band collapses uniformly to the irreducible σ_n-noise level. Toggle “show posterior samples” to see joint draws — coherent functions, not pointwise marginal draws.
The §3 verification confirms four numerical claims that Theorem 1 implies and the figure illustrates: (i) far from training data the predictive variance equals the prior variance to machine precision; (ii) at a training point the predictive mean is close to the observation, with discrepancy of order (MAE = 0.0129 on the §3 sparse data); (iii) in the limit the predictive mean at a training point matches the observation to numerical precision (MAE ≈ 1e-8); (iv) Cholesky timing scales cubically — the bottleneck §3.5 takes up next.
3.5 Computational cost: the Cholesky bottleneck
The closed-form posterior of Theorem 1 has a number staring at us: . The standard recipe is the Cholesky factorization. Compute , where is the lower-triangular Cholesky factor (existing and unique with positive diagonal because the matrix is symmetric positive definite). Cholesky factorization costs flops — half the cost of LU factorization, with markedly better numerical stability than direct inversion. Once is in hand, the predictive mean comes from two triangular solves and the predictive covariance from one triangular solve plus an outer product; total .
The bottleneck is the Cholesky on the training-kernel matrix. In practice this puts a soft ceiling on standard “exact” GPs of about — beyond that, the cubic scaling makes wall-clock time prohibitive, the memory footprint of storing approaches a workstation’s RAM, and conditioning issues require ever-larger jitter. Three structural responses — Nyström approximation, sparse variational GPs, random Fourier features — are the subject of §6.
4. Kernel design and the inductive bias
§3 took the kernel as given. But the kernel is the only design choice in a GP model — change the kernel and you change every prior expectation about the function, every notion of “similar inputs,” every smoothness assumption. §4.1 reads the kernel geometrically. §4.2 develops the Matérn family with smoothness as a tunable parameter. §4.3 surveys the working zoo and the additive/multiplicative composition rules. §4.4 introduces automatic relevance determination. §4.5 packages the choices into a small decision tree.
4.1 Stationarity, isotropy, and the lengthscale
A kernel is stationary if it depends on the inputs only through their difference: . It is isotropic if it depends only through the Euclidean distance: . Isotropic implies stationary; the converse fails (the periodic kernel is stationary but not isotropic in ).
For an isotropic kernel, the lengthscale is the input-distance over which the kernel decays from its maximum to a small fraction of it. At input distances much smaller than , function values are nearly perfectly correlated, and at distances much larger than , they are nearly independent. The lengthscale sets the scale of the function’s variation; equivalently, it controls how aggressively the GP extrapolates from training data.
We can read the lengthscale’s effect on the posterior from §3.3’s predictive-mean formula: each training point contributes a Gaussian bump of width centered at , and the predictive mean is the sum of these weighted bumps. A small gives narrow bumps and conservative extrapolation. A large gives wide bumps and aggressive extrapolation. §5 turns into a learning problem: pick it to maximize the marginal likelihood, which has a characteristic peak where matches the data’s correlation scale.
4.2 The Matérn family and the smoothness parameter
The squared-exponential kernel produces samples that are infinitely differentiable in mean-square. Real-world phenomena are rarely so smooth. The Matérn family interpolates between the squared-exponential’s analytic smoothness and a much rougher Brownian-motion-like roughness, with a single tunable parameter controlling the smoothness level.
Definition 3 (Matérn-ν kernel).
For , , , and inputs , the Matérn- kernel is where is the gamma function and is the modified Bessel function of the second kind of order . The kernel is positive-definite on for every (standard proof via Bochner’s theorem and the Matérn spectral density ).
The general formula is unwieldy and almost never used directly. The half-integer cases simplify to the closed forms we wrote down in §2.3: A third half-integer case, , recovers the exponential kernel — the kernel of a stationary Ornstein-Uhlenbeck process. The limit recovers the squared-exponential.
A Matérn- GP has samples that are times mean-square differentiable. So Matérn-1/2 samples are continuous but nowhere-differentiable; Matérn-3/2 samples are once-differentiable; Matérn-5/2 samples are twice-differentiable; SE samples are infinitely differentiable. Stein 1999 makes the case that for most modeling tasks Matérn-5/2 is the right default. The GP literature has largely converged on Matérn-5/2 as the working default.
The smoothness parameter itself is rarely treated as a continuous hyperparameter — the marginal-likelihood landscape in is flat for the smoothness range that matters in practice, and the half-integer cases are computationally cheap. The standard workflow is to pick by domain knowledge and optimize continuously.
Figure 4 demonstrates the smoothness ladder. Panel (a) overlays prior samples from Matérn-1/2, Matérn-3/2, Matérn-5/2, and squared-exponential at the same lengthscale — the visual transition from rough to smooth is unmistakable. Panel (b) shows what happens to the regression posterior on the §3 data when we vary the kernel. Panel (c) shows the lengthscale axis for a fixed kernel (squared-exponential), with : small produces a wiggly mean that interpolates noise, large produces a too-smooth mean, intermediate is the qualitatively-right answer.
Sweeping ℓ from small (e.g. 0.2) to large (e.g. 1.5) traces the bias–variance axis: too small overfits, too large underfits. The kernel choice axis is orthogonal — Mat-1/2 gives jagged interpolations, Mat-5/2 looks similar to SE in this regime. Toggle bands on to see how each kernel quantifies its own uncertainty in the gaps.
4.3 The working zoo and kernel composition
Beyond the squared-exponential and Matérn families, four other kernels appear in practical work:
Linear kernel. . Non-stationary. GP samples are straight lines through the origin with random slope. Rarely used standalone but earns its place as a building block.
Periodic kernel. Defined on one-dimensional inputs (multidimensional generalizations exist but are less common); useful for time series with known seasonality.
White-noise kernel. . Adds a “spike” to the diagonal. As a kernel component in additive composition it lets us model multiple variance components.
Constant kernel. . Encodes a global random-intercept term.
The reason this short list is enough is kernel composition. The space of positive-definite kernels is closed under three operations.
Proposition 2 (Kernel composition rules).
Let and be positive-definite kernels on , and let . Then:
- is positive-definite.
- is positive-definite.
- is positive-definite.
Proof.
For (1) and (2), the kernel matrices satisfy and . The first is PSD because and is PSD; the second is PSD because the sum of two PSD matrices is PSD ().
For (3) — the Schur product theorem — the kernel matrix is the elementwise (Hadamard) product. Write the spectral decompositions and with . The Hadamard product expands as using the elementary identity . The right-hand side is a non-negative combination of rank-1 PSD matrices, and is therefore PSD.
∎The composition rules are powerful in practice. The classical example is seasonal trend decomposition of atmospheric CO: each component carrying its own lengthscale and amplitude. Rasmussen and Williams 2006 (§5.4.3) develops this exact decomposition in detail.
4.4 Automatic relevance determination
When inputs are multidimensional, the squared-exponential of §2.3 used a single scalar lengthscale for every coordinate. Different features are measured in different units, vary on different scales, and have different relevance. The fix is to give each input coordinate its own lengthscale — the anisotropic or automatic-relevance-determination (ARD) squared-exponential: The “automatic relevance determination” name comes from the fact that an irrelevant coordinate pushes its lengthscale to a large value during marginal-likelihood optimization. Inspecting the trained values is then a feature-importance diagnostic. The §4 ARD demonstration on synthetic 2D data with one relevant + one irrelevant feature recovers for the relevant dimension and for the irrelevant one — the ratio is the diagnostic signal.
ARD generalizes naturally from squared-exponential to the Matérn family (replace with the Mahalanobis distance) and is the canonical multidimensional kernel parametrization in modern GP libraries.
4.5 Choosing a kernel: a small decision tree
- Smoothness. If the truth is genuinely smooth, use squared-exponential. If smoothness is finite or unknown — the realistic default — use Matérn-5/2. Matérn-3/2 for once-differentiable functions; Matérn-1/2 for Brownian-motion-like processes.
- Periodicity. If the data have known period , include a periodic kernel component. For quasi-periodic phenomena, multiply periodic by squared-exponential ().
- Multidimensional inputs. Use the ARD form by default. Inspect optimized lengthscales as a feature-relevance diagnostic.
- Multiple variance components. Use kernel addition. A trend + seasonality + irregularity + noise decomposition is the standard structured-time-series template.
- Linear baseline. When in doubt, include as an additive component.
§5 takes the kernel as fixed (in functional form) and makes the hyperparameters into things we learn from the marginal likelihood.
5. Learning hyperparameters from the marginal likelihood
§4 introduced the kernel hyperparameters and treated them as quantities we set by hand. The standard fix is to learn the hyperparameters from data by maximizing the marginal likelihood — the probability the training data are assigned by the GP model with those hyperparameters, after the latent function has been integrated out. §5.1 derives the marginal-likelihood formula. §5.2 reads it as a model-selection criterion (Bayesian Occam’s razor). §5.3 develops the gradient-based optimization. §5.4 returns to the §3 example and recovers from data.
5.1 The marginal likelihood
Stack the kernel hyperparameters into . The marginal likelihood is Both factors are Gaussian; the integral is a Gaussian convolution and is closed-form.
Proposition 3 (Marginal likelihood for GP regression).
For the GP regression model of §3 with kernel hyperparameters , the log marginal likelihood of the training data is where .
Proof.
Write with independent of . The sum of two independent Gaussian vectors is itself Gaussian with covariance equal to the sum of the covariances (see formalStatistics: Multivariate Distributions ). So , and the log density of a multivariate Normal evaluated at gives the formula.
∎The formula has three terms. Data fit: . Complexity penalty: . Constant: . The Cholesky factorization of makes the formula computable. The data-fit term factors as where ; the log-determinant factors as . So one Cholesky gives both terms — same cost as a single GP prediction.
5.2 Occam’s razor in the marginal likelihood
The data-fit and complexity-penalty terms trade off in a way that gives GP regression an automatic model-selection mechanism — what MacKay 1992 christened the Bayesian Occam’s razor.
Small (rough functions). is close to — nearly diagonal. is large in magnitude (very negative complexity penalty), and the model can explain any data, so the data-fit term is also large in magnitude — but the complexity penalty wins. Verdict: the model is too flexible.
Large (very smooth functions). has all entries close to — rank-1-plus-noise. The complexity penalty is small but the model can essentially only produce constant functions, so the data-fit term is poor. Verdict: too rigid.
Intermediate . Both terms are moderate. Verdict: the marginal likelihood prefers this regime, and the optimum recovers the data-correct lengthscale.
This is Occam’s razor for free — the marginal likelihood automatically prefers the simplest model that adequately explains the data, without explicit regularization or held-out validation. The mechanism is purely Bayesian: integrating out of the joint puts probability mass on the data only to the extent that the model places probability on outputs near . The marginal-likelihood-as-evidence framing connects directly to Bayesian model comparison (formalstatistics’s formalStatistics: Bayesian Model Comparison and BMA ).
The empirical-Bayes view: maximizing the marginal likelihood with respect to is type-II maximum likelihood. Full hierarchical-Bayes — putting a prior on and using HMC — is more principled but computationally expensive (each HMC step is one Cholesky), and in moderately-sized data regimes the marginal-likelihood landscape is concentrated enough that point estimation suffices.
5.3 Gradient-based optimization
Maximizing the marginal likelihood is a numerical optimization problem in . The landscape is non-convex — multiple local maxima exist for non-trivial kernels. Standard recipes: (i) compute analytic gradients (closed-form, much faster than finite differences); (ii) optimize in log-parameter space so positivity constraints on are automatic; (iii) run multiple restarts from random initializations.
The analytic gradient is one application of the matrix-derivative identity and the Jacobi formula .
Proposition 4 (Marginal-likelihood gradient).
With and , the partial derivative of the log marginal likelihood with respect to a hyperparameter is
Proof.
The log marginal likelihood has three terms: data fit , complexity penalty , and a constant. Differentiating the data-fit term: using and trace cyclicity . Differentiating the complexity-penalty term via the Jacobi formula: Combining:
∎The cost of one gradient evaluation is for the Cholesky plus per hyperparameter for the trace term — same as one function evaluation. Each L-BFGS-B step costs one Cholesky; a typical optimization run is – Choleskys.
The non-convexity requires care. Two pathologies recur. The flat-likelihood pathology: when is small, multiple distant combinations can produce comparable marginal likelihoods. The signal-noise confounding pathology: at optima where is small and large, the model attributes all variation to noise; vice versa otherwise. The mitigation is multi-restart optimization: 5–10 random log-space initializations, optimize each to convergence, retain the best.
5.4 Worked example: recovering hyperparameters from data
Returning to the §3 worked example with training points (the dense set). The data-generating hyperparameters were , , . The §5 question is: with no knowledge of the truth, can the marginal likelihood recover them from the data alone?
Figure 5 has three panels. Panel (a) — marginal-likelihood landscape: a 2D heatmap of as a function of at the optimal obtained by profiling. The peak is unambiguous; the contours show the characteristic banana shape with and partially confounded. Panel (b) — recovered posterior with marginal-likelihood-optimized hyperparameters: nearly identical to the §3 hand-set posterior. Panel (c) — optimization curves for five random restarts: all five converge to the same neighborhood despite different starting points.
Click anywhere on the landscape to set (ℓ, σ_n) and watch the predictive posterior update in real time. The black "+" marks the truth (ℓ=0.6, σ_n=0.15) and the red "★" tracks your selection. Run the optimizer to overlay all five L-BFGS restart trajectories (start dots → endpoint at the optimum); on this dataset all five converge to the same neighborhood, recovering (σ_f, ℓ, σ_n) ≈ (0.66, 0.68, 0.11).
The recovered hyperparameters are approximately — within of the true generating values , the right ballpark given the small sample size. With more data ( or ), the optimum sharpens and the recovered values converge to the true ones, as the consistency theory of type-II MLE predicts.
The §5 workflow is the standard recipe for fitting a GP in practice: pick a kernel form (§4), maximize the marginal likelihood for hyperparameters (§5), use the resulting posterior for prediction (§3). For moderate this is the entire pipeline. When grows large enough that the Cholesky becomes prohibitive, §6 offers three structural responses.
6. Scaling, neighbors, and limits
§3 ended with the Cholesky bottleneck; §5’s marginal-likelihood optimization is dozens of full Choleskys per fit, multiplying the bottleneck across the optimization loop. For exact GP regression on a single CPU, the practical ceiling is around — beyond that, both wall-clock time and the memory footprint become prohibitive, and conditioning degrades to the point where ever-larger jitter is needed. The literature has developed several structural responses; this section surveys three. §6.1 covers the Nyström approximation (the spectral baseline, earning its place via the PCA and Low-Rank Approximation prerequisite). §6.2 covers sparse variational GPs (the modern workhorse, earning its place via the Variational Inference prerequisite). §6.3 covers random Fourier features. §6.4–§6.6 lay out neighbors and limits.
6.1 Nyström approximation
The Mercer expansion of §2.4 wrote a kernel as . Truncating at the top eigenvalues gives a rank- kernel approximation. The Nyström approximation is the practical version: pick inducing inputs (random subsample of , or -means clustering of ), define the inducing-block , the cross-block , and the training-block , and replace with the rank- surrogate Equivalently — the connection to PCA and Low-Rank Approximation — is the projection of onto the column space of . The truncation error is controlled by the discarded tail of the kernel-operator spectrum, which decays exponentially for analytic kernels and polynomially for the Matérn family; Drineas-Mahoney 2005 makes this precise.
Predictions through Nyström use in place of with a Woodbury-identity simplification: Cost: per fit, memory.
The structural cost is that Nyström is a kernel-matrix approximation, not a probabilistic-model approximation. The implied modified GP has a degenerate kernel matrix and produces over-confident predictive variance. For predictions where uncertainty calibration matters, Nyström’s variance is unreliable. Quiñonero-Candela and Rasmussen 2005 develop this critique in detail; SVGP was developed in response.
6.2 Sparse variational GPs (SVGP)
The modern answer is to wrap the inducing-point construction in the variational machinery of Variational Inference. The construction is due to Titsias 2009; mini-batch SGD by Hensman et al. 2013 scales it to .
Augment the model with . The variational family is parametrized over alone: , with . This factorization embeds the inducing-point assumption directly into the variational family. The ELBO becomes with the data-fit term factorizing across training points (one univariate Gaussian expectation per point), allowing mini-batch stochastic gradients. Per-step cost: full-batch, at mini-batch size .
The variational predictive distribution is calibrated: overly-confident predictions are penalized by the KL term, and the construction generalizes immediately to non-Gaussian likelihoods (Bernoulli for classification, Poisson for counts) by replacing the data-fit term with the appropriate expected log-likelihood. SVGP is the substrate of essentially all modern scalable-GP work.
6.3 Random Fourier features
The third response sidesteps inducing points entirely. Random Fourier features (Rahimi-Recht 2007) approximate a stationary kernel by an explicit finite-dimensional inner product. Bochner’s theorem says a stationary kernel is the inverse Fourier transform of a non-negative spectral density : Treating as a probability density, Monte Carlo estimation gives with and . For squared-exponential, . With features in hand, the problem becomes Bayesian linear regression on — exactly the §1 parametric model that motivated GPs in the first place, except now the features are randomly sampled to approximate a target kernel rather than chosen by hand.
Cost: . Error decays as . For tasks with moderate kernel hyperparameters, – recovers near-exact predictive accuracy at training-set sizes that exact GP cannot touch.
The interactive component below sweeps all three approximations against the exact GP baseline at training points (scaled down from the brief’s for browser-side computation). Slide to watch Nyström and SVGP converge to the exact GP as ; toggle methods on/off to compare predictive bands; read fit-time off the per-method labels.
Slide m up: Nyström and SVGP converge toward exact GP as m → n. Nyström's variance is omitted because it's structurally overconfident; SVGP and RFF produce calibrated bands. Inducing-point locations are marked along the bottom of the plot. Wall-clock fit-times are reported per method — the takeaway is that for modest m and D, sparse approximations recover near-exact predictive mean accuracy at substantially lower cost than the O(n³) exact GP baseline.
6.4 Within formalML
GPs sit at the junction of several formalML topics.
PCA and Low-Rank Approximation. The Nyström approximation of §6.1 is principal-component analysis applied to the kernel matrix.
Spectral Theorem. The Mercer expansion of §2.4 is the spectral theorem for self-adjoint compact integral operators. Eigenvalue decay (exponential for analytic kernels, polynomial for Matérn) controls Nyström’s convergence rate and RFF’s required feature count.
Variational Inference. The SVGP construction of §6.2 is variational inference applied to GPs. The ELBO of variational-inference is the exact objective Titsias 2009 maximizes.
KL Divergence. The KL term in the SVGP ELBO is reverse KL between two Gaussians, with a closed-form via the multivariate-Normal KL identity.
Forward links to planned T5 topics. GPs are the substrate, in different ways, of:
- Bayesian Neural Networks. The infinite-width limit of a BNN with i.i.d. Gaussian weight priors converges to a Gaussian process (Neal 1996), with a kernel that depends on the activation function and the layer-wise prior variances.
- Neural Tangent Kernel (coming soon). In the infinite-width-and-zero-learning-rate limit of gradient-descent training, the resulting predictive function is exactly a GP with a specific kernel (Jacot et al. 2018) computable in closed form.
- Meta-Learning (coming soon). Neural Processes (Garnelo et al. 2018) are amortized GPs: the variational posterior over is the output of an encoder network conditioned on a context set.
- Bayesian Optimization (coming soon, planned T8). The GP is the surrogate model in nearly every modern Bayesian optimization framework.
- Deep Kernel Learning (planned T5). Wilson et al. 2016 proposed a neural network as a feature extractor whose output is fed into a GP kernel.
6.5 Cross-site connections
formalstatistics. The multivariate-Normal density and Gaussian-Gaussian conjugacy that drive §3’s closed-form posterior are the substrate of every formalstatistics Bayesian-conjugate-prior treatment. The marginal likelihood of §5 is exactly the evidence in Bayesian model comparison, and type-II MLE is the empirical-Bayes specialization of the full hierarchical-Bayes treatment. Fully-Bayesian inference over GP hyperparameters via HMC is the natural extension and is precisely what formalStatistics: Bayesian Computation and MCMC covers.
formalcalculus. Bochner’s theorem of §6.3 is harmonic analysis grounded in the Fourier transform machinery of formalcalculus. The Jacobi formula that drives §5.3’s gradient is a multivariable-calculus identity that appears across statistics and ML.
6.6 Limits and what GPs can’t do
GPs are an extremely capable function-space prior, but they have structural limits worth knowing about up front.
Computational scaling, even with approximations. Exact GPs are , capped near . Sparse approximations push this to at the cost of a structural-modeling assumption (the function is well-summarized by inducing points). None approach the -training-point scale of modern deep-learning regression.
Input dimensionality. Standard GP kernels suffer from the curse of dimensionality. The “effective” training-set size for prediction at any test input drops with dimension. Practical GP regression past – requires either a learned feature representation (deep kernel learning), an additive-kernel structural prior, or a different model class.
Non-Gaussian likelihoods. Conjugacy fails for Bernoulli, Poisson, Student-, and most other useful likelihoods. Approximate inference is required — Laplace, expectation propagation, or variational. The §6.2 SVGP machinery is the modern recipe.
Kernel choice as inductive bias. A wrong kernel choice gives wrong predictions, and the marginal likelihood does not protect against gross misspecification. Marginal-likelihood comparison between candidate kernels is the standard mitigation.
Stationarity assumptions. Most practical kernels are stationary. Many real-world functions are not. Non-stationary GP kernels exist but require extra machinery.
No causal structure. The GP’s “prior over functions” has no notion of cause and effect. A GP fit to observational data cannot answer counterfactual questions any better than the observational regression it represents.
GPs are, despite all this, the workhorse function-space prior for moderate-scale ML, the canonical Bayesian regression model, the natural surrogate for Bayesian optimization, and the conceptual scaffold for understanding the infinite-width-network correspondence. The function-space view they introduce — place the prior on the function, not on the parameters — has become the default framing for thinking about uncertainty in regression, even in settings where the underlying machinery is not literally a GP.
Connections
- The SVGP construction of §6.2 wraps GP inference in the variational machinery: the ELBO of variational-inference is the exact objective Titsias 2009 maximizes, with the inducing-point augmentation embedded directly into the variational family. variational-inference
- The Mercer expansion of §2.4 is the spectral theorem for self-adjoint compact integral operators applied to the kernel-as-operator framing; eigenvalue decay (exponential for analytic kernels, polynomial for Matérn) controls Nyström's convergence rate and RFF's required feature count. spectral-theorem
- The Nyström approximation of §6.1 is principal-component analysis of the kernel matrix; Drineas-Mahoney's sampling theory and the subspace-projection bounds developed in pca-low-rank are the rigorous foundation of Nyström's error analysis. pca-low-rank
- The KL term in the SVGP ELBO is reverse KL between two Gaussians, with a closed-form via the standard multivariate-Normal KL identity. Reverse-KL's mode-seeking pathology means SVGP can underestimate inducing-point posterior variance when the marginal-likelihood landscape is multimodal. kl-divergence
- The infinite-width MLP prior converges to a Gaussian process (NNGP); BNN §9 derives this connection and uses GP machinery for the function-space view, including the closed-form Cho-Saul arc-cosine kernel that makes infinite-width BNN inference exactly GP regression. bayesian-neural-networks
References & Further Reading
- book Gaussian Processes for Machine Learning — Rasmussen & Williams (2006) The canonical GP textbook. §3 follows its derivation closely; §4.3 composition rules and §5.3 hyperparameter optimization track the GPML treatment (MIT Press).
- paper Introduction to Gaussian Processes — MacKay (1998) Pedagogical introduction. The periodic kernel of §2.3 is MacKay's. §5.2 Bayesian Occam's razor framing originates here (NATO ASI Series F).
- book Interpolation of Spatial Data: Some Theory for Kriging — Stein (1999) The canonical reference for kernel smoothness in spatial statistics. The §4 argument for Matérn-5/2 as the working default originates here (Springer).
- paper A Statistical Approach to Some Basic Mine Valuation Problems on the Witwatersrand — Krige (1951) The original kriging paper — what GP regression is called in geostatistics. §3.3 mentions kriging variance as the geostatistics name for predictive variance (J. Chem. Metall. Mining Soc. SA).
- book Pattern Recognition and Machine Learning — Bishop (2006) Chapter 6 covers kernel methods; §6.4 develops GPs in the form §3 takes here. Standard ML-track companion (Springer).
- paper A Unifying View of Sparse Approximate Gaussian Process Regression — Quiñonero-Candela & Rasmussen (2005) The taxonomy of sparse GP approximations §6 surveys. Identifies the §6.1 Nyström variance pathology and motivates §6.2's variational-GP response (JMLR).
- paper Variational Learning of Inducing Variables in Sparse Gaussian Processes — Titsias (2009) The original SVGP paper. §6.2's ELBO is Eq. 5–8 of this paper; the closed-form q(u) for conjugate Gaussian likelihoods is the §6 code's reference (AISTATS).
- paper Gaussian Processes for Big Data — Hensman, Fusi & Lawrence (2013) Mini-batch SGD for SVGP, scaling GPs to n ~ 10^6. §6.2 mentions this as the production version of the Titsias construction (UAI).
- paper Random Features for Large-Scale Kernel Machines — Rahimi & Recht (2007) The original RFF paper. §6.3 follows its Bochner-theorem construction and the D^{-1/2} approximation-error decay (NeurIPS).
- paper On the Nyström Method for Approximating a Gram Matrix for Improved Kernel-Based Learning — Drineas & Mahoney (2005) Rate-of-convergence theory for the Nyström approximation; the bound §6.1 alludes to (JMLR).
- book Bayesian Learning for Neural Networks — Neal (1996) The infinite-width-NN-as-GP correspondence §6.4 forward-references; the original derivation that an i.i.d.-prior wide BNN converges to a GP at initialization (Springer LNS 118).
- paper Practical Bayesian Optimization of Machine Learning Algorithms — Snoek, Larochelle & Adams (2012) The canonical modern application of GPs as a BO surrogate; §6.4 forward-link (NeurIPS).
- paper Deep Kernel Learning — Wilson, Hu, Salakhutdinov & Xing (2016) Neural-network feature extractor + GP head; the deep-kernel approach §6.4 forward-references (AISTATS).
- paper Neural Processes — Garnelo, Schwarz, Rosenbaum, Viola, Rezende, Eslami & Teh (2018) Amortized GPs via encoder-decoder networks; the meta-learning relative §6.4 forward-references (ICML Workshop).
- paper Neural Tangent Kernel: Convergence and Generalization in Neural Networks — Jacot, Gabriel & Hongler (2018) The NTK regime of infinite-width gradient-descent training; §6.4 forward-link to the NN-as-GP-via-training correspondence (NeurIPS).