Computing Library › Probability Statistics
Probability Statistics

Monte Carlo Methods

Monte Carlo methods estimate quantities by random sampling, converting hard integrals and expectations into averages.

The core idea

Monte Carlo estimation replaces a hard calculation with an average over random samples. To estimate E[g(X)], draw many samples of X, evaluate g on each, and average. By the law of large numbers the average converges to the true expectation.

Estimating integrals

Any integral can be written as an expectation and estimated this way. The classic demonstration estimates π by throwing random points into a square and counting the fraction inside the inscribed circle. The method shines in high dimensions, where grid-based quadrature becomes impossible.

python

import random
inside = 0; N = 1_000_000
for _ in range(N):
    x, y = random.random(), random.random()
    if x*x + y*y <= 1: inside += 1
print(round(4*inside/N, 4))  # ~3.14

Convergence rate

Monte Carlo error scales as σ/√N regardless of dimension — a strength in high dimensions but a weakness overall, since cutting error in half needs four times the samples. This 1/√N rate is the defining cost and benefit of the method.

Variance reduction

Where it is used

Monte Carlo is standard for neutron and photon transport, where particle histories are simulated one random interaction at a time and results are averaged over many histories. Simulation studies of a machine like the breeder Hyperion use exactly this approach to estimate quantities such as wall loading, always reporting a statistical error bar alongside the estimate.