advanced37 min studyLesson 267 in Mathematics

Importance sampling and effective sample size

Reweight independent proposal draws while checking support, tail behavior, ratio bias, and the limits of weight diagnostics.

On this page

What you’ll understand

  • Derive ordinary and self-normalized importance estimators.
  • Calculate normalized weights and their concentration-based ESS.
  • Identify missing support and unstable tails that an attractive diagnostic can conceal.

Importance sampling replaces difficult target draws with easier proposal draws and corrects their distribution through weights. It can estimate posterior expectations or normalizing constants, but the correction works only where the proposal can reach the relevant target mass. A proposal that rarely visits important regions produces volatile weights and misleadingly stable short runs. Understanding this method requires separating a valid expectation identity, a finite-sample estimator, an asymptotic guarantee under stated integrability, and a diagnostic computed only from the draws actually obtained.

A change of probability measure

Let a normalized target density be π\pi and proposal density be qq on a common base measure. Require proposal positivity wherever the target contribution matters. For independent draws from qq, multiplying f(X)f(X) by π(X)/q(X)\pi(X)/q(X) changes its proposal expectation into the target expectation. Absolute integrability supports the expectation identity and a law of large numbers; a finite second moment of the weighted integrand is needed for the usual independent-sample variance and central limit analysis. Correct algebra does not ensure those moments are finite.

A proposal with lighter tails than the target can produce enormous weights in rare regions. Drawing more points in an already overrepresented region does not fix a missing-support defect, because its contribution is never seen. Proposal design should address the integrand too: a rare-event probability and a posterior mean can need different proposals. On finite support all relevant moments are finite if every target state has positive proposal probability, but the variance can still be so large that a small sample is practically uninformative.

Eπ[f(X)]=Eq ⁣[f(X)π(X)q(X)],I^IS=1N∑i=1Nf(Xi)π(Xi)q(Xi)\mathbb E_\pi[f(X)]=\mathbb E_q\!\left[f(X)\frac{\pi(X)}{q(X)}\right],\qquad \widehat I_{\mathrm{IS}}=\frac1N\sum_{i=1}^N f(X_i)\frac{\pi(X_i)}{q(X_i)}
The estimator is unbiased for an integrable weighted integrand when the target is normalized and draws are independent from the stated proposal.↔ Scroll wide equations horizontally.

Unknown normalizers lead to a ratio

For an unnormalized target π~\widetilde\pi with finite positive integral, compute weights wi=π~(Xi)/q(Xi)w_i=\widetilde\pi(X_i)/q(X_i) and normalize them by their sum. The ratio of weighted function sum to weight sum cancels the unknown target normalizer. Under proposal support coverage and the relevant integrability, separate laws of large numbers give consistency. The ratio is generally biased for finite sample size, even when the numerator and denominator separately estimate their integrals without bias. Denominator zero must also be excluded or handled as a failed sample.

Evaluate weights on the logarithmic scale when products of many densities underflow. Subtracting a common maximum log weight before exponentiating preserves normalized weights, although it does not repair inadequate overlap. The sample average of unnormalized weights estimates the target normalizer if all its constants were retained. Self-normalization can obscure those constants deliberately for an expectation, so a routine returning only normalized weights does not automatically provide a marginal likelihood estimate. Keep the target and proposal density conventions explicit.

wˉi=wi∑jwj,I^SN=∑iwˉif(Xi),ESS⁡w=1∑iwˉi2=(∑iwi)2∑iwi2\bar w_i=\frac{w_i}{\sum_jw_j},\qquad\widehat I_{\mathrm{SN}}=\sum_i\bar w_i f(X_i),\qquad\operatorname{ESS}_w=\frac1{\sum_i\bar w_i^2}=\frac{(\sum_iw_i)^2}{\sum_iw_i^2}
The weight ESS lies between 1 and N for nonnegative weights with positive sum; it measures realized weight concentration.↔ Scroll wide equations horizontally.

ESS is useful evidence with boundaries

