Probabilistic inference, Monte Carlo, and posterior computation · Probabilistic computation and inference foundations · INF017 · Algorithm
Annealed importance sampling (AIS)
Bridges an easy reference distribution and a difficult target through intermediate distributions, using invariant Markov transitions and importance weights.
In CodeSplash
Documented in the Academy only. There's no Set up button.
- Availability
- Explained here
- Code example
- Component demo, not a trained model
- Who ran it
- CodeSplash's run and the reference's record
- CodeSplash's run
- The reference's example ran in Python and R here, and they agree.
- The reference's record
- Python: Ran in the reference's review. The report doesn't record which version of the code ran. R: Reviewed but not run: R wasn't available to the reference's authors.
Purpose
Bridges an easy reference distribution and a difficult target through intermediate distributions, using invariant Markov transitions and importance weights. It estimates normalizing-constant ratios and target expectations in settings such as energy-based latent models.
Question / hypotheses
Can a sequence of smaller distribution changes produce usable importance weights when direct proposal-to-target weighting would collapse?
Architecture / computational structure
Draw x0 from the reference, accumulate each log-density-ratio increment at the pre-transition state, and apply a kernel invariant to the next bridge distribution. Average weights across independent runs to estimate the normalizer ratio; use stable log-sum-exp for numerical aggregation.
Assumptions
The reference distribution must be sampleable with known normalizer, supports must be compatible, and transitions must preserve their stated intermediate distributions. Finite transitions need not perfectly mix for the standard weighting identity, but poor mixing can make variance enormous.
Formula / computational definition
Parameters and notation
Intermediate states and weights are Monte Carlo variables, not learned model parameters. Hyperparameters are temperature grid, number of runs, transitions per temperature, transition scale, and reference distribution. Model parameters defining f_K are held fixed while estimating its normalizer; changing them changes the integration target.
Fitting, fine-tuning, and adaptation
Choose bridge spacing and kernels on pilot runs, with denser temperatures where distributions change sharply. Recompute weights under a new trained energy model; old weights are not automatically valid. Training-time use requires accounting for estimation variance and any differentiation strategy through the estimator.
How to use and calibrate
Inspect log-weight dispersion, repeated-run normalizer estimates, and sensitivity to temperature count and transitions. Validate on a model with known Z. Plot an annealing schedule and energy distributions across it; average weights, not logarithms, when estimating the normalizer ratio.
Example application
Estimate a partition function for an energy-based image model or compare approximate log likelihoods when direct normalized density evaluation is unavailable.
Interpretation / pitfalls
Watch out
An unbiased normalizer estimate does not make its logarithm unbiased. A few rare runs can dominate the mean, and missing modes can remain undetected. An arbitrary sequence of states plugged into the weight formula is only an arithmetic illustration, not valid AIS output.
Python and R code examples
Scope: Log-weight accumulation for supplied states along a Gaussian bridge; states are not generated by invariant transitions, so this is not an AIS estimator or normalizer result.
Implementation route: Native NumPy/base R implement the illustrated weighting. A complete AIS implementation in either language needs the reference sampler and a correctly invariant kernel at every temperature, plus stable multi-run weight aggregation.
Dependencies and validation: Python — executed successfully on the supplied synthetic inputs; imports identify NumPy/SciPy dependencies. R — base R, reviewed but not executed because Rscript is unavailable. Random-number streams differ between languages; matching seed integers do not imply matching draws.
Python and R
The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.
Component demo, not a trained model — Log-weight accumulation for supplied states along a Gaussian bridge; states are not generated by invariant transitions, so this is not an AIS estimator or normalizer result. · needs numpy
import numpy as np
beta=np.array([0.,.3,.7,1.]); pretransition_states=np.array([.1,.5,1.2])
# f0=N(0,1), fK=N(2,1): log(fK/f0)=2*x-2.
increments=np.diff(beta)*(2*pretransition_states-2)
print('supplied-path log-weight increments',increments,'total',increments.sum())
# This supplied path is not claimed to be an AIS simulation.
Component demo, not a trained model — Log-weight accumulation for supplied states along a Gaussian bridge; states are not generated by invariant transitions, so this is not an AIS estimator or normalizer result.
beta <- c(0,.3,.7,1); pretransition.states <- c(.1,.5,1.2)
increments <- diff(beta)*(2*pretransition.states-2)
print(list(log.weight.increments=increments,total=sum(increments)))
# Arithmetic on a supplied path; not a valid AIS run by itself.
Sources
- Primary/official source 1arxiv.org
From the CodeSplash reference, entry INF017.