A13 · Lesson 48 · Monte Carlo methods
Integrating by sampling at random, with an error that shrinks the same way in any dimension
A circuit has 20 components, each within its tolerance. What fraction of built boards will meet the spec? That's an integral over a 20-dimensional box, and a grid with just 10 points per axis would need circuit simulations. Monte Carlo draws random component values, simulates, and counts. Its error shrinks only as , slowly, but that rate doesn't depend on the dimension at all, which is why yield analysis, bit-error-rate simulation and radiation transport all run on it. A11 used Monte Carlo to explore probability; here it's a numerical method, with an error bar you can compute and tricks that shrink it.
- The running mean of for uniform random U estimates (the marked line). Each trial adds one random sample.
- Early on the estimate wanders a lot; it settles as . The readouts give the estimate and its standard error, , computed from the samples themselves.
- Raise n by 100: the error bar shrinks by only 10. Each extra digit costs 100 times the samples.
Predict
A Monte Carlo estimate has a standard error of 0.002 with samples. How many samples bring it to 0.0002?
: the error goes as , so 10 times smaller needs 100 times the samples. That's the price of Monte Carlo, and also why it's used only where nothing else works: in many dimensions, or when the "integrand" is a whole simulation.
Name it
Monte Carlo integration
For over a region of volume V, draw uniformly in Ω:
where s is the samples' standard deviation. The error is in any dimension. A grid rule of order p in d dimensions, with N points in all, has error : better than Monte Carlo when , worse in high dimensions.
Probabilities and yield
An event's probability is the mean of an indicator (1 if it happens, 0 if not). With from N trials, the standard error is . To see about 100 occurrences of an event of probability p you need about 100/p trials, which is why simulating a bit error rate of by brute force takes bits.
Reducing the variance
- Antithetic pairs: use both U and 1 − U; for monotone f their errors partly cancel.
- Control variates: subtract a similar function g with a known integral: estimate .
- Importance sampling: draw from a density q concentrated where f matters and average . Shifting the noise toward the decision threshold is how bit error rates of are simulated in seconds.
- Quasi-Monte Carlo: low-discrepancy sequences (Halton, Sobol) fill the region more evenly than random points; error about for smooth integrands.
Random numbers
Use a good generator (PCG, Mersenne Twister, NumPy's default), and seed it so a run can be repeated exactly.
Worked example
Estimate with samples. How accurate is it?
Show the solution
- The standard error. The integrand's standard deviation over [0, 1] is 0.201, so about two good digits.
- For an error of . You'd need samples.
- Compare with Simpson. Simpson's rule with 10 intervals gets . In one dimension, Monte Carlo is a poor choice.
Answer the standard error is 0.0020, about two good digits.
Worked example
A yield simulation passes 9530 of 10 000 boards. What's the yield and its uncertainty?
Show the solution
- The estimate. .
- Its standard error.
- Report. Report 95.3% ± 0.4% (two standard errors).
Answer the yield is 95.3% ± 0.4%.
Worked example
Estimate by Monte Carlo with antithetic pairs . How much does that help?
Show the solution
- One sample's variance.
- The covariance. The pair's two halves are negatively correlated:
- The pair average's variance.
- Compare. Two independent samples would have variance , so for the same number of evaluations the antithetic pairs cut the variance 31-fold.
- Why it works. is monotone: when one half of a pair is high, the other is low.
Answer the pair average's variance is 0.0039, 31 times less than for two independent samples.
Check
Samples of a Monte Carlo integrand have standard deviation 1.5. What's the standard error of the mean of 1000 of them (unit volume)?
Check
How many samples bring a Monte Carlo standard error to 0.001, if the integrand's standard deviation is 0.2?
Check
About how many trials does it take to see 100 occurrences of an event with probability 1 × 10⁻⁶?
Check
A simulation estimates a yield of 0.8 from 1000 trials. What's its standard error?
Check
A grid rule of order 2 in 3 dimensions has error in the total number of points N. What's q?
Check
A link must be verified at a bit error rate of . Which simulation approach is practical?
Check
Each sample has variance 0.242, and the two halves of an antithetic pair have covariance −0.2.
(a)
What is the variance of the pair's average?
(b)
By what factor does that beat two independent samples?
Check
Monte Carlo sample sizes.
Step 1
How many samples bring a standard error to e, with per-sample standard deviation s?
Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.
Step 2
How many trials estimate a probability p to relative error r?
Explain why
Why doesn't Monte Carlo's error depend on the number of dimensions, when a grid's does?
A Monte Carlo estimate is the mean of N independent random samples of the integrand, and the standard error of a mean is the samples' standard deviation divided by . Nothing in that depends on how many coordinates each sample has: the dimension affects only how much the integrand varies, its standard deviation, not the rate. A grid with N points in d dimensions has only points along each axis, so its spacing shrinks slowly in high dimensions and its error, a power of the spacing, falls as . Past a handful of dimensions that's slower than .
Practice
Keep practicing
9 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.