1.3.14Probability & Statistics

Law of large numbers

2,606 words12 min readdifficulty · medium6 backlinks

What Exactly Is the Law of Large Numbers?

Why two versions? WLLN says "the sample mean is probably close to μ\mu for large nn." SLLN says something stronger: "the sample mean will eventually settle at μ\mu and stay there, guaranteed." For machine learning, WLLN is usually sufficient.

Derivation from First Principles

Let's prove the Weak Law using Chebyshev's inequality.

Step 1: What We Know

We have i.i.d. random variables X1,,XnX_1, \ldots, X_n with:

  • Mean: E[Xi]=μE[X_i] = \mu
  • Variance: Var(Xi)=σ2\text{Var}(X_i) = \sigma^2 (assumed finite)

Sample mean: Xˉn=1ni=1nXi\bar{X}_n = \frac{1}{n}\sum_{i=1}^{n} X_i

Step 2: Expected Value of Sample Mean

E[Xˉn]=E[1ni=1nXi]=1ni=1nE[Xi]=1nnμ=μE[\bar{X}_n] = E\left[\frac{1}{n}\sum_{i=1}^{n} X_i\right] = \frac{1}{n}\sum_{i=1}^{n} E[X_i] = \frac{1}{n} \cdot n\mu = \mu

Why this step? Expectation is linear, so we can move it inside the sum. Each XiX_i has the same mean μ\mu.

Step 3: Variance of Sample Mean

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

Since the XiX_i are independent, variances add: =1n2Var(i=1nXi)=1n2i=1nVar(Xi)= \frac{1}{n^2} \text{Var}\left(\sum_{i=1}^{n} X_i\right) = \frac{1}{n^2}\sum_{i=1}^{n} \text{Var}(X_i)

Why this step? When you multiply a random variable by a constant cc, variance scales by c2c^2. Independence means Var(X+Y)=Var(X)+Var(Y)\text{Var}(X + Y) = \text{Var}(X) + \text{Var}(Y).

=1n2nσ2=σ2n= \frac{1}{n^2} \cdot n\sigma^2 = \frac{\sigma^2}{n}

Key insight: The variance of the sample mean decreases as nn increases. This is why larger samples are more reliable.

Step 4: Apply Chebyshev's Inequality

Chebyshev's inequality states that for any random variable YY with mean μY\mu_Y and variance σY2\sigma_Y^2: P(YμYϵ)σY2ϵ2P(|Y - \mu_Y| \geq \epsilon) \leq \frac{\sigma_Y^2}{\epsilon^2}

Apply to Xˉn\bar{X}_n: P(Xˉnμϵ)Var(Xˉn)ϵ2=σ2nϵ2P(|\bar{X}_n - \mu| \geq \epsilon) \leq \frac{\text{Var}(\bar{X}_n)}{\epsilon^2} = \frac{\sigma^2}{n\epsilon^2}

Step 5: Take the Limit

limnP(Xˉnμϵ)limnσ2nϵ2=0\lim_{n \to \infty} P(|\bar{X}_n - \mu| \geq \epsilon) \leq \lim_{n \to \infty} \frac{\sigma^2}{n\epsilon^2} = 0

Therefore: limnP(Xˉnμϵ)=0\lim_{n \to \infty} P(|\bar{X}_n - \mu| \geq \epsilon) = 0

Why this step? As nn \to \infty, the upper bound goes to zero, so the probability itself must go to zero. This proves the Weak Law.∎

Worked Examples

Figure — Law of large numbers

Common Mistakes & Steel-Manning

Why This Matters for Machine Learning

  1. Training Convergence: Stochastic gradient descent (SGD) uses LN—the gradient of a mini-batch converges to the true gradient as batch size increases.

  2. Monte Carlo Methods: Estimating expectations (value functions in RL, posterior means in Bayesian ML) relies on LLN to guarantee accuracy.

  3. Sample Complexity: LN tells us how many examples we need to estimate quantities to desired precision. The O(1/n)O(1/n) variance decay is fundamental to learning theory.

  4. Ensemble Methods: Why does averaging predictions from many models reduce error? LN! Individual model errors average out.

  5. A/B Testing: LLN justifies using sample proportions to estimate click-through rates, conversion rates, etc.

Recall Explain to a 12-Year-Old

Imagine you're trying to figure out how tall kids in your school are on average. You measure one kid—maybe they're really tall, like 180 cm. You think, "Wow, everyone must be tall!" But then you measure another kid—150 cm. Now you're confused.

But what if you measure 10 kids? Then 50 kids? Then 200 kids? As you measure more and more, your average gets closer to the real average height of all kids in the school.

The Law of Large Numbers is like a magical promise: "If you keep collecting more data, your average will get closer and closer to the truth." It's not that randomness goes away—some kids are tall, some are short—but the average stabilizes.

