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.

GP on a 2D Grid with Kronecker Structure

When data lives on a regular grid, the kernel matrix factorizes as K=Kx⊗KyK = K_x \otimes K_y. This enables GP inference on grids with thousands of points that would be intractable with a dense kernel.

This example fits a 2D GP to noisy observations on a grid using Kronecker structure for solve, logdet, and prediction.

Background

When inputs lie on a Cartesian product grid X={x1,…,xn1}×{y1,…,yn2}\mathcal{X} = \{x_1, \ldots, x_{n_1}\} \times \{y_1, \ldots, y_{n_2}\} and the kernel is separable,

k((x,y),(x′,y′))=kx(x,x′) ky(y,y′),k\bigl((x,y),(x',y')\bigr) = k_x(x,x')\, k_y(y,y'),

the kernel matrix factorizes as a Kronecker product K=Kx⊗KyK = K_x \otimes K_y where Kx∈Rn1×n1K_x \in \mathbb{R}^{n_1 \times n_1} and Ky∈Rn2×n2K_y \in \mathbb{R}^{n_2 \times n_2}. With N=n1n2N = n_1 n_2, this reduces:

  • Storage from O(N2)O(N^2) to O(n12+n22)O(n_1^2 + n_2^2).
  • Solve from O(N3)O(N^3) to O(n13+n23)O(n_1^3 + n_2^3).
  • Log-determinant via log⁡∣Kx⊗Ky∣=n2log⁡∣Kx∣+n1log⁡∣Ky∣\log|K_x \otimes K_y| = n_2 \log|K_x| + n_1 \log|K_y|.

These savings make GP inference feasible on grids with thousands of points that would be intractable with a dense kernel matrix. See Saatci (2012) for a comprehensive treatment and Gilboa et al. (2015) for extensions to higher-dimensional grids.

Generate 2D grid data

Grid: 15x15 = 225 points
<Figure size 1000x400 with 4 Axes>

Build Kronecker kernel

Separable RBF: 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)

Separability holds for any product of 1D stationary kernels (RBF, Matern, periodic). For non-separable kernels, sums of Kronecker products ∑rKx(r)⊗Ky(r)\sum_r K_x^{(r)} \otimes K_y^{(r)} can be used as approximations.

Kronecker kernel: 225x225
Storage: 15x15 + 15x15 = 450
Dense would be: 225x225 = 50,625

Add noise and solve

We need (Kx⊗Ky+σ2I)α=zobs(K_x \otimes K_y + \sigma^2 I) \alpha = z_\mathrm{obs}. For now we add noise to the dense matrix; a full implementation would keep this structured.

Solve residual: 3.15e-14

Log-marginal likelihood

The log-marginal likelihood (LML) for GP regression is

log⁡p(z∣X)=−12z⊤(K+σ2I)−1z−12log⁡∣K+σ2I∣−N2log⁡2π.\log p(\mathbf{z} \mid X) = -\tfrac{1}{2}\mathbf{z}^\top (K + \sigma^2 I)^{-1}\mathbf{z} - \tfrac{1}{2}\log|K + \sigma^2 I| - \tfrac{N}{2}\log 2\pi.

Note that the noise term σ2I\sigma^2 I breaks the pure Kronecker structure of Kx⊗KyK_x \otimes K_y. However, eigendecomposition-based approaches (Saatci, 2012) or Krylov methods can handle Kx⊗Ky+σ2IK_x \otimes K_y + \sigma^2 I efficiently by working with the per-factor eigenvalues.

Log-marginal likelihood: 55.04

Visualize results

<Figure size 1400x400 with 6 Axes>

Kronecker-only operations

Even though we fell back to dense for the noisy solve, the Kronecker structure enables cheap operations on the kernel itself.

logdet(Kx kron Ky):
  Structured: -4064.3464
  Dense:      -3904.5906

trace(Kx kron Ky):
  Structured: 225.0000
  Dense:      225.0000

cholesky type: Kronecker

References

  • Gilboa, E., Saatci, Y., & Cunningham, J. P. (2015). Scaling multidimensional inference for structured Gaussian processes. IEEE TPAMI, 37(2), 424--436.
  • Rasmussen, C. E. & Williams, C. K. I. (2006). Gaussian Processes for Machine Learning. MIT Press.
  • Saatci, Y. (2012). Scalable Inference for Structured Gaussian Process Models. PhD thesis, University of Cambridge.