Simple Algorithm
Machine Learning · Convergence · 28 min

Probability & Concentration Inequalities

From the law of large numbers to Hoeffding and Bernstein.

Every guarantee in learning theory comes down to one question: how far can an average of random quantities stray from its mean? The law of large numbers says "eventually, not far." Concentration inequalities say exactly how far, at every sample size, with explicit probabilities. This lesson builds them from Markov's inequality up and turns them into the first generalization bound.

What you’ll learn

  • Prove Markov's and Chebyshev's inequalities and the weak law of large numbers, and explain why the central limit theorem cannot replace a finite-sample bound.
  • Derive the Chernoff method, Hoeffding's lemma and Hoeffding's inequality, and relate them to the KL form of the Chernoff bound.
  • Define sub-Gaussian variables, bound the expected maximum of NN of them, and state Bernstein's and McDiarmid's inequalities with their conditions.
  • Combine Hoeffding's inequality with the union bound to prove that, with probability 1−δ1-\delta, every hypothesis in a finite class satisfies ∣R(h)−R^n(h)∣≤(ln⁡∣H∣+ln⁡(2/δ))/(2n)\abs{R(h)-\hat R_n(h)}\le\sqrt{(\ln\abs{\mathcal H}+\ln(2/\delta))/(2n)}.

From Markov to the law of large numbers

DerivationMarkov, Chebyshev and the weak law
  1. Pr⁡[X≥t]≤E[X]t\Pr[X\ge t]\le\frac{\E[X]}t

    Markov. For a nonnegative random variable XX and t>0t>0, the pointwise inequality t 1{X≥t}≤Xt\,\mathbf 1\{X\ge t\}\le X holds; take expectations:

  2. Pr⁡[∣X−μ∣≥t]=Pr⁡[(X−μ)2≥t2]≤σ2t2\Pr\big[\abs{X-\mu}\ge t\big]=\Pr\big[(X-\mu)^2\ge t^2\big]\le\frac{\sigma^2}{t^2}

    Chebyshev. Apply Markov to (X−μ)2(X-\mu)^2, where μ=EX\mu=\E X and σ2=Var⁡X\sigma^2=\Var X:

  3. Pr⁡[∣Xˉn−μ∣≥t]≤σ2nt2 → n→∞  0\Pr\big[\abs{\bar X_n-\mu}\ge t\big]\le\frac{\sigma^2}{nt^2}\ \xrightarrow{\ n\to\infty\ }\ 0

    The weak law. For the mean Xˉn\bar X_n of nn i.i.d. copies, Var⁡Xˉn=σ2/n\Var\bar X_n=\sigma^2/n, so the probability of any fixed deviation vanishes, which is the weak law of large numbers:

The central limit theorem describes the shape of the fluctuations: n(Xˉn−μ)/σ\sqrt n(\bar X_n-\mu)/\sigma converges in distribution to N(0,1)\mathcal N(0,1). It is a limit statement, though, not a bound. The Berry–Esseen theorem quantifies the approximation, sup⁡x∣Pr⁡[n(Xˉn−μ)/σ≤x]−Φ(x)∣≤C E∣X−μ∣3/(σ3n)\sup_x\abs{\Pr[\sqrt n(\bar X_n-\mu)/\sigma\le x]-\Phi(x)}\le C\,\E\abs{X-\mu}^3/(\sigma^3\sqrt n) with an absolute constant CC below 12\tfrac12, and an error of order 1/n1/\sqrt n is useless for certifying tail probabilities like 10−610^{-6}.

Learning theory needs exactly such tiny tails, because it controls many averages at once: one per hypothesis. Chebyshev's 1/δ1/\delta dependence is too weak for that, as the next step shows. What is needed are inequalities whose tails decay exponentially in nn, with explicit constants, valid at every nn: concentration inequalities.

The Chernoff method and Hoeffding's inequality