This is why scientists do lots of experiments, why polls ask thousands of people, and why casinos always make money (they've played millions of games, so the average always works out in their favor).

Connections

  • Central Limit Theorem — LLN says where the sample mean goes; CLT says how it gets there (normal distribution)
  • Chebyshev Inequality — The tool we used to prove LLN; gives probability bounds for any distribution
  • Variance and Standard Deviation — Variance σ2/n\sigma^2/n controls convergence rate
  • Monte Carlo Methods — Direct application of LLN to estimate integrals and expectations
  • Confidence Intervals — LN justifies using sample statistics to estimate population parameters
  • Bias-Variance Tradeoff — Variance of estimates decreases with sample size per LN
  • Stochastic Gradient Descent — Mini-batch gradients converge to true gradient by LN
  • Bootstrap Sampling — Relies on LLN for resampling-based inference
  • Expected Value — The μ\mu that sample means converge to
  • Independent and Identically Distributed — The i.i.d. assumption required for LLN

#flashcards/ai-ml

What does the Law of Large Numbers state? :: As you repeat an experiment more times, the sample mean Xˉn\bar{X}_n converges to the expected value μ\mu. The probability that Xˉnμ|\bar{X}_n - \mu| exceds any fixed ϵ\epsilon goes to zero as nn \to \infty.

What is the difference between Weak LN and Strong LLN?
Weak LLN: P(Xˉnμϵ)0P(|\bar{X}_n - \mu| \geq \epsilon) \to 0 (convergence in probability). Strong LLN: P(limnXˉn=μ)=1P(\lim_{n\to\infty} \bar{X}_n = \mu) = 1 (almost sure convergence). SLN is stronger—guarantees eventual settling at μ\mu.
What is the variance of the sample mean Xˉn\bar{X}_n if each XiX_i has variance σ2\sigma^2?
Var(Xˉn)=σ2/n\text{Var}(\bar{X}_n) = \sigma^2/n. This decreases as nn increases, which is why larger samples give more precise estimates.
How fast does the error in sample mean decrease with sample size?
The standard deviation of Xˉn\bar{X}_n is σ/n\sigma/\sqrt{n}, so error decreases as O(1/n)O(1/\sqrt{n}). To halve the error, you need 4× the samples.
What assumptions are required for the Law of Large Numbers?
The random variables must be (1) independent and (2) identically distributed (i.i.d.) with (3) finite expected value μ\mu (and finite variance for WLLN via Chebyshev).
If you flip a fair coin nn times, what does LN say about the proportion of heads?
The proportion of heads Xˉn\bar{X}_n converges to p=0.5p = 0.5 as nn \to \infty. The probability that Xˉn0.5>ϵ|\bar{X}_n - 0.5| > \epsilon goes to zero for any ϵ>0\epsilon > 0.
How is LN used in Monte Carlo integration?
Sample random points; compute a function value at each point. The sample mean of these values converges to the expected value (the integral) by LLN. Error scales as 1/n1/\sqrt{n}.
Why do mini-batch gradients in SGD converge to the true gradient?
By LLN. Each mini-batch gives a noisy gradient estimate. As batch size increases, the sample mean of gradients converges to the true gradient L\nabla L.
What bound does Chebyshev's inequality give for LN?
P(Xˉnμϵ)σ2/(nϵ2)P(|\bar{X}_n - \mu| \geq \epsilon) \leq \sigma^2/(n\epsilon^2). This provides a distribution-free guarantee that works for any random variable with finite variance.
Why doesn't LLN mean you'll get exactly 500 heads in 1000 fair coin flips?
LN guarantees convergence in probability, not deterministic convergence. The sample mean gets arbitrarily close to 0.5, but randomness remains—you might get 498, 501503 heads. Absolute fluctuations don't vanish.

Concept Map

averaged into

target of

E of sample mean

independence gives

shrinks as n grows

bounds

plugged into

proves

stronger version

justifies

guarantees

i.i.d. random variables Xi

Sample mean X-bar n

Expected value mu

E X-bar n equals mu

Var X-bar n equals sigma^2 over n

Larger samples more reliable

Chebyshev inequality

P deviation shrinks to 0

Weak Law of Large Numbers

Strong Law of Large Numbers

Estimate probabilities from data

X-bar n converges to mu

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Law of Large Numbers ek bahut powerful concept hai joume bata hai ki jab hum kisi experiment kobaar-baar repeat karte hain, toh average result true expected value ke pas ata jata hai. Sochiye ek sika phenk rahe ho—pehli baar heads aya, toh ap soch sakte ho "100% heads!" Lekin jaise-jaise ap aur phenkte ho (10 baar, phir 100 baar, phir 10,000 baar), toh proportion 50% ke karib settle hone lagta hai. Yahi LN ka essence hai.

Machine learning mein yeh concept critical hai. Jab aap SGD use karte ho training ke liye, har mini-batch ek noisy gradient deta hai, lekin LLN guarantee karta hai ki average gradient true gradient ke paas converge karega as batch size badhegi. Isi tarah, Monte Carlo methods mein hum expectations ko estimate karte hain by sampling—sample mean converges to true mean by LLN. Yeh principle A/B testing, ensemble methods, aur confidence intervals ka bhi base hai.

Ek important baat: error decrease hoti hai as 1/n1/\sqrt{n} rate se. Matlab agar aapko error half karni hai, toh 4 times zyada samples chahiye. Isliye ML models ko perfect banana itna expensive hota hai—last 1% accuracy ke liye exponentially zyada data aur compute chahiye. LN hume yeh mathematical guarantee deta hai ki consistent sampling se truth ke paas pahunch sakte hain, chahe individual samples random hi kyun na ho.

Go deeper — visual, from zero

Test yourself — Probability & Statistics

Connections