Laplace approximation

On this page 7

The Laplace approximation is a method that replaces an intractable probability distribution, usually a Bayesian posterior, with a Gaussian centered at the distribution’s mode, whose covariance is the inverse of the negative Hessian of the log density at that point. Probabilistic models in machine learning use it to obtain fast uncertainty estimates and an approximation of the marginal likelihood without sampling.

The technique goes back to Pierre-Simon Laplace’s work on integrals in the late eighteenth century. In modern artificial intelligence it is valued because it reuses an optimization result: once a maximum a posteriori estimate is found, only second-order curvature information is needed to turn a point estimate into a full approximate posterior.

How the Laplace approximation is constructed

The Laplace approximation is constructed by a second-order Taylor expansion of the log posterior around its mode. Because the gradient is zero at the mode, the expansion contains only a constant and a quadratic term, and the exponential of a quadratic is a Gaussian density.

  1. Find the mode by maximizing the log joint density, which yields the maximum a posteriori estimate.
  2. Compute the Hessian matrix of the negative log posterior at that mode.
  3. Use the mode as the mean and the inverse Hessian as the covariance.
  4. Optionally evaluate the evidence approximation from the same quantities.

The evidence approximation follows directly: the log marginal likelihood is approximated by the log joint density at the mode, plus half of the dimension times the log of two pi, minus half of the log determinant of the Hessian. This term acts as an automatic Occam factor that penalizes models whose posterior is sharply peaked relative to the prior.

The table lists the core quantities and the role each one plays in the approximation.

QuantityHow it is obtainedRole in the approximation
ModeGradient-based optimizationMean of the Gaussian
HessianSecond derivatives of the negative log posteriorPrecision matrix
CovarianceInverse of the HessianUncertainty in parameters
Log determinantFrom the Hessian factorizationVolume term in the evidence
Components of the Laplace approximation

Hessian approximations and scalable variants

Scalable variants of the Laplace approximation exist because the exact Hessian is too expensive for models with millions of parameters. Storing a full matrix grows quadratically with the parameter count, and inverting it grows cubically, so practitioners trade fidelity for tractability.

VariantCurvature structureTypical use
Full HessianDense matrixSmall models, logistic regression
DiagonalPer-parameter variance onlyLarge networks with tight budgets
Kronecker-factored (KFAC)Per-layer Kronecker productsDeep neural networks
Generalized Gauss-NewtonPositive semidefinite approximationStable curvature in deep learning
Last-layer LaplaceFull curvature on final layer onlyCheap uncertainty for pretrained models
Common curvature structures

In a Bayesian neural network, the generalized Gauss-Newton matrix is often preferred because the true Hessian can be indefinite away from an exact optimum, which would produce an invalid covariance. A prior precision term is added to the curvature, and tuning that term by maximizing the approximate evidence is a standard step.

Laplace approximation compared with other inference methods

Compared with other approximate inference methods, the Laplace approximation is the cheapest and the most local. It describes the posterior only through the shape of one peak, whereas sampling and optimization-based methods can capture more of the global structure.

MethodApproximation typeMain strengthMain weakness
Laplace approximationGaussian at the modePost hoc and fastIgnores skew and other modes
Variational inferenceOptimized family memberScales with stochastic gradientsUnderestimates variance
Markov chain Monte CarloSamples from the posteriorAsymptotically exactSlow on large models
Expectation propagationMoment matching per factorAccurate marginalsConvergence not guaranteed
Approximate inference methods side by side

Variational inference optimizes the evidence lower bound and therefore chooses its Gaussian globally, while the Laplace approximation fixes its Gaussian locally from curvature. For Gaussian process classification, the Laplace approximation was historically a standard choice because the posterior over latent function values is unimodal and log-concave under common likelihoods.

When the approximation works and when it fails

The Laplace approximation works well when the posterior is unimodal, roughly symmetric and concentrated, which tends to happen as the amount of data grows. The Bernstein-von Mises theorem formalizes this: under regularity conditions, posteriors approach a Gaussian as the sample size increases.

  • Multimodal posteriors: only one mode is described, so other plausible solutions are missed.
  • Skewed or bounded parameters: variances and rates near zero produce poor Gaussian fits unless the parameter is reparameterized on the log scale.
  • Small data: curvature at the mode may not represent the overall spread.
  • Non-converged optimization: a Hessian taken away from the true mode can be indefinite.
  • Overconfident predictions: in deep networks, naive sampling from the Gaussian can perform poorly, so the linearized predictive is often used instead.

The parameterization matters because the approximation is not invariant to reparameterization. Transforming constrained parameters to an unconstrained space before expanding usually improves accuracy substantially.

Practical use in modern machine learning

In modern machine learning, the Laplace approximation is used mainly for post hoc uncertainty quantification and model selection. Because it starts from a trained model, it can add calibrated predictive uncertainty to an existing network without retraining.

The decision table matches common goals with a suitable configuration.

GoalRecommended setupReason
Calibrate a pretrained classifierLast-layer KFAC LaplaceLow cost with useful uncertainty
Compare model architecturesEvidence from full or KFAC curvatureOccam factor penalizes complexity
Hierarchical statistical modelNested Laplace methods such as INLAAccurate marginals for latent Gaussian models
Detect out-of-distribution inputsLinearized predictive varianceAvoids overconfident softmax outputs
Choosing a Laplace configuration

Libraries for Laplace inference in deep learning typically expose the subset of weights, the Hessian structure and the prior precision as separate choices. A reliable workflow is to train normally, fit curvature on the training data, tune the prior precision on the evidence and then validate calibration on held-out data.

Understanding it simply

Imagine a hill that shows how likely each answer is. The top of the hill is the best single answer. The Laplace approximation looks only at that top. It measures how sharply the hill curves there.

A sharp peak means the model is confident. A wide, gentle peak means it is unsure. The method then draws a simple bell-shaped hill with the same top and the same curve. That bell shape is easy to work with. The catch is clear: if the real hill has two peaks or a lopsided shape, the bell shape misses part of the picture.

Applied in practice

A team building a medical image classifier already has a trained convolutional network with high accuracy on its validation set. Clinicians, however, need to know when the model is uncertain, so that doubtful scans go to a radiologist instead of being labeled automatically.

Retraining with sampling-based methods would take weeks. The team instead applies a last-layer Laplace approximation with Kronecker-factored curvature, tunes the prior precision by maximizing the approximate evidence and uses the linearized predictive distribution for each scan. The extra computation takes under an hour on one GPU.

On held-out data, the expected calibration error drops noticeably, and scans from an unfamiliar scanner receive higher predictive variance. The hospital sets a variance threshold that routes about one scan in ten for human review, which keeps automated decisions limited to cases where the model is genuinely confident.