How Monte Carlo Works
Random Sampling
Drawing observations from a distribution
As we draw more samples, the histogram starts to resemble a uniform distribution. The mean is settling closer to 0.5.
Step 1 of 6: Random Sampling
Drawing observations from a distribution
As we draw more samples, the histogram starts to resemble a uniform distribution. The mean is settling closer to 0.5.
Step 2 of 6: Law of Large Numbers
Sample means converge to the true mean
The running mean is settling down and approaching 0.5. Fluctuations are smaller, but the estimate still wanders around the true value.
Step 3 of 6: Estimating π
Throw darts to approximate a circle's area
As we throw more darts, the estimate improves. The area of a quarter-circle with radius 1 is π/4, so multiplying the ratio by 4 gives us π. More darts = better estimate.
Step 4 of 6: Monte Carlo Integration
Approximate integrals by random sampling
With few samples, each random x-value contributes a noisy estimate of the integral. The average of f(xᵢ) values is a rough approximation of the area under sin(πx).
Step 5 of 6: Importance Sampling
Sample smarter, not harder
The proposal distribution closely matches the target peak. Importance sampling concentrates samples where the target is large, reducing variance compared to uniform sampling.
Step 6 of 6: MCMC — Metropolis-Hastings
A random walk that samples from any distribution
Good balance! The chain accepts enough proposals to move efficiently while rejecting enough to avoid wandering too far. In 2D, acceptance rates around 40–70% give efficient exploration.