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.

Laplace approximation for non-conjugate GPs

When the likelihood p(y∣f)p(y \mid f) is not Gaussian, the posterior p(f∣y)∝p(y∣f) p(f)p(f \mid y) \propto p(y \mid f)\,p(f) no longer admits a closed-form Gaussian. The Laplace approximation replaces it with a Gaussian centered at the posterior mode f^\hat f with covariance set to the inverse of the negative log-posterior Hessian at that mode:

q(f)=N(f∣f^,(Λ+K−1)−1),Λ=−∇f2log⁡p(y∣f)∣f^.q(f) = \mathcal{N}(f \mid \hat f, (\Lambda + K^{-1})^{-1}), \qquad \Lambda = -\nabla^2_f \log p(y \mid f)\big|_{\hat f}.

Newton iteration. Each step solves a linear-Gaussian regression with synthetic per-point precision Λn\Lambda_n and synthetic targets y~n=(Λnfn+gn)/Λn\tilde y_n = (\Lambda_n f_n + g_n)/\Lambda_n, where gn=∂fnlog⁡p(yn∣fn)g_n = \partial_{f_n} \log p(y_n \mid f_n). This is the standard GP-Laplace fixed-point iteration (Rasmussen & Williams, Algorithm 3.1). For log-concave likelihoods (Bernoulli, Poisson) it converges quadratically.

Approximate log marginal.

log⁡p(y)≈log⁡p(y∣f^)−12f^⊤K−1f^−12log⁡∣I+KΛ∣.\log p(y) \approx \log p(y \mid \hat f) - \tfrac12 \hat f^\top K^{-1} \hat f - \tfrac12 \log|I + K\Lambda|.

This notebook fits Laplace on a 1-D Bernoulli classification problem and inspects the convergence trace, posterior mean / variance, and predictive distribution.

/home/azureuser/localfiles/pyrox/.venv/lib/python3.13/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
  from .autonotebook import tqdm as notebook_tqdm

Synthetic 1-D classification

Latent function f(x)=2sin⁡(x)+0.4 xf(x) = 2\sin(x) + 0.4\,x, observations yn∼Bernoulli(σ(f(xn)))y_n \sim \text{Bernoulli}(\sigma(f(x_n))).

<Figure size 770x330 with 1 Axes>

Fit

RBF prior, lengthscale 0.6, variance 1.5. We run Laplace to convergence and inspect the iteration count.

converged: True
iterations used: 6
approximate log marginal: -25.6915
posterior mean range: [-1.887, 2.245]
posterior var range:  [0.3910, 0.8180]

Predictive distribution

Predict the latent at a fine grid, then push the mean ±2σ through σ(⋅)\sigma(\cdot) to get a probabilistic decision boundary.

<Figure size 1210x396 with 2 Axes>

Diagnostic — site precisions

The Laplace approximation gives each observation a Gaussian site with diagonal precision Λn=σ(f^n)(1−σ(f^n))\Lambda_n = \sigma(\hat f_n)(1 - \sigma(\hat f_n)). Sites at confidently-classified points (where σ(f^)\sigma(\hat f) is near 0 or 1) have low precision; sites near the decision boundary (where σ(f^)≈0.5\sigma(\hat f) \approx 0.5) have the largest precision =0.25= 0.25.

<Figure size 770x330 with 1 Axes>

Summary

  • The Newton loop converges in a small number of iterations (typically ≤ 10) for log-concave likelihoods.
  • The posterior mean tracks the true latent; uncertainty grows in regions with sparse data and shrinks where many same-labeled observations cluster.
  • Site precisions reflect the standard σ(1−σ)\sigma(1-\sigma) Bernoulli curvature, peaking near the decision boundary — a useful diagnostic for whether the linearization is well-behaved.

LaplaceInference is the simplest entry to non-Gaussian GP inference. Trade-offs against the alternatives (Gauss-Newton, EP, PL, QN) are explored in the companion notebooks.