§19.0 The other intractability
Chapter 18 fought the intractable partition function — the negative phase. This chapter fights the intractable posterior — the hard positive phase. Computing , or expectations under it, is needed for maximum-likelihood learning but costs exponential time for most multi-layer models. The culprit is latent-variable interaction (fig 19.1):
Some models (an RBM, probabilistic PCA) do have a tractable — but most, including single-layer sparse coding, do not. Approximate inference approximate inference Techniques for the intractable posterior p(h|v) (or expectations under it) needed for learning; usually cast as approximately maximizing a lower bound on log p(v). defined in ch. 19 — open in glossary handles the rest.
§19.1 Inference is optimization
The unifying trick: bound below by the evidence lower bound evidence lower bound (elbo) L(v,θ,q) = log p(v) − D_KL(q(h|v)‖p(h|v)) = E_{h∼q}[log p(h,v)] + H(q): a tractable lower bound on log p(v), tight iff q = p(h|v). Inference = maximize it over q. defined in ch. 19 — open in glossary (ELBO), also called the negative variational free energy variational free energy The negative of the ELBO; the 'free energy' name from statistical physics for the same quantity. defined in ch. 19 — open in glossary :
The evidence lower bound (eq 19.1)
| the quantity we actually want — the (intractable) log-evidence | scalar | |
| the KL divergence from our approximation q to the true posterior — always ≥ 0, so L ≤ log p(v) | scalar ≥ 0 | |
| the lower bound; equals log p(v) EXACTLY when q = p(h|v). The gap between L and log p(v) IS the KL divergence | scalar |
The magic is that rearranges (eqs 19.2–19.6) into a form with no intractable posterior in it:
The tractable form of the ELBO (eq 19.7)
| expected JOINT log-probability under q — the joint is easy (it is what the model defines directly) | scalar | |
| the entropy of q — for a simple q (e.g. factorial) this is cheap | scalar |
So inference = find the that maximizes . Exact inference searches a family rich enough to contain ; approximate inference either restricts the family or optimizes imperfectly. Drive the bound yourself — as approaches the posterior, the gap closes:
L is always ≤ log p(v), and the shortfall is exactly the KL divergence D(q‖p). Move q toward the posterior p(h|v) and the red gap closes as L rises to the ceiling. Inference = maximize L over q; it's the same as fitting q to the posterior.
§19.2 Expectation maximization
EM is the classic algorithm built on this bound — coordinate ascent on , alternating which argument it climbs:
- 1repeat until convergence:
- 2E-step: set ⓘ
- 3M-step: maximize over ⓘ
EM expectation maximization (em) Coordinate ascent on the ELBO: E-step sets q to the exact posterior at the current θ; M-step maximizes L over θ with q fixed. Learning with an approximate posterior, not approximate inference. defined in ch. 19 — open in glossary is learning with an approximate posterior, not approximate inference — the E-step e-step The expectation step of EM: set q(h|v) = p(h|v; θ⁰) using the current parameters (exact inference), making the ELBO tight. defined in ch. 19 — open in glossary is exact. Its signature move is reusing one across a big M-step m-step The maximization step of EM: maximize Σ L(v⁽ⁱ⁾,θ,q) over θ holding q fixed (possibly a large or analytic step). defined in ch. 19 — open in glossary jump in ; in deep learning, posteriors are usually too complex for large analytic M-steps, so plain SGD (EM with a one-step M) is the norm.
§19.3 MAP inference and sparse coding
Instead of the whole posterior, compute only its peak — the single most likely latent value:
Maximum a posteriori inference (eqs 19.9, 19.11)
| the MAP estimate — one point, not a distribution | vector | |
| restrict q to a DIRAC at µ; maximizing L over µ then reduces to the MAP problem. The bound is infinitely loose (Dirac entropy = −∞) unless noise is added | point mass |
MAP inference map inference Compute the single most likely latent value h* = argmax_h p(h|v) instead of the whole posterior; equivalent to restricting q to a Dirac δ(h−µ) in the ELBO. The workhorse for sparse coding. defined in ch. 19 — open in glossary is exact-argmax, but as a source of it is approximate — a point instead of the true posterior. It is the engine of sparse coding (§13.4): a factorial Laplace prior plus Gaussian gives an intractable (every are co-parents of → one giant clique under explaining away), so we learn by alternating MAP inference of and a gradient step on , minimizing:
Sparse coding as MAP learning (eq 19.16)
| the L¹ (Laplace-prior) term — drives the codes H sparse | scalar | |
| Gaussian reconstruction error. Alternating min over H (MAP inference; feature-sign search) and over W (linear regression) — each convex, jointly not | scalar |
§19.4 Variational inference — and which KL
Variational inference maximizes over a restricted family of . The mean field mean field The variational approximation with a fully factorial q(h|v) = Πᵢ q(hᵢ|v); each latent is independent given v. defined in ch. 19 — open in glossary choice makes fully factorial, (eq 19.17); structured variational inference structured variational inference Variational inference with any chosen graphical-model structure on q (richer than mean field's full factorization). defined in ch. 19 — open in glossary allows any chosen graph on . The elegance: you specify only how factorizes — the optimization derives its optimal functional form.
Why variational inference is mode-seeking
Maximizing minimizes — the reverse KL, opposite to maximum likelihood’s . The two directions behave very differently: reverse KL is mode-seeking (it refuses to put q-mass where p is low, so it locks onto one mode), forward KL is mean-seeking (it refuses to leave a p-mode uncovered, so it spreads wide). Variational inference uses reverse KL for a computational reason: its expectations are taken under the simple , which we control.
Variational inference variational inference Maximize the ELBO over a RESTRICTED family of q (specifying only how q factorizes); the optimization derives q's optimal form. Minimizes the reverse KL D_KL(q‖p). defined in ch. 19 — open in glossary uses the reverse KL, so a simple fit to a multimodal posterior picks one mode and ignores the rest (fig 3.6). See both directions on a bimodal target:
Reverse KL (variational inference) is MODE-SEEKING: putting q-mass in the empty valley is heavily penalized, so the best q locks onto ONE mode and ignores the other.
Next: making this concrete for discrete latent variables — the mean-field fixed-point equations and binary sparse coding.
Check yourself — the ELBO, EM, MAP & variational inference
1.What is the evidence lower bound L(v,θ,q), and what is the gap between it and log p(v)?
2.How is the EM algorithm a form of coordinate ascent, and what makes its E-step special?
3.How does MAP inference fit into the ELBO framework, and why is its bound loose?
4.Variational inference minimizes the reverse KL D(q‖p(h|v)). Why this direction, and what is its effect on a multimodal posterior?
5.Predict the outcome — in KLDirectionLab you fit a single Gaussian q to a bimodal p, then click 'find best q' under reverse KL, then under forward KL. What differs?