Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

LOVE: Fast Leave-One-Out Cross-Validation

Leave-one-out cross-validation (LOO-CV) is a gold standard for GP model selection: it evaluates how well each training point is predicted by the model trained on the remaining n−1n - 1 points. Unlike the marginal likelihood, LOO-CV directly measures predictive quality and is less sensitive to model misspecification.

The catch is that naive LOO-CV requires nn separate GP solves, each costing O(n2)O(n^2) after the initial factorization -- O(n3)O(n^3) total. The LOVE method (Pleiss et al., 2018) sidesteps this by using a Lanczos decomposition to approximate K−1K^{-1} cheaply, enabling fast predictive variance at arbitrary test points from a single cached factorization.

What you’ll learn:

  1. How to build a LOVE cache via Lanczos factorization
  2. How to compute fast predictive variances from the cache
  3. How to use the cache for LOO-CV scoring
  4. Kronecker GP: exact MLL and posterior predictions on grids
  5. Comparing LOO-CV vs MLL for hyperparameter selection

1. Background

Given a GP with kernel matrix KK and noise variance σ2\sigma^2, the noisy kernel matrix is K~=K+σ2I\tilde{K} = K + \sigma^2 I. The predictive variance at a test point x∗x_* is

Var(f∗)=k∗∗−k∗⊤K~−1k∗\text{Var}(f_*) = k_{**} - k_*^\top \tilde{K}^{-1} k_*

where k∗=k(X,x∗)k_* = k(X, x_*) is the cross-covariance vector and k∗∗=k(x∗,x∗)k_{**} = k(x_*, x_*) is the prior variance.

Computing K~−1k∗\tilde{K}^{-1} k_* exactly requires an O(n3)O(n^3) factorization upfront, and each subsequent solve costs O(n2)O(n^2). LOVE approximates K~−1≈QΛ−1Q⊤\tilde{K}^{-1} \approx Q \Lambda^{-1} Q^\top using a rank-mm Lanczos decomposition (m≪nm \ll n), so that each variance computation costs only O(nm)O(nm) for the matrix-vector product Q⊤k∗Q^\top k_*, followed by an O(m)O(m) diagonal scaling.

For LOO-CV, the key identities are:

μLOO,i=yi−αi[K~−1]ii,σLOO,i2=1[K~−1]ii\mu_{\text{LOO},i} = y_i - \frac{\alpha_i}{[\tilde{K}^{-1}]_{ii}}, \qquad \sigma^2_{\text{LOO},i} = \frac{1}{[\tilde{K}^{-1}]_{ii}}

where α=K~−1y\alpha = \tilde{K}^{-1} y. The diagonal entries [K~−1]ii[\tilde{K}^{-1}]_{ii} can be approximated efficiently using the LOVE cache, since [K~−1]ii=ei⊤QΛ−1Q⊤ei[\tilde{K}^{-1}]_{ii} = e_i^\top Q \Lambda^{-1} Q^\top e_i.

2. Setup: 1D GP regression

We generate 100 noisy observations from a smooth function and build the RBF kernel matrix.

<Figure size 1000x400 with 1 Axes>

Kernel and noise parameters

Training points:  100
Kernel matrix:    (100, 100)

3. Build LOVE cache

The gaussx.love_cache function runs a Lanczos iteration on the kernel operator, producing a low-rank approximation of K~−1\tilde{K}^{-1}. The result is a LOVECache containing:

  • Q — orthonormal Lanczos basis, shape (n, m)
  • inv_eigvals — reciprocal eigenvalues of the tridiagonal matrix, shape (m,)
LOVECache fields:
  Q shape:            (100, 50)
  inv_eigvals shape:  (50,)

The Lanczos order m=50m = 50 is half the matrix size here, but in practice m≪nm \ll n suffices. The cache can be reused for any number of test points.

4. Fast predictive variance

For each test point x∗x_*, we need the cross-covariance vector k∗=k(X,x∗)k_* = k(X, x_*) and the prior variance k∗∗=k(x∗,x∗)k_{**} = k(x_*, x_*). LOVE gives us the quadratic form k∗⊤K~−1k∗k_*^\top \tilde{K}^{-1} k_* cheaply.

LOVE predictive variance: shape (200,)

Compare against exact variance

We compute the exact predictive variance via a dense solve for validation.

Max absolute error:  1.89e-15
Max relative error:  4.88e-13
<Figure size 1200x300 with 2 Axes>

Speedup: vmap over many test points

