Computational Inference
Outside conjugate models the posterior distribution is known only up to its normalising constant, since the marginal likelihood has no closed form, and posterior summaries such as 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 these integrals either by simulation from the posterior or by approximating the posterior with a tractable distribution. Below is the unnormalised posterior, which can be evaluated, and is the target.
Let be iid draws from the posterior distribution. The Monte Carlo estimate of a posterior expectation is the average of the function over the draws.
The estimate is unbiased, converges almost surely to the posterior expectation by the strong law of large numbers and, if has finite posterior variance is asymptotically normal by the central limit theorem with Monte Carlo standard error estimated by replacing with the sample standard deviation of the The 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 is generating the draws.
Rejection sampling draws from the target using a proposal distribution that is easy to sample from and a constant with A draw is accepted with probability and otherwise discarded, and 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.
Importance sampling reweights draws from a proposal distribution rather than discarding them. For a proposal with wherever
so with draws and importance weights the self-normalised importance sampling estimate is
which is consistent and needs only the unnormalised posterior, while is an unbiased estimate of the marginal likelihood. Its variance is governed by the variability of the weights and is summarised by the effective sample size the number of iid posterior draws that would give the same precision. The variance is infinite if has lighter tails than the posterior, and 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) constructs an irreducible, aperiodic Markov chain on whose stationary distribution is the posterior and runs it to obtain dependent draws 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 The initial draws before the chain has approached its stationary distribution are the burn-in and are discarded. Because successive draws are correlated, the Monte Carlo standard error is larger than for iid draws: with autocorrelation at lag in the sequence the effective sample size is Convergence is assessed by running several chains from dispersed starting points and comparing the variance between chains with the variance within chains through the potential scale reduction factor which approaches one when the chains have mixed.
The Metropolis–Hastings algorithm generates the next state from the current state by drawing a candidate from a proposal distribution and accepting it with the acceptance probability
setting if accepted and otherwise. The resulting chain satisfies detailed balance with respect to the posterior for any proposal that makes it irreducible. With a symmetric proposal such as the algorithm is random walk Metropolis and the acceptance probability reduces to so moves to higher posterior density are always accepted and moves to lower density are accepted with probability equal to the density ratio. The independence sampler proposes from a fixed distribution that approximates the posterior. 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 for random walk proposals in high dimensions. Random walk Metropolis explores a -dimensional posterior in a number of steps that grows like which is slow for large
Let and denote all components except The full conditional distribution of is its posterior distribution given the other components, viewed as a function of alone. The Gibbs sampler 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. It is the Metropolis–Hastings algorithm with the full conditional as proposal, for which every candidate is accepted, and it requires no tuning but does require 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, and components that are not conjugate can be updated with a Metropolis–Hastings step inside the cycle. Introducing latent variables whose full conditionals, together with those of are tractable is data augmentation and is how mixture and censored models are sampled.
Hamiltonian Monte Carlo (HMC) uses the gradient of the log posterior to propose distant states with high acceptance probability. The parameter is augmented with an auxiliary momentum vector with distribution for a positive definite mass matrix and the Hamiltonian is the negative log joint density of
the sum of a potential energy and a kinetic energy. Each iteration draws a fresh momentum, then simulates Hamilton’s equations for a fixed time using the leapfrog integrator with step size and steps, which alternates half-step momentum updates with full-step position updates, and accepts the end point with probability Exact Hamiltonian dynamics conserve and would always be accepted, and the leapfrog integrator is reversible and volume preserving so that the Metropolis correction exactly removes its discretisation error. 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) chooses adaptively by extending the trajectory until it starts to double back, and is the default sampler in modern probabilistic programming software.
Analytic approximations replace the posterior by a tractable distribution rather than sampling from it. The Laplace approximation fits a normal distribution at the posterior mode using the second-order Taylor expansion of the log posterior,
where is the negative Hessian matrix of the log posterior at the mode, and gives the approximation of the marginal likelihood by integrating the normal density. It is accurate when the posterior is close to normal, which by the Bernstein–von Mises theorem holds for large in regular models, and poor for skewed, multimodal or bounded posteriors.
Variational inference chooses a family of tractable distributions and finds the member closest to the posterior in Kullback–Leibler divergence,
which turns integration into optimisation. The divergence involves the unknown marginal likelihood, but expanding it gives
where the evidence lower bound (ELBO) depends only on the unnormalised posterior and, since the divergence is non-negative, 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 The mean-field family consists of distributions that factorise over components, for which coordinate ascent variational inference maximises the ELBO one factor at a time with the closed-form update
the expectation of the log joint density over the other factors, mirroring the Gibbs sampler with expectations in place of draws. Alternatively, is a parametric family such as multivariate normal distributions and the ELBO is maximised by gradient methods using Monte Carlo estimates of its gradient. Variational inference is much faster than MCMC and scales to large data sets, but 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, and the mean-field family cannot represent posterior correlations.