Monte Carlo Methods
Compute with random numbers — integration, simulation, and uncertainty quantification
When a problem has too many dimensions, too much geometric complexity, or too much randomness baked into its physics, deterministic methods grind to a halt. Monte Carlo sidesteps the difficulty by sampling randomly and letting the law of large numbers do the work.
Three things make Monte Carlo special:
- The error scales as regardless of dimension. This is bad for low-dimensional smooth integrals (deterministic quadrature crushes it) and unbeatable in high dimensions.
- It needs almost no problem structure — you only have to be able to sample and evaluate.
- It produces an error estimate as a byproduct.
A first example: estimating
Drop random points uniformly into the unit square. The fraction that lands inside the unit quarter-disk approximates .
A million samples buy you about three correct digits. To get one more digit you would need 100× as many samples. This scaling is the central law of Monte Carlo — slow, but unaffected by the dimensionality of the problem.
Monte Carlo integration
For any integrable over a domain with volume ,
The estimator's standard error is where over the domain. Compare to a -D deterministic grid which requires points: in 10 dimensions, grid points vs Monte Carlo's samples for similar accuracy.
In 10 dimensions, the unit ball occupies only about of its bounding box. Monte Carlo handles this effortlessly while a deterministic grid would be hopeless.
Variance reduction: importance sampling
If is large only in a small region, uniform sampling wastes most of its budget. Importance sampling draws from a distribution that mirrors 's shape, then re-weights:
The importance-sampled estimator has dramatically lower variance. The principle is universal: sample where the integrand matters.
Random walks and diffusion
Monte Carlo is also a simulation tool, not just an integration tool. A random walk in 2-D models a pollen grain bouncing through fluid, a stock price diffusing in time, or a photon scattering in tissue.
The mean-squared displacement grows linearly with time — the diffusion law. This same simulation underlies Brownian motion, neutron transport, and option pricing.
Simulating a stochastic process: Ornstein–Uhlenbeck
A more interesting random process: the OU process, which is a random walk pulled back toward zero by a restoring force. It models interest rates, particle velocities, and many biological signals.
After enough time, every walker's marginal distribution converges to the same Gaussian — the stationary distribution. Monte Carlo lets you see analytical results emerge from raw randomness.
Uncertainty quantification by bootstrap
Got a sample of measurements and want a confidence interval for the mean, median, or any statistic? Resample with replacement many times and compute the statistic on each resample. The spread of resampled statistics estimates the spread of the estimator.
The bootstrap works for any statistic — median, regression coefficient, correlation, anything you can compute on a sample. It is one of the most powerful applications of Monte Carlo to statistics.
A multi-file Monte Carlo experiment
Notice how the error bars shrink as — every 100× increase in samples buys you one extra digit. This is both the power and the limitation of Monte Carlo.
Challenge: estimate the area of an irregular region
Implement mc_area(predicate, bounds, n_samples, seed=0) that estimates the area of the region ${(x, y) : \text{predicate}(x, y) = \text{True}}$ inside the rectangle defined by bounds = (xlow, xhigh, ylow, yhigh).
Use numpy.random.default_rng(seed) for reproducibility.
Test on the unit disk where the true area is $\pi$.
Check your understanding
You are integrating a smooth 12-dimensional function. You compare deterministic Gauss quadrature with nodes per axis against a Monte Carlo estimator with total samples. Both are forced to use the same total budget of evaluations. Which usually wins, and why?
Deterministic quadrature always wins because it is higher order
Monte Carlo usually wins because deterministic quadrature costs evaluations — only fits in any reasonable budget — while MC's error is independent of dimension
They are always equivalent
Neither converges
You ran a Monte Carlo estimator with samples and obtained a standard error of . About how many samples would you need to reduce the standard error to (one extra digit)?
About
About
About
About