Skip to content
BIASED

The law of large numbers

Why averages settle down: the weak law via Chebyshev's inequality, the strong law, convergence in probability and almost surely, empirical risk as a sample mean, and the cases where averages fail to converge.

Where the average sits

The topic Inequalities and concentration bounded how far an average can stray from its mean. For the sample mean, Chebyshev's inequality gave

P(∣Xˉn−μ∣≥ε)≤σ2nε2,P(|\bar X_n - \mu| \ge \varepsilon) \le \frac{\sigma^2}{n\varepsilon^2},

and Hoeffding's inequality gave a far smaller bound for bounded variables. Each bound is about one fixed nn. What is still missing is the limit: what happens to the average itself as the data keep coming. That is the law of large numbers.

The setup for the whole topic: X1,X2,…X_1, X_2, \dots are i.i.d. with mean μ\mu and, where needed, variance σ2\sigma^2. The sample mean is

Xˉn=X1+⋯+Xnn.\bar X_n = \frac{X_1 + \dots + X_n}{n}.

Two facts from earlier topics say where it sits and how widely it spreads. By linearity, E[Xˉn]=μ\mathbb E[\bar X_n] = \mu. Variances of independent variables add (Joint distributions and independence), and the factor 1/n1/n comes out of a variance squared, so

Var⁡(Xˉn)=nσ2n2=σ2n.\operatorname{Var}(\bar X_n) = \frac{n\sigma^2}{n^2} = \frac{\sigma^2}{n}.

The centre stays put while the variance shrinks like 1/n1/n, and the standard deviation like σ/n\sigma/\sqrt n.

The running example is a classifier that errs on each test example independently with probability pp. Let Xi=1X_i = 1 if example ii is misclassified and 00 otherwise. Then Xˉn\bar X_n is the error rate measured on a test set of size nn, with μ=p\mu = p and σ2=p(1−p)\sigma^2 = p(1-p).

The weak law

The weak law of large numbers. If X1,X2,…X_1, X_2, \dots are i.i.d. with mean μ\mu, then for every ε>0\varepsilon > 0

P(∣Xˉn−μ∣≥ε)→0as n→∞.P(|\bar X_n - \mu| \ge \varepsilon) \to 0 \quad \text{as } n \to \infty.

With a finite variance the proof takes one line. The sample mean has mean μ\mu and variance σ2/n\sigma^2/n, so Chebyshev's inequality bounds the left side by σ2/(nε2)\sigma^2/(n\varepsilon^2). Hold ε\varepsilon fixed and let nn grow: the bound goes to zero, and the probability is squeezed to zero with it.

This kind of limit has a name. A sequence YnY_n converges in probability to a number cc if, for every ε>0\varepsilon > 0,

P(∣Yn−c∣≥ε)→0,P(|Y_n - c| \ge \varepsilon) \to 0,

written Yn→PcY_n \xrightarrow{P} c. The weak law says Xˉn→Pμ\bar X_n \xrightarrow{P} \mu.

Read the order of the quantifiers carefully. First you choose a tolerance ε\varepsilon, as small as you like. Then the chance that the average misses μ\mu by ε\varepsilon or more can be made as small as you like by taking nn large enough. A tighter tolerance simply costs more data.

Frequency becomes a theorem

Now take any event AA with P(A)=pP(A) = p and repeat the experiment independently. Let Xi=1X_i = 1 if AA happened on trial ii and 00 otherwise. This indicator has mean pp and variance p(1−p)p(1-p), and its sample mean Xˉn\bar X_n is the frequency of AA in nn trials. The weak law says that the frequency converges to pp in probability.

In the topic What probability is, the frequency reading was an observation: toss a coin many times and the share of heads drifts towards 1/21/2. Here it is a theorem. Nothing about frequencies went into Kolmogorov's axioms, yet frequencies come out of them. The share of heads, a classifier's error rate on a test set and the conversion rate in an A/B test are all frequencies of this kind.

A finite variance was needed only for the short proof. Khinchin (1929) proved the weak law for i.i.d. terms with a finite mean, E∣X∣<∞\mathbb E|X| < \infty, and nothing more. His proof cuts off large values, applies Chebyshev to the truncated part and shows that the cut-off part is negligible. We will not need the details.

The mean, however, cannot be dropped. Without it there is no number for the average to converge to, and the block on failures below shows what happens then.

The strong law

The weak law speaks about each nn separately: at n=1000n = 1000 a miss by ε\varepsilon is unlikely, and at n=106n = 10^6 it is even less likely. But your running average is one path, Xˉ1(ω),Xˉ2(ω),…\bar X_1(\omega), \bar X_2(\omega), \dots for a single outcome ω\omega. Could that path keep making rare excursions forever, each one unlikely, yet never stopping?

The strong law of large numbers (Kolmogorov) says no. If X1,X2,…X_1, X_2, \dots are i.i.d. with a finite mean μ\mu, then

P(Xˉn→μ)=1.P\big(\bar X_n \to \mu\big) = 1.

Inside PP stands an event: the set of outcomes ω\omega whose whole sequence of averages converges to μ\mu in the ordinary sense of a limit. A sequence YnY_n converges almost surely to cc if P(Yn→c)=1P(Y_n \to c) = 1, written Yn→a.s.cY_n \xrightarrow{\text{a.s.}} c. "Almost" because exceptional outcomes exist, such as a coin showing heads forever, but together they have probability zero, like the single points of [0,1][0, 1] in the topic Kolmogorov's axioms.

