advanced31 min studyLesson 59 in Mathematics

Monte Carlo and variance reduction

Estimate expectations with controlled sampling error, redesign unbiased estimators, and distinguish independence, finite variance, and model error.

On this page

What you’ll understand

  • Derive the variance of an IID sample mean and state the finite-variance CLT assumptions.
  • Construct an unbiased control-variate estimator.
  • Explain support and moment requirements for importance sampling.

Monte Carlo turns an expectation into an average of reproducible random experiments. Its attraction is not that randomness makes error disappear, but that the sampling error has a statistical description. The basic square-root sample-size rule can be expensive when each experiment is a large simulation or the target event is rare. Variance reduction changes what is averaged while preserving the target expectation. The key question becomes how to use mathematical structure to spend computation on informative fluctuations instead of repeatedly measuring avoidable noise.

Separate the target, the estimator, and its uncertainty

Let Y₁,…,Y_N be independent identically distributed copies of a quantity Y with finite variance. Their average is unbiased for E[Y], and its variance is Var(Y)/N because all cross covariances vanish. The central limit theorem describes its centered error after multiplication by √N as approximately normal for large N, with a limiting variance fixed by the model. A standard error estimates the standard deviation of the estimator, not the spread of individual observations and not a deterministic maximum error.

Finite expectation is enough for an IID law of large numbers, but the familiar finite-variance standard error and classical CLT require a finite second moment. Correlated samples from one trajectory require covariance or long-run variance analysis instead of blindly dividing an empirical variance by the number of saved states. A confidence interval also addresses sampling uncertainty conditional on the specified model. It does not include bias from a wrong model, an inaccurate time integrator, or a coding error that every replicate faithfully repeats.

μ^N=1N∑i=1NYi,E[μ^N]=μ,Var⁡(μ^N)=σY2N\widehat\mu_N=\frac1N\sum_{i=1}^NY_i,\qquad\mathbb E[\widehat\mu_N]=\mu,\qquad\operatorname{Var}(\widehat\mu_N)=\frac{\sigma_Y^2}{N}
The Yᵢ are IID with mean μ and finite variance σᵧ². Independence removes cross terms; correlated samples need a different variance expression.↔ Scroll wide equations horizontally.

Subtract a fluctuation whose mean is already known

Suppose a correlated auxiliary quantity Z has a known expectation m. Replace Y by Y−c(Z−m). The expected value stays unchanged for any fixed coefficient c, while a well-chosen c cancels fluctuations shared with Z. Minimizing its quadratic variance yields c=Cov(Y,Z)/Var(Z), provided Z has nonzero finite variance and Y also has finite variance. The residual variance becomes Var(Y) times one minus the squared correlation. Large correlation can therefore be valuable even when the auxiliary model is only an approximation.

The coefficient must be handled honestly in implementation. Estimating it from a separate pilot sample and fixing it for the main run preserves the simple unbiasedness argument. Estimating and reusing it on the same sample can introduce finite-sample bias, although consistent procedures may retain desirable asymptotics. Another strategy is conditional averaging: replacing Y by E[Y|G] keeps the mean and cannot increase variance when Y is square integrable. This Rao–Blackwell principle removes randomness that can be integrated analytically instead of simulated.

Yc=Y−c(Z−m),c∗=Cov⁡(Y,Z)Var⁡(Z),Var⁡(Yc∗)=Var⁡(Y)(1−ρ2)Y_c=Y-c(Z-m),\qquad c_* =\frac{\operatorname{Cov}(Y,Z)}{\operatorname{Var}(Z)},\qquad\operatorname{Var}(Y_{c_*})=\operatorname{Var}(Y)(1-\rho^2)
m=E[Z] is known, c is fixed, both variables have finite second moments, Var(Z)>0, and ρ is their correlation when Var(Y)>0.↔ Scroll wide equations horizontally.

Sampling somewhere else requires exact reweighting

Importance sampling draws X under a proposal density q instead of target density p, then averages f(X)p(X)/q(X). The proposal must be positive wherever the target integrand contributes, up to the relevant null sets. With absolute integrability the expectation is preserved, but usable error bars also require the weighted quantity to have finite second moment under q. A proposal that misses an important tail can produce an infinite-variance estimator or deceptively quiet runs that have simply not encountered enormous weights yet.