Weight ESS is largest when the observed weights are equal and approaches one when one draw dominates. It is a convenient warning about concentration, but it is not a universal count of independent target observations for every function. Error also depends on how the chosen function varies with the weights, and an unseen important region can leave all observed weights deceptively similar. Distinguish this diagnostic from autocorrelation-based MCMC ESS, which measures a different source of Monte Carlo inefficiency.

A practical investigation repeats sampling with different seeds and stronger proposals, examines the largest weights, and checks estimates against analytical cases or another method. Tail diagnostics can warn about unstable importance ratios, but finite diagnostics cannot certify complete support coverage or finite population moments. If the estimate changes substantially after one exceptional draw, treat the earlier apparent precision cautiously. Increasing proposal coverage or changing the estimator may be more effective than simply reporting a larger nominal sample size with the same unstable weighting mechanism.

A rare proposal success dominates

The target is Bernoulli(0.8), the proposal is Bernoulli(0.2), and four independent proposal draws happen to be (1,0,0,0). Estimate the target success probability by self-normalized importance sampling and calculate weight ESS.

  1. The success weight is 0.8/0.2=4. Each failure weight is 0.2/0.8=0.25. The sum of weights is 4.75, or 19/4, and the sum of their squares is 16+3/16=259/16.

  2. Only the success draw contributes to the weighted indicator numerator, so the self-normalized estimate is 4/(19/4)=16/19, approximately 0.8421. This realized estimate need not equal the true target probability 0.8.

  3. Weight ESS is (19/4) squared divided by 259/16, equal to 361/259, approximately 1.394. For comparison, ordinary importance sampling with the normalized target gives numerator 4 divided by four draws, or 1, in this realization.

The result

The self-normalized estimate is 16/19 with weight ESS about 1.394 out of four draws. The ordinary estimator is unbiased across repeated samples, not guaranteed exact or constrained to the parameter's natural range in every realization.

Explore the model

Interactive lab

Interactive lab · probability

Inspect target-proposal overlap

Pause and Reset, then set both controls to p=0.20 and n=1; predict masses (0.80,0.20) for the proposal. Reset and set p=0.80 and n=1; predict target masses (0.20,0.80). Form the two target/proposal ratios yourself and compare 0.25 with 4. These are exact masses, not simulated importance draws or a live ESS estimate.

Inspect target-proposal overlapThese are exact binomial probabilities for independent trials with one fixed success probability. Playback tours the distribution; it does not resample outcomes. Current readings: Mean · np: 5; Variance · np(1−p): 2.5; Total probability: 1. All parameters are adjustable with the labeled controls below.03581000.070.150.220.3Successes kP(X = k)k = 0 · P = 9.77e-4
Exact probabilityHighlighted outcomeMean np
Mean · np
5
Variance · np(1−p)
2.5
Total probability
1
t = 0 s

These are exact binomial probabilities for independent trials with one fixed success probability. Playback tours the distribution; it does not resample outcomes. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forA proposal that makes target-important states uncommon produces large correction weights when those states finally appear.

Check your understanding

All observed importance weights are equal, so weight ESS equals the sample size. What conclusion is justified?

Try it yourself

Three proposal draws have unnormalized importance weights (1,1,2). An indicator function is zero at the first two and one at the third. Find its self-normalized estimate and weight ESS. What happens to both if every weight is multiplied by seven?

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

Compute the weight sum and sum of squared weights separately; common scale factors should cancel.

Compare with the solution

Normalized weights are (1/4,1/4,1/2), so the indicator estimate is 1/2. The squared weights sum to 1+1+4=6 and their sum is four, giving ESS=16/6=8/3. Multiplying all weights by seven leaves both quantities unchanged because their numerators and denominators acquire matching scale factors. This scale invariance is why unknown normalizers cancel for posterior expectations; it does not establish that the proposal has adequate support or that the estimate is close to the true expectation.

Take it with you

  • Importance weighting requires proposal support wherever target contributions matter.
  • Self-normalized estimates are consistent under suitable assumptions but generally biased at finite N.
  • Weight ESS is a concentration diagnostic rather than a universal accuracy certificate.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.