ADAM / SYSTEM003

Getting π out of random numbers

Notes on probability.

PROBABILITY3 MIN READ

Draw a circle with radius one inside a square whose sides have length two. The circle has area π; the square has area four. Their area ratio is π/4.

Now forget the formula for the circle’s area. Throw points uniformly at the square and count how many land inside the circle.

π̂ = 4 · points inside / total points

Why this works

A point chosen uniformly from the square lands inside the circle with probability π/4. The fraction of successful points estimates that probability. Multiplying by four estimates π.

For each independent sample, define Iᵢ as one if xᵢ² + yᵢ² ≤ 1, and zero otherwise. The estimator is just a scaled sample average:

π̂ₙ = (4/n) ∑ Iᵢ
𝔼[π̂ₙ] = π

Unbiased does not mean exact. It means that its expected value over repeated runs equals π. Any single run fluctuates.

The price of another digit

The variance of the estimator is π(4 − π)/n. Its standard deviation therefore decreases in proportion to 1/√n.

σ = √[π(4 − π)/n]

Four times as many samples halves the typical error. One hundred times as many samples reduces it by a factor of ten. Random sampling is wonderfully general, but this particular problem has much faster numerical methods.

Convergence is not a straight line

An estimate can get worse after more samples. The guarantee is about the behavior over large numbers of samples, not a promise that every next point improves the result. Watch the estimate move in the lab; the occasional step away from π is part of the idea.

Let randomness do the calculation ↗
← The notebook
SEARCH THE SITE
↑ ↓ to navigate ↵ to open
ADAM / SYSTEM — TERMINAL