---
title: Variational Inference (VI)
url: https://www.emergentmind.com/topics/variational-inference-vi
type: topic
---

# Variational Inference (VI)

Variational Inference (VI) is a class of optimization-based methods for approximating intractable posterior distributions in probabilistic models. VI recasts Bayesian inference—finding $p(z \mid x)$ given a model $p(x, z)$—as the problem of selecting the closest distribution $q(z)$ from a tractable family, typically by minimizing a statistical divergence such as the Kullback-Leibler (KL), Rényi, $\chi^n$, or a general $f$-divergence. VI has achieved prominence due to its computational efficiency relative to sampling-based methods, scalability to large datasets, and adaptability to a wide spectrum of models, including deep and physics-informed generative models.

## 1. Formalization and Divergence Criteria

At its core, VI seeks a tractable $q(z)$ to approximate the true posterior $p(z|x) = p(x,z)/p(x)$, frequently by solving
\[
\min_{q \in \mathcal{Q}} D(q \;\|\; p(z|x)),
\]
where $D$ is a divergence functional and $\mathcal{Q}$ is an admissible family. The most widely used divergence is the **reverse KL**,
\[
\mathrm{KL}(q \| p) = \int q(z) \log \frac{q(z)}{p(z|x)}\,dz,
\]
as maximizing the Evidence Lower Bound (ELBO) is equivalent to minimizing this quantity:
\[
\mathrm{ELBO}(q) = \mathbb{E}_q[\log p(x,z)] - \mathbb{E}_q[\log q(z)] \leq \log p(x),
\]
with equality only if $q=p(\cdot|x)$. However, the choice of divergence defines the character of approximation:

| Divergence         | Generator or Expression                                                 | Typical Behavior            |
|--------------------|------------------------------------------------------------------------|-----------------------------|
| KL$(q||p)$         | $f(t)= t\log t$                                                        | Mode-seeking                |
| KL$(p||q)$         | $f(t)= -\log t$                                                        | Mass-covering               |
| Rényi $\alpha$     | $D_{\alpha}(p||q) = \frac{1}{\alpha-1} \log \int p(z)^\alpha q(z)^{1-\alpha} dz$      | Tunable (mode-mass tradeoff) |
| $\chi^n$           | $f(t)= t^n - 1$                                                        | Mass-covering ($n>1$)       |
| General $f$        | $D_f(q||p) = \int p(z) f(q(z)/p(z)) dz$, $f$ convex, $f(1)=0$          | Flexible by $f$             |

By generalizing VI to the full class of $f$-divergences, as in $f$-VI, one can standardize the treatment of divergence selection and define surrogates with well-characterized properties [2009.13093].

## 2. Variational Bounds and Objective Construction

A fundamental step is to derive a tractable variational bound on the model evidence (marginal likelihood) $p(x)$. The classical approach is the ELBO for reverse KL, but extensions to $f$-divergences require more nuanced constructions. The $f$-VI bound is derived using a surrogate $f_\lambda(t) = f(\lambda t) - f(\lambda)$:
\[
L_f(q) \equiv \mathbb{E}_q[f^*(p(z,x)/q(z))] \geq f^*(p(x)),
\]
where $f^*(t) = t f(1/t)$ is the "dual generator". For some $f$, the bound is an upper bound; for others, a lower bound. By pairing $f$ and $g$ with duals of opposite monotonicity, a "sandwich" estimator for $p(x)$ emerges:
\[
(g^*)^{-1}\left(\mathbb{E}_q[g^*(p/q)]\right) \leq p(x) \leq (f^*)^{-1}\left(\mathbb{E}_q[f^*(p/q)]\right).
\]
This unifies bounds such as ELBO (reverse KL), $\chi$-upper bound (CUBO), and Rényi bounds within a single formalism [2009.13093, 1611.00328, 1602.02311].

When using Rényi's $\alpha$-VI, variational objectives interpolate smoothly between mass-covering and mode-seeking behaviors, controlled by $\alpha$:
\[
L_\alpha(q) = \frac{1}{1-\alpha} \log \mathbb{E}_q\left[\left(\frac{p(z, x)}{q(z)}\right)^{1-\alpha}\right].
\]
Finite-sample Monte Carlo approximations yield biased lower bounds for $\alpha < 1$, upper bounds for $\alpha > 1$, and unbiased estimates at $\alpha=1$ (ELBO) [1602.02311].

## 3. Optimization Schemes: Stochastic Gradients and Mean-Field Updates