Almost sure convergence implies convergence in probability. The converse fails. Take independent events A1,A2,…A_1, A_2, \dots with P(An)=1/nP(A_n) = 1/n, and let YnY_n be the indicator of AnA_n. Since P(Yn=1)=1/n→0P(Y_n = 1) = 1/n \to 0, Yn→0Y_n \to 0 in probability. Yet the expected number of events among the first nn is 1+12+⋯+1n≈ln⁡n1 + \tfrac12 + \dots + \tfrac1n \approx \ln n, which grows without bound; by n=105n = 10^5 it is already about 12.112.1. With probability one the events never stop, so Yn=1Y_n = 1 again and again and the path does not converge.

Why this matters in ML: one long run of stochastic gradient descent, or one long Markov chain, is a single path, and the strong law is the statement about that path. For i.i.d. averages both laws hold under the same finite-mean condition, so they differ in what they claim, not in when they apply.

Empirical risk is a sample mean

Here is the law at work in learning. A model hh is scored by a loss ℓ(h(x),y)\ell(h(x), y), and data (X,Y)(X, Y) come from some distribution. The risk is the expected loss from Expectation and variance:

R(h)=E[ℓ(h(X),Y)].R(h) = \mathbb E\big[\ell(h(X), Y)\big].

We cannot compute it, because the distribution is unknown. Given nn i.i.d. examples, we compute the empirical risk instead:

R^n(h)=1n∑i=1nℓ(h(xi),yi).\hat R_n(h) = \frac1n \sum_{i=1}^n \ell(h(x_i), y_i).

For a fixed hh, the losses Li=ℓ(h(Xi),Yi)L_i = \ell(h(X_i), Y_i) are i.i.d. with mean R(h)R(h), so R^n(h)\hat R_n(h) is just a sample mean and R^n(h)→R(h)\hat R_n(h) \to R(h). This is why a test error estimates the true error, and why minimizing empirical risk is a sensible proxy for minimizing risk. With the 0–1 loss, R^n(h)\hat R_n(h) is the error rate from the first block.

Two words in that argument carry weight.

  • Fixed. A model trained on the same data depends on the examples, and its training error is optimistic. The topic Inequalities and concentration handled a finite set of candidates with a union bound; in practice we keep a separate test set.
  • Identically distributed. If production data drift away from the test data, the average still converges, but to the risk on the old distribution.

The same trick estimates any expectation: average g(Xi)g(X_i) over samples to get E[g(X)]\mathbb E[g(X)]. This is a Monte Carlo estimate. For two independent U(0,1)U(0, 1) variables, P(U12+U22≤1)=π/4P(U_1^2 + U_2^2 \le 1) = \pi/4, so four times the share of points that land in the quarter disc converges to π\pi; in one run 2000 points gave 3.1663.166. A minibatch gradient is the same idea: the average of per-example gradients estimates the full gradient. The topic Monte Carlo methods develops this.

When averages fail

The law has conditions, and each of them can break.

No mean. The standard Cauchy distribution has density and CDF

p(x)=1π(1+x2),F(x)=12+arctan⁡xπ.p(x) = \frac{1}{\pi(1 + x^2)}, \qquad F(x) = \frac12 + \frac{\arctan x}{\pi}.

Its tails fall only like 1/x21/x^2, so E∣X∣=∞\mathbb E|X| = \infty. Worse, the average of nn independent standard Cauchy variables is again standard Cauchy. Averaging does not help at all: in one simulation the averages of 10210^2, 10410^4 and 10610^6 draws were −0.01-0.01, −0.33-0.33 and 2.862.86. A Cauchy variable is not exotic; the ratio of two independent standard normals has this distribution.

A mean but no variance. The Pareto distribution with tail index 1.51.5 has density 1.5/x2.51.5/x^{2.5} for x≥1x \ge 1, mean 33 and infinite variance. Khinchin's law still holds, but Chebyshev is gone and convergence is slow and jumpy: the same sample sizes gave 3.223.22, 3.743.74 and 3.043.04. Every so often one enormous value arrives and drags the average away. Incomes, file sizes and occasional gradient spikes have such heavy tails.

Dependence. In the extreme case X1=X2=…X_1 = X_2 = \dots are one and the same draw, and Xˉn=X1\bar X_n = X_1 forever. Milder cases are everywhere: neighbouring states of a Markov chain, near-duplicate examples in a dataset, the same user counted many times in an A/B test. The average may still converge, but it behaves like an average of fewer independent terms. That smaller number is the effective sample size.

How big is the error

The law of large numbers names the destination, not the speed. It says Xˉn→μ\bar X_n \to \mu, and says nothing about how close the average is at n=1000n = 1000.

Two quantitative tools are already on the table. The standard deviation σ/n\sigma/\sqrt n gives the typical distance. It shrinks slowly: to cut the error by a factor kk you need k2k^2 times the data. The same n\sqrt n governs test sets, A/B tests and Monte Carlo.

Chebyshev's bound holds for every nn, but it is loose. For 100 coin tosses and ε=0.1\varepsilon = 0.1 it gives 0.250.25 against the exact 0.0570.057 (see Inequalities and concentration). For 1000 die rolls and the same ε\varepsilon it gives 0.290.29, and simulation gives about 0.060.06. Hoeffding is tighter, but it is still only a bound.

The gap means the fluctuations have a definite shape that Chebyshev ignores. Take Xˉn−μ\bar X_n - \mu, scale it up by n\sqrt n and draw a histogram. For coins, dice, error rates and exponential waiting times alike, the same bell appears. That is the next topic, The central limit theorem: the standardized average n(Xˉn−μ)/σ\sqrt n (\bar X_n - \mu)/\sigma approaches N(0,1)\mathcal N(0, 1), whatever the distribution of the terms, as long as the variance is finite.

Check your understanding

The same questions as in Pulse. Answers are shared between modes.

Full notes

Answers are saved on the server and tied to this browser until you sign in.