Optional workshopsOptional workshops · 14 min

Benchmark a Monte Carlo estimate

Use an exact symbolic expectation to check a seeded simulation under the same model.

Maths refresher: Spread of outcomes versus error of a mean

Outcome variance describes how individual areas vary. To estimate the standard error of the mean for independent draws with finite variance, divide the sample standard deviation by the square root of the draw count.

E[A]=∫12πr2 dr=7π3,MCSE⁡(Aˉ)≈sAnE[A]=\int_1^2\pi r^2\,dr=\frac{7\pi}3,\qquad\operatorname{MCSE}(\bar A)\approx\frac{s_A}{\sqrt n}
Worked example

More draws refine the simulated mean. They do not narrow the model’s distribution of possible individual areas.

Maths prerequisite map ↗

Symbolic calculation can provide a reference for a numerical simulation. The comparison is meaningful only if both methods use the same inputs, domain and target quantity. Here radius is uniformly distributed between one and two, and area is πr2\pi r^2.

See the mathematics
exact meanπ4πarea (squared length units)
exact meanπ4πarea (squared length units)
E[πr2]=7π3,r∼U(1,2)E[\pi r^2]=\frac{7\pi}3,\quad r\sim U(1,2)
Starter reference. Distribution from the published seeded simulation: 20,000 independent radii uniform on [1, 2], transformed into area. The amber marker is the exact model mean; this is a worked reference, not your run.

Integrate over the stated uniform density to obtain exact mean area and variance. Then generate independent radius draws, transform each into area, and estimate the mean and its Monte Carlo standard error. The standard error describes numerical variability of the estimated mean, not the spread of individual areas.

A discrepancy larger than expected prompts inspection of the model translation or calculation. Agreement checks an implementation under this authored probability model; it does not establish that real radii are uniform. Preserve the seed, draw count, exact target, actual result and assumptions in the report.

Will increasing simulation draws reduce uncertainty about whether real radii follow the assumed uniform model?

Write a prediction (optional)

Exact model reference and seeded teaching simulation

Select Run Python with the code unchanged.

Tools
About Python

Python and the course packages can load while you read. Each run starts with fresh user variables; imported modules stay loaded. Stop replaces the worker. Runtime details ↗

Ctrl+Enter or ⌘+Enter runs Python.

Compare with the worked example

Executed from the published Python during the site build. Your own run appears above. Build environment ↗

Seed
20262026
Draws
2000020000
Exact mean area
7π3\frac{7 \pi}{3}
Exact outcome variance
34π245\frac{34 \pi^{2}}{45}
Simulated mean
7.340244733278227.34024473327822
Estimated MCSE
0.01925650223165620.0192565022316562
Difference in estimated SE units
0.5121322025877170.512132202587717
Worked text output
Seed: 2026
Draws: 20000
Exact mean area: 7*pi/3
Exact outcome variance: 34*pi**2/45
Simulated mean: 7.340244733278218
Estimated MCSE: 0.019256502231656206
Difference in estimated SE units: 0.5121322025877172
Plot generated by the executed Python example. Read its labelled axes and the lesson explanation together.
Open full-size figure ↗

Read the starter result

Compare Simulated mean with Exact mean area for the same authored model. The histogram shows the spread of individual areas. Estimated MCSE measures how much the simulated mean would vary across repeated runs.

Edit and compare

Replace draws = 20000 with draws = 80000 and select Run Python. Then replace seed = 2026 with seed = 2027 and select Run Python again. Compare Estimated MCSE and Simulated mean with the original run. Which quantity shows the more regular change when the sample size increases?

Return to the editor

Scope. Independent uniform radii and finite moments are assumed. Agreement cannot validate those assumptions against reality.

Try a fresh case

A simulated mean agrees closely with the exact model mean. What does that support?

Choose an answer
Need a hint?
Hint 1

Separate “does the code implement this model?” from “does this model describe reality?”

Hint 2

Identify what the exact integral assumes.

Write your investigation report

Record the question, mathematical assumptions and proposed checks before interpreting the result. After execution, add the derivation, numerical comparison and limits. The export includes the last successful run.

Your notesNotes save in this browser when storage is available.