For a rare event, move proposal mass toward the event while retaining the exact likelihood ratio. More frequent event observations are helpful only if the resulting weighted variance is smaller at comparable computational cost. Antithetic pairs and stratification offer other routes, but no variance-reduction label guarantees improvement for every integrand. Compare estimator variance, wall-clock cost, and reproducibility together. Exact small models are particularly valuable test cases because their known answers expose bias that an attractive confidence interval alone cannot detect.

Ep[f(X)]=Eq ⁣[f(X)p(X)q(X)],∫f(x)2p(x)2q(x) dx<∞\mathbb E_p[f(X)]=\mathbb E_q\!\left[f(X)\frac{p(X)}{q(X)}\right],\qquad \int f(x)^2\frac{p(x)^2}{q(x)}\,dx<\infty
The identity needs integrability and proposal support wherever fp contributes. The displayed integral is the weighted second-moment condition needed for finite variance under q.↔ Scroll wide equations horizontally.

A control variate that removes most of the noise

For U uniform on [0,1], estimate E[U2]=1/3\mathbb E[U^2]=1/3 using Z=U with known mean 1/2. Find the optimal fixed coefficient and variance reduction.

  1. Compute Var⁡(U2)=E[U4]−(1/3)2=1/5−1/9=4/45\operatorname{Var}(U^2)=\mathbb E[U^4]-(1/3)^2=1/5-1/9=4/45. Also Var⁡(U)=1/12\operatorname{Var}(U)=1/12 and Cov⁡(U2,U)=1/4−(1/3)(1/2)=1/12\operatorname{Cov}(U^2,U)=1/4-(1/3)(1/2)=1/12.

  2. The optimal coefficient is c*=1. The controlled observation is U2−U+1/2U^2-U+1/2, still with mean 1/3. Its variance is 4/45−(1/12)2/(1/12)=4/45−1/12=1/1804/45-(1/12)^2/(1/12)=4/45-1/12=1/180.

  3. The variance ratio is (4/45)/(1/180)=16, so standard error is reduced by a factor of 4 at the same sample count. With N=100 independent observations, the original standard error is about 0.029814 and the controlled standard error is about 0.007454, using the exact model variances.

The result

Subtracting U−1/2 with coefficient one retains the target mean and reduces variance sixteenfold. More accurate estimator design can substitute for many additional samples.

Explore the model

Interactive lab

Interactive lab · probability

An exact benchmark for a random estimator

Choose p and n, then read the exact binomial mean np and variance np(1−p). If Monte Carlo were estimating the event probability p from n independent indicators, the sample proportion would have variance p(1−p)/n. Compute that value and compare changes as n increases. The bars are exact probabilities and are not repeatedly sampled experiments, confidence intervals, or a control-variate simulation.

An exact benchmark for a random estimatorThese 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 forKnown probability models provide benchmarks for estimator uncertainty; an exact distribution plot should not be mistaken for Monte Carlo output.

Check your understanding

Which statement is necessary for the usual IID Monte Carlo variance formula Var(mean)=Var(Y)/N?

Try it yourself

An IID estimator has one-sample standard deviation 3. How many samples give theoretical standard error 0.01? What if a valid fixed control variate reduces one-sample variance by a factor of 9?

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

Give me a hint

Solve σ/√N=0.01. A variance reduction divides the required sample count by the same factor.

Compare with the solution

The original requirement is N=(3/0.01)²=90,000. Dividing variance by 9 changes standard deviation from 3 to 1, so N=(1/0.01)²=10,000. These are standard-error targets under the IID finite-variance model, not guarantees that the realized error is below 0.01; a confidence level would require an additional probability statement.

Take it with you

  • The square-root sample-size rule relies on independence and a finite variance for the averaged quantity.
  • A fixed control variate preserves expectation while canceling correlated fluctuations.
  • Importance sampling needs support coverage and controlled weighted moments, not merely more frequent rare events.

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.