Gradient-based stochastic optimization underpins modern VI, leveraging the reparameterization trick and Monte Carlo approximation for unbiased, low-variance gradient estimates:
\[
\text{If } z = g_\theta(\epsilon),~\epsilon\sim p(\epsilon),~L_f(q_\theta) = \mathbb{E}_{\epsilon}[f^*(p(g_\theta(\epsilon),x)/q_\theta(g_\theta(\epsilon))].
\]
The associated gradient can be approximated by
\[
\nabla_\theta L_f \approx \frac{1}{K} \sum_k \nabla_\theta f^*\big( p/q \big) \Big|_{z = g_\theta(\epsilon_k)}.
\]
Importance weighting further tightens stochastic bounds, producing a sequence converging monotonically to $f^*(p(x))$ [2009.13093, 1602.02311].

For factorized variational families,
\[
q(z) = \prod_{j=1}^J q_j(z_j),
\]
coordinate-ascent VI (CAVI) generalizes to arbitrary $f$-divergences under mild shifted-homogeneity conditions on $f$. The update for factor $j$ becomes:
- For reverse KL type ($f^*\in\mathcal{F}_0$):
  \[
  q_j^*(z_j) \propto (f^*)^{-1} \mathbb{E}_{q_{-j}} f^*(p(z_j, z_{-j}, x)/q_{-j}(z_{-j}))
  \]
- For forward type divergences ($f\in\mathcal{F}_0$), a comparable formula applies.

In the common case of exponential family models, these reduce to classical CAVI [2009.13093, 1601.00670, 1711.05597].

## 4. Sandwich Bounds, Mass-Covering, and Mode-Seeking Tradeoffs

The divergence used in VI fundamentally shapes posterior approximation:

- **Reverse KL**: "zero-forcing," focusing on high-density regions (mode-seeking), often underestimating posterior variance.
- **Forward KL, $\chi^n$, Rényi with $\alpha<1$**: "zero-avoiding," encouraging $q$ to cover all regions where $p$ has support, thus yielding more realistic uncertainty estimates and improved calibration in predictive intervals [1611.00328].

Practical algorithms can leverage both ELBO and CUBO to yield a sandwich estimate for the model evidence, crucial for model comparison:
\[
\mathrm{ELBO}(q^*) \leq \log p(x) \leq \mathrm{CUBO}_n(q^*).
\]
Empirical evidence on regression and Bayesian neural network tasks shows that the mass-covering nature of $\chi^n$-divergence and variants can result in superior uncertainty quantification compared to conventional VI [1611.00328, 2009.13093].

## 5. Extensions to Amortized, Black-Box, and Meta-Learned VI

Modern VI integrates deep learning machinery via *amortized inference* (e.g., VAEs) where $q_\phi(z|x)$ is parameterized by neural networks and optimized over dataset minibatches using stochastic gradients and the reparameterization trick [2108.13083]. Score matching approaches enable black-box variational inference, replacing KL minimization with score matching of log-density gradients,
\[
\nabla_\theta \log q_w(\theta) \stackrel{!}{=} \nabla_\theta \log p(\theta, x),
\]
with efficient closed-form updates for Gaussian variational families, yielding significant speedups compared to standard BBVI [2307.07849].

Automated divergence selection through meta-learning enables task-adaptive VI. By meta-optimizing divergence hyperparameters (e.g., $\alpha$ in Rényi, or the generator $f$ itself), one can learn divergences suitable for the downstream task, with empirical improvements in held-out likelihood and reduced gradient variance [2007.02912]. This approach notably improves few-shot and rapid adaptation scenarios without assuming a fixed divergence a priori.

## 6. Mixture Models, Geometry, and Further Theoretical Guarantees

VI over mixtures (e.g., mixtures of Gaussians with fixed or variable covariance) can be framed as mollified entropy minimization, connecting VI to particle systems and smooth functionals of distributional measures [2406.04012]. The theoretical analysis extends to convergence proofs for gradient descent on particle locations and explicit bounds on KL approximation error, which decrease as $O(\frac{1 + \log n}{n})$ with the number of mixture components. This connects VI to optimal transport theory, with further extensions to gradient-flow VI on Bures--Wasserstein geometry for Gaussian measures [2205.15902].

The geometric framework allows explicit spectral and monotonicity bounds for VI over exponential families, enabling non-asymptotic convergence rates for both natural and Euclidean gradient descent, governed by the Fisher information spectrum [2510.15548].

## 7. Real-World Applications and Empirical Performance

Empirical demonstrations of VI and its generalizations span variational autoencoders (MNIST, Omniglot), Bayesian neural networks (UCI regression datasets), probabilistic modeling in scientific domains (e.g., physics-informed surrogates for PDEs), and large-scale Bayesian models in topic modeling, sequential data, and recommendation systems [2409.06560, 2009.13093, 1602.02311]. Notably, non-KL divergences (Rényi, $\chi$-VI, $f$-VI) can outperform classical VI on uncertainty quantification and even prediction metrics, with the modularity of $f$-VI making it straightforward to evaluate and deploy new divergences.

Inference strategies interpolating between pure sampling and deterministic VI via infinite stochastic mixtures allow continuous tuning of the bias-variance tradeoff in posterior approximation, yielding strictly better mean-squared errors than either approach alone for appropriate tradeoff parameters [2110.09618].

## Conclusion

VI has evolved into a highly flexible, theoretically grounded, and empirically validated class of inference frameworks. Advances in divergence criteria, optimization, meta-learning, mixture modeling, and geometric analysis have expanded both its theoretical scope and practical efficacy. The choice of divergence and variational family, as well as algorithmic considerations such as the use of stochastic gradients, reparameterization, and approximating mixture families, can be tuned based on the needs of the specific inference problem, the characteristics of the posterior, and the downstream utility of the approximation. Ongoing research continues to refine the foundational theory, convergence guarantees, and applicability of VI in increasingly complex and high-dimensional settings [2009.13093, 1611.00328, 2007.02912, 2506.13613, 2510.15548, 2406.04012].

Source: https://www.emergentmind.com/topics/variational-inference-vi