The Chernoff method. For any s>0s>0, Markov's inequality applied to esXe^{sX} gives Pr⁡[X≥t]≤e−st E[esX]\Pr[X\ge t]\le e^{-st}\,\E[e^{sX}], and the bound can then be optimized over ss. For a sum of independent variables the moment generating function factorizes, Ees∑iXi=∏iEesXi\E e^{s\sum_iX_i}=\prod_i\E e^{sX_i}, so everything reduces to bounding one factor.

DerivationHoeffding's lemma
  1. esx≤b−xb−aesa+x−ab−aesb⟹EesX≤b esa−a esbb−a=eφ(u)e^{sx}\le\frac{b-x}{b-a}e^{sa}+\frac{x-a}{b-a}e^{sb}\quad\Longrightarrow\quad\E e^{sX}\le\frac{b\,e^{sa}-a\,e^{sb}}{b-a}=e^{\varphi(u)}

    Let X∈[a,b]X\in[a,b] with EX=0\E X=0, so a≤0≤ba\le0\le b. Since esxe^{sx} is convex, on [a,b][a,b] it lies below its chord; take expectations, using EX=0\E X=0:

  2. φ(u)≤u28⟹E es(X−EX)≤exp⁡(s2(b−a)28)\varphi(u)\le\frac{u^2}8\qquad\Longrightarrow\qquad\E\,e^{s(X-\E X)}\le\exp\Big(\frac{s^2(b-a)^2}8\Big)

    Here u=s(b−a)u=s(b-a), θ=−a/(b−a)∈[0,1]\theta=-a/(b-a)\in[0,1] and φ(u)=−θu+ln⁡(1−θ+θeu)\varphi(u)=-\theta u+\ln(1-\theta+\theta e^u). Direct differentiation gives φ(0)=φ′(0)=0\varphi(0)=\varphi'(0)=0 and φ′′(u)=ρ(1−ρ)≤14\varphi''(u)=\rho(1-\rho)\le\tfrac14 with ρ=θeu/(1−θ+θeu)\rho=\theta e^u/(1-\theta+\theta e^u). Taylor's theorem with remainder then gives:

Predict before you look

You estimate the mean of a [0,1][0,1]-valued variable from nn i.i.d. samples. How many samples does Hoeffding's inequality require to guarantee ∣Xˉn−μ∣<0.05\abs{\bar X_n-\mu}<0.05 with probability at least 95%?

Show the answer

738 samples

Solve 2e−2nt2≤δ2e^{-2nt^2}\le\delta: n≥ln⁡(2/δ)/(2t2)=ln⁡40/0.005≈737.8n\ge\ln(2/\delta)/(2t^2)=\ln40/0.005\approx737.8, so 738. Chebyshev, with the worst-case variance 14\tfrac14, needs n≥1/(4t2δ)=2,000n\ge1/(4t^2\delta)=2{,}000. The CLT approximation suggests about 385, but it is not a guarantee. The gap widens as δ\delta shrinks: at δ=10−6\delta=10^{-6}, Hoeffding needs 2,902 samples and Chebyshev 10810^8, because Hoeffding pays ln⁡(1/δ)\ln(1/\delta) where Chebyshev pays 1/δ1/\delta.

For Bernoulli variables the Chernoff method can be pushed to the exact optimum, which gives a bound in terms of the KL divergence between Bernoulli distributions: Pr⁡[Xˉn≥p+ε]≤exp⁡(−n DKL(p+ε ∥ p))\Pr[\bar X_n\ge p+\varepsilon]\le\exp\big(-n\,\KL(p+\varepsilon\,\|\,p)\big), a result also due to Hoeffding (1963). The technique carries Chernoff's name from his 1952 paper, although Chernoff himself attributed the bound to Herman Rubin. Pinsker's inequality gives DKL(p+ε ∥ p)≥2ε2\KL(p+\varepsilon\,\|\,p)\ge2\varepsilon^2, so the KL form is never weaker than Hoeffding's, and it is much stronger near the boundary: for p=0.01p=0.01 and ε=0.05\varepsilon=0.05 the exponent per sample is 0.0590.059 instead of 0.0050.005. Information Theory for ML develops the KL divergence and what it measures.