The LOVE cache makes it trivial to compute variance for a batch of test points via jax.vmap.

LOVE variance (200 points): 0.09 ms
Exact solve   (200 points): 0.59 ms
Speedup: 6.2x

5. LOO-CV via LOVE

Leave-one-out cross-validation computes, for each training point ii, the predictive mean and variance when that point is held out. The classical identities (Rasmussen & Williams, 2006, Eq. 5.12) give:

μLOO,i=yi−αi[K~−1]ii,σLOO,i2=1[K~−1]ii\mu_{\text{LOO},i} = y_i - \frac{\alpha_i}{[\tilde{K}^{-1}]_{ii}}, \qquad \sigma^2_{\text{LOO},i} = \frac{1}{[\tilde{K}^{-1}]_{ii}}

where α=K~−1y\alpha = \tilde{K}^{-1} y. The diagonal of K~−1\tilde{K}^{-1} is the expensive part; LOVE approximates it cheaply.

LOO predictive mean:     shape (100,)
LOO predictive variance: shape (100,)

LOO log-predictive density

The LOO log-predictive density (LPD) is a standard model selection criterion:

LOO-LPD=∑i=1nlog⁡p(yi∣X∖i,y∖i)=−n2log⁡(2π)−12∑i=1n[log⁡σLOO,i2+(yi−μLOO,i)2σLOO,i2]\text{LOO-LPD} = \sum_{i=1}^{n} \log p(y_i \mid X_{\setminus i}, y_{\setminus i}) = -\frac{n}{2}\log(2\pi) - \frac{1}{2}\sum_{i=1}^{n}\left[\log \sigma^2_{\text{LOO},i} + \frac{(y_i - \mu_{\text{LOO},i})^2}{\sigma^2_{\text{LOO},i}}\right]
LOO log-predictive density: -170.9582
<Figure size 1000x400 with 1 Axes>

6. Kronecker GP

When data lies on a 2D grid, the kernel matrix factorizes as a Kronecker product K=K1⊗K2K = K_1 \otimes K_2, reducing O(N3)O(N^3) to O(n13+n23)O(n_1^3 + n_2^3) where N=n1n2N = n_1 n_2.

gaussx provides kronecker_mll for the marginal log-likelihood and kronecker_posterior_predictive for predictions.

2D grid problem

Grid: 10 x 10 = 100 points
K1: (10, 10), K2: (10, 10)

Marginal log-likelihood

Kronecker MLL: -4.0269

Verify against dense GP

For this small grid we can also compute the dense MLL directly.

Kronecker MLL: -4.0269
Dense MLL:     -4.0269
Difference:    1.71e-13

Posterior predictions

We predict at a finer test grid using kronecker_posterior_predictive. The function accepts per-dimension cross-covariance arrays and test diagonal arrays.

Posterior mean shape: (400,)
Posterior var shape:  (400,)
<Figure size 1400x400 with 6 Axes>

7. Hyperparameter selection: LOO-CV vs MLL

We sweep over a range of lengthscales and compare two model selection criteria:

  • Marginal log-likelihood (MLL) — the standard Bayesian criterion
  • LOO log-predictive density — approximated via LOVE

Both should favour similar lengthscales, but LOO-CV can be more robust when the model is misspecified.

<Figure size 1200x400 with 2 Axes>
Best lengthscale (MLL):    0.87
Best lengthscale (LOO-CV): 1.15

8. Summary

MethodFunctionCost
LOVE cachelove_cacheO(nm)O(nm) one-time
LOVE varlove_varianceO(nm+m)O(nm+m)/point
LOO-CVCache diagonalO(nm)O(nm) all pts
Kron MLLkronecker_mllO(nd3)O(n_d^3)
Kron predkronecker_posterior_predictiveO(nd3)O(n_d^3)

Key takeaways:

  • love_cache computes a Lanczos factorization once; love_variance reuses it for fast predictive variance at any test point.
  • LOO-CV diagonals come for free from the LOVE cache -- no additional solves needed.
  • Kronecker structure turns grid GPs from O(N3)O(N^3) into O(∑nd3)O(\sum n_d^3).
  • MLL and LOO-CV generally agree on hyperparameters, but LOO-CV provides a complementary, directly predictive criterion.

References:

  • Pleiss, G., Gardner, J., Weinberger, K., & Wilson, A. G. (2018). Constant-time predictive distributions for Gaussian processes. ICML.
  • Rasmussen, C. E. & Williams, C. K. I. (2006). Gaussian Processes for Machine Learning. MIT Press.