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.

Whitened SVGP & Bayesian Linear Regression

This notebook demonstrates the whitened parameterization for sparse variational GPs and its connection to Bayesian linear regression (BLR) in the “last-layer” GP setting. We cover:

  1. Standard (unwhitened) SVGP with the Titsias ELBO
  2. Whitened SVGP for improved optimization geometry
  3. The variance adjustment operator QQ
  4. BLR natural-parameter updates (full and diagonal)
  5. GGN and Hutchinson diagonal Hessian approximations
  6. Comparative plots

1. Background: Whitened Parameterization

In a standard SVGP we place a variational distribution q(u)=N(m,S)q(\mathbf{u}) = \mathcal{N}(\mathbf{m}, \mathbf{S}) over the inducing values u=f(Z)\mathbf{u} = f(\mathbf{Z}). The KL divergence against the prior p(u)=N(0,Kzz)p(\mathbf{u}) = \mathcal{N}(0, K_{zz}) involves Kzz−1K_{zz}^{-1} and log⁡∣Kzz∣\log|K_{zz}|, which couples the variational parameters to the kernel hyperparameters and makes optimization hard.

The whitened reparameterization introduces v=Lzz−1u\mathbf{v} = L_{zz}^{-1}\mathbf{u} where LzzL_{zz} is the Cholesky factor of KzzK_{zz}. We parameterize:

q(v)=N(mw,Sw)q(\mathbf{v}) = \mathcal{N}(\mathbf{m}_w, \mathbf{S}_w)

so that the induced distribution over u\mathbf{u} is:

q(u)=N(Lzzmw,  LzzSwLzz⊤)q(\mathbf{u}) = \mathcal{N}(L_{zz}\mathbf{m}_w,\; L_{zz}\mathbf{S}_w L_{zz}^\top)

The prior in whitened space is simply N(0,I)\mathcal{N}(0, I), so the KL divergence simplifies to:

KL(q(v)∥p(v))=12(∥mw∥2+tr(Sw)−log⁡∣Sw∣−M)\mathrm{KL}(q(\mathbf{v})\|p(\mathbf{v})) = \tfrac{1}{2}\bigl(\|\mathbf{m}_w\|^2 + \mathrm{tr}(\mathbf{S}_w) - \log|\mathbf{S}_w| - M\bigr)

This decouples the variational parameters from the kernel hyperparameters and yields better-conditioned gradients.

2. Setup: 1D Regression Problem

3. Kernel Matrices

We use an RBF kernel throughout. All covariance matrices are wrapped as lineax operators so they plug directly into gaussx primitives.

4. Standard (Unwhitened) SVGP

We initialize q(u)=N(m,S)q(\mathbf{u}) = \mathcal{N}(\mathbf{m}, \mathbf{S}) with m=0\mathbf{m} = 0 and S=I\mathbf{S} = I, then optimize the ELBO.

Trace correction: 0.0247
Unwhitened ELBO (final): -611.0572

5. Whitened SVGP

Now we use the whitened parameterization. The variational parameters are mw\mathbf{m}_w (whitened mean) and LwL_w (Cholesky of whitened covariance Sw=LwLw⊤\mathbf{S}_w = L_w L_w^\top). The predictive distribution is computed by whitened_svgp_predict.

Whitened ELBO (final): -158.7193

6. SVGP Variance Adjustment

The operator Q=Kzz−1SuKzz−1−Kzz−1Q = K_{zz}^{-1} S_u K_{zz}^{-1} - K_{zz}^{-1} appears in the predictive variance of any SVGP:

Var[f∗]=k∗∗−k∗z(Kzz−1−Q) kz∗\mathrm{Var}[f_*] = k_{**} - \mathbf{k}_{*z} (K_{zz}^{-1} - Q)\,\mathbf{k}_{z*}

svgp_variance_adjustment builds this operator lazily.

