§19.0–19.4Inference as Optimization · EM · MAP Inference · Variational Inference

Part III DL pp. 631–638 · ~7 min read

  • approximate inference
  • evidence lower bound (elbo)
  • variational free energy
  • expectation maximization (em)
  • e-step
  • m-step
  • map inference
  • variational inference
  • mean field
  • structured variational inference

§19.0 The other intractability

Chapter 18 fought the intractable partition function — the negative phase. This chapter fights the intractable posterior p(hv)p(\boldsymbol{h}\mid\boldsymbol{v}) — the hard positive phase. Computing p(hv)p(\boldsymbol{h}\mid\boldsymbol{v}), 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):

Fig 19.1 — three sources of an intractable posterior. Left: a semi-restricted Boltzmann machine with direct hidden–hidden edges. Center: a deep Boltzmann machine (no intra-layer edges, but inter-layer coupling). Right: a directed model where observing v makes every pair of latent co-parents interact by explaining away.
semi-RBMdeep Boltzmann machinedirected co-parentsobserve v → all latents interact

Some models (an RBM, probabilistic PCA) do have a tractable p(hv)p(\boldsymbol{h}\mid\boldsymbol{v}) — but most, including single-layer sparse coding, do not. Approximate inference handles the rest.

§19.1 Inference is optimization

The unifying trick: bound logp(v)\log p(\boldsymbol{v}) below by the evidence lower bound (ELBO), also called the negative variational free energy :

The evidence lower bound (eq 19.1)

L(v,θ,q)=logp(v;θ)DKL ⁣(q(hv)p(hv;θ))\mathcal{L}(\boldsymbol{v}, \boldsymbol{\theta}, q) = \log p(\boldsymbol{v}; \boldsymbol{\theta}) - D_{\mathrm{KL}}\!\left(q(\boldsymbol{h}\mid\boldsymbol{v}) \,\|\, p(\boldsymbol{h}\mid\boldsymbol{v}; \boldsymbol{\theta})\right)
logp(v)\log p(\boldsymbol{v})the quantity we actually want — the (intractable) log-evidencescalar
DKL(qp(hv))D_{\mathrm{KL}}(q \| p(\boldsymbol{h}\mid\boldsymbol{v}))the KL divergence from our approximation q to the true posterior — always ≥ 0, so L ≤ log p(v)scalar ≥ 0
L\mathcal{L}the lower bound; equals log p(v) EXACTLY when q = p(h|v). The gap between L and log p(v) IS the KL divergencescalar

The magic is that L\mathcal{L} rearranges (eqs 19.2–19.6) into a form with no intractable posterior in it:

The tractable form of the ELBO (eq 19.7)

L(v,θ,q)=Ehq ⁣[logp(h,v)]+H(q)\mathcal{L}(\boldsymbol{v}, \boldsymbol{\theta}, q) = \mathbb{E}_{\boldsymbol{h}\sim q}\!\left[\log p(\boldsymbol{h}, \boldsymbol{v})\right] + H(q)
Ehq[logp(h,v)]\mathbb{E}_{\boldsymbol{h}\sim q}[\log p(\boldsymbol{h}, \boldsymbol{v})]expected JOINT log-probability under q — the joint is easy (it is what the model defines directly)scalar
H(q)H(q)the entropy of q — for a simple q (e.g. factorial) this is cheapscalar

So inference = find the qq that maximizes L\mathcal{L}. Exact inference searches a family rich enough to contain p(hv)p(\boldsymbol{h}\mid\boldsymbol{v}); approximate inference either restricts the family or optimizes imperfectly. Drive the bound yourself — as qq approaches the posterior, the gap closes:

The ELBO in action. L = log p(v) − D(q‖p(h|v)). log p(v) is a fixed ceiling; the red gap is the KL divergence. Move q toward the target posterior and the gap collapses as L rises to meet the ceiling — maximizing L is exactly fitting q to the posterior.
p(h|v)q(h|v)
log p(v)
-1.20 (ceiling)
L
-4.96
gap = KL
3.759

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 L\mathcal{L}, alternating which argument it climbs:

