Lite / Engineering Complex Systems / Week 29
Monte Carlo: propagate by simulation
Your model has six uncertain inputs and a square root, an exponential and an if-statement. Is there a formula for its uncertainty? You don't need one.
Why should I care?
Real engineering models are messy: thresholds, lookup tables, simulations that take seconds. Monte Carlo treats the model as a black box: sample the inputs, run, collect outputs, and read the uncertainty straight off the histogram. It is how mission designers estimate landing ellipses and how this school's simulators can quantify their own uncertainty.
- Propagate input uncertainties through any computation by repeated random sampling.
- Choose a sample size from the Monte Carlo standard error, which shrinks like 1/√N.
- Report a Monte Carlo result reproducibly, with its seed, distributions and N.
Predict
A Monte Carlo estimate of a standard deviation uses N = 1,000 samples. How many samples would halve its sampling noise?
- 2,000
- 4,000
- 10,000
- 1,000,000
Guess first, then reveal
Monte Carlo noise falls as 1/√N, exactly like a standard error: halving it needs four times the samples. The good news: that rate doesn't depend on how many inputs the model has.
Discover
In the Code Lab, write a function that samples V ~ N(12, 0.24²) and I ~ N(1.5, 0.06²), computes P = V·I one hundred thousand times with a fixed seed, and prints the mean and SD of P. Compare with the quadrature formula. Then replace P with a model that has a threshold (for example, a heater that switches on below 16 °C) and see the histogram the formula can't predict.
What the interactive shows (text version)
In the Code Lab, the learner writes a loop that draws random V and I from normal distributions, multiplies them, and prints the mean and standard deviation of the products. For V = 12 ± 0.24 V and I = 1.5 ± 0.06 A the formula gives P = 18 W ± about 0.80 W, and the simulation agrees closely. A model with a threshold produces a lopsided, two-humped histogram that no single ± number describes well.
Watch (optional)
Watch for: Watch why sums of many random effects become bell-shaped; it explains why many Monte Carlo outputs look normal, and why some (with thresholds or products of many factors) don't.
Shows why sums and averages of many random effects drift towards a bell curve, which is what licenses the normal approximation.
“But what is the Central Limit Theorem?” by 3Blue1Brown (opens YouTube; streaming video uses a lot of data)
The video is optional. Everything you need is in this lesson's text.
Understand
The algorithm
- Describe each uncertain input with a distribution (normal with its standard uncertainty is the default; uniform for a resolution limit). 2. Draw one value of every input. 3. Run the model. 4. Repeat N times. 5. Summarise the outputs: mean, SD, percentiles (the 2.5th and 97.5th give a 95% interval without assuming normality).
How big should N be?
The Monte Carlo estimate of a mean has standard error s_out/√N; estimates of an SD or of tail percentiles need more samples than estimates of a mean. A practical check: run with two different seeds. If the results differ in a digit you intend to report, increase N. For a 95% interval from percentiles, N ≥ 10,000 is a sensible start.
Correlated inputs
If two inputs share a cause (the same reference voltage, the same temperature), sample that shared cause once per trial and derive both from it. Sampling them independently would understate or overstate the output's uncertainty. This is far easier to get right in Monte Carlo than in a formula.
Reproducible randomness
Use a seeded pseudo-random generator and record the seed, the distributions, their parameters and N. Then anyone can regenerate your histogram exactly. Every simulator and practice generator on this site is seeded for exactly this reason: the server can recompute your result from the seed to check it.
Explain it another way
Intuitive
Instead of solving how wobbly the answer is, build a thousand slightly different worlds where each input is a bit off, run them all, and look at how much the answers disagree.
Technical
Monte Carlo propagation (GUM Supplement 1): sample x⁽ᵏ⁾ ~ p(x), compute q⁽ᵏ⁾ = f(x⁽ᵏ⁾), estimate the distribution of q empirically. Convergence O(N^−½), independent of dimension.
Mathematical
By the law of large numbers the sample mean of q⁽ᵏ⁾ converges to E[q]; by the central limit theorem its error is approximately N(0, Var(q)/N). The same applies to any expectation, including P(q > threshold).
Applied
Mars landing teams run thousands of simulated entries with varied atmosphere density, wind and parachute performance to draw the landing ellipse, and choose a landing site whose ellipse avoids hazards.
Worked example 1
A Monte Carlo run gives SD(P) = 0.92 W with N = 1,000, and 0.89 W with a different seed. You want to report SD to two significant figures. Is N enough?
The two seeds disagree in the second figure (0.92 vs 0.89), so no. With N = 16,000 the sampling noise drops by 4×, and repeated seeds should then agree to about ±0.01 W.
Common mix-ups
Monte Carlo is random, so its answers can't be trusted.
✓ Its error is predictable (it shrinks as 1/√N) and seeded runs are exactly reproducible.More inputs need exponentially more Monte Carlo samples.
✓ That is true of grid methods. Monte Carlo's convergence rate doesn't depend on the number of inputs.
Practice
Practice, not a test. Answers are checked on our server; a wrong answer gets a hint and another try. Nothing is saved.
Apply it
Monte Carlo the rover's two-hour drive energy from the planetary-rover Build (motor power 100 ± 8 W, camera 20 ± 2 W, duration 2.0 ± 0.1 h). Report the mean, SD and a 95% percentile interval with your seed and N.
Reflect
What inputs to a model you have built in this course were treated as exact but are really uncertain?
Write your answer on paper or in your own notes. Lite never stores what you write.