Computing the evidence: annealed importance and nested sampling
Bayes factors need the normalizing constant that every sampler avoids. Learn two ways to compute it, bridging through temperatures and shrinking prior mass, and why evidence is so sensitive to the prior.
What runs in CodeSplash
- INF017Annealed importance sampling (AIS) Explained here
- INF019Nested sampling Explained here
You will be able to
- Say why posterior samplers don't give the evidence, and why it matters for Bayes factors
- Describe annealed importance sampling's bridge and weight
- Describe nested sampling's live points and prior-mass integral
- Explain why an evidence estimate can look converged yet miss a mode, and why it depends on the prior's width
The constant everyone cancels
ReadMetropolis–Hastings, HMC and self-normalized importance sampling all work because the normalizing constant cancels. But that constant is the evidenceBayesian evidence (marginal likelihood)The probability of the data averaged over the prior, p(y) = ∫ p(y | θ) p(θ) dθ; ratios of it between models are Bayes factors.,
and a Bayes factorBayes factorHow much more likely the data are under one hypothesis than another; it can support H₀ as well as H₁. is a ratio of two of them. Posterior draws alone don't give it: the "harmonic mean" trick that seems to can have infinite variance. Computing needs methods built for it. This lesson covers two of them.
Annealed importance sampling
ReadImportance sampling from the prior straight to the posterior fails when the posterior is much narrower. Annealed importance samplingAnnealed importance samplingBridges an easy distribution to the target through tempered steps, multiplying weight increments, to estimate a normalizing constant. (AIS) walks there through tempered bridges
Start each run with a draw from (often the prior, whose constant is known). At each temperature, multiply the weight by at the current state, then move the state with an MCMC step that keeps . Then .
Reference · INF017 · Explained hereAnnealed importance sampling (AIS)Bridges an easy reference distribution and a difficult target through intermediate distributions, using invariant Markov transitions and importance weights.AIS details that bite
Read- Average weights, not logs. is the ratio; the mean of is a biased, lower estimate. Use log-sum-exp to average stably.
- A few runs dominate. Log-weights with a wide spread mean a handful of runs carry the estimate; add temperatures where the distributions change fast.
- Missing modes are invisible. If no run reaches a mode, its mass is never counted, and repeated runs agree on the wrong value.
The reference's program only accumulates the increments for three supplied states (total −0.82); because those states weren't produced by MCMC moves, it illustrates the bookkeeping, not an evidence estimate.
Nested sampling
ReadNested samplingNested samplingEstimates the evidence by repeatedly replacing the lowest-likelihood live point with a prior draw above it, shrinking the prior mass. rewrites the evidence as a one-dimensional integral over prior mass , the prior probability of the region where the likelihood exceeds :
Keep points drawn from the prior. Repeatedly remove the one with the lowest likelihood, record it, and replace it with a new prior draw whose likelihood is higher. The remaining prior mass shrinks by about each time. Weighted discarded points double as posterior samples.
Reference · INF019 · Explained hereNested samplingRewrites Bayesian evidence as a one-dimensional integral over remaining prior mass, estimated through increasingly restrictive likelihood contours. Posterior weighted samples arise as a by-product;Where nested sampling breaks
ReadThe hard part is drawing from the prior inside a likelihood contour; methods use bounding ellipsoids or short MCMC walks, and correlated replacements make the shrinkage formula optimistic. A mode the live points never find is silently left out, as in AIS.
The reference's program checks only the quadrature, on a curve with a known answer: the bounds it gets, 0.5000 to 0.5000, bracket the exact evidence 0.5. Real runs also report the evidence's uncertainty from random shrinkage; report it separately from sensitivity to the prior.
The prior decides the evidence
ReadMake a coefficient's prior ten times wider and the posterior hardly moves, but the evidence falls: the prior now spends most of its mass where the likelihood is negligible. That is why Bayes factors with "vague" priors can favor the simpler model almost regardless of the data. Evidence is a statement about the prior and the likelihood, and it is not a p-value or a posterior probability of a model by itself.
EExplorable · The Savage–Dickey Bayes factor
Can you read a Bayes factor off a picture of the prior and the posterior?
Do these data favor the null (θ = 0.5) over the alternative?
Small values spread the prior out; large values pile it at 0.5.
The two dots are the densities at the null value. Posterior over prior: 0.45 / 1.00 = BF₀₁ = 0.452.
Commit your prediction above to see the result
Make your prediction to see the result.
Where they stand in CodeSplash
ReadCheck your understanding
CheckpointCheck yourself
Your AIS runs give log-weights. How do you estimate the evidence ratio?
Show the answer
Answer: b
is unbiased for the ratio; the mean of is biased low. Unbiased for also doesn't mean unbiased for .
Check yourself
Twenty AIS runs all agree closely on the evidence of a model with two well-separated modes. Should you trust it?
Show the answer
Answer: b
Agreement shows low variance, not correctness. Missing regions are invisible to every Monte Carlo method that never visits them.
Check yourself
In nested sampling, what replaces the live point with the lowest likelihood?
Show the answer
Answer: b
The constrained prior draw keeps the live points spread over the shrinking region, so the prior mass shrinks by a known factor on average. Drawing it accurately is the hard part.
Check yourself
You widen a coefficient's prior from SD 10 to SD 1,000. The posterior barely changes. What happens to the evidence?
Show the answer
Answer: b
Evidence averages the likelihood over the prior. Wider priors dilute that average, which is why Bayes factors need deliberate priors.
Recap
Recap- Samplers cancel the evidence; Bayes factors need it.
- AIS bridges prior to posterior through temperatures; average weights, not logs.
- Nested sampling integrates likelihood over shrinking prior mass with live points.
- Both miss unvisited modes silently, and evidence depends strongly on the prior's width.
- Explained here: CodeSplash has no general evidence calculator yet.
Concepts in this lesson