Sub-Gaussian variables, maxima and Bernstein

DerivationThe maximum of N sub-Gaussian variables
  1. es Emax⁡iXi≤E esmax⁡iXi=Emax⁡iesXi≤∑i=1NE esXi≤N es2σ2/2e^{s\,\E\max_iX_i}\le\E\,e^{s\max_iX_i}=\E\max_ie^{sX_i}\le\sum_{i=1}^{N}\E\,e^{sX_i}\le N\,e^{s^2\sigma^2/2}

    Let X1,…,XNX_1,\dots,X_N be mean-zero and sub-Gaussian with variance proxy σ2\sigma^2, not necessarily independent. For s>0s>0, Jensen's inequality (exe^x is convex), then bounding a maximum of nonnegative terms by their sum:

  2. Emax⁡iXi≤ln⁡Ns+sσ22\E\max_iX_i\le\frac{\ln N}s+\frac{s\sigma^2}2

    Take logarithms and divide by ss:

  3. Emax⁡i≤NXi≤σ2ln⁡N\E\max_{i\le N}X_i\le\sigma\sqrt{2\ln N}

    Choose s=2ln⁡N/σs=\sqrt{2\ln N}/\sigma. The maximum of NN such variables grows only like the square root of ln⁡N\ln N. This is the source of the ln⁡N\sqrt{\ln N} in the regret of exponential weights and of the ln⁡∣H∣\sqrt{\ln\abs{\mathcal H}} in the Rademacher complexity of a finite class (Massart's lemma):

Hoeffding's inequality implicitly assumes the worst variance a bounded variable can have, (b−a)2/4(b-a)^2/4. Bernstein's uses the actual one, and the difference is dramatic for rare events, such as estimating a small error rate, a click-through rate or a failure probability, where σ2=p(1−p)\sigma^2=p(1-p) is tiny.

Check your understanding

A classifier's error rate is about p=0.01p=0.01. You want to estimate it to within ±0.005\pm0.005 with 95% confidence. Compare the sample sizes guaranteed by Hoeffding's and Bernstein's inequalities.

  1. Hoeffding needs fewer, because Bernstein's extra 2bt/32bt/3 term costs samples
  2. They need the same number, since both are exponential bounds
  3. Bernstein needs about half as many
  4. Bernstein needs about 20 times fewer: about 3,400 against about 74,000
Show the answer

D. Bernstein needs about 20 times fewer: about 3,400 against about 74,000

Hoeffding: n≥ln⁡(2/δ)/(2t2)=3.69/(5×10−5)≈73,800n\ge\ln(2/\delta)/(2t^2)=3.69/(5\times10^{-5})\approx73{,}800. Bernstein, with σ2=0.0099\sigma^2=0.0099 and b≈0.99b\approx0.99: n≥ln⁡(2/δ) (2σ2+2bt/3)/t2=3.69×0.0231/(2.5×10−5)≈3,400n\ge\ln(2/\delta)\,(2\sigma^2+2bt/3)/t^2=3.69\times0.0231/(2.5\times10^{-5})\approx3{,}400. The variance 0.00990.0099 is 25 times smaller than Hoeffding's implicit 14\tfrac14, and the linear term costs little at this tt.

Bounded differences, the union bound and generalization

DerivationProof sketch: a martingale of revealed information
  1. f(X)−Ef(X)=∑k=1nDk,Dk=Zk−Zk−1f(X)-\E f(X)=\sum_{k=1}^{n}D_k,\qquad D_k=Z_k-Z_{k-1}

    Reveal the variables one at a time. The Doob martingale Zk=E[f(X)∣X1,…,Xk]Z_k=\E[f(X)\mid X_1,\dots,X_k] runs from Z0=EfZ_0=\E f to Zn=f(X)Z_n=f(X), so the deviation is a sum of increments:

  2. E[esDk∣X1,…,Xk−1]≤es2ck2/8\E\big[e^{sD_k}\mid X_1,\dots,X_{k-1}\big]\le e^{s^2c_k^2/8}

    Given X1,…,Xk−1X_1,\dots,X_{k-1}, the increment DkD_k is a function of XkX_k alone (the later variables are averaged out, and they are independent of XkX_k), with conditional mean zero; the bounded-difference property confines it to an interval of length at most ckc_k. Hoeffding's lemma applies conditionally:

  3. E es(f−Ef)≤exp⁡(s28∑kck2)⟹Pr⁡[f−Ef≥t]≤exp⁡(−2t2∑kck2)\E\,e^{s(f-\E f)}\le\exp\Big(\frac{s^2}8\sum_kc_k^2\Big)\quad\Longrightarrow\quad\Pr[f-\E f\ge t]\le\exp\Big(-\frac{2t^2}{\sum_kc_k^2}\Big)

    Peel off one increment at a time with the tower property, then apply the Chernoff method with s=4t/∑kck2s=4t/\sum_kc_k^2 (this is the Azuma–Hoeffding inequality):

For a loss with values in [0,1][0,1], the worst-case gap Φ(S)=sup⁡h∈H(R(h)−R^S(h))\Phi(S)=\sup_{h\in\mathcal H}\big(R(h)-\hat R_S(h)\big) changes by at most 1/n1/n when one example of SS changes, whatever the class. McDiarmid therefore pins Φ\Phi within ln⁡(1/δ)/(2n)\sqrt{\ln(1/\delta)/(2n)} of its mean, and the whole difficulty of learning theory moves into bounding E Φ\E\,\Phi, which is what VC dimension and Rademacher complexity do in the Generalization & Model Selection topic. For a finite class, a cruder tool suffices: the union bound, Pr⁡[⋃jAj]≤∑jPr⁡[Aj]\Pr[\bigcup_jA_j]\le\sum_j\Pr[A_j].

DerivationProof
  1. Pr⁡[∣R^n(h)−R(h)∣≥ε]≤2e−2nε2\Pr\big[\abs{\hat R_n(h)-R(h)}\ge\varepsilon\big]\le2e^{-2n\varepsilon^2}

    Fix hh before seeing the data. Its losses on the nn examples are i.i.d. in [0,1][0,1] with mean R(h)R(h), so Hoeffding's inequality gives

  2. Pr⁡[∃ h∈H: ∣R^n(h)−R(h)∣≥ε]≤2∣H∣ e−2nε2\Pr\big[\exists\,h\in\mathcal H:\ \abs{\hat R_n(h)-R(h)}\ge\varepsilon\big]\le2\abs{\mathcal H}\,e^{-2n\varepsilon^2}

    The hypothesis that training selects depends on the data, so a bound for each fixed hh is not enough. The union bound over all of H\mathcal H covers whichever one is selected:

  3. R(h^)≤R^n(h^)+εn≤R^n(h⋆)+εn≤R(h⋆)+2εnR(\hat h)\le\hat R_n(\hat h)+\varepsilon_n\le\hat R_n(h^\star)+\varepsilon_n\le R(h^\star)+2\varepsilon_n

    Set the right side to δ\delta and solve for ε\varepsilon. On the resulting event, chain the inequalities for ERM's choice h^\hat h and the best hypothesis h⋆h^\star:

Think first With ∣H∣=106\abs{\mathcal H}=10^6 hypotheses, n=104n=10^4 examples and δ=0.05\delta=0.05, how large is εn\varepsilon_n? What happens if the class grows to 101210^{12} hypotheses?

ln⁡106≈13.8\ln10^6\approx13.8 and ln⁡40≈3.7\ln40\approx3.7, so εn=17.5/20,000≈0.030\varepsilon_n=\sqrt{17.5/20{,}000}\approx0.030: every one of a million hypotheses has its training error within 3 points of its true error, and ERM is within 6 points of the best. Squaring the class to 101210^{12} only doubles ln⁡∣H∣\ln\abs{\mathcal H}, and εn\varepsilon_n grows to about 0.0400.040. Exponential tails make the union bound cheap; for infinite classes, ln⁡∣H∣\ln\abs{\mathcal H} is replaced by the VC dimension or a Rademacher complexity, and No Free Lunch & Inductive Bias explains why some such restriction is unavoidable.

Key takeaways

  • Markov (Pr⁡[X≥t]≤EX/t\Pr[X\ge t]\le\E X/t) and Chebyshev (σ2/t2\sigma^2/t^2) give the weak law of large numbers; the central limit theorem gives the shape of the fluctuations but, with an error of order 1/n1/\sqrt n, no usable tail bounds.
  • The Chernoff method plus Hoeffding's lemma, Ees(X−EX)≤es2(b−a)2/8\E e^{s(X-\E X)}\le e^{s^2(b-a)^2/8}, gives Hoeffding's inequality Pr⁡[∣Xˉn−μ∣≥t]≤2e−2nt2/(b−a)2\Pr[\abs{\bar X_n-\mu}\ge t]\le2e^{-2nt^2/(b-a)^2}: about ln⁡(2/δ)/(2t2)\ln(2/\delta)/(2t^2) samples, against Chebyshev's 1/(4t2δ)1/(4t^2\delta). For Bernoulli means, the KL form e−nDKL(p+ε∥p)e^{-n\KL(p+\varepsilon\|p)} is never weaker.
  • Sub-Gaussian variables have Gaussian-type tails, and the maximum of NN of them has mean at most σ2ln⁡N\sigma\sqrt{2\ln N}, the source of logarithmic dependence on the number of experts or hypotheses.
  • Bernstein's inequality uses the true variance and wins by large factors for rare events; McDiarmid's inequality extends Hoeffding to any function of independent variables with bounded differences, including the worst-case gap over a hypothesis class.
  • Hoeffding plus the union bound gives uniform convergence for finite classes, εn=(ln⁡∣H∣+ln⁡(2/δ))/(2n)\varepsilon_n=\sqrt{(\ln\abs{\mathcal H}+\ln(2/\delta))/(2n)}, and ERM within 2εn2\varepsilon_n of the best hypothesis.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

To guarantee ∣Xˉn−μ∣<t\abs{\bar X_n-\mu}<t with probability at least 1−δ1-\delta for variables in [0,1][0,1], how does the required nn scale with δ\delta under Chebyshev's and under Hoeffding's inequality?

  1. Both like ln⁡(1/δ)\ln(1/\delta)
  2. Chebyshev like 1/δ1/\delta, Hoeffding like ln⁡(1/δ)\ln(1/\delta)
  3. Chebyshev like ln⁡(1/δ)\ln(1/\delta), Hoeffding like 1/δ1/\delta
  4. Neither depends on δ\delta
Show the answer

B. Chebyshev like 1/δ1/\delta, Hoeffding like ln⁡(1/δ)\ln(1/\delta)

Chebyshev's tail σ2/(nt2)\sigma^2/(nt^2) decays only polynomially in nn, so n∝1/δn\propto1/\delta; Hoeffding's tail 2e−2nt22e^{-2nt^2} decays exponentially, so n∝ln⁡(2/δ)/t2n\propto\ln(2/\delta)/t^2. That logarithm is what lets union bounds over many events stay cheap.

Question 2

When does Bernstein's inequality give a much smaller sample size than Hoeffding's for estimating a mean?

  1. When the variables are unbounded
  2. When the required accuracy tt is very large
  3. Never: Hoeffding's inequality is always at least as sharp
  4. When the variance is much smaller than the squared range, as for rare events
Show the answer

D. When the variance is much smaller than the squared range, as for rare events

Bernstein's exponent is nt2/(2σ2+2bt/3)nt^2/(2\sigma^2+2bt/3), Hoeffding's 2nt2/(b−a)22nt^2/(b-a)^2. When σ2≪(b−a)2/4\sigma^2\ll(b-a)^2/4 and tt is small compared with σ2/b\sigma^2/b, Bernstein's exponent is far larger, by up to the ratio of the worst-case variance to the true one.

Question 3

Why does Φ(S)=sup⁡h∈H(R(h)−R^S(h))\Phi(S)=\sup_{h\in\mathcal H}\big(R(h)-\hat R_S(h)\big), for a loss in [0,1][0,1], concentrate around its mean even when H\mathcal H is infinite?

  1. Because each R^S(h)\hat R_S(h) concentrates by Hoeffding, and a supremum of concentrated variables is concentrated
  2. Because the central limit theorem applies to suprema
  3. Because changing one example changes every R^S(h)\hat R_S(h), hence Φ\Phi, by at most 1/n1/n, so McDiarmid's inequality applies with ci=1/nc_i=1/n
  4. It does not: concentration requires a finite class
Show the answer

C. Because changing one example changes every R^S(h)\hat R_S(h), hence Φ\Phi, by at most 1/n1/n, so McDiarmid's inequality applies with ci=1/nc_i=1/n

McDiarmid needs only bounded differences, and Φ\Phi has them with ci=1/nc_i=1/n regardless of the size of H\mathcal H: Pr⁡[Φ−EΦ≥t]≤e−2nt2\Pr[\Phi-\E\Phi\ge t]\le e^{-2nt^2}. The class enters only through the mean E Φ\E\,\Phi, which is what Rademacher complexity bounds.

Question 4

In the bound εn=(ln⁡∣H∣+ln⁡(2/δ))/(2n)\varepsilon_n=\sqrt{(\ln\abs{\mathcal H}+\ln(2/\delta))/(2n)}, why does the size of the class enter only through its logarithm?

  1. Because the union bound multiplies the failure probability by ∣H∣\abs{\mathcal H}, and an exponential tail e−2nε2e^{-2n\varepsilon^2} absorbs that factor at the cost of adding ln⁡∣H∣\ln\abs{\mathcal H} to 2nε22n\varepsilon^2
  2. Because hypotheses in a large class are highly correlated, so they count as fewer
  3. Because ERM only ever evaluates one hypothesis
  4. Because of the central limit theorem
Show the answer

A. Because the union bound multiplies the failure probability by ∣H∣\abs{\mathcal H}, and an exponential tail e−2nε2e^{-2n\varepsilon^2} absorbs that factor at the cost of adding ln⁡∣H∣\ln\abs{\mathcal H} to 2nε22n\varepsilon^2

Solving 2∣H∣e−2nε2=δ2\abs{\mathcal H}e^{-2n\varepsilon^2}=\delta gives 2nε2=ln⁡∣H∣+ln⁡(2/δ)2n\varepsilon^2=\ln\abs{\mathcal H}+\ln(2/\delta). With Chebyshev's polynomial tail instead, the union bound would cost a factor ∣H∣\abs{\mathcal H} in nn, which is why exponential concentration is the engine of learning theory.

Further reading

  • W. Hoeffding, "Probability inequalities for sums of bounded random variables," Journal of the American Statistical Association 58(301), 13–30 (1963).
  • C. McDiarmid, "On the method of bounded differences," in Surveys in Combinatorics, 1989 (Cambridge University Press, 1989), 148–188.
  • S. Boucheron, G. Lugosi & P. Massart, Concentration Inequalities: A Nonasymptotic Theory of Independence (Oxford University Press, 2013).
  • R. Vershynin, High-Dimensional Probability: An Introduction with Applications in Data Science (Cambridge University Press, 2018), chapter 2.
  • G. Lugosi & S. Mendelson, "Mean estimation and regression under heavy-tailed distributions: a survey," Foundations of Computational Mathematics (2019).