- Introduced by
- Jordan, Ghahramani, Jaakkola & Saul
- Year
- 1999
- Type
- Approximate Bayesian inference
What does it do?
Variational inference (VI) approximates a Bayesian posterior by optimisation rather than by sampling.
It posits a tractable family of distributions and selects the member closest to the true posterior by maximising the evidence lower bound (ELBO), which is equivalent to minimising a Kullback–Leibler divergence. The graphical-model form of the method is attributed to Jordan, Ghahramani, Jaakkola and Saul (1999), and Blei, Kucukelbir and McAuliffe (2017) describe VI as a method that tends to be faster than classical approaches such as Markov chain Monte Carlo sampling.
The intuition behind the method
Suppose you cannot compute the posterior exactly, but you can score how well a candidate distribution explains the data. Variational inference restricts the search to a manageable family of distributions, for instance a product of independent Gaussians, and tunes the chosen candidate by climbing the ELBO, which increases as the approximation improves. Because the optimisation can use gradient methods and mini-batches of data, VI can handle datasets that would make MCMC impractically slow. The price is that the answer is only as good as the chosen family.
History
Jordan, Ghahramani, Jaakkola and Saul (1999) formalised variational methods for graphical models in the machine-learning literature, presenting the ELBO and the coordinate-ascent updates. Bishop (2006) includes a treatment of variational Bayes in the chapter on approximate inference. Blei, Kucukelbir and McAuliffe (2017) reviewed VI for statisticians, covering mean-field VI, its application to exponential-family models, and a stochastic-optimisation variant for large data.
When to use it
Variational inference is the right choice when (1) the posterior is intractable and MCMC would be too slow for the dataset size or model complexity; (2) the expectations required by the ELBO and its optimisation are tractable under the chosen variational family, which holds for both continuous and discrete latent variables (for example, categorical topic assignments in latent Dirichlet allocation); and (3) an approximate but fast answer is acceptable. It is routinely applied to topic models, deep generative models (variational autoencoders), Gaussian process approximations, and any hierarchical Bayesian model fit to large data. VI is not suited when the posterior has sharp multimodality or heavy tails that a unimodal or mean-field family cannot capture, or when exact posterior summaries are required.
Limitations and considerations
- The mean-field assumption ignores posterior correlations, which can cause variances to be underestimated and the approximation to be overconfident.
- KL(q || p) is asymmetric: it penalises q for placing mass where p is small, so VI tends to concentrate on one mode and miss others in multimodal posteriors.
- The ELBO is a lower bound on the log marginal likelihood, not the marginal likelihood itself, because the gap equals the KL divergence from q to the true posterior. Differences in ELBO values between models are therefore not reliable evidence for model comparison, since the size of the gap may differ across models and variational families. Check conclusions with held-out predictive performance.
- Convergence to a local maximum of the ELBO is not guaranteed; different initialisations may yield different solutions.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Scales to large datasets through mini-batch stochastic optimisation, where MCMC sampling typically becomes slow.
- The ELBO can be monitored during optimisation, and its increase indicates that the approximation is improving, although it does not by itself certify that the approximation is accurate.
- Gradient-based VI can be applied to models for which closed-form coordinate updates are unavailable, because the ELBO can be optimised directly with gradient methods, including stochastic variants on mini-batches.
- Produces a full approximate posterior distribution rather than a point estimate, so uncertainty is represented, though its accuracy depends on the chosen family.
Applications
- Fitting topic models such as Latent Dirichlet Allocation to large document collections.
- Training variational autoencoders for generative modelling and representation learning.
- Scalable Gaussian process regression and classification via sparse variational approximations.
- Approximate posterior inference in hierarchical Bayesian models fitted to large datasets.
- Approximate posterior inference in Bayesian neural networks.
How it works
How it works
The central identity states that log p(x) equals the ELBO plus the KL divergence between the approximate and true posteriors. Since log p(x) does not depend on q, maximising the ELBO over q is the same as minimising KL(q || p). The ELBO has two terms: an expected log-joint, which rewards approximations that explain the data well, and the entropy of q, which discourages approximations from collapsing to a point.
Formula
\mathcal{L}(q) = \mathbb{E}_{q}[\log p(\mathbf{x}, \mathbf{z})] - \mathbb{E}_{q}[\log q(\mathbf{z})] = \log p(\mathbf{x}) - \mathrm{KL}(q(\mathbf{z}) \| p(\mathbf{z} \mid \mathbf{x}))The Kullback–Leibler divergence KL(q || p) is non-negative and equals zero only when q = p. Its non-negativity is what makes the ELBO a lower bound on log p(x). Minimising this divergence drives q toward the true posterior; because the posterior is intractable, the minimisation is carried out indirectly by maximising the ELBO.
Formula
\mathrm{KL}(q \| p) = \mathbb{E}_{q}\!\left[\log \frac{q(\mathbf{z})}{p(\mathbf{z} \mid \mathbf{x})}\right] \geq 0The mean-field assumption factorises the approximate posterior over the latent variables into independent factors, one per variable or group of variables. This makes the ELBO tractable to compute and optimise, but it ignores posterior correlations among the latent variables. Mean-field VI is the classical form of the method.
Formula
q(\mathbf{z}) = \prod_{j=1}^{m} q_j(z_j)Coordinate ascent variational inference (CAVI) is the standard algorithm under the mean-field factorisation. Each factor q_j is set in turn to its optimal update, which is proportional to the exponentiated expected log-joint with the other factors held fixed. This update has a closed form only when the required expectations are tractable, as is typical for conjugate-exponential models; otherwise it must be approximated. The sweep repeats until the ELBO converges. Stochastic variants replace the full-data expectations with mini-batch estimates, which allows the approach to be applied to larger datasets.
Formula
q_j^*(z_j) \propto \exp\!\left(\mathbb{E}_{-j}[\log p(\mathbf{z}, \mathbf{x})]\right)Common pitfalls
- Declaring convergence from a flat ELBO without checking that the approximation is genuinely close to the posterior.
- Using mean-field VI on a model with strong posterior correlations and trusting the resulting (underestimated) posterior variances.
- Comparing ELBO values across models with different variational families as if they measured the same quantity.
- Forgetting to reparametrise continuous latent variables before computing stochastic ELBO gradients, leading to high-variance gradient estimates.
- Neglecting posterior predictive checks: a well-optimised ELBO does not guarantee the model fits the data well.
Frequently asked questions
How does variational inference differ from MCMC?
MCMC draws correlated samples that, given enough time, represent the posterior exactly. VI approximates the posterior with a simpler distribution found by optimisation. VI is typically faster and scales to larger data, but its accuracy depends on how well the chosen variational family can represent the true posterior. MCMC is asymptotically exact but can be much slower for large models.
What is the ELBO and why does maximising it matter?
ELBO stands for evidence lower bound. It equals log p(x) minus KL(q || p). Since log p(x) does not depend on q, maximising the ELBO over q is the same as minimising the KL divergence between the approximate posterior q and the true posterior p. The ELBO is therefore the quantity that is actually optimised, and its maximum defines the best approximation within the chosen family.
What is the mean-field assumption and when does it fail?
Mean-field assumes the approximate posterior factors into independent components, one per latent variable or group. This makes the ELBO tractable but ignores all correlations in the posterior. It fails when latent variables are genuinely correlated, for example the slope and intercept in a regression posterior, and the resulting marginal approximations can be overconfident, with variances that are too narrow.
Can I use variational inference for model comparison?
Not directly. The ELBO is a lower bound on the log marginal likelihood, and the gap between the two is the KL divergence from q to the true posterior. That gap is unobserved and can differ across models and variational families, so a higher ELBO for one model does not reliably show that the model is better. For model comparison, use held-out predictive performance. Treat ELBO values as a measure of optimisation progress for a fixed model.
Related methods
Sources
Jordan, M. I., Ghahramani, Z., Jaakkola, T. S., & Saul, L. K. (1999). An introduction to variational methods for graphical models. Machine Learning, 37(2), 183–233.
Open DOI referenceBlei, D. M., Kucukelbir, A., & McAuliffe, J. D. (2017). Variational inference: A review for statisticians. Journal of the American Statistical Association, 112(518), 859–877.
Open DOI referenceBishop, C. M. (2006). Pattern Recognition and Machine Learning. Springer. (Chapter 10: Approximate Inference.)
ISBN: 978-0387310732