W04 · Part 1 — Metropolis–Hastings, and why it cannot generate an image
Invalid Date
Everything this course does reduces to one request: produce a draw from a distribution. Today we solve that request in the case where you can write the target down — and find that the case we care about is not that one.
You can evaluate the target, but only up to a constant:
This is not a special case. It is the generic case.
Bayesian posterior
Numerator: prior × likelihood, both chosen by you. Denominator: intractable.
Energy-based model — , and is the partition function
Conditioning — restricted to a region ; the mass is unknown
Note 06: draw , accept if . Exact — and useless.
Target , proposal : acceptance rate .
| 1 | 0.91 | 0.67 |
| 10 | 0.39 | 0.017 |
| 100 |
A proposal ten percent too wide is already dead at . Every draw is a fresh, independent gamble against the same odds — nothing is ever learned.
Stop starting over. Move from where you already are.
A Markov chain: the next state depends on the past only through the present.
The kernel is all the chain is.
Run the kernel forward from any starting law :
There is not one distribution here — there are flowing.
Note 06 computed this flow exactly for Gibbs on a bivariate normal: . Mean decays, variance climbs. Burn-in is the stretch where the flow is still visibly incomplete.
is stationary for when one more step changes nothing:
Add irreducibility (can reach anywhere) and aperiodicity (no fixed cycle) and the chain is ergodic: from any start, and
Checking directly means an integral over the whole space, which is the thing we are trying to avoid. We need a condition that is local, so it can be engineered pointwise.
A chain is reversible with respect to if for every pair of states
At equilibrium, mass flowing equals mass flowing . Every pairwise exchange balances.
It implies stationarity, in one line:
Pick any proposal you can sample from. From state :
enters only through a ratio:
For a Bayesian posterior with a symmetric proposal the rule is literally
Prior × likelihood at two points. The evidence integral — the entire reason the posterior was intractable — never appears.
A rejected proposal means the chain emits the current state again.
For the kernel is . Push the positive factor inside the :
The right-hand side is symmetric in — swapping labels swaps the two arguments of a and changes nothing.
So : detailed balance, hence stationarity.
The acceptance rule was reverse-engineered to make that appear.
Symmetric proposal , so the -ratio is 1:
The downhill move is not a defect — it is the difference between sampling and optimisation. A hill-climber reports the mode; a sampler must visit the tails in proportion to their mass.
Independence sampler — , ignoring the current state. Then with : accept if the candidate’s importance weight beats the incumbent’s.
Gibbs is MH with — propose one coordinate from its exact conditional ; substitute into the ratio and everything cancels.
Gibbs never rejects. The price is that you must be able to sample every conditional exactly.
Nothing says the proposal has to be blind. Drift toward high density first:
then accept/reject as usual.
It needs only — the score. The normalising constant differentiates away. Drop the accept/reject step and this is Langevin dynamics.
This is the closest classical ancestor of a score-based generative model. Module 4 learns that score from data instead of deriving it.
| Burn-in | early samples come from and are discarded |
| Autocorrelation | consecutive states are dependent by construction |
| Effective sample size |
Note 06’s Gibbs example: lag-1 autocorrelation . A target with gives ESS about a fiftieth of the chain length.
| acceptance | what happens | |
|---|---|---|
| too small | every move accepted, every move tiny — needs steps to cross | |
| too large | proposals land in the tails; the chain sticks for hundreds of steps | |
| tuned | the asymptotically optimal rate (Roberts, Gelman & Gilks, 1997) |
The beginner’s instinct — “95% acceptance, it must be working” — is exactly backwards. It almost always means the chain is crawling.
Steps needed per independent sample, for product-form targets:
| sampler | scaling |
|---|---|
| random-walk Metropolis | |
| MALA (adjusted Langevin) | |
| Hamiltonian Monte Carlo |
Against rejection sampling’s this is a triumph — polynomial, not exponential. Against for a modest image, it is still nowhere near enough.
A chain in one mode of a well-separated bimodal target must cross a low-density valley. The probability of proposing across it can be .
The chain then looks perfectly healthy:
It has converged — to a mode, not to . Tempering, parallel chains and mode-hopping proposals help; none is a general solution. Remember this slide when we meet mode collapse in Part 2.
Rejection sampling as darts under an envelope; Gibbs as a staircase walk, with 4,000 parallel chains whose histogram at step is drawn against the exact .
Perfect tuning. No multimodality. Dimension-free mixing.
It still cannot generate an image. The obstruction is not efficiency — it is the input.
MH answers:
“I can write the target down up to a constant. Give me samples.”
Generative modelling asks:
“I cannot write it down at all. I have 60,000 samples. Give me more.”
And MH never learns. A million steps, then a fresh start, and you pay the full burn-in again. Nothing is trained, nothing amortised.
In rejection sampling, in MH, in Gibbs — a human picks the proposal for convenience and hopes it resembles the target. In high dimension it does not.
So stop picking it. Learn it.
Which immediately raises the question that defines Part 2: if you never evaluate a density, how do you know your generator is any good? You cannot compute a likelihood, so you cannot maximise one.
| Today | Where it returns |
|---|---|
| Detailed balance / reversibility | forward and reverse diffusion, Module 3 |
| as a flow of laws | the Fokker–Planck equation, Module 5 |
| Langevin needing only | score matching, Module 4 |
| Accept/reject patching a bad proposal | why diffusion needs no such step |
| The ratio , cancelling | the discriminator’s logit, Part 2 |
| A chain trapped in one mode | mode collapse, Part 2 |
Metropolis–Hastings corrects a proposal chosen for convenience. A generative model learns one that was never wrong.
Reference: 08 · Metropolis–Hastings. Demo: The Sampling Lab. Next: 09 · Generative Adversarial Networks.