Introduction to variational inference
In probabilistic machine learning, our goal is often not just to find a single “best” set of parameters for a model, but to quantify our uncertainty over all possible parameters. We accomplish this using Bayesian inference.
Let denote the parameter space, and let be the vector of all parameters in our model (e.g., the weights and biases of a neural network). Let be our observed training data, consisting of input–target pairs. Bayesian inference updates our prior beliefs about the parameters, , after observing the data, yielding the posterior distribution .
This update is governed by Bayes’ theorem:
Here,
is the posterior distribution, summarising our updated beliefs about given the data;
is the likelihood, viewed as a function of : for a given choice of parameters, it quantifies how likely the observed data are under the model;
is the prior distribution, which encodes our beliefs about before observing any data; and
is the marginal likelihood, also called the evidence.
The central computational challenge in most modern Bayesian inference problems is evaluating , which requires integrating the joint distribution over the parameter space . For models such as Bayesian neural networks, this integral is high-dimensional and generally lacks an analytic closed-form solution. Consequently, the posterior density usually cannot be evaluated in normalised form, motivating approximate inference methods. This chapter focuses on variational inference, also known as variational Bayes, a widely used family of scalable approximate inference methods Jordan et al., 1999Wainwright & Jordan, 2008Blei et al., 2017.
A Variational Approach: Bayesian Inference as Optimisation¶
The core idea of variational inference (VI) is to reframe Bayesian inference as an optimisation problem. Instead of representing the generally intractable posterior exactly, we choose a tractable distribution from a variational family , where denotes its variational parameters. Concretely, could be a family of Gaussian distributions or a family of factorised distributions, as developed in Chapter Gaussian mean-field variational inference. The goal is to find the member that best approximates the posterior.
The Kullback–Leibler Divergence¶
Following Kullback & Leibler (1951), the Kullback–Leibler (KL) divergence from to the posterior is
Because the KL divergence is asymmetric, its direction must be stated explicitly. VI seeks variational parameters satisfying
Rewriting the KL Objective¶
Expanding the posterior in Equation (2) using Bayes’ theorem gives
Although the KL divergence itself cannot generally be evaluated exactly because is unavailable, the log-evidence term is constant with respect to and therefore does not affect the optimiser in Equation (3). The remaining expectation does not require evaluating and can be estimated using samples from whenever the joint density and variational density can be evaluated.
The Evidence Lower Bound (ELBO)¶
Rearranging Equation (4) yields
The first term defines the evidence lower bound (ELBO) . Because the KL divergence is non-negative,
The gap between the ELBO and the log evidence is exactly ; the closer the variational distribution is to the posterior in this divergence, the smaller the gap. Since is constant with respect to , Equation (5) also gives
Thus, VI replaces evaluation of the posterior in normalised form with optimisation of an objective that can be estimated under suitable choices of likelihood, prior, and variational family.
Interpreting the ELBO¶
Using , the ELBO can be written as
The alternative form in Equation (8) reveals a trade-off between two terms:
Expected log-likelihood (data fit): This term rewards variational distributions that place more probability in regions of parameter space where the observed data have high likelihood.
KL penalty (regularisation): This term penalises departures of from the prior and can therefore be viewed as a complexity penalty.
VI selects the member of that balances fit to the observed data against departure from the prior.
Other Lower Bounds on the Log-Evidence¶
The ELBO is one lower bound on . More generally, strictly positive unbiased estimators of can induce lower bounds through Jensen’s inequality; this optional subsection states the construction underlying importance-weighted and sequential Monte Carlo objectives.
Assume that whenever . Then
For a concave function and random variable , Jensen’s inequality states that . Taking in Equation (9) gives
More generally, let denote the sampling density of all random variables used to construct a strictly positive unbiased estimator of , and suppose that . Then
Jensen’s inequality gives the lower bound
The standard ELBO is recovered by taking , , and . For example, Burda et al. (2016) introduce the importance-weighted autoencoder (IWAE) objective, which uses independent samples and the estimator
Related lower bounds can be constructed using sequential Monte Carlo Maddison et al., 2017. Although may not be available in closed form, it can often be optimised using Monte Carlo gradient estimators. However, a tighter bound alone does not guarantee better optimisation or predictive performance, because the signal-to-noise ratio and other properties of the associated gradient estimator also matter Rainforth et al., 2018.
In summary, VI approximates by optimising a distribution from a tractable family, with the ELBO providing an objective that balances data fit against departure from the prior. Chapter Gaussian mean-field variational inference develops the mean-field construction in detail, and subsequent chapters consider further variational families and optimisation methods.
- 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.
- Wainwright, M. J., & Jordan, M. I. (2008). Graphical Models, Exponential Families, and Variational Inference. Foundations and Trends in Machine Learning, 1(1–2), 1–305.
- Blei, D. M., Kucukelbir, A., & McAuliffe, J. D. (2017). Variational Inference: A Review for Statisticians. Journal of the American Statistical Association, 112(518), 859–877.
- Kullback, S., & Leibler, R. A. (1951). On Information and Sufficiency. The Annals of Mathematical Statistics, 22(1), 79–86.
- Burda, Y., Grosse, R., & Salakhutdinov, R. (2016). Importance weighted autoencoders. International Conference on Learning Representations (ICLR).
- Maddison, C., Lawson, J., Tucker, G., Heess, N., Norouzi, M., Mnih, A., Doucet, A., & Teh, Y. (2017). Filtering Variational Objectives. In I. Guyon, U. V. Luxburg, S. Bengio, H. Wallach, R. Fergus, S. Vishwanathan, & R. Garnett (Eds.), Advances in Neural Information Processing Systems (Vol. 30). Curran Associates, Inc.
- Rainforth, T., Kosiorek, A., Le, T. A., Maddison, C., Igl, M., Wood, F., & Teh, Y. W. (2018). Tighter Variational Bounds are Not Necessarily Better. In J. Dy & A. Krause (Eds.), Proceedings of the 35th International Conference on Machine Learning (Vol. 80, pp. 4277–4285). PMLR.