Monte Carlo method in this visualization
A Monte Carlo method estimates a fixed number by random sampling. Here the number is an area: points are dropped uniformly at random in the unit square, of them land in a region, and estimates the region’s area . The quarter circle has area , so estimates ; the region under turns an integral with no elementary antiderivative into the same kind of count. The lower plot follows the estimate as grows to a million, with the range it should fall in 95% of the time.
Why the share estimates the area
A point spread evenly over a square of area 1 lands in a region with probability equal to the region’s area. Each point is an independent trial with that chance, so the share of hits settles towards by the law of large numbers. Nothing about the shape matters except the ability to tell whether a point is inside.
How accurate it is
The number of hits is binomial, so the share has standard deviation . The typical error shrinks like : ten times as many points narrow it by about , so making it ten times smaller takes about a hundred times as many points; a million points still leave π uncertain by about ±0.003. The true area is not needed to judge this: putting the observed share in place of gives the range , an approximate 95% confidence interval, used here once there are at least ten hits and ten misses. If the whole experiment were repeated many times with the same , about one range in twenty would miss the true value; the lower plot’s blue funnel is that range around the truth for each separately, not a band the whole path must stay in, and a single run’s error does not fall steadily: more points can land a little further from the truth. What shrinks reliably is the range.
When it pays
For a smooth function of one variable, a deterministic rule such as Simpson’s (see numerical integration) is far more accurate for the same number of evaluations. The strength of the Monte Carlo method is that the exponent in its rate, , does not change with the number of dimensions, while a grid with points per side needs points in dimensions; in high-dimensional problems it can therefore be the better choice. Its weakness shows with small targets: the standard error relative to the area is , so a region a hundredth of the square needs far more points for the same relative accuracy.
Things to notice
- Random points are not spread evenly: with a few hundred of them, clusters and empty patches are normal.
- The points come from a pseudo-random generator with a numbered seed, so a shared link brings back the same points; at a million, Drop points starts again with the next seed.