- Home
- Library
- Computational Quantum Field Theory
- Sampling Measures and Estimating Free Energies
- Importance Sampling and Reweighting
Importance Sampling and Reweighting
An expectation value may be difficult to sample even when its integrand is easy to evaluate. Importance sampling draws from a convenient distribution and corrects the mismatch with weights. The correction is an exact integral identity, but a finite collection of weights can fail badly if important configurations are almost never proposed.
We derive ordinary and self-normalized estimates, then test both a Gaussian moment and a double-well integral. The double well illustrates a striking failure: thousands of apparently effective samples can still miss a quarter of the target probability.
Preparation: Probability densities, expectation values, and variance. All draws on this page are independent; the additional errors of correlated draws are treated in Autocorrelation and Effective Sample Size.
Change the sampling distribution
Let be a normalized target density, where is finite and positive. A normalized proposal must be positive wherever the target contributes. For independent , write
If is known, the ordinary estimator
is unbiased whenever is integrable under . Its variance, when finite, is
This follows by computing the second moment of one weighted draw and dividing by . The denominator reveals the danger: a proposal that is very small where matters can produce enormous fluctuations.
The variance-minimizing density is proportional to , when this can be normalized and sampled. To see this, apply Cauchy–Schwarz to and :
Equality requires . If has one sign this would make every weighted contribution identical, but constructing that proposal may require the very integral or sampling problem we are trying to solve. The result still gives practical guidance: proposal quality depends on the observable as well as the target.
An unknown partition function gives a ratio
Field-theory weights usually have a known action and an unknown partition function. Define . Then and , so use
Laws of large numbers for the two integrable variables give consistency as . At finite , however, the expectation of a ratio is generally not the ratio of expectations.
Put and . Expanding about gives the leading fluctuation
Provided this expansion and the relevant second moments are controlled,
The numerator and denominator fluctuate together. Treating their errors as independent drops their covariance. Keeping the quadratic terms also gives the leading bias, under the stronger moment and remainder assumptions needed for an expectation expansion:
These are large-sample approximations, not promises that an available run has reached that regime. For example, with only one sample, the self-normalized estimate is simply and its expectation is under , regardless of the nonzero weight.
Reweighting between actions is the same identity. Samples from can estimate a target with using in the ratio. This requires target support and integrable weights. This page assumes positive weights; complex phases and sign cancellations require separate analysis.
A Gaussian can have infinite sampling variance
Take , , and . The desired answer is . Both densities are positive on the whole real line, but support alone does not guarantee a finite variance. The ordinary estimator's second-moment integrand is proportional to
It is integrable exactly when . In that regime, differentiating the Gaussian integral twice gives
At this is , as expected for the mean of . At the mean remains well defined and the ordinary estimator remains unbiased, but its variance is infinite. A finite run still prints a finite sample variance; that output cannot establish the usual normal error scaling. The self-normalized estimator also lacks the finite influence variance used in its ordinary central-limit error formula here.
The supplied experiment uses 512 runs of 8,192 draws. For self-normalized estimates of , it obtains:
| Proposal standard deviation | Average estimate | Root mean square error | Nominal 95% interval coverage |
|---|---|---|---|
| 0.5 | 0.9251 | 0.3721 | 51.0% |
| 1 | 0.9994 | 0.01564 | 95.3% |
| 2 | 1.0008 | 0.01280 | 94.7% |
The broad proposal improves this moment despite differing more from the target near its peak. The narrow proposal's rare large contributions make averages and uncertainty estimates unstable. An empirical root mean square error from 512 runs is not a finite theoretical variance where the latter does not exist.
A double well with deceptive weight statistics
Now use the dimensionless zero-dimensional scalar action
Adaptive quadrature gives , , and . Repeating the integrations over with tighter tolerances changes the mean by about in the retained double-precision run. That agreement checks this integral; it is not an analytic proof of the quadrature error bound.
Compare three proposals: a Gaussian centered on the right well, an equal mixture centered on both wells, and a broad centered Gaussian. Here denotes mean and standard deviation .
| Proposal | Average estimate | Root mean square error | Median weight ESS | Nominal 95% coverage |
|---|---|---|---|---|
| 1.9193 | 0.9177 | 6,860 | 0.2% | |
| 1.0031 | 0.02786 | 5,225 | 93.6% | |
| 1.0010 | 0.02809 | 2,107 | 95.5% |
The weight diagnostic in the fourth column is
For the one-well proposal, 511 of 512 runs contain no negative draw, although the negative half-line carries almost a quarter of the target probability. The weights can look well distributed among sampled positive configurations and still omit essential contributions. A large weight ESS therefore cannot establish overlap. The broader proposal has a lower weight ESS yet dramatically better accuracy for the desired mean.
The two-well proposal improves the result, but the retained root mean square error of 0.02786 exceeds its median reported standard error of 0.01703. Rare contributions between the narrow proposal peaks still matter. This comparison is a reason to examine repeated runs and different proposal widths, rather than declaring a sampler optimal from its weight ESS.
The normal intervals here use the plug-in influence variance
It is asymptotically useful under finite-moment conditions; it is not an exact finite-sample interval. For 512 repetitions, a coverage near 95% itself has a sampling uncertainty of about one percentage point. Difficulties diagnosing importance-sampling convergence from a sample's own fluctuations are discussed in [1, §2].
Reproduce and improve the calculation
Run the retained source with Python 3, NumPy, and SciPy:
python3 examples/computational-qft/importance-sampling/check.py
The seed is 20261022; the source records all proposal parameters and saves results.json. It compares the ordinary Gaussian estimator with its analytic variance, checks the double-well integral with two domains and tolerance settings, and preserves the poor-overlap result as a deliberate failure example. It uses log weights and log-sum-exp normalization to avoid preventable overflow, without truncating or altering weights.
For a new target, compare proposals that cover physically distinct regions, repeat runs, increase sample size, and inspect the observable's weighted contributions as well as the weights alone. Proposal adaptation should be designed separately from evaluation, or its effect on the estimator must be included. Stable arithmetic cannot compensate for unsampled probability.
Summary
Importance sampling changes where points are drawn, not the desired integral. Ordinary weights give an unbiased estimator when normalization is known; self-normalization removes an unknown partition function at the price of finite-sample bias. Support, moment conditions, observable dependence, and actual overlap all matter. The weight ESS is a diagnostic of the observed weights, not a guarantee of accuracy.
Exercises
1. Expose ratio bias at one sample. For the Gaussian target and , calculate the expectation of the self-normalized estimate at .
Solution
The weight cancels between numerator and denominator, giving . Since , its expectation is , not the target value one unless . Consistency as sample size grows does not imply finite-sample unbiasedness.
2. Change an overall normalization. If is multiplied by an unknown positive constant , which quantities change?
Solution
and every raw weight multiply by . The normalized target , normalized weights , ratio estimate, weight ESS, and plug-in variance remain unchanged. An estimate of the unnormalized partition function does multiply by ; its absolute value requires a specified measure and normalization.
References
- S. Chatterjee and P. Diaconis, “The sample size required in importance sampling,” Annals of Applied Probability 28 (2018), 1099–1135. Full text, arXiv version 3. Section 1 sets out ordinary and self-normalized estimators; §2 analyzes convergence diagnostics.
Scrollable formula. Use Left and Right arrow keys to reveal hidden content.
Scrollable table. Use Left and Right arrow keys to reveal hidden columns.
Scrollable figure. Use Left and Right arrow keys to reveal hidden content.