A1348 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

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 1020 circuit simulations. Monte Carlo draws random component values, simulates, and counts. Its error shrinks only as 1/N, 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 e−U2 for uniform random U estimates ∫01e−x2dx=0.746824 (the marked line). Each trial adds one random sample.
  • Early on the estimate wanders a lot; it settles as 1/n. The readouts give the estimate and its standard error, s/n, 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 104 samples. How many samples bring it to 0.0002?

Name it

Monte Carlo integration

For I=∫ΩfdV over a region of volume V, draw x1,…,xN uniformly in Ω:

I^=VN∑f(xi),standard error≈VsN

where s is the samples' standard deviation. The error is O(N−1/2) in any dimension. A grid rule of order p in d dimensions, with N points in all, has error O(N−p/d): better than Monte Carlo when p/d>12, 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 p^ from N trials, the standard error is p^(1−p^)/N. 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 10−9 by brute force takes 1011 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 ∫(f−g)+∫g.
  • Importance sampling: draw from a density q concentrated where f matters and average f/q. Shifting the noise toward the decision threshold is how bit error rates of 10−12 are simulated in seconds.
  • Quasi-Monte Carlo: low-discrepancy sequences (Halton, Sobol) fill the region more evenly than random points; error about (log⁡N)d/N 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 ∫01e−x2dx with 104 samples. How accurate is it?

Show the solution
  1. The standard error. The integrand's standard deviation over [0, 1] is 0.201, so 0.201/104=0.0020 about two good digits.
  2. For an error of 10−4. You'd need (0.201/10−4)2=4×106 samples.
  3. Compare with Simpson. Simpson's rule with 10 intervals gets 10−6. 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
  1. The estimate. Y^=0.953.
  2. Its standard error. 0.953×0.047/10000=0.0021
  3. Report. Report 95.3% ± 0.4% (two standard errors).

Answer the yield is 95.3% ± 0.4%.

Worked example

Estimate ∫01exdx by Monte Carlo with antithetic pairs eU+e1−U2. How much does that help?

Show the solution
  1. One sample's variance. e2−12−(e−1)2=0.2420
  2. The covariance. The pair's two halves are negatively correlated: Cov(eU,e1−U)=e−(e−1)2=−0.2342
  3. The pair average's variance. 0.2420−0.23422=0.0039
  4. Compare. Two independent samples would have variance 0.2420/2=0.121, so for the same number of evaluations the antithetic pairs cut the variance 31-fold.
  5. Why it works. ex 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 O(Nq) in the total number of points N. What's q?

Check

A link must be verified at a bit error rate of 10−12. 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°.

Explain why

Why doesn't Monte Carlo's error depend on the number of dimensions, when a grid's does?

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.