§19.4.2 Calculus of variations
For discrete latents the variational parameters are numbers; for continuous latents, the optimization is over a function , and we need calculus of variations calculus of variations Optimizing over a space of FUNCTIONS (rather than vectors); the origin of the 'variational' in variational inference. Used to derive the functional form of q. defined in ch. 19 — open in glossary — the source of the word “variational”. A functional functional A mapping from functions to real numbers; viewing the cost as a functional lets calculus of variations show which statistic each loss recovers. defined in ch. 6 — open in glossary maps a whole function to a scalar (like the entropy of a density); its functional derivative functional derivative δJ/δf(x): the variational derivative of a functional w.r.t. the value of f at a point x; set to zero at every x to optimize a functional (generalizes ∇J = 0). defined in ch. 19 — open in glossary generalizes the gradient:
The functional derivative (eq 19.46)
| the functional derivative w.r.t. the VALUE of f at the point x — think of f as a vector with uncountably many entries indexed by x | per-point | |
| just the ordinary partial derivative of the integrand w.r.t. its function-value slot. Optimize a functional by setting this to 0 at every x | per-point |
(The general form, allowing to depend on ‘s derivatives too, is the Euler–Lagrange equation euler-lagrange equation The general functional-derivative condition allowing the functional to depend on f and its derivatives; the full form of the optimality condition for functionals. defined in ch. 19 — open in glossary ; this book doesn’t need it.) The classic payoff: which density maximizes entropy at a fixed mean and variance? Build the Lagrangian + constraints (∫p = 1, mean = µ, variance = σ²) and set (eqs 19.50–19.52); the algebra derives (eq 19.54) — we never assumed a Gaussian. See it: every curve below has the same variance, but the Gaussian wins on entropy:
Every curve here has the same variance σ², yet their entropies differ — and the entropy H[p] peaks exactly at the Gaussian (β=2). Calculus of variations proves this: solving δ/δp = 0 with a fixed-variance constraint derivesp(x)=N(µ,σ²). It's why we assume a Gaussian when we know only the variance — the least-committal choice.
This is the max-entropy justification for the normal distribution. (One caveat: the method finds stationary functions, so it misses degenerate solutions like Dirac mixtures, which don’t live in function space — those must be found by guessing and verifying.)
§19.4.3 Continuous latent variables
Happily, practitioners rarely solve a variational problem by hand. There is a general mean-field fixed-point equation giving the optimal factor for any model:
The universal mean-field update (eq 19.56)
| average the joint log-probability over the OTHER latents, using their current q — hold q(h_j) fixed for j ≠ i | expectation | |
| the unnormalized optimal factor; normalize it to get q(hᵢ|v). Iterating over i is the fixed-point loop | unnormalized density |
Its power is that it hands you not just an iterative update but the functional form of the optimum. For a toy model , , carrying out the expectation (eqs 19.57–19.67) reveals has a Gaussian form — derived, not assumed. You can then treat its mean and variance as parameters and optimize them however you like.
§19.4.4 Learning and inference feed back
Approximate inference doesn’t just approximate — it reshapes the model. Since variational learning increases (eq 19.68), it raises where is large and lowers it where is small:
The self-fulfilling prophecy
Train with a unimodal approximate posterior and the model’s TRUE posterior drifts toward being unimodal — the approximation makes its own assumptions come true. This makes the harm of a variational approximation hard to measure: you might find at the learned and conclude “the approximation is accurate,” yet a better inference algorithm could have reached a with much higher likelihood that your simple can never fit. The only sure way to detect it is to already have a superior learner for comparison.
§19.5 Learned approximate inference
Iterating fixed-point equations for every example is slow. Since inference is just the map , we can learn it — approximate that whole optimization with a single neural network that outputs the approximate posterior in one forward pass. This is learned approximate inference learned approximate inference Replace the slow iterative optimization q* = argmax_q L(v,q) with a neural network f̂(v;θ) trained to output the approximate posterior in one pass (e.g. the VAE encoder). defined in ch. 19 — open in glossary .
§19.5.1 Wake-sleep
The obstacle: there are no supervised targets — given we don’t know the right . The wake-sleep wake-sleep Train an inference network by sampling (h,v) from the model (ancestral sampling) and learning the reverse map v→h; supplies the missing supervised targets, but only trains on model samples. A candidate account of dreaming. defined in ch. 19 — open in glossary algorithm (Hinton et al. 1995) manufactures them by sampling from the model:
A second theory of dreaming
Chapter 18 floated dreams as negative-phase samples for the partition function; wake-sleep offers another reading — dreams could be model samples for training an inference network. It fits the schedule better: animals are awake (improving ) for hours, then asleep (the generative model held fixed) for hours, which is awkward for Monte Carlo partition-function training but natural for maximizing . Purely speculative, of course.
Next: other forms of learned inference — from DBM inference nets to the variational autoencoder.
Check yourself — calculus of variations & learned inference
1.What does calculus of variations let us do that ordinary calculus does not, and why is it needed here?
2.The calculus-of-variations entropy example derives which density, and what does that justify?
3.What does the universal mean-field fixed-point equation q̃(hᵢ|v) = exp(E_{h₋ᵢ∼q}[log p̃(v,h)]) provide beyond an iterative update?
4.How does approximate inference create a 'self-fulfilling prophecy' during learning?
5.How does the wake-sleep algorithm obtain training targets for its inference network, and what is the drawback?