Concentration inequalities: how far can an average stray?
Markov, Chebyshev, Chernoff and Hoeffding from one picture, with step-by-step proofs, interactive figures, and the places they decide real numbers: sample sizes, generalisation bounds, random features and high-dimensional geometry.
Contents
- 1. The one idea behind all of them
- 2. Markov: knowing only the mean
- 3. Chebyshev: knowing the variance
- 4. Chernoff: using every moment at once
- 5. Hoeffding: bounded variables are sub-Gaussian
- 6. Where these numbers are used
- How big must a test set be?
- Why a model chosen on training data still generalises
- Random features approximate a kernel
- In high dimensions, Gaussians live on a shell
- 7. Beyond Hoeffding
- Questions
- References
Almost every number in machine learning is an average: a test accuracy, a Monte Carlo estimate, a minibatch gradient, a kernel approximated with random features. Each comes with the same two questions. How far from the truth can it be, and how many samples make that unlikely? Concentration inequalities answer both, without knowing the distribution.
Below, each sample is the mean of fair coin flips. The left panel shows its distribution, with the outcomes more than from highlighted. The right panel shows the probability of such a miss as grows, on a log scale: the exact value, and two bounds that hold for any variables bounded in .
On a log scale the exact tail is a straight line falling at a constant rate: it decays exponentially in . Hoeffding’s bound is parallel to it, which is why it is useful. Chebyshev’s bound bends: it decays only like , and by it is wrong by many orders of magnitude. The difference between those two shapes is the subject of this post.
1. The one idea behind all of them
Each inequality below is the same move with a different function.
Lemma 1 (Bounding an indicator)
Let be an event defined by , and let with whenever . Then .
Proof
Step 1. Write the probability as an expectation. .
Step 2. Compare pointwise. On the indicator is ; off it is . So for every .
Step 3. Take expectations. Expectation preserves pointwise inequalities: .
So a tail bound is a choice of a function lying above a step. The closer it hugs the step where the distribution has mass, the tighter the bound. Below, is the number of heads in 20 fair flips and the event is . Markov uses a line, Chebyshev a parabola, Chernoff an exponential whose steepness you choose.
The line and the parabola stay well above zero across the bulk of the distribution, where the probability mass sits, and pay for it. The exponential can be made almost zero on the bulk and still reach at the threshold. Push towards 20: Markov barely moves, Chebyshev improves, Chernoff keeps pace with the truth.
2. Markov: knowing only the mean
Theorem 1 (Markov’s inequality)
If and , then .
Proof
Step 1. Choose . Let . It is non-negative because , and whenever .
Step 2. Apply Lemma 1. .
Example 1 (Markov cannot be improved without more information)
Let with probability and otherwise. Then and : equality. Any distribution with all its tail mass exactly at makes Markov tight, so a better bound needs more than the mean.
Corollary 1 (Bounded above instead of below)
If and , then .
Proof
Step 1. Flip. , and exactly when .
Step 2. Apply Theorem 1 to . .
For example, if a classifier’s accuracy, averaged over a family of tasks, is , then (since accuracy is at most ) at most of those tasks can have accuracy below .
3. Chebyshev: knowing the variance
Theorem 2 (Chebyshev’s inequality)
If and , then .
Proof
Step 1. Choose . , and whenever .
Step 2. Apply Lemma 1. .
Applied to an average, Chebyshev already proves that averages work.
Proposition 1 (Weak law of large numbers, with a sample size)
Let be independent with mean and variance , and . Then , so samples give .
Proof
Step 1. Mean of the average. By linearity, .
Step 2. Variance of a sum of independent variables. Independence makes every covariance with vanish, so .
Step 3. Scale. .
Step 4. Apply Theorem 2 to , then solve for .
The weakness is the . Asking for ten times more confidence costs ten times more samples. The figure at the top shows why this is pessimistic: the true tail falls exponentially. To see that, the bound must use more than two moments.
4. Chernoff: using every moment at once
Theorem 3 (Chernoff bound)
For any and , .
Proof
Step 1. Choose . For any , , and whenever , because there.
Step 2. Apply Lemma 1. .
Step 3. Optimise. Step 2 holds for every , so it holds for the infimum.
is the moment generating function, : one function that packs every moment, weighted by . Two properties make it the right tool for averages.
Lemma 2 (MGFs of independent sums multiply)
If are independent, .
Proof
Step 1. .
Step 2. The factors are functions of independent variables, so they are independent, and the expectation of a product of independent variables is the product of the expectations.
Example 2 (The Gaussian tail, by Chernoff)
For , the MGF is (complete the square in the integral; see Gaussian identities, Proposition 3, Step 1).
Step 1. The bound for fixed . .
Step 2. Minimise the exponent. at .
Step 3. Substitute. , so .
The exact tail is times a factor of order , so Chernoff captures the exponential rate exactly and loses only a polynomial factor.
Definition 1 (Sub-Gaussian variable)
with mean is sub-Gaussian with variance proxy if for all . By the example, such an has Gaussian-type tails: .
5. Hoeffding: bounded variables are sub-Gaussian
Bounded variables are the common case: accuracies, losses clipped to , indicators, features with bounded range. The key fact is that boundedness alone gives a Gaussian-type MGF.
Lemma 3 (Hoeffding’s lemma)
If and , then for all . That is, is sub-Gaussian with .
Proof
Step 1. Convexity. On , the convex function lies below its chord:
Step 2. Take expectations, using .
Step 3. Rewrite as one exponential. Let (note because the mean is ) and . Then , and the right side of Step 2 equals with
Step 4. Value and slope at zero. . Differentiating, , so .
Step 5. Curvature is at most . Write . Differentiating once more gives , and for every (its maximum is at ).
Step 6. Taylor’s theorem with remainder. For some between and , .
Theorem 4 (Hoeffding’s inequality)
Let be independent with , and . For ,
For the mean of variables in : .
Proof
Step 1. Chernoff (Theorem 3) for the centred sum: .
Step 2. Factorise (Lemma 2), since is a sum of independent terms.
Step 3. Bound each factor with Hoeffding’s lemma: has mean and lies in an interval of length . So
Step 4. Optimise . Writing , the exponent is minimised at , where it equals .
Step 5. The mean. With , ; the event is , giving . The lower tail is the same bound applied to ; adding both tails gives the factor .
Solving gives the sample size that every estimate in machine learning quietly relies on:
The dependence on the confidence is now logarithmic. For and variables in (so in Chebyshev):
| confidence | Chebyshev: | Hoeffding: |
|---|---|---|
| 95% | 2 000 | 738 |
| 99% | 10 000 | 1 060 |
| 99.9% | 100 000 | 1 521 |
Each extra “9” of confidence multiplies Chebyshev’s requirement by ten, but adds only a few hundred samples to Hoeffding’s.
6. Where these numbers are used
How big must a test set be?
A classifier’s test accuracy is the mean of indicators. By Hoeffding, with test examples the measured accuracy is within points of the true accuracy with probability at least , whatever the classifier. To claim point at the same confidence takes times more, : halving the error bar always costs four times the data.
Why a model chosen on training data still generalises
Pick the hypothesis with the lowest training error from a finite class . For each fixed , Hoeffding controls the gap between its training error and true error ; the danger is that we chose after seeing the data. One more tool handles that.
Lemma 4 (Union bound)
For any events , .
Proof
Step 1. pointwise: the left side is only if at least one term on the right is .
Step 2. Take expectations.
Proposition 2 (Generalisation bound for a finite class)
For a loss in and independent training examples, with probability at least , simultaneously for every ,
Proof
Step 1. One hypothesis. For a fixed , is a mean of independent losses in with mean . By Theorem 4, .
Step 2. All hypotheses at once. The event “some has a gap ” is the union over . By Lemma 4 its probability is at most .
Step 3. Solve for . Setting gives the stated . Because the bound holds for every simultaneously, it holds for whichever the learning algorithm picked.
is the number of nats needed to name a hypothesis. The bound says: the gap grows only with the log of how many models you tried, which is why trying a thousand hyperparameter settings costs little, and trying all functions costs everything. Replacing by a capacity measure (VC dimension, Rademacher complexity) extends the argument to infinite classes.
Random features approximate a kernel
Random Fourier features approximate a stationary kernel by an average: with , drawn from the kernel’s spectral measure (Bochner’s theorem, GP Theorem 1) and uniform on .
Proposition 3 (How many random features)
For each fixed pair , .
Proof
Step 1. Each term is unbiased. Using , the term is . The second part averages to over uniform ; the first averages to over by Bochner’s theorem.
Step 2. Each term is bounded. , an interval of length .
Step 3. Hoeffding for the mean of independent terms in an interval of length : the bound of Theorem 4 with and gives per tail.
So features reach accuracy at a given pair: about for at confidence. The wavelet post builds on these features.
In high dimensions, Gaussians live on a shell
Draw . The density is largest at the origin, yet as grows almost no samples are near it. Move the slider.
Proposition 4 (Norms concentrate)
For and , .
Proof
Step 1. One coordinate’s MGF. For and , completing the square in the Gaussian integral gives . So the centred variable has .
Step 2. Bound it for . Expand . The term cancels , and for , so
Step 3. Upper tail by Chernoff. The coordinates are independent, so by Lemma 2 and Step 2,
Choose : the exponent is .
Step 4. Lower tail. For , , using . Chernoff with gives .
Step 5. Add the two tails.
So with fluctuations of order one: in dimensions, essentially every sample lies within of the sphere of radius . This is why random vectors in high dimensions are nearly orthogonal, why the Johnson–Lindenstrauss lemma can compress dimension while preserving distances, and why the noise in a diffusion model is a thin shell, not a ball.
7. Beyond Hoeffding
Hoeffding uses only the range. Two refinements are worth knowing by name; their proofs follow the same Chernoff pattern.
- Bernstein’s inequality uses the variance too. If the are independent with mean , and , then . When the variance is much smaller than the range suggests (rare events), it is far tighter.
- McDiarmid’s inequality replaces the sum by any function that changes by at most when only changes: . With a sum it is Hoeffding; with a supremum over hypotheses it is the start of Rademacher complexity.
- Matrix concentration (Tropp, 2015) extends these bounds to sums of random matrices, which is what controls random-feature and sketching approximations of whole Gram matrices rather than single entries.
Questions
Question 1
In the indicator figure, why does Markov’s bound barely improve as moves towards 20, while Chernoff’s tracks the truth?
Answer
Markov’s function is a line through the origin; at it still equals , so most of the probability mass contributes heavily. Chernoff’s is exponentially small on the bulk for large , so only mass near the tail contributes.
Question 2
Chebyshev needs samples, Hoeffding only . Is Chebyshev ever the better choice?
Answer
Yes, when the variables are unbounded and only a variance is known (heavy-tailed data, where the MGF may not exist and Chernoff-type bounds fail), or when the variance is far below the square of the range, at moderate .
Question 3
You tune 50 hyperparameter settings and report the best validation accuracy, measured on examples. How much optimism should you expect at 95% confidence?
Answer
By Proposition 2 with : , about 4.4 points. A fresh test set removes it.
References
- S. Boucheron, G. Lugosi, P. Massart. Concentration Inequalities: A Nonasymptotic Theory of Independence. Oxford University Press, 2013.
- R. Vershynin. High-Dimensional Probability. Cambridge University Press, 2018.
- M. J. Wainwright. High-Dimensional Statistics: A Non-Asymptotic Viewpoint. Cambridge University Press, 2019.
- W. Hoeffding. Probability inequalities for sums of bounded random variables. Journal of the American Statistical Association, 1963.
- H. Chernoff. A measure of asymptotic efficiency for tests of a hypothesis based on the sum of observations. Annals of Mathematical Statistics, 1952.
- A. Rahimi, B. Recht. Random features for large-scale kernel machines. NeurIPS 2007.
- J. A. Tropp. An Introduction to Matrix Concentration Inequalities. Foundations and Trends in Machine Learning, 2015.
Was this useful?
Thanks, that helps me decide what to write next.