aldus.nexus

Monte Carlo

Meteors rain on a starfield to estimate pi, areas and curves, with racing sampler bots and a live bell curve.

call it

Will the estimate stay inside the 95% band for the next 1,000 meteors?

no bets yet

The numbers

convergence, with the 95% band
error against meteors

Many runs

200 experiments at once

sampler bots race

More experiments

Buffon's needle on space lanes

integrate a curve

random-walk diffusion

Monte Carlo for decisions

Monte Carlo tree search

Random games can pick a move as well as measure an area. Each playout walks down a growing tree of moves, choosing by UCB1, finishes the game at random and counts who won. Good moves collect wins, so they get played more; the bonus term keeps the others from being forgotten.

UCB1(i) = wᵢ / nᵢ + c √(ln N / nᵢ)wᵢ wins and nᵢ visits of move i, N visits of the position, c = √2 by default

How it works

Throw meteors at a square without aiming. The share that lands inside the circle matches the share of the square the circle covers, which is pi / 4 when the circle just fits. Count, multiply by four, and pi falls out of pure chance.

The law of large numbers says the average of many random tries settles on the true value. It settles slowly: the typical error shrinks like 1 / √n, so a hundred times the meteors buys one more correct digit. That is the band on the chart, and why 200 runs at once pile up into a bell curve that narrows as n grows.

Smarter sampling helps. Stratified bots spread their throws over a grid, and Halton points fill gaps on purpose, so their error falls faster. The same trick prices options, renders film lighting, runs weather and nuclear physics models, and plans spacecraft routes when the exact answer is too hard to work out.

Monte Carlo also makes decisions. Tree search plays random games from a position, keeps score for each move and uses UCB1 to spend more playouts on the promising ones, so the same law of large numbers that finds pi finds a good move. Game programs from Go to Connect Four use it.

Randomness, used enough times, turns into certainty.

π ≈ 4 × inside / totalfor a circle that just fits the square; in general area ≈ square × inside / total
error ≈ 1 / √nmore exactly √(p(1 - p) / n) for the fraction p inside, times the scale
π ≈ 2 l n / (d × crossings)Buffon: needles of length l on lanes d apart