Gradium × TensorTonic Voice Challenge is open for registration.Register now
Modules
07/10
Probability

Contents

The Law of Large Numbers (LLN)

Why the average of many independent samples converges to the true mean, with an interactive simulation and the link to Monte Carlo, SGD and ERM.

By Pratham Grover

Last updated 13 November 2026

What is the law of large numbers?

The law of large numbers says that the average of many independent samples from the same distribution gets closer and closer to the true expected value as the number of samples grows. Flip a fair coin ten times and you may see 70% heads; flip it ten thousand times and the share of heads will be very close to 50%. It is the reason sample averages, Monte Carlo estimates and mini-batch gradients can be trusted. On TensorTonic you implement Monte Carlo estimation and the sampling distribution of the mean from scratch, with tests that check your output.

The Law of Large Numbers (LLN) is the anchor of statistics. It states a simple but powerful truth: as you collect more data, the sample average converges to the true expected value.

The Core Promise

Xˉn→n→∞μ\bar{X}_n \xrightarrow{n \to \infty} \mu

Sample mean approaches population mean as sample size grows

Without LLN, machine learning would be impossible. We assume that training loss approximates true generalization error. LLN is the mathematical license for that assumption.

The Casino Intuition

Why Casinos Always Win

Bet on Red (Roulette)

Win: 18/38 = 47.4%

Lose: 20/38 = 52.6%

Expected Value

E[X] = (1)(0.474) + (-1)(0.526)

= -$0.052 per bet

1 game:Player might win. Luck matters.
10 games:Still volatile. Streaks happen.
1,000,000 games:Average profit per game = exactly $0.052.

The casino is not gambling. It is running a business based on LLN.

Mathematical Statement

Let X1,X2,…,XnX_1, X_2, \dots, X_n be i.i.d. random variables with mean μ\mu. The sample mean is:

Xˉn=1n∑i=1nXi\bar{X}_n = \frac{1}{n} \sum_{i=1}^n X_i

Sample mean = sum of observations divided by count

Law of Large Numbers

As n approaches infinity, the sample mean converges to the true mean:

Xˉn→μasn→∞\bar{X}_n \to \mu \quad \text{as} \quad n \to \infty

Interactive: Watch Convergence

Try different distributions and sample sizes. Notice how the running average stabilizes around the true mean as n grows. Small n = noisy. Large n = stable.

Samples0 / 2000
True Mean0.50
Sample Mean0.000
μ = 0.5

Notice how the "swings" (variance) are huge at the start (small N),
but the line inevitably tightens around the True Mean as N grows.

Why It Works: Variance Reduction

The intuition comes from looking at the variance of the sample mean.

Start with variance of sample mean:

Var(Xˉn)=Var(1n∑i=1nXi)Var(\bar{X}_n) = Var\left(\frac{1}{n} \sum_{i=1}^n X_i\right)

For independent variables:

=1n2∑i=1nVar(Xi)=1n2⋅nσ2= \frac{1}{n^2} \sum_{i=1}^n Var(X_i) = \frac{1}{n^2} \cdot n\sigma^2

Result:

Var(Xˉn)=σ2nVar(\bar{X}_n) = \frac{\sigma^2}{n}

The Key Insight

As n→∞n \to \infty, variance →0\to 0. A random variable with zero variance is a constant. Therefore, the sample mean becomes the constant μ\mu.

What is the difference between the weak and strong law of large numbers?

The weak law says that, for a large enough sample, the average is very likely to be close to the true mean; the strong law says that the sequence of averages actually converges to the true mean with probability 1. The strong law is the stronger guarantee, because it describes the whole sequence rather than one sample size at a time.

Weak lawStrong law
Type of convergenceIn probabilityAlmost surely
What it guaranteesLarge deviations become unlikely for large nThe averages converge to the mean with probability 1
StrengthWeaker (implied by the strong law)Stronger

Weak LLN

Convergence in Probability

lim⁡n→∞P(∣Xˉn−μ∣>ϵ)=0\lim_{n\to\infty} P(|\bar{X}_n - \mu| > \epsilon) = 0

For any margin ϵ\epsilon, probability of being far from μ\mu goes to zero.

Strong LLN

Almost Sure Convergence

P(lim⁡n→∞Xˉn=μ)=1P\left(\lim_{n\to\infty} \bar{X}_n = \mu\right) = 1

The sample average converges with probability 1.

For most ML applications, the distinction does not matter. Both guarantee convergence.

What is the difference between the law of large numbers and the central limit theorem?

The law of large numbers tells you where the sample mean ends up, which is at the true mean, while the central limit theorem tells you how the sample mean is spread around that value for a finite sample, which is approximately a normal distribution whose width shrinks like one over the square root of the sample size. They describe different aspects of the same process and are often confused.

TheoremWhat it saysAnalogy
LLNSample mean converges to true meanWhere the arrow lands (the target)
CLTDistribution of sample means is NormalThe shape of the arrow pattern

See Central Limit Theorem for the distribution story.

The Gambler's Fallacy

The Mistake

"I got 10 heads in a row. LLN says it balances to 50%, so tails is 'due' next."

Why It's Wrong

The coin has no memory. LLN works by dilution, not compensation.

Example

After 10 heads:10H, 0T = 100% heads
Flip 1000 more (fair):~510H, ~500T
New ratio:510/1010 = 50.5%

The streak did not disappear. It just became statistically insignificant.

Interactive: Gambler's Fallacy Demo

Start with a streak of heads, then flip more. Watch how the ratio approaches 50% through dilution, not correction.

10

Starting with 10 Heads in a row (100%)

Add Fair Flips
0 / 500
Dilution Tank
100.0%
Heads %
50% Target

Total Stats

Heads10
Tails0
Absolute Diff10

Observed: The percentage drops towards 50%, but the absolute number of Heads is still much higher than Tails (diff: 10).

The universe didn't generate extra tails to "fix" the streak. It just buried the streak under a mountain of new, normal data. That is Dilution.

ML Applications

Monte Carlo Methods

Replace intractable integrals with sample averages:

∫f(x)p(x)dx≈1N∑i=1Nf(xi)\int f(x)p(x)dx \approx \frac{1}{N} \sum_{i=1}^N f(x_i)

Used in MCMC, Reinforcement Learning (value estimation), Bayesian inference.

Empirical Risk Minimization

Training loss approximates true generalization loss:

1n∑i=1nL(f(xi),yi)≈E[L(f(X),Y)]\frac{1}{n} \sum_{i=1}^n L(f(x_i), y_i) \approx E[L(f(X), Y)]

The entire justification for training on finite datasets.

Stochastic Gradient Descent

Mini-batch gradient is an unbiased estimate of full gradient. Over many steps, the noise averages out. SGD converges because of LLN.

AlphaGo & MCTS

Cannot compute exact game tree values. Instead, play thousands of random games from a position. Average outcome converges to true value of the position.

Frequently asked questions about the law of large numbers

Why does the sample mean converge to the true mean?

For independent samples with variance σ², the variance of the sample mean is σ²/n, which shrinks toward zero as the sample size n grows. A quantity whose variance goes to zero settles at a constant, and for the sample mean that constant is the true mean μ.

Does the law of large numbers mean a streak will balance out?

No, because a fair coin has no memory, so later flips never compensate for a streak. The law of large numbers works by dilution. After 10 heads in a row, about 1000 more fair flips give roughly 510 heads out of 1010 flips, or 50.5%, so the streak still exists but barely moves the ratio.

Practice this

On TensorTonic you implement this from scratch and test it in the browser.