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
The question for today
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.
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.
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.
Work it through
A control variate that removes most of the noise
For U uniform on [0,1], estimate using Z=U with known mean 1/2. Find the optimal fixed coefficient and variance reduction.
Compute . Also and .
The optimal coefficient is c*=1. The controlled observation is , still with mean 1/3. Its variance is .
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.
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.
The living notebook
Explore the model
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.
- Mean · np
- 5
- Variance · np(1−p)
- 2.5
- Total probability
- 1
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.
Pause & reason
Check your understanding
Your turn
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.
Keep the idea
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.