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.

Structured GP: Kronecker and Low-Rank

This notebook shows where gaussx shines: exploiting structure in kernel matrices for Gaussian process inference.

We cover two common patterns:

  1. Kronecker structure — GP on a grid (e.g. spatial data on a regular mesh)
  2. Low-rank + diagonal — sparse GP with inducing points (Nystrom approximation)

The two most common forms of kernel structure in GP models are (1) Kronecker products from separable kernels on grids, and (2) low-rank approximations from inducing point methods. Both reduce the O(N3)O(N^3) cost of dense GP inference. gaussx supports both through its operator type system, dispatching to the optimal algorithm automatically.


Part 1: Kronecker GP on a grid

When input data lies on a grid, the kernel matrix factorizes as a Kronecker product: K=K1⊗K2K = K_1 \otimes K_2. This turns O(N3)O(N^3) operations into O(n13+n23)O(n_1^3 + n_2^3) where N=n1n2N = n_1 n_2.

For a separable kernel on 2D inputs the factorization is:

k((x1,y1),(x2,y2))=kx(x1,x2)⋅ky(y1,y2)k((x_1,y_1),(x_2,y_2)) = k_x(x_1,x_2) \cdot k_y(y_1,y_2)

This includes products of any 1D stationary kernels (e.g. RBF, Matern). See Saatci (2012) for a comprehensive treatment of Kronecker methods in GP models.

Setup: 2D grid data

Grid: 10 x 12 = 120 points
Dense kernel would be 120 x 120 = 14,400 entries
Kronecker stores 10x10 + 12x12 = 244 entries

Build the Kronecker kernel

Kronecker operator size: 120

Kronecker logdet

The key identity: log⁡∣K1⊗K2∣=n2log⁡∣K1∣+n1log⁡∣K2∣\log|K_1 \otimes K_2| = n_2 \log|K_1| + n_1 \log|K_2|

gaussx computes this automatically — no need to form the N×NN \times N matrix.

logdet (structured): -805.280930
logdet (dense):      -805.280929
Match: True

Kronecker solve and Cholesky

Solve and Cholesky also decompose per-factor.

solve residual: 2.27e-07
cholesky type: Kronecker
L factors: ['MatrixLinearOperator', 'MatrixLinearOperator']
Cholesky reconstruction error: 4.44e-16

Part 2: Low-rank GP (Nystrom / inducing points)

For non-grid data, a common approximation is K≈KnmKmm−1KmnK \approx K_{nm} K_{mm}^{-1} K_{mn}. The resulting covariance is diag(σ2)+UU⊤\text{diag}(\sigma^2) + U U^\top — a low-rank update.

The Woodbury identity gives an efficient solve:

(σ2I+UU⊤)−1=σ−2I−σ−2U(I+σ−2U⊤U)−1U⊤σ−2(\sigma^2 I + UU^\top)^{-1} = \sigma^{-2} I - \sigma^{-2} U (I + \sigma^{-2} U^\top U)^{-1} U^\top \sigma^{-2}

and the matrix determinant lemma gives an efficient logdet:

log⁡∣σ2I+UU⊤∣=Nlog⁡σ2+log⁡∣I+σ−2U⊤U∣\log|\sigma^2 I + UU^\top| = N \log \sigma^2 + \log|I + \sigma^{-2} U^\top U|

Both reduce the cost from O(N3)O(N^3) to O(NM2+M3)O(NM^2 + M^3).

Setup: random 1D data with inducing points

Data points: 200
Inducing points: 15
Dense kernel: 200x200 = 40,000 entries
Low-rank: 200x15 + 15x15 = 3,225 entries

Build the low-rank approximation

U shape: (200, 15)

Construct gaussx LowRankUpdate operator

Σ=σ2I+UU⊤\Sigma = \sigma^2 I + U U^\top

LowRankUpdate rank: 15
Operator size: 200
gaussx.is_low_rank: True

Solve and logdet via Woodbury

gaussx automatically uses the Woodbury identity for solve and the matrix determinant lemma for logdet — O(nk^2 + k^3) instead of O(n^3).

solve residual: 4.56e-13
logdet (Woodbury):  -421.679302
logdet (dense):     -421.679302
Match: True

Log-marginal likelihood

Sparse GP LML: 12.4216

Visualize the sparse GP fit

<Figure size 1000x400 with 1 Axes>

Summary

StructureWhen to useSolve costLogdet cost
Kronecker(K1, K2)Grid dataO(n1^3 + n2^3)O(n1^3 + n2^3)
low_rank_plus_diagInducing pointsO(nk^2 + k^3)O(nk^2 + k^3)
DenseUnstructuredO(n^3)O(n^3)

gaussx dispatches to the right algorithm automatically based on the operator type — write the math once, get efficient computation for free.

References

  • Quinonero-Candela, J. & Rasmussen, C. E. (2005). A unifying view of sparse approximate Gaussian process regression. JMLR, 6, 1939--1959.
  • Saatci, Y. (2012). Scalable Inference for Structured Gaussian Process Models. PhD thesis, University of Cambridge.
  • Rasmussen, C. E. & Williams, C. K. I. (2006). Gaussian Processes for Machine Learning. MIT Press.