Q operator shape: (15, 15)
Q diagonal (first 5): [  251.85061536  2341.3502385   7943.0540259  17398.49272776
 30485.00022851]
Max error vs explicit Q: 2.04e-10

7. BLR Connection: “Last-Layer” GP

A GP with random Fourier features (RFF) or a neural-network feature extractor Φ(x)\Phi(\mathbf{x}) reduces to Bayesian linear regression in the feature space. The posterior is maintained in natural parameters (η1,η2)(\eta_1, \eta_2) where:

  • η1=Σ−1μ\eta_1 = \Sigma^{-1}\mu
  • η2=−12Σ−1\eta_2 = -\tfrac{1}{2}\Sigma^{-1}

Updates use the gradient and Hessian of the expected log-likelihood.

7a. Full-Rank BLR Update

blr_full_update performs a damped natural-parameter update:

η2new=(1−α)η2+α(−12H),η1new=(1−α)η1+α(g−Hμ)\eta_2^{\mathrm{new}} = (1-\alpha)\eta_2 + \alpha\bigl(-\tfrac{1}{2}H\bigr), \quad \eta_1^{\mathrm{new}} = (1-\alpha)\eta_1 + \alpha\bigl(g - H\mu\bigr)
BLR full-rank posterior mean norm: 1925361.0952

7b. Diagonal BLR Update

blr_diag_update is the diagonal counterpart where η2\eta_2 is stored as a vector (diagonal entries only).

BLR diagonal posterior mean norm: 504875906821993725952.0000

8. GGN Diagonal

The Generalized Gauss-Newton (GGN) matrix J⊤JJ^\top J approximates the Hessian of the loss with respect to network parameters. Its diagonal is cheap to compute and useful for diagonal Laplace or diagonal natural gradient updates.

GGN diagonal (first 5): [135.07625653  46.44496623  29.1838574    3.02410062   3.60572277]
Max error vs explicit: 1.14e-13

9. Hutchinson Hessian Diagonal

When the Hessian is only accessible via Hessian-vector products (HVPs), we can estimate its diagonal stochastically using the Hutchinson identity:

diag(H)=E[z⊙(Hz)]\mathrm{diag}(H) = \mathbb{E}[\mathbf{z} \odot (H\mathbf{z})]

where z\mathbf{z} is a Rademacher random vector.

Hutchinson diagonal (first 5): [-127.21368545  -29.12704184  299.00913616  -57.2356223   -74.60313243]
Exact diagonal      (first 5): [1350.76256529  464.4496623   291.838574     30.24100616   36.05722768]
Relative error: 0.7343

10. Plots

<Figure size 1400x1000 with 4 Axes>

Summary

PrimitivePurpose
whitened_svgp_predictPredictive mean and variance in whitened space
svgp_variance_adjustmentBuild the QQ operator for predictive variance
trace_correctionTitsias trace penalty
variational_elbo_gaussianClosed-form ELBO for Gaussian likelihoods
dist_kl_divergenceGeneral KL between two multivariate normals
blr_full_updateFull-rank natural-parameter BLR step
blr_diag_updateDiagonal natural-parameter BLR step
ggn_diagonalDiagonal of J⊤JJ^\top J (GGN approximation)
hutchinson_hessian_diagStochastic Hessian diagonal via Hutchinson

Key takeaways:

  • The whitened parameterization decouples variational parameters from kernel hyperparameters, giving faster and more stable convergence.
  • svgp_variance_adjustment encapsulates the algebraic bookkeeping of Kzz−1SuKzz−1−Kzz−1K_{zz}^{-1} S_u K_{zz}^{-1} - K_{zz}^{-1} behind a lazy operator.
  • BLR in natural parameters converges in very few steps (often a single pass through the data suffices for Gaussian likelihoods).
  • The GGN diagonal is exact and cheap; the Hutchinson estimator trades accuracy for the ability to work with implicit HVP access only.