Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Tracing a complicated shape with a simple stencil
Suppose the answer to your problem is a complicated, lumpy shape that’s expensive to describe. You only have a few stencils: circles and ovals of any size. Variational inference picks the stencil that best matches the shape, by sliding and stretching it until it overlaps as well as possible.
It’s much faster than exploring the whole shape point by point (as MCMC does), so it scales to models with millions of parameters. The price: a simple stencil can’t capture everything, so it may hide in one lump or make the shape look tighter than it really is.
Variational autoencoders, Bayesian deep learning, large-scale topic models and fast approximate filters all use variational inference. Knowing its typical errors (overconfidence and missed modes) tells you when to trust it on a robot or spacecraft, and when to double-check with sampling.
- 1. Variational inference turns posterior computation into…
- 2. Compared with MCMC, VI is usually…
- 3. A common failure of simple VI approximations is…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.The ELBO
For any distribution over the latent variables or parameters,
Since KL ≥ 0, the ELBO is a lower bound on the log evidence. Because doesn’t depend on , maximizing the ELBO = minimizing KL(q‖posterior), and we never need the intractable . The ELBO is “expected fit” + “entropy of ”.
Mean-field
The most common family is : independent factors. The coordinate-ascent update (CAVI) for each factor is
For conjugate exponential-family models this has closed form, and CAVI is like Gibbs with expectations instead of samples. The ELBO never decreases.
- 1. log p(x) − ELBO =
- 2. Mean-field assumes the latent variables are…
- 3. Maximizing the ELBO requires knowing p(x)?
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 45 minUndergraduate students and practising engineers.Black-box / stochastic VI
For non-conjugate models, maximize the ELBO by stochastic gradient ascent. With , reparameterize with (A4.3-2):
Estimate it with a few samples per step and use Adam. Minibatches of data make it scale to millions of points (stochastic VI; Hoffman et al., 2013). A VAE amortizes this: an encoder network outputs for each data point (Kingma and Welling, 2014).
What VI gets wrong
- Variance underestimation. For a Gaussian target with precision , mean-field gives marginal variances instead of . With correlation 0.9, that’s 0.19 instead of 1.
- Mode-seeking. KL(q‖p) is infinite if puts mass where has none, so retreats into one mode.
- Better families help: full-covariance or low-rank Gaussians, normalizing flows (A4.3-2), mixtures. Always validate VI against MCMC on a subproblem, or use diagnostics such as PSIS- (Yao et al., 2018).
- 1. The reparameterization trick writes z = …
- 2. Mean-field variance for a Gaussian target is…
- 3. A VAE's encoder outputs…
Level 3: Advanced
★★★★☆ Advanced⏱ 45 minGraduate level, with full derivations and proofs.Deriving the ELBO decomposition
The first term is the ELBO and the second is . Equivalently, Jensen: . ∎ The same bound gives EM (A5.2-10).
Deriving the CAVI update
Holding fixed, the ELBO as a functional of is , where . It’s maximized by . ∎ For a Gaussian target, this gives with .
Why reverse KL is mode-seeking
blows up wherever and , so avoids the valley between modes and fits under one. blows up wherever and , so must cover all of ’s mass. Its optimum within Gaussians is moment matching. Expectation propagation uses the forward direction locally (Minka, 2001).
Exercise 3.1: Compute KL(q ‖ p) for mean-field vs a 2-D Gaussian with correlation ρ
With and unit-variance : . So . That’s 0.83 nats at ρ = 0.9.
- 1. The ELBO is a lower bound by…
- 2. The optimal mean-field factor is ∝ …
- 3. Minimizing forward KL(p‖q) over Gaussians gives…
Level 4: Expert
★★★★★ Expert⏱ 40 minResearchers: original papers and open problems.VI vs MCMC for grasp-success regression
Black-box VI with a mean-field Gaussian on the same logistic-regression posterior as A5.2-7 converges in a few hundred Adam steps. Its means match MCMC’s, but its posterior standard deviations are smaller (here by about 6%). The parameters are correlated, and mean-field can’t represent that. For decisions near a safety threshold, that overconfidence matters. Practical recipes: use full-rank or flow-based , check against MCMC on a subsample, or use VI only for the initial fit and then run NUTS.
Variational inference in AI, robotics and aerospace
- Variational autoencoders and deep generative models maximize the ELBO with amortized encoders (Kingma and Welling, 2014; Rezende, Mohamed and Wierstra, 2014). World models for model-based RL use sequential VAEs (Hafner et al., 2019).
- Bayesian neural networks: Bayes by Backprop (Blundell et al., 2015) and MC dropout (Gal and Ghahramani, 2016) give approximate weight uncertainty for perception and control.
- Variational filters and smoothers: variational Bayes Kalman filters that adapt unknown noise covariances online (Särkkä and Nummenmaa, 2009).
- Topic and mixture models at scale: stochastic VI over millions of documents or log lines (Hoffman et al., 2013).
- Control as inference: maximum-entropy RL and MPPI can be derived as variational inference on trajectories (Levine, 2018).
References
- M. Jordan, Z. Ghahramani, T. Jaakkola, L. Saul (1999). “An introduction to variational methods for graphical models.” Machine Learning, 37.
- D. Blei, A. Kucukelbir, J. McAuliffe (2017). “Variational inference: a review for statisticians.” JASA, 112(518).
- M. Hoffman, D. Blei, C. Wang, J. Paisley (2013). “Stochastic variational inference.” JMLR, 14.
- D. Kingma, M. Welling (2014). “Auto-encoding variational Bayes.” ICLR.
- R. Ranganath, S. Gerrish, D. Blei (2014). “Black box variational inference.” AISTATS.
- T. Minka (2001). “Expectation propagation for approximate Bayesian inference.” UAI.
- Y. Yao, A. Vehtari, D. Simpson, A. Gelman (2018). “Yes, but did it work? Evaluating variational inference.” ICML.
- C. Blundell, J. Cornebise, K. Kavukcuoglu, D. Wierstra (2015). “Weight uncertainty in neural networks.” ICML.
- S. Särkkä, A. Nummenmaa (2009). “Recursive noise adaptive Kalman filtering by variational Bayesian approximations.” IEEE Transactions on Automatic Control, 54(3).
- S. Levine (2018). “Reinforcement learning and control as probabilistic inference: tutorial and review.” arXiv:1805.00909.