The Laplace approximation and Bayesian classification
When the posterior is not Gaussian, replace it with a Gaussian at the mode whose covariance is the inverse Hessian: Bayesian logistic regression and IRLS, the moderated output via the probit approximation, the Laplace evidence and BIC, relevance vector classification and the cases where the approximation fails.
Where conjugacy ends
In the topics Bayesian linear regression and The relevance vector machine every step was exact. A Gaussian likelihood times a Gaussian prior gave a Gaussian posterior, and the evidence was a Gaussian integral. Classification breaks this at the first step.
Let the labels be and let the model say
This is logistic regression. The likelihood of all labels is a product of Bernoulli terms, and with the usual prior the posterior is
The logarithm of a sigmoid is not quadratic in , so this is not a Gaussian. No prior over is conjugate to it. Two integrals that were routine before now have no closed form: the normalizer , which is the evidence, and the predictive probability .
This topic replaces the posterior with a Gaussian chosen locally: centred at the posterior mode, with a width read off the curvature there. That is the Laplace approximation. It gives an approximate posterior, an approximate evidence and, for classification, a predictive probability that knows how uncertain the weights are.
A Gaussian at the mode
Write the posterior as , where is the unnormalized posterior and . Let be the mode, so the gradient of vanishes there. A second-order Taylor expansion of the log at the mode has no linear term:
Exponentiate, and the right-hand side is the kernel of a Gaussian:
Three remarks.
- Only is needed. is a constant, and constants vanish under derivatives. This is what makes the method usable: is exactly what we cannot compute.
- must be positive definite, which holds at a strict maximum. A sharp peak means large curvature and a narrow Gaussian.
- When the posterior is Gaussian, is exactly quadratic and the approximation is exact. In Bayesian linear regression is the posterior precision found in that topic.
Now the coin. Take a uniform prior on the probability of heads and observe 3 heads and 1 tail. Then and
The Laplace posterior is a Gaussian at with standard deviation . The exact posterior is , with mean and standard deviation . The Gaussian sits at the mode, not the mean, and it is too wide: the true posterior is skewed and bounded by , and a Gaussian can be neither.
The Laplace evidence and BIC
The same Gaussian also gives the normalizer. Integrate the approximation of instead of itself. The Gaussian integral in dimensions is known:
In logarithms, with ,
The first term is the fit. The other three are the log of the Occam factor from the topic Bayesian model selection: the prior density at the mode times the volume of the posterior. In one dimension it is roughly the posterior width divided by the prior width. A model pays for every parameter that the data pin down much more tightly than the prior did.
For the coin, and , so the Laplace evidence is . The exact evidence of this sequence is . Laplace overshoots by about , the price of the skew.
With many data points the formula simplifies further. For i.i.d. points is a sum of per-point curvatures plus the prior's, so for some fixed matrix and . Keep only the terms that grow with , and becomes the maximum likelihood estimate:
This is the Bayesian information criterion (BIC); it is often multiplied by and then minimized. Each parameter costs nats. The prior and all terms are gone, so BIC needs large and a full-rank , and for small samples it is crude.
Bayesian logistic regression
Back to classification. Put the features into the design matrix with rows , as in Bayesian linear regression. The log-posterior is
With the derivatives come out short:
The Hessian is negative definite for every , so the log-posterior is strictly concave: one mode, no local optima. Newton's method finds it,
with and recomputed at the current . Each step solves a weighted least-squares problem with weights , hence the name iteratively reweighted least squares (IRLS). Without the prior () and with separable classes, the likelihood keeps growing as and there is no mode at all; the prior keeps it finite.
At the mode, the Laplace approximation is
Compare it with in linear regression. The noise precision is replaced by a weight per point. It is largest at : points near the decision boundary say the most about , and confidently classified points say little.
A running example with one feature and no bias: , labels , prior precision . Newton from converges in three steps to . There , so the Laplace standard deviation is . Five points barely pin the weight down.
The predictive and the probit approximation
The predictive probability for a new point averages the sigmoid over the posterior:
The integrand depends on only through the activation . Under the Laplace posterior is a linear function of a Gaussian vector, so it is Gaussian:
What remains is a one-dimensional integral , still without a closed form. The trick is the probit approximation. Let be the standard normal CDF. Scaled to match the slope of at zero, it is very close to the sigmoid:
with a maximum error below . A Gaussian average of a probit is again a probit, . Converting back to the sigmoid gives the moderated output:
Since , the activation is pulled toward zero, more strongly where the weights are uncertain. The sign of does not change, so the decision boundary at probability is the same as for . What changes is the confidence away from the data.
In the running example take . Then , and . Plugging in gives ; the moderated output is . Integrating over the exact posterior numerically gives . The plug-in estimate is overconfident; the moderated one is close.
Relevance vector classification
The Laplace evidence lets classification use the machinery of The relevance vector machine. Give every weight its own precision, with for basis functions. The exact evidence is out of reach, but the Laplace one is not:
Setting its derivatives in to zero, with held fixed, gives the same fixed-point updates as in regression. The Gaussian posterior that was exact there is now the Laplace one. Training alternates two loops:
- For the current , run Newton (IRLS) to the mode , warm-started from the previous one.
- At the mode, form .
- Update and .
- Remove the basis functions whose has run off to infinity, and repeat.
The result is a relevance vector classifier: sparse like an SVM, usually with far fewer kept vectors, and with probabilities as outputs through the moderated predictive. The cost is the nested loop: every evidence step needs a fresh Newton solve.
Where Laplace fails and what comes next
A Gaussian fitted at one point sees only the local curvature. Four things escape it.
- Skew and bounded support. For the coin the Gaussian sits at the mode while the mean is , puts of its mass above , and overestimates the evidence by .
- Parametrization. A density changes by a Jacobian when the variable changes, so the mode moves and the Laplace answer depends on the coordinates. In the log-odds the coin's Gaussian covers the whole line and maps back inside . It gives a mean of of , a standard deviation and an evidence , much closer to the exact , and .
- Several modes. Observe with , noise standard deviation and prior . The posterior has peaks at . The Gaussian at one of them has standard deviation , while the whole posterior spreads with standard deviation : almost eight times wider. The other peak is invisible.
- Heavy tails and cost. The curvature at the mode says nothing about mass far away. And is a matrix: for large models it is expensive to form and invert, and nearly flat directions make it close to singular. Laplace for neural networks returns in Bayesian deep learning.
The method works well when the posterior is unimodal and close to Gaussian, typically with plenty of data. Log-concave posteriors such as logistic regression's are the safe case.
Everything here started from the mode. With latent variables even that becomes hard. In a mixture model each point has a hidden component label, and the likelihood puts a sum inside the logarithm: no closed-form maximum, and many equivalent modes from relabelling the components. The next topic, EM and Bayesian PCA, builds an algorithm that climbs such likelihoods by filling in the hidden variables.
Check your understanding
The same questions as in Pulse. Answers are shared between modes.
Answers are saved on the server and tied to this browser until you sign in.