Computational Inference
Let be a Bayesian model. The unnormalised posterior is the product of the likelihood and the prior, which can be evaluated without the marginal likelihood.
The posterior distribution is and is the target of the methods below.
Let be a function. An intractable integral is a posterior summary such as the marginal likelihood or a posterior expectation that has no closed form. Outside conjugate models the posterior distribution is known only up to its normalising constant and its summaries are intractable integrals over a parameter space whose dimension is often large. Numerical integration on a grid is only feasible in one or two dimensions, since the number of grid points grows exponentially with the dimension. Computational inference approximates intractable integrals either by simulation from the posterior or by approximating the posterior with a tractable distribution.
Let be iid draws from the posterior distribution and be a function. The Monte Carlo estimate of the posterior expectation of is the average of over the draws.
Let be a Monte Carlo estimate from iid draws and be the posterior variance of The Monte Carlo standard error of is estimated by replacing with the sample standard deviation of the The Monte Carlo estimate has the following properties:
- it is unbiased;
- it converges almost surely to the posterior expectation by the strong law of large numbers;
- if is finite it is asymptotically normal by the central limit theorem, so its error decreases as regardless of the dimension of
- posterior probabilities are estimated by averaging indicators, quantiles by sample quantiles of the draws and the posterior predictive distribution by drawing for each
The difficulty of Monte Carlo estimation is generating the draws.
Let be an unnormalised posterior. A proposal distribution is a probability distribution on that is easy to sample from.
Let be an unnormalised posterior, be a proposal distribution and be a constant with for all Rejection sampling is the method that draws accepts it with probability and otherwise discards it. Rejection sampling has the following properties:
- the accepted draws are iid from the posterior;
- the probability that a draw is accepted is which is typically tiny in more than a few dimensions because no simple matches the posterior closely enough for to be small.
Let be an unnormalised posterior and be a proposal distribution with wherever The importance weight of is the ratio of the unnormalised posterior to the proposal density.
The posterior expectation of is a ratio of expectations under
Let be iid draws from a proposal distribution with importance weights Importance sampling is the method that reweights the draws by their importance weights rather than discarding them. The self-normalised importance sampling estimate of the posterior expectation of is the weighted average of over the draws.
Let be importance weights. The effective sample size of the weighted draws is the number of iid posterior draws that would give the same precision.
Importance sampling has the following properties:
- the self-normalised estimate is consistent and needs only the unnormalised posterior;
- is an unbiased estimate of the marginal likelihood;
- the variance of the estimate is governed by the variability of the weights and is summarised by the effective sample size;
- the variance is infinite if has lighter tails than the posterior;
- the effective sample size collapses in high dimensions, so importance sampling is used for low-dimensional problems or to correct draws from an approximate posterior.
Markov chain Monte Carlo (MCMC) is the method that constructs an irreducible, aperiodic Markov chain on whose stationary distribution is the posterior and runs it to obtain dependent draws MCMC has the following properties:
- by the ergodic theorem for Markov chains the sample path average converges almost surely to the posterior expectation from any starting point, and the distribution of converges to the posterior;
- the chain is constructed to satisfy the detailed balance equations with respect to which only requires ratios of the target and so needs only
Let be the draws of an MCMC chain. The burn-in is the initial draws before the chain has approached its stationary distribution, which are discarded.
Let be the draws of an MCMC chain and be the autocorrelation at lag of the sequence The effective sample size of the chain is the number of iid draws that would give the same precision as the correlated draws.
Because successive draws are correlated, the Monte Carlo standard error of an MCMC estimate is larger than for iid draws.
Let several MCMC chains be run from dispersed starting points. The potential scale reduction factor is the ratio that compares the variance between chains with the variance within chains, which approaches one when the chains have mixed. Convergence of MCMC is assessed by running several chains and computing
Let be an unnormalised posterior and be a proposal distribution that depends on the current state The acceptance probability of a candidate is the quantity
Let be an unnormalised posterior and be a proposal distribution. The Metropolis–Hastings algorithm is the MCMC method that generates the next state from the current state by drawing a candidate setting with probability and setting otherwise. The resulting chain satisfies detailed balance with respect to the posterior for any proposal that makes it irreducible.
Let be a symmetric proposal distribution such as Random walk Metropolis is the Metropolis–Hastings algorithm with a symmetric proposal, for which the acceptance probability reduces to Random walk Metropolis has the following properties:
- moves to higher posterior density are always accepted and moves to lower density are accepted with probability equal to the density ratio;
- the proposal scale trades off the size of moves against the acceptance rate: too small and the chain moves slowly, too large and almost every candidate is rejected, with an acceptance rate near optimal in high dimensions;
- it explores a -dimensional posterior in a number of steps that grows like which is slow for large
The independence sampler is the Metropolis–Hastings algorithm with a proposal that does not depend on the current state and approximates the posterior.
Let and denote all components except The full conditional distribution of is the posterior distribution of given the other components, which is viewed as a function of alone.
Let with full conditional distributions The Gibbs sampler is the MCMC method that updates one component at a time by drawing it from its full conditional distribution with the other components fixed at their current values, cycling through to produce each new state. The Gibbs sampler has the following properties:
- it is the Metropolis–Hastings algorithm with the full conditional as proposal, for which every candidate is accepted;
- it requires no tuning but requires the full conditionals to be standard distributions, which is the case when each parameter has a conjugate prior given the others;
- strongly correlated components make the sampler move slowly, since each update is restricted to a coordinate direction;
- components that are not conjugate can be updated with a Metropolis–Hastings step inside the cycle.
Let be the parameter of a Bayesian model. Latent variables are additional unobserved random variables introduced into the model. Data augmentation is the method that introduces latent variables whose full conditionals, together with those of are tractable, which is how mixture and censored models are sampled.
Let be an unnormalised posterior on and be a positive definite matrix. The momentum is an auxiliary vector with distribution and is the mass matrix. The Hamiltonian is the negative log joint density of which is the sum of a potential energy and a kinetic energy.
Let be a Hamiltonian. Hamilton’s equations are the differential equations and Exact Hamiltonian dynamics conserve
Let and The leapfrog integrator with step size and steps is the numerical method for Hamilton’s equations that alternates half-step momentum updates with full-step position updates. The leapfrog integrator is reversible and volume preserving.
Let be a differentiable unnormalised posterior with Hamiltonian Hamiltonian Monte Carlo (HMC) is the MCMC method in which each iteration draws a fresh momentum, simulates Hamilton’s equations for a fixed time using the leapfrog integrator and accepts the end point with probability HMC has the following properties:
- exact Hamiltonian dynamics would always be accepted, and the Metropolis correction exactly removes the discretisation error of the leapfrog integrator;
- the trajectory follows the geometry of the posterior rather than diffusing, so HMC explores a -dimensional posterior in a number of steps that grows like and far outperforms random walk methods for large
- it requires a differentiable log posterior and tuning of and
The No-U-Turn sampler (NUTS) is the variant of HMC that chooses adaptively by extending the trajectory until it starts to double back. NUTS is the default sampler in probabilistic programming software.
An analytic approximation is a method that replaces the posterior by a tractable distribution rather than sampling from it.
Let be an unnormalised posterior on with mode and be the negative Hessian matrix of the log posterior at the mode. The Laplace approximation is the normal distribution fitted at the posterior mode using the second-order Taylor expansion of the log posterior.
The Laplace approximation has the following properties:
- integrating the normal density gives the approximation of the marginal likelihood
- it is accurate when the posterior is close to normal, which by the Bernstein–von Mises theorem holds for large in regular models;
- it is poor for skewed, multimodal or bounded posteriors.
Let be a family of tractable distributions on Variational inference is the method that finds the member of closest to the posterior in Kullback–Leibler divergence, which turns integration into optimisation.
Let be a distribution on and be an unnormalised posterior. The evidence lower bound (ELBO) of is the expected log unnormalised posterior under minus the expected log density of under
The ELBO has the following properties:
- the log marginal likelihood decomposes as
- since the divergence is non-negative, the ELBO is a lower bound on the log marginal likelihood that is tight when equals the posterior;
- minimising the divergence is therefore equivalent to maximising the ELBO over which depends only on the unnormalised posterior.
Let The mean-field family is the family of distributions that factorise over components.
Let be the mean-field family and denote the factors other than Coordinate ascent variational inference is the method that maximises the ELBO one factor at a time with the closed-form update
the expectation of the log joint density over the other factors, which mirrors the Gibbs sampler with expectations in place of draws. Alternatively, is a parametric family such as the multivariate normal distributions and the ELBO is maximised by gradient methods using Monte Carlo estimates of its gradient. Variational inference has the following properties:
- it is much faster than MCMC and scales to large data sets;
- the fitted underestimates the posterior variance, because minimising penalises placing mass of where the posterior is small more than it penalises missing mass of the posterior;
- the mean-field family cannot represent posterior correlations.