The ELBO and KL Divergence Minimization

Summary

The variational objective cannot be computed because it contains the log evidence . Dropping that constant gives the evidence lower bound, , which needs only the unnormalized posterior. The identity (Blei et al. 2017, Eq. 14) shows that maximizing the ELBO minimizes the KL and that the ELBO lower-bounds the log evidence. The direction of the KL, with the expectation under , is what makes VI computable and also what makes it mode-seeking and variance-underestimating.

Overview

Every algorithm in the VI cluster maximizes the same quantity; they differ only in the family and in how the expectation under is computed or estimated. This note collects the properties of the objective itself: three equivalent forms, the bound, the relation to EM, what reverse KL does to the optimum, and why the ELBO’s value is nearly useless as a quality measure.

Main Content

Kullback-Leibler divergence (reverse / exclusive form) ^def-reverse-kl

With all expectations taken under ,

It is non-negative, zero iff , and asymmetric: (Blei et al., Eq. 11 and fn. 2). Expanding the conditional,

which “reveals its dependence on ” (Eq. 12), the very quantity that made inference hard.

Evidence lower bound (ELBO) ^def-elbo

“The ELBO is the negative KL divergence of Equation (12) plus , which is a constant with respect to . Maximizing the ELBO is equivalent to minimizing the KL divergence” (Blei et al., Eq. 13).

Evidence decomposition and the bound ^thm-evidence-decomposition

For any density ,

with equality iff (Blei et al., Eq. 14). The bound follows from ; the original literature derived it from Jensen’s inequality, (Jordan et al. 1999).

Three readings of the same objective.

  1. Energy plus entropy. . The first term rewards mass on configurations with high joint density; the entropy term rewards spreading out. Kucukelbir et al. (2017, Eq. 2) and Ranganath et al. (2014) use this form. Its negative is the variational free energy of Rezende & Mohamed (2015).
  2. Fit minus complexity. Splitting the joint,

“The first term is an expected likelihood; it encourages densities that place their mass on configurations of the latent variables that explain the observed data. The second term is the negative divergence between the variational density and the prior; it encourages densities close to the prior. Thus the variational objective mirrors the usual balance between likelihood and prior” (Blei et al., p. 7). This is the form the VAE optimizes: reconstruction error plus a KL regularizer. 3. Evidence minus gap. : the bound is tight exactly to the extent the approximation is good.

Relation to EM ^thm-em-relation

The first ELBO term is the expected complete-data log likelihood optimized by EM. EM exploits that the ELBO equals when : the E-step sets to the exact conditional, the M-step maximizes over fixed parameters. “Unlike variational inference, EM assumes the expectation under is computable… Unlike EM, variational inference does not estimate fixed model parameters” (Blei et al., p. 7). Variational EM is EM with a variational E-step, which is exactly what the VAE does: by (approximate) maximum likelihood, by VI. Compare EM and Gradient Optimization for the Delayed Feedback Model for a case where the exact E-step is available.

What the direction of the KL does

Support constraint and zero-forcing ^thm-zero-forcing

Reverse KL integrates . Wherever but the integrand is , so the optimization carries the implicit constraint (Kucukelbir et al. 2017, Eq. 3 and fn. 3). More generally the objective “penalizes placing mass in on areas where has little mass, but penalizes less the reverse” (Blei et al., p. 9). Consequences:

  • Variance underestimation. A factorized fitted to a correlated target must shrink to stay inside the high-density region (Blei et al., Fig. 1). To match the marginal variances “the circular would have to expand into territory where has little mass.”
  • Mode-seeking. Against a multimodal target a unimodal locks onto one mode rather than straddling them.
  • Light tails. Yao et al. (2018): the VI solution “has a lighter tail than as a result of entropy penalization,” giving importance ratios a heavy right tail, which is what the [[Diagnosing Variational Inference (PSIS k-hat and VSBC)| diagnostic]] measures.

The opposite direction, , is mass-covering and moment-matching but requires expectations under the unknown posterior. Expectation propagation “is inspired by the KL divergence ‘in the other direction’” (Blei et al., Sec. 5.4; see Approximation Methods). The - and Renyi-divergence family interpolates between the two; Variational Inference and Pathfinder summarizes the Bayesian Workflow book’s view of these alternatives and of score-based divergences.

What the ELBO value does not tell you

  • Not a fit measure. Yao et al. (Sec. 1): an unknown multiplicative constant in “changes with reparametrization, making it meaningless to compare ELBO across two approximations. Moreover, the ELBO is a quantity on an uninterpretable scale… This makes it next to useless as a method to assess how well the variational inference has fit.” The gap is the KL, but is unknown.
  • Not a principled model-selection criterion. The ELBO has been used as a stand-in for the marginal likelihood, but “selecting based on a bound is not justified in theory” (Blei et al., p. 7), because the slack differs across models. For predictive comparison prefer PSIS-LOO and the criteria in Overfitting and Information Criteria.
  • Non-convex. “The ELBO is (generally) a non-convex objective function”; ten random initializations of a Gaussian mixture reach ten different ELBO values (Blei et al., Sec. 2.5, Fig. 2). Convergence of the ELBO means a local optimum has been reached, nothing more. Blei et al. suggest monitoring the average held-out log predictive as a cheaper proxy, but Yao et al. show (logistic regression, Sec. 4.2) that held-out log predictive density can improve while the approximation gets worse.

Examples

Mode-seeking on a bimodal target ^ex-bimodal

Yao et al. (Sec. 5.1) consider with well-separated modes. A Gaussian fitted by reverse KL “will converge to one of the modes,” say . On the support of the ratio is then essentially the constant . Two lessons:

  1. The KL at that optimum is about nats, small, even though misses 20% of the posterior mass entirely. Reverse KL is a local measure.
  2. Any diagnostic built from samples of (including ) is blind to the missing mode; it must be found by multiple dispersed initializations or by a prior-predictive check such as VSBC.

Monte Carlo ELBO for a Gaussian

The energy-plus-entropy form gives a generic estimator requiring only an unnormalized log posterior:

import numpy as np
 
def elbo_hat(log_joint, mu, log_sigma, S=1000, rng=np.random.default_rng(0)):
    """ELBO estimate for q = N(mu, diag(exp(log_sigma)^2)).
    log_joint(z) returns log p(z, x) up to a constant."""
    K = mu.size
    eps = rng.standard_normal((S, K))
    z = mu + np.exp(log_sigma) * eps              # samples from q
    energy = np.mean([log_joint(zs) for zs in z])  # E_q[log p(z, x)]
    entropy = 0.5 * K * (1 + np.log(2 * np.pi)) + log_sigma.sum()
    return energy + entropy

Writing is already the reparameterization trick: differentiate through z and this estimator becomes the ADVI gradient. Note that adding a constant to log_joint shifts the ELBO by the same constant, the concrete face of Yao et al.’s “uninterpretable scale.”

Connections

See Also