L5.1 What can we optimize when the required marginal is intractable?
Builds on3 notes
An extra, unobserved variable
How should we score how well a model explains the data? provided a clean score: log probability mass or density of the observed data. It assumed we can evaluate .
A handwritten digit records pixels, not its writer’s style. If the model first chooses a style and then draws an image, evaluating that image requires averaging over possible styles rather than selecting just one. Such unobserved variables are latent variables.
- Points form clusters, but cluster membership is not recorded.
- An image has an underlying content code, but only pixels are observed.
- Speech has hidden phonetic states, while the recording contains a waveform.
Call the latent variable . The joint model factors into a prior and a conditional observation model: sample , then generate . The desired score instead uses the marginal:
Two discrete clusters require only two terms. A latent sequence of length with states per position has possibilities, although special structure may permit dynamic programming. High-dimensional continuous integrals often need approximation. We seek an objective that is easier to estimate and optimize.
We cannot sum over every hidden explanation.
Can we optimize a tractable substitute
that is guaranteed not to overestimate log-likelihood?
DiscussionQ1
Derive a lower bound on in two ways: Jensen’s inequality, and an identity that also gives the exact gap. Why is the second route especially useful?
Show the reasoning
Route 1: Jensen. Fix observed and choose a distribution that is easy to sample and evaluate. For the following importance-ratio equality, assume is positive wherever the joint contributes mass, and the expressions are well-defined:
Logarithm is concave, so Jensen gives . The right side is the evidence lower bound, or ELBO:
The expectation need not have a closed form. If the joint and are evaluable, samples from can estimate it without directly calculating the marginal likelihood.
This route gives an inequality, but not its gap. A small, controlled gap would make the bound informative about likelihood. A large parameter-dependent gap can distort the optimization objective.
Route 2: calculate the difference. Substitute the factorization of the joint into marginal likelihood times posterior:
Equivalently,
This is an identity, giving three conclusions:
- Nonnegative KL yields the same lower bound as Jensen.
- The gap is precisely the KL from the chosen to the true posterior.
- The bound is exact when equals that posterior, up to null sets, assuming the relevant terms are defined.
The third conclusion becomes an algorithm below.
The gap really is KL
Treat the identity as a numerical claim we can check.
Use a two-component one-dimensional Gaussian mixture with , means and , and common standard deviation . Its marginal is a sum of two terms, so both log-likelihood and bound are exactly computable.
At , the true posterior probability is and log-likelihood is . Let and vary :
r = 0.0500 ELBO = -2.9758 gap = 1.4067 posterior KL = 1.4067
r = 0.2000 ELBO = -2.4530 gap = 0.8840 posterior KL = 0.8840
r = 0.5000 ELBO = -1.8186 gap = 0.2495 posterior KL = 0.2495
r = 0.8134 ELBO = -1.5691 gap = 0.0000 posterior KL = 0.0000
r = 0.8000 ELBO = -1.5697 gap = 0.0006 posterior KL = 0.0006
r = 0.9500 ELBO = -1.6507 gap = 0.0816 posterior KL = 0.0816
Repeat at three observations and two choices of ; the gap and posterior KL still agree to the displayed precision:
x = -2.0 r = 0.3 gap = 0.830826 KL = 0.830826
x = -2.0 r = 0.6 gap = 2.201990 KL = 2.201990
x = 0.0 r = 0.3 gap = 0.132907 KL = 0.132907
x = 0.0 r = 0.6 gap = 0.004070 KL = 0.004070
x = +2.0 r = 0.3 gap = 3.050125 KL = 3.050125
x = +2.0 r = 0.6 gap = 1.421288 KL = 1.421288
The bound’s error has an exact identity: KL from the approximate posterior to the true posterior.
At , the gap is only about . In this smooth, interior Bernoulli example, the KL expansion starts at second order, so a small parameter deviation costs .
Nearby-looking parameters do not universally imply small KL. Support and tail mismatch can matter greatly. At , the gap is already about .
Figure: Posterior KL exactly separates ELBO from log-likelihood. In a smooth local neighborhood of the optimum, the gap can grow quadratically with parameter error.
EM: alternating improvements to one bound
The identity holds for any admissible . Regard the bound as an objective in two variables, and , and optimize them alternately.
- E-step: hold fixed and maximize the bound over unrestricted . This minimizes posterior KL, giving and making ELBO equal log-likelihood.
- M-step: hold fixed and maximize expected complete-data log-likelihood over . In this Gaussian mixture, weighted estimates solve the update; other models may require numerical optimization.
Sample observations and start deliberately poorly, with means and equal mixing weights:
init ELBO = -1119.412 log-lik = -1094.282
iter 1 after E: -1094.282 (= current log-lik) after M: -998.819 mu = -0.113, +0.966
iter 2 after E: -978.036 (= current log-lik) after M: -949.100 mu = -0.271, +1.268
iter 3 after E: -923.753 (= current log-lik) after M: -906.253 mu = -0.594, +1.475
iter 4 after E: -898.532 (= current log-lik) after M: -894.940 mu = -0.762, +1.517
iter 5 after E: -893.098 (= current log-lik) after M: -891.803 mu = -0.854, +1.500
iter 6 after E: -890.823 (= current log-lik) after M: -890.030 mu = -0.919, +1.475
true means = -1.000, +1.500
Three observations follow.
First, every exact E-step makes the bound equal the current log-likelihood. It sets posterior KL to zero.
Second, ELBO never decreases across these substeps: both improve the same objective.
Third, log-likelihood never decreases. The E-step makes the old bound tight; the M-step raises that bound; the new likelihood cannot be below its new bound. This is an inequality argument, not a coincidence of the numerical example.
The E-step makes the bound touch the current likelihood; the M-step raises that bound, forcing the new likelihood at least as high.
Monotonicity does not guarantee a global optimum, nor decreasing distance to the true parameters each round. The objective is sample likelihood, and EM can depend on initialization or approach local solutions.
For dataset log-likelihood and bound , an exact E-step followed by any M-step that does not decrease the same bound gives
DetailsWhy can an M-step have a closed form when direct likelihood optimization does not?
Directly maximizing a log of a mixture sum couples components through the denominator created by differentiation.
The M-step instead maximizes an expectation of the log joint, with fixed responsibilities . The logarithm is inside the weighted sum. For this Gaussian mixture, the component updates become weighted estimates:
These are averages weighted by posterior responsibilities. They produce the M-step updates above under the stated fixed-variance setup.
After the exact E-step the gap is zero. Changing in the M-step can reopen it. Restricted variational inference need not eliminate the gap at all: we know its identity even when we cannot compute its value.
When the posterior is intractable too
Exact EM requires a feasible E-step. A small discrete latent variable permits direct posterior calculation. A continuous latent vector with a neural decoder generally has no tractable closed-form posterior, although special cases exist.
Restrict to a tractable parameterized family. An inference network can predict its parameters from , sharing computation across examples instead of separately optimizing every posterior. This is amortized inference. A VAE [2] jointly trains and :
This simply regroups the original ELBO into an expected reconstruction log-likelihood and a posterior-to-prior KL penalty.
The first term rewards useful latent information for explaining ; the second penalizes deviation from the prior. If the decoder models the data without using , an inference distribution equal to the prior makes the KL zero. This is posterior collapse: a good-looking objective can coexist with an uninformative latent variable.
A precisely computable analogy uses two increasingly similar mixture components. As they merge, observing reveals less about the component label. Under the model’s own true posterior, the average posterior-to-prior KL equals mutual information:
|μ₁-μ₀| = 4.00 E_x[KL(p(z|x) ‖ p(z))] = 0.556150 nats
|μ₁-μ₀| = 2.00 0.291858
|μ₁-μ₀| = 1.00 0.094910
|μ₁-μ₀| = 0.50 0.025576
|μ₁-μ₀| = 0.20 0.004182
|μ₁-μ₀| = 0.05 0.000262
|μ₁-μ₀| = 0.00 0.000000
Near zero separation, this example’s information shrinks approximately quadratically. It does not describe VAE training dynamics or prove a collapse feedback loop. Inspect KL, reconstruction, and actual latent use before considering KL annealing, free bits, or decoder changes.
SupplementAverage VAE KL contains more than mutual information
Define the joint and aggregate posterior . Under suitable integrability conditions,
The first term measures information about carried by ; the second measures aggregate-posterior mismatch with the prior. The average KL equals mutual information only when the latter term vanishes.
SupplementA restricted posterior approximation may cover only one mode
The ELBO identity fixes the direction , with expectation under the sampleable . A restricted family may avoid low-density regions of by omitting some modes [3].
Approximate a symmetric mixture of two Gaussians centered at and , each with standard deviation , by a single Gaussian:
minimize KL(q || p): mu = +1.9998 sigma = 0.5004 value 0.6931
minimize KL(p || q): mu = -0.0000 sigma = 2.0616 value 0.7236The first numerical solution follows one mode at a cost near . The second matches the full mean and variance but places more mass between modes. The mixture density is positive everywhere: the gap is low-density, not zero-density.
The two directions weigh errors differently. Mass placed by where is tiny is costly for ; mass of poorly covered by is costly for the reverse direction. These tendencies depend on the distributions and family, rather than being universal single-mode guarantees. See The Cost of a Wrong Probability Table: KL Divergence and Cross-Entropy.
This example concerns the approximate posterior. It does not prove that the generated data distribution necessarily underestimates spread; the decoder, variational family, data, and optimization also matter.
Move and watch the bound and KL gap
Interactive demo: Advance one substep at a time. The exact E-step closes the gap; the M-step raises the now-tight bound.
When is this approach informative?
Check three requirements.
First, the joint must be evaluable. The method starts with a tractable joint and an intractable marginal. An unavailable joint log-density leaves the standard ELBO without its required ingredients.
Second, the inference family must be adequate. A restrictive family can leave a substantial, parameter-dependent gap. That gap is often unavailable numerically because exact likelihood is unavailable. Family approximation, amortization, and incomplete optimization can all limit inference quality.
Third, a larger ELBO does not by itself rank likelihoods. Improvement can come from better inference, a better generative model, or both. Different models may have different gaps, even when evaluated on the same held-out data.
ELBO is the quantity we can estimate; log-likelihood is the quantity we want; posterior KL is their often-unavailable difference.
Check your understanding
References
- Jordan, M., Ghahramani, Z., Jaakkola, T. & Saul, L. An Introduction to Variational Methods for Graphical Models. Machine Learning 37, 1999.
- Kingma, D. & Welling, M. Auto-Encoding Variational Bayes. ICLR 2014.
- Blei, D., Kucukelbir, A. & McAuliffe, J. Variational Inference: A Review for Statisticians. JASA 112, 2017.