Expectation maximization (coordinate ascent on L)
  1. 1repeat until convergence:
  2. 2E-step: set q(hv)=p(hv;θ(0))q(\boldsymbol{h}\mid\boldsymbol{v}) = p(\boldsymbol{h}\mid\boldsymbol{v}; \boldsymbol{\theta}^{(0)})
  3. 3M-step: maximize iL(v(i),θ,q)\sum_i \mathcal{L}(\boldsymbol{v}^{(i)}, \boldsymbol{\theta}, q) over θ\boldsymbol{\theta}

EM is learning with an approximate posterior, not approximate inference — the E-step is exact. Its signature move is reusing one qq across a big M-step jump in θ\boldsymbol{\theta}; 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)

h=argmaxhp(hv)q(hv)=δ(hμ)\boldsymbol{h}^{*} = \arg\max_{\boldsymbol{h}} p(\boldsymbol{h}\mid\boldsymbol{v}) \quad\Longleftrightarrow\quad q(\boldsymbol{h}\mid\boldsymbol{v}) = \delta(\boldsymbol{h} - \boldsymbol{\mu})
h\boldsymbol{h}^{*}the MAP estimate — one point, not a distributionvector
δ(hμ)\delta(\boldsymbol{h} - \boldsymbol{\mu})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 addedpoint mass

MAP inference is exact-argmax, but as a source of qq 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 p(vh)p(\boldsymbol{v}\mid\boldsymbol{h}) gives an intractable p(hv)p(\boldsymbol{h}\mid\boldsymbol{v}) (every hi,hjh_i, h_j are co-parents of v\boldsymbol{v} → one giant clique under explaining away), so we learn by alternating MAP inference of h\boldsymbol{h} and a gradient step on θ\boldsymbol{\theta}, minimizing:

Sparse coding as MAP learning (eq 19.16)

J(H,W)=i,jHi,j+i,j(VHW)i,j2J(\boldsymbol{H}, \boldsymbol{W}) = \sum_{i,j} \lvert H_{i,j} \rvert + \sum_{i,j} \left(\boldsymbol{V} - \boldsymbol{H}\boldsymbol{W}\right)_{i,j}^{2}
Hi,j\sum \lvert H_{i,j} \rvertthe L¹ (Laplace-prior) term — drives the codes H sparsescalar
VHW2\lVert \boldsymbol{V} - \boldsymbol{H}\boldsymbol{W} \rVert^2Gaussian reconstruction error. Alternating min over H (MAP inference; feature-sign search) and over W (linear regression) — each convex, jointly notscalar

§19.4 Variational inference — and which KL

Variational inference maximizes L\mathcal{L} over a restricted family of qq. The mean field choice makes qq fully factorial, q(hv)=iq(hiv)q(\boldsymbol{h}\mid\boldsymbol{v}) = \prod_i q(h_i\mid\boldsymbol{v}) (eq 19.17); structured variational inference allows any chosen graph on qq. The elegance: you specify only how qq factorizes — the optimization derives its optimal functional form.

Why variational inference is mode-seeking

Maximizing L\mathcal{L} minimizes DKL(qp(hv))D_{\mathrm{KL}}(q \| p(\boldsymbol{h}\mid \boldsymbol{v})) — the reverse KL, opposite to maximum likelihood’s DKL(pdatapmodel)D_{\mathrm{KL}}(p_\text{data} \| p_\text{model}). 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 qq, which we control.

Variational inference uses the reverse KL, so a simple qq fit to a multimodal posterior picks one mode and ignores the rest (fig 3.6). See both directions on a bimodal target:

The two KL directions fitting a single Gaussian q to a bimodal target p. Reverse D(q‖p) (variational inference) is mode-seeking — q locks onto one bump. Forward D(p‖q) (maximum likelihood) is mean-seeking — q spreads to cover both, sitting in the empty valley. This is why variational inference under-represents multimodal posteriors.
p (bimodal)q
D(q‖p) = 1.687

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?

5 questions