Introduction to Concentration Inequalities: From Markov to McDiarmid

Basic inequalities that bound how far a quantity computed from finitely many samples can deviate from its expectation, and how to choose among them

0. Introduction

In probability and statistics, we often care less about the value of a random quantity itself than about how far it can deviate from its typical value.

As an example, consider the sample mean

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

of independent and identically distributed (i.i.d.) random variables X1,…,XnX_1, \dots, X_n. If E[∣X1∣]<∞\mathbb{E}[|X_1|] < \infty, the law of large numbers states that Xˉn\bar{X}_n converges to the expectation μ:=E[X1]\mu := \mathbb{E}[X_1] with probability 11 as n→∞n \to \infty. In real data analysis, however, nn is finite. What we want to know is how small the following probability is for a given nn and ε>0\varepsilon > 0:

Pr⁡(∣Xˉn−μ∣≥ε) \Pr\left(|\bar{X}_n - \mu| \geq \varepsilon\right)

Inequalities that bound this probability from above in terms of nn, ε\varepsilon, and properties of the distribution (such as its range or variance) are called concentration inequalities.

The central limit theorem also describes the fluctuations of Xˉn\bar{X}_n, but it states the shape of the distribution in the limit n→∞n \to \infty and says nothing about the size of the error at a finite nn. Concentration inequalities give bounds that hold as they are at a finite nn.

Running example: estimating a success probability

Throughout this article, we compare the inequalities on the following problem.

Example: estimating a success probability

We run nn independent trials, each succeeding with probability pp, and set Xi=1X_i = 1 if the ii-th trial succeeds and Xi=0X_i = 0 otherwise. When we estimate pp by the success rate p^:=1n∑i=1nXi\hat{p} := \frac{1}{n} \sum_{i=1}^n X_i, how large must nn be for the probability of an error of ε\varepsilon or more to be at most δ\delta?

We use the following two settings, each with δ=0.05\delta = 0.05 and δ=10−6\delta = 10^{-6}:

  • (A) p=0.5p = 0.5, ε=0.05\varepsilon = 0.05: the variance of one trial, p(1−p)p(1-p), takes its maximum value 1/41/4.
  • (B) p=0.01p = 0.01, ε=0.005\varepsilon = 0.005: successes are rare, and the variance p(1−p)≈0.0099p(1-p) \approx 0.0099 is small.

First, we examine the distribution of p^\hat{p} in setting (A) with Python. The following code generates p^\hat{p} 10510^5 times for each of n=10,100,1000n = 10, 100, 1000 and plots histograms.

concentration.py
import numpy as np
import matplotlib.pyplot as plt

rng = np.random.default_rng(0)
p, eps, trials = 0.5, 0.05, 100_000

for n in [10, 100, 1000]:
    # Success rates of n trials with success probability p, repeated trials times
    p_hat = rng.binomial(n, p, size=trials) / n
    # Fraction with an error of eps or more (1e-12 guards against rounding errors)
    miss = np.mean(np.abs(p_hat - p) >= eps - 1e-12)
    bins = (np.arange(n + 2) - 0.5) / n  # bins of width 1/n centered at k/n
    plt.hist(p_hat, bins=bins, density=True, histtype="step", lw=2,
             label=f"$n = {n}$ ({miss:.3f})")

plt.axvspan(p - eps, p + eps, color="gray", alpha=0.2)
plt.xlim(0.2, 0.8)
plt.xlabel(r"$\hat p$")
plt.ylabel("Density")
plt.legend(loc="upper left")
plt.show()
Image
Figure 1: Distribution of the success rate in setting (A) (p = 0.5). The gray band is |p̂ − p| < 0.05, and the number in parentheses is the fraction of runs with an error of 0.05 or more.

As Figure 1 shows, the distribution of p^\hat{p} concentrates around p=0.5p = 0.5 as nn grows, and the fraction of runs with an error of 0.050.05 or more drops from 0.7520.752 at n=10n = 10 to 0.3670.367 at n=100n = 100 and 0.0020.002 at n=1000n = 1000. Concentration inequalities give upper bounds on this fraction without computing the distribution in detail.

All figures in this article, including Figures 2 and 5 whose code is not shown here, can be regenerated with code/concentration/make_figures.py.

Roadmap

The inequalities covered in each section and the information each one uses are as follows:

  1. Markov's inequality (Section 2): nonnegativity and the expectation
  2. Chebyshev's inequality (Section 3): the variance
  3. The Chernoff method (Section 4): the moment generating function
  4. Hoeffding's inequality (Section 5): independence and the range
  5. Bernstein's inequality (Section 6): independence, the range, and the variance
  6. McDiarmid's inequality (Section 7): independence and a bound on how much the output changes when one input changes

Section 8 compares the results for the running example, and Section 9 introduces tools for cases where the assumptions fail. An inequality in a later section is not always stronger than one in an earlier section. Which inequality gives the smallest bound depends on the available assumptions and the conditions of the problem.

1. Notation and basics

Notation
  • Pr⁡(A)\Pr(A) denotes the probability of an event AA, E[X]\mathbb{E}[X] the expectation of a random variable XX, and Var⁡(X):=E[(X−E[X])2]\operatorname{Var}(X) := \mathbb{E}[(X - \mathbb{E}[X])^2] its variance.
  • 1A\mathbf{1}_A is the indicator function of an event AA: it equals 11 if AA occurs and 00 otherwise.
  • "X≥0X \geq 0 a.s." means that X≥0X \geq 0 holds with probability 11 (almost surely).
  • For random variables X1,…,XnX_1, \dots, X_n, we write their sum as Sn:=∑i=1nXiS_n := \sum_{i=1}^n X_i and their sample mean as Xˉn:=Sn/n\bar{X}_n := S_n / n.
  • log⁡\log denotes the natural logarithm.

Tail probabilities and the union bound

The probability that a random variable XX deviates from its expectation by t>0t > 0 or more is called a tail probability. Depending on the direction of the deviation, there are three kinds:

  • Upper tail probability: Pr⁡(X−E[X]≥t)\Pr(X - \mathbb{E}[X] \geq t)
  • Lower tail probability: Pr⁡(X−E[X]≤−t)\Pr(X - \mathbb{E}[X] \leq -t)
  • Two-sided tail probability: Pr⁡(∣X−E[X]∣≥t)\Pr(|X - \mathbb{E}[X]| \geq t)

Concentration inequalities give upper bounds on these tail probabilities (tail bounds). Because Pr⁡(A∪B)≤Pr⁡(A)+Pr⁡(B)\Pr(A \cup B) \leq \Pr(A) + \Pr(B) holds for any events AA and BB (the union bound), the two-sided tail probability is at most the sum of the upper and lower tail bounds. Therefore, when the same bound holds for both the upper and the lower tail, the two-sided bound has a factor of 22.

2. Markov's inequality

Markov's inequality bounds a tail probability using only nonnegativity and the expectation. Every other inequality in this article uses it somewhere in its proof.

Theorem 1 (Markov's inequality)

Suppose that X≥0X \geq 0 a.s. and E[X]<∞\mathbb{E}[X] < \infty. Then, for any t>0t > 0,

Pr⁡(X≥t)≤E[X]t. \Pr(X \geq t) \leq \frac{\mathbb{E}[X]}{t}.

Proof. Because X≥0X \geq 0 a.s., the inequality X≥t1{X≥t}X \geq t \mathbf{1}_{\{X \geq t\}} holds with probability 11 (the right-hand side is tt when X≥tX \geq t and 00 otherwise). Taking expectations of both sides gives E[X]≥tPr⁡(X≥t)\mathbb{E}[X] \geq t \Pr(X \geq t), and dividing by tt gives Theorem 1. □\square

Setting t=c E[X]t = c\, \mathbb{E}[X] with c>0c > 0 gives Pr⁡(X≥c E[X])≤1/c\Pr(X \geq c\, \mathbb{E}[X]) \leq 1/c. For example, the probability that a nonnegative random variable is at least 1010 times its expectation is at most 1/101/10. In exchange for the weak assumptions, the bound decreases only as 1/t1/t.

Bounding the indicator function with nonnegative functions

The proof bounds the indicator function 1{X≥t}\mathbf{1}_{\{X \geq t\}} from above by a nonnegative function and takes the expectation. In general, if a random variable YY and a nonnegative function φ\varphi satisfy φ(y)≥1{y≥t}\varphi(y) \geq \mathbf{1}_{\{y \geq t\}} for every value yy that YY can take, then

Pr⁡(Y≥t)=E[1{Y≥t}]≤E[φ(Y)]. \Pr(Y \geq t) = \mathbb{E}\left[\mathbf{1}_{\{Y \geq t\}}\right] \leq \mathbb{E}[\varphi(Y)].

Different choices of φ\varphi give different inequalities (Figure 2).

Image
Figure 2: Nonnegative functions that bound the indicator function 1{y ≥ t} (black, t = 1) from above. Panel (a) shows the region near t, and panel (b) shows a wide range, where the dashed box marks the region of (a). Markov's inequality uses y/t (for y ≥ 0), Chebyshev's inequality uses y²/t², and the Chernoff method uses exp(λ(y − t)).
  • Markov's inequality (Section 2) uses φ(y)=y/t\varphi(y) = y/t with a nonnegative Y=XY = X.
  • Chebyshev's inequality (Section 3) uses φ(y)=y2/t2\varphi(y) = y^2/t^2 with Y=X−E[X]Y = X - \mathbb{E}[X]. This φ\varphi is also at least 11 for y≤−ty \leq -t, so it bounds the two-sided tail probability at once.
  • The Chernoff method (Section 4) uses φ(y)=eλ(y−t)\varphi(y) = e^{\lambda(y - t)} with λ>0\lambda > 0 and Y=X−E[X]Y = X - \mathbb{E}[X].

The closer φ\varphi is to the indicator function where YY is likely to take values, the smaller the bound. In the Chernoff method, λ\lambda controls the shape of φ\varphi. Near tt in Figure 2(a), the curve for λ=4\lambda = 4 is closer to the indicator function for y<ty < t than the curve for λ=1.5\lambda = 1.5, but it grows faster for y>ty > t. Section 4 optimizes this λ\lambda.

The wide range in Figure 2(b) shows how differently the functions grow far from tt. Markov's y/ty/t is linear in yy, and Chebyshev's y2/t2y^2/t^2 grows in both directions away from 00. The Chernoff function eλ(y−t)e^{\lambda(y - t)} approaches 00 as yy decreases but grows exponentially for y>ty > t. Therefore, for E[φ(Y)]\mathbb{E}[\varphi(Y)] to be finite in the Chernoff method, the moment generating function of YY (Section 4) must be finite; that is, the upper tail of YY must decay at least exponentially fast.

3. Chebyshev's inequality

Chebyshev's inequality uses the variance to bound how far a random variable deviates from its expectation.

Theorem 2 (Chebyshev's inequality)

Suppose that the variance Var⁡(X)\operatorname{Var}(X) of XX is finite. Then, for any t>0t > 0,

Pr⁡(∣X−E[X]∣≥t)≤Var⁡(X)t2. \Pr(|X - \mathbb{E}[X]| \geq t) \leq \frac{\operatorname{Var}(X)}{t^2}.

Proof. Applying Markov's inequality to the nonnegative random variable (X−E[X])2(X - \mathbb{E}[X])^2 gives

Pr⁡(∣X−E[X]∣≥t)=Pr⁡((X−E[X])2≥t2)≤E[(X−E[X])2]t2=Var⁡(X)t2.□ \begin{aligned} \Pr(|X - \mathbb{E}[X]| \geq t) &= \Pr\left((X - \mathbb{E}[X])^2 \geq t^2\right) \\ &\leq \frac{\mathbb{E}\left[(X - \mathbb{E}[X])^2\right]}{t^2} = \frac{\operatorname{Var}(X)}{t^2}. \quad \square \end{aligned}

Application to the sample mean

Suppose that X1,…,XnX_1, \dots, X_n are pairwise uncorrelated with a common expectation μ\mu and a common variance σ2\sigma^2. Then Var⁡(Xˉn)=σ2/n\operatorname{Var}(\bar{X}_n) = \sigma^2/n, and Theorem 2 gives

Pr⁡(∣Xˉn−μ∣≥ε)≤σ2nε2. \Pr(|\bar{X}_n - \mu| \geq \varepsilon) \leq \frac{\sigma^2}{n\varepsilon^2}.

The calculation of Var⁡(Xˉn)\operatorname{Var}(\bar{X}_n) uses only the additivity of variance, so uncorrelatedness, which is weaker than independence, is enough.

Running example. The variance of one trial is σ2=p(1−p)\sigma^2 = p(1-p), so the right-hand side is at most δ\delta if

n≥p(1−p)ε2δ. n \geq \frac{p(1-p)}{\varepsilon^2 \delta}.

In setting (A) with δ=0.05\delta = 0.05, this gives n≥2,000n \geq 2{,}000. Because the required nn is proportional to 1/δ1/\delta, it becomes n≥108n \geq 10^8 for δ=10−6\delta = 10^{-6}.

4. The Chernoff method

The bound from Chebyshev's inequality decreases only polynomially in tt. Using an exponential function gives bounds that decrease exponentially in tt. This technique is called the Chernoff method or the Cramér–Chernoff method (Chernoff, 1952; Boucheron et al., 2013, §2.2).

General form

The function λ↦E[eλX]\lambda \mapsto \mathbb{E}[e^{\lambda X}] of λ∈R\lambda \in \mathbb{R} is called the moment generating function (MGF) of XX. In this article, we use the logarithm of the MGF of the centered random variable:

ψX(λ):=log⁡E[eλ(X−E[X])]. \psi_X(\lambda) := \log \mathbb{E}\left[e^{\lambda (X - \mathbb{E}[X])}\right].

If ψX(λ)\psi_X(\lambda) is finite for λ>0\lambda > 0, then, because x↦eλxx \mapsto e^{\lambda x} is increasing, Markov's inequality gives

Pr⁡(X−E[X]≥t)=Pr⁡(eλ(X−E[X])≥eλt)≤e−λt E[eλ(X−E[X])]=exp⁡(−λt+ψX(λ)). \begin{aligned} \Pr(X - \mathbb{E}[X] \geq t) &= \Pr\left(e^{\lambda (X - \mathbb{E}[X])} \geq e^{\lambda t}\right) \\ &\leq e^{-\lambda t}\, \mathbb{E}\left[e^{\lambda (X - \mathbb{E}[X])}\right] = \exp\left(-\lambda t + \psi_X(\lambda)\right). \end{aligned}

Because this holds for every λ>0\lambda > 0 with ψX(λ)<∞\psi_X(\lambda) < \infty, minimizing the right-hand side over λ\lambda gives

Pr⁡(X−E[X]≥t)≤exp⁡(−sup⁡λ>0{λt−ψX(λ)}). \Pr(X - \mathbb{E}[X] \geq t) \leq \exp\left(-\sup_{\lambda > 0} \left\{\lambda t - \psi_X(\lambda)\right\}\right).

This bound is called the Chernoff bound. Any upper bound on ψX\psi_X turns it into a concrete bound. The lower tail probability is bounded by applying the same argument to −X-X.

Sums of independent random variables

With the exponential function, the MGF of a sum of independent random variables factors into the product of their MGFs. If X1,…,XnX_1, \dots, X_n are independent, then

E[eλ(Sn−E[Sn])]=∏i=1nE[eλ(Xi−E[Xi])], \mathbb{E}\left[e^{\lambda (S_n - \mathbb{E}[S_n])}\right] = \prod_{i=1}^n \mathbb{E}\left[e^{\lambda (X_i - \mathbb{E}[X_i])}\right],

and taking logarithms gives ψSn(λ)=∑i=1nψXi(λ)\psi_{S_n}(\lambda) = \sum_{i=1}^n \psi_{X_i}(\lambda). Therefore, bounds on each ψXi\psi_{X_i} give a bound on the tail probability of the sum SnS_n. Hoeffding's inequality in Section 5 and Bernstein's inequality in Section 6 are derived in this way.

Sub-Gaussian random variables

Definition: sub-Gaussian

A random variable XX is sub-Gaussian with variance parameter ν>0\nu > 0 if, for all λ∈R\lambda \in \mathbb{R},

ψX(λ)≤νλ22. \psi_X(\lambda) \leq \frac{\nu \lambda^2}{2}.

For a normal random variable with variance ν\nu, ψX(λ)=νλ2/2\psi_X(\lambda) = \nu\lambda^2/2 holds with equality. In other words, a sub-Gaussian random variable is one whose centered MGF is at most that of a normal distribution. For a sub-Gaussian XX, the function λt−νλ2/2\lambda t - \nu\lambda^2/2 attains its maximum t2/(2ν)t^2/(2\nu) at λ=t/ν\lambda = t/\nu, so the Chernoff method gives

Pr⁡(X−E[X]≥t)≤exp⁡(−t22ν). \Pr(X - \mathbb{E}[X] \geq t) \leq \exp\left(-\frac{t^2}{2\nu}\right).

Because the definition also covers λ<0\lambda < 0, the same bound holds for the lower tail, and the two-sided bound has a factor of 22 (Boucheron et al., 2013, §2.3).

In addition, if independent XiX_i are sub-Gaussian with variance parameters νi\nu_i, then ψSn=∑iψXi\psi_{S_n} = \sum_i \psi_{X_i} implies that SnS_n is sub-Gaussian with variance parameter ∑i=1nνi\sum_{i=1}^n \nu_i. Section 5 uses this property to derive Hoeffding's inequality.

A relative-error bound for sums of Bernoulli random variables

Applying the Chernoff method to sums of Bernoulli random variables gives a bound on the error relative to the expectation (Mitzenmacher & Upfal, 2017, Chapter 4).

Theorem 3 (Relative-error Chernoff bound)

Let X1,…,XnX_1, \dots, X_n be independent random variables with Xi∈{0,1}X_i \in \{0, 1\} and Pr⁡(Xi=1)=pi\Pr(X_i = 1) = p_i. With m:=E[Sn]=∑i=1npim := \mathbb{E}[S_n] = \sum_{i=1}^n p_i, for any η>0\eta > 0,

Pr⁡(Sn≥(1+η)m)≤(eη(1+η)1+η)m≤exp⁡(−η2m2+η). \begin{aligned} \Pr\left(S_n \geq (1 + \eta) m\right) &\leq \left(\frac{e^{\eta}}{(1 + \eta)^{1 + \eta}}\right)^m \\ &\leq \exp\left(-\frac{\eta^2 m}{2 + \eta}\right). \end{aligned}

In addition, for 0<η<10 < \eta < 1,

Pr⁡(Sn≤(1−η)m)≤exp⁡(−η2m2). \Pr\left(S_n \leq (1 - \eta) m\right) \leq \exp\left(-\frac{\eta^2 m}{2}\right).

The second inequality in the first display follows from log⁡(1+η)≥2η/(2+η)\log(1 + \eta) \geq 2\eta/(2 + \eta), which holds for η≥0\eta \geq 0. This theorem measures the error by its ratio η\eta to the expectation mm. When mm is small compared with nn, it can give a smaller bound than Hoeffding's inequality in Section 5 (see Section 8).

Running example. If pi=pp_i = p, then m=npm = np. The event ∣p^−p∣≥ε|\hat{p} - p| \geq \varepsilon is the event that a relative error of η:=ε/p\eta := \varepsilon/p occurs upward or downward. When η<1\eta < 1, the lower-tail exponent η2m/2\eta^2 m/2 is at least the upper-tail exponent η2m/(2+η)\eta^2 m/(2 + \eta), so combining both tails gives

Pr⁡(∣p^−p∣≥ε)≤2exp⁡(−η2np2+η). \Pr(|\hat{p} - p| \geq \varepsilon) \leq 2\exp\left(-\frac{\eta^2 np}{2 + \eta}\right).

The right-hand side is at most δ\delta if n≥(2+η)log⁡(2/δ)/(η2p)n \geq (2 + \eta)\log(2/\delta) / (\eta^2 p); in setting (B) (η=0.5\eta = 0.5) with δ=0.05\delta = 0.05, this gives n≥3,689n \geq 3{,}689.

5. Hoeffding's inequality

When independent random variables take values in known bounded intervals, the Chernoff method yields Hoeffding's inequality (Hoeffding, 1963). The key is the following lemma, which shows that bounded random variables are sub-Gaussian.

Lemma (Hoeffding's lemma)

If a≤X≤ba \leq X \leq b a.s., then, for all λ∈R\lambda \in \mathbb{R},

ψX(λ)≤λ2(b−a)28. \psi_X(\lambda) \leq \frac{\lambda^2 (b - a)^2}{8}.

That is, XX is sub-Gaussian with variance parameter (b−a)2/4(b - a)^2/4.

For a proof, see Chapter 2 of Boucheron et al. (2013).

Theorem 4 (Hoeffding's inequality)

Let X1,…,XnX_1, \dots, X_n be independent random variables with ai≤Xi≤bia_i \leq X_i \leq b_i a.s. for each ii. Then, for any t>0t > 0,

Pr⁡(Sn−E[Sn]≥t)≤exp⁡(−2t2∑i=1n(bi−ai)2). \Pr(S_n - \mathbb{E}[S_n] \geq t) \leq \exp\left(-\frac{2t^2}{\sum_{i=1}^n (b_i - a_i)^2}\right).

The same bound holds for the lower tail, and the two-sided bound is twice the right-hand side.

Proof. By Hoeffding's lemma, each XiX_i is sub-Gaussian with variance parameter (bi−ai)2/4(b_i - a_i)^2/4. As shown in Section 4, the independent sum SnS_n is sub-Gaussian with variance parameter ν:=∑i=1n(bi−ai)2/4\nu := \sum_{i=1}^n (b_i - a_i)^2/4, so

Pr⁡(Sn−E[Sn]≥t)≤exp⁡(−t22ν)=exp⁡(−2t2∑i=1n(bi−ai)2).□ \begin{aligned} \Pr(S_n - \mathbb{E}[S_n] \geq t) &\leq \exp\left(-\frac{t^2}{2\nu}\right) \\ &= \exp\left(-\frac{2t^2}{\sum_{i=1}^n (b_i - a_i)^2}\right). \quad \square \end{aligned}

Sample mean and required sample size

If each Xi∈[a,b]X_i \in [a, b] a.s. with a common expectation μ\mu, setting t=nεt = n\varepsilon in Theorem 4 gives

Pr⁡(∣Xˉn−μ∣≥ε)≤2exp⁡(−2nε2(b−a)2). \Pr(|\bar{X}_n - \mu| \geq \varepsilon) \leq 2\exp\left(-\frac{2n\varepsilon^2}{(b - a)^2}\right).

For fixed ε\varepsilon, this bound decreases exponentially in nn. Chebyshev's bound σ2/(nε2)\sigma^2/(n\varepsilon^2) in Section 3 decreases only as 1/n1/n.

Setting the right-hand side to δ\delta and solving gives two equivalent forms:

  • If n≥(b−a)22ε2log⁡2δn \geq \dfrac{(b - a)^2}{2\varepsilon^2} \log\dfrac{2}{\delta}, then Pr⁡(∣Xˉn−μ∣≥ε)≤δ\Pr(|\bar{X}_n - \mu| \geq \varepsilon) \leq \delta.
  • For any nn, with probability at least 1−δ1 - \delta, ∣Xˉn−μ∣<(b−a)log⁡(2/δ)2n|\bar{X}_n - \mu| < (b - a)\sqrt{\dfrac{\log(2/\delta)}{2n}}.

Running example. Because Xi∈[0,1]X_i \in [0, 1], the condition is n≥log⁡(2/δ)/(2ε2)n \geq \log(2/\delta)/(2\varepsilon^2). In setting (A), this gives n≥738n \geq 738 for δ=0.05\delta = 0.05 and only n≥2,902n \geq 2{,}902 for δ=10−6\delta = 10^{-6}. The required nn grows in proportion to log⁡(1/δ)\log(1/\delta), so the gap from Chebyshev's inequality, whose nn grows in proportion to 1/δ1/\delta, widens as δ\delta decreases. In setting (B), however, even δ=0.05\delta = 0.05 requires n≥73,778n \geq 73{,}778. Because Hoeffding's inequality uses only the range [0,1][0, 1], it cannot reflect that the variance in (B), p(1−p)≈0.0099p(1-p) \approx 0.0099, is about 1/251/25 of 1/41/4, the maximum variance of a random variable on [0,1][0, 1]. Bernstein's inequality in Section 6 addresses this limitation.

Use known bounds of the distribution, not observed values

The bounds aia_i and bib_i in Theorem 4 must be known in advance as properties of the distribution. Using the observed minimum min⁡iXi\min_i X_i and maximum max⁡iXi\max_i X_i of the sample instead ignores values that have not been observed yet, and the bound is no longer guaranteed.

6. Bernstein's inequality

Hoeffding's inequality uses only the range. For random variables whose values mostly lie near the expectation despite a wide range, Bernstein's inequality, which also uses the variance, gives a smaller bound (Boucheron et al., 2013, §2.8).

Theorem 5 (Bernstein's inequality)

Let X1,…,XnX_1, \dots, X_n be independent random variables, and suppose that, for some M>0M > 0, ∣Xi−E[Xi]∣≤M|X_i - \mathbb{E}[X_i]| \leq M a.s. for each ii. With V:=∑i=1nVar⁡(Xi)V := \sum_{i=1}^n \operatorname{Var}(X_i), for any t>0t > 0,

Pr⁡(Sn−E[Sn]≥t)≤exp⁡(−t22(V+Mt/3)). \Pr(S_n - \mathbb{E}[S_n] \geq t) \leq \exp\left(-\frac{t^2}{2(V + Mt/3)}\right).

The same bound holds for the lower tail, and the two-sided bound is twice the right-hand side.

Two rates of decay

How fast the bound decays depends on which of the two terms in the denominator V+Mt/3V + Mt/3 is larger. Because V+Mt/3≤2max⁡{V,Mt/3}V + Mt/3 \leq 2\max\{V, Mt/3\},

exp⁡(−t22(V+Mt/3))≤exp⁡(−min⁡{t24V,3t4M}). \exp\left(-\frac{t^2}{2(V + Mt/3)}\right) \leq \exp\left(-\min\left\{\frac{t^2}{4V}, \frac{3t}{4M}\right\}\right).
  • For t≤3V/Mt \leq 3V/M, the exponent is at least t2/(4V)t^2/(4V). Like the tail of a normal distribution with variance VV, the bound decays with an exponent proportional to t2t^2.
  • For t>3V/Mt > 3V/M, the exponent is at least 3t/(4M)3t/(4M). Like the tail of an exponential distribution, the bound decays with an exponent proportional to tt.

Sample mean and comparison with Hoeffding's inequality

Suppose that X1,…,XnX_1, \dots, X_n are i.i.d. with E[Xi]=μ\mathbb{E}[X_i] = \mu, Var⁡(Xi)=σ2\operatorname{Var}(X_i) = \sigma^2, and ∣Xi−μ∣≤M|X_i - \mu| \leq M a.s. Substituting V=nσ2V = n\sigma^2 and t=nεt = n\varepsilon into Theorem 5 gives

Pr⁡(∣Xˉn−μ∣≥ε)≤2exp⁡(−nε22(σ2+Mε/3)). \Pr(|\bar{X}_n - \mu| \geq \varepsilon) \leq 2\exp\left(-\frac{n\varepsilon^2}{2(\sigma^2 + M\varepsilon/3)}\right).

When Xi∈[a,b]X_i \in [a, b], the variance is at most (b−a)2/4(b - a)^2/4. Replacing σ2\sigma^2 with this maximum and ignoring Mε/3M\varepsilon/3 gives the exponent 2nε2/(b−a)22n\varepsilon^2/(b - a)^2, which equals the exponent of Hoeffding's bound in Section 5. In this sense, Hoeffding's inequality is a bound that assumes the largest possible variance. Comparing the two exponents shows that Bernstein's bound is smaller when σ2+Mε/3<(b−a)2/4\sigma^2 + M\varepsilon/3 < (b - a)^2/4.

Running example. With σ2=p(1−p)\sigma^2 = p(1-p) and M=max⁡{p,1−p}M = \max\{p, 1 - p\}, the condition is

n≥2(σ2+Mε/3)ε2log⁡2δ. n \geq \frac{2(\sigma^2 + M\varepsilon/3)}{\varepsilon^2} \log\frac{2}{\delta}.

In setting (B) with δ=0.05\delta = 0.05, this gives n≥3,409n \geq 3{,}409, about 1/221/22 of Hoeffding's 73,77873{,}778. In setting (A), σ2=1/4\sigma^2 = 1/4 is already the maximum, so n≥763n \geq 763, slightly more than Hoeffding's 738738.

7. McDiarmid's inequality

Sections 5 and 6 dealt with sums of random variables. McDiarmid's inequality, also called the bounded differences inequality, deals with general functions f(X1,…,Xn)f(X_1, \dots, X_n) of independent random variables, not only sums (McDiarmid, 1989; Boucheron et al., 2013, §6.1).

Definition: bounded differences condition

A function f:X1×⋯×Xn→Rf: \mathcal{X}_1 \times \cdots \times \mathcal{X}_n \to \mathbb{R} satisfies the bounded differences condition with constants c1,…,cn≥0c_1, \dots, c_n \geq 0 if, for every ii and any two points that differ only in the ii-th input,

∣f(x1,…,xi,…,xn)−f(x1,…,xi′,…,xn)∣≤ci. \left|f(x_1, \dots, x_i, \dots, x_n) - f(x_1, \dots, x_i', \dots, x_n)\right| \leq c_i.

The bounded differences condition expresses stability: changing only the ii-th input changes the output by at most cic_i.

Theorem 6 (McDiarmid's inequality)

Let X1,…,XnX_1, \dots, X_n be independent random variables, with XiX_i taking values in Xi\mathcal{X}_i. If ff satisfies the bounded differences condition with constants c1,…,cnc_1, \dots, c_n, then Z:=f(X1,…,Xn)Z := f(X_1, \dots, X_n) satisfies, for any t>0t > 0,

Pr⁡(Z−E[Z]≥t)≤exp⁡(−2t2∑i=1nci2). \Pr(Z - \mathbb{E}[Z] \geq t) \leq \exp\left(-\frac{2t^2}{\sum_{i=1}^n c_i^2}\right).

The same bound holds for the lower tail, and the two-sided bound is twice the right-hand side.

Relation to Hoeffding's inequality

Consider the sum f(x1,…,xn)=∑i=1nxif(x_1, \dots, x_n) = \sum_{i=1}^n x_i with xi∈[ai,bi]x_i \in [a_i, b_i]. Changing the ii-th input changes the sum by at most bi−aib_i - a_i, so substituting ci=bi−aic_i = b_i - a_i into Theorem 6 gives the same formula as Theorem 4 (Hoeffding's inequality). McDiarmid's inequality extends the assumption of Hoeffding's inequality from "a sum of independent bounded random variables" to "a function that is stable under changes of each input."

Example: uniform deviation of the empirical distribution function

As an example of a function that is not a sum, let X1,…,XnX_1, \dots, X_n be i.i.d. with cumulative distribution function FF, and consider the largest difference between FF and the empirical distribution function Fn(x):=1n∑i=1n1{Xi≤x}F_n(x) := \frac{1}{n} \sum_{i=1}^n \mathbf{1}_{\{X_i \leq x\}}:

Z:=sup⁡x∈R∣Fn(x)−F(x)∣. Z := \sup_{x \in \mathbb{R}} |F_n(x) - F(x)|.

ZZ is called the Kolmogorov–Smirnov statistic and is used to test whether a sample follows the distribution FF. Changing one XiX_i changes Fn(x)F_n(x) by at most 1/n1/n at every xx, so it also changes the supremum ZZ by at most 1/n1/n. With ci=1/nc_i = 1/n, we have ∑i=1nci2=1/n\sum_{i=1}^n c_i^2 = 1/n, and Theorem 6 gives

Pr⁡(Z−E[Z]≥t)≤e−2nt2. \Pr(Z - \mathbb{E}[Z] \geq t) \leq e^{-2nt^2}.

The exact distribution of ZZ at a finite nn is not easy to compute, but this bound holds for every FF.

We check this bound with Python. The following code draws n=100n = 100 and n=1000n = 1000 samples from the uniform distribution Uniform(0,1)\mathrm{Uniform}(0, 1) (so F(x)=xF(x) = x) 10410^4 times, computes ZZ, and estimates Pr⁡(Z−E[Z]≥t)\Pr(Z - \mathbb{E}[Z] \geq t). It uses the mean over the 10410^4 runs as E[Z]\mathbb{E}[Z].

mcdiarmid.py
import numpy as np
import matplotlib.pyplot as plt

rng = np.random.default_rng(0)
reps = 10_000
s = np.linspace(0, 1.5, 151)  # the horizontal axis is sqrt(n) * t

for n in [100, 1000]:
    # Draw reps samples of size n from Uniform(0, 1) and sort each sample
    u = np.sort(rng.random((reps, n)), axis=1)
    i = np.arange(1, n + 1)
    # Z = sup_x |F_n(x) - x| (largest gap between the empirical CDF and F(x) = x)
    z = np.maximum(i / n - u, u - (i - 1) / n).max(axis=1)
    tail = [np.mean(z - z.mean() >= x / np.sqrt(n)) for x in s]
    plt.semilogy(s, tail, lw=2, label=f"Simulation ($n = {n}$)")

plt.semilogy(s, np.exp(-2 * s**2), "k--", lw=2,
             label=r"McDiarmid bound $e^{-2nt^2}$")
plt.ylim(1e-4, 1.5)
plt.xlabel(r"$\sqrt{n}\,t$")
plt.ylabel(r"$\Pr(Z - \mathbb{E}[Z] \geq t)$")
plt.legend()
plt.show()
Image
Figure 3: Upper tail probability of the Kolmogorov–Smirnov statistic Z (simulation) and McDiarmid's bound. With √n t on the horizontal axis, the bound is a single curve independent of n. The vertical axis is logarithmic.

With n t\sqrt{n}\, t on the horizontal axis, the bound e−2nt2=e−2(n t)2e^{-2nt^2} = e^{-2(\sqrt{n}\, t)^2} becomes a single curve that does not depend on nn. In Figure 3, the simulation results for n=100n = 100 and n=1000n = 1000 almost coincide, and both lie below the bound. In other words, the fluctuations of Z−E[Z]Z - \mathbb{E}[Z] are of order 1/n1/\sqrt{n}, and McDiarmid's inequality captures this order correctly.

The same structure appears in machine learning. Let G\mathcal{G} be a set of loss functions with values in [0,1][0, 1], and consider sup⁡g∈G∣1n∑i=1ng(Xi)−E[g(X1)]∣\sup_{g \in \mathcal{G}} \left|\frac{1}{n} \sum_{i=1}^n g(X_i) - \mathbb{E}[g(X_1)]\right|; the same argument shows the bounded differences condition with ci=1/nc_i = 1/n. This quantity is the largest gap between the average loss on the training data and the expected loss, and it is used to bound the generalization error. In generalization bounds based on Rademacher complexity, McDiarmid's inequality keeps this quantity close to its expectation, and the expectation is then bounded by the Rademacher complexity (Bartlett & Mendelson, 2002).

Column: Proof idea (martingale decomposition)

McDiarmid's inequality is proved by decomposing Z−E[Z]Z - \mathbb{E}[Z] into the changes that occur as X1,X2,…X_1, X_2, \dots are revealed one at a time. Let Y0:=E[Z]Y_0 := \mathbb{E}[Z], and for k=1,…,nk = 1, \dots, n, let

Yk:=E[Z∣X1,…,Xk]. Y_k := \mathbb{E}[Z \mid X_1, \dots, X_k].

Because Yn=ZY_n = Z,

Z−E[Z]=∑k=1n(Yk−Yk−1). Z - \mathbb{E}[Z] = \sum_{k=1}^n (Y_k - Y_{k-1}).

Given X1,…,Xk−1X_1, \dots, X_{k-1}, the conditional expectation of the increment Yk−Yk−1Y_k - Y_{k-1} is 00. A sequence of random variables (Yk)(Y_k) with this property is called a martingale.

Moreover, by independence and the bounded differences condition, once X1,…,Xk−1X_1, \dots, X_{k-1} are fixed, YkY_k as a function of XkX_k takes values in an interval of length at most ckc_k. Applying Hoeffding's lemma conditionally to each increment and taking conditional expectations for k=n,n−1,…,1k = n, n-1, \dots, 1 gives

E[eλ(Z−E[Z])]≤exp⁡(λ28∑k=1nck2). \mathbb{E}\left[e^{\lambda (Z - \mathbb{E}[Z])}\right] \leq \exp\left(\frac{\lambda^2}{8} \sum_{k=1}^n c_k^2\right).

That is, ZZ is sub-Gaussian with variance parameter ∑kck2/4\sum_k c_k^2/4, and applying the Chernoff method as in Section 5 gives Theorem 6.

8. Comparison and choosing an inequality

Results for the running example

Table 1 summarizes the sample sizes derived in Sections 3 to 6 that guarantee Pr⁡(∣p^−p∣≥ε)≤δ\Pr(|\hat{p} - p| \geq \varepsilon) \leq \delta. For comparison, it also shows the sample sizes actually required, computed numerically from the binomial distribution. Chebyshev's and Bernstein's inequalities use the true variance p(1−p)p(1-p). In practice, pp is unknown, so an upper bound on the variance is used instead (for example, 0.00990.0099 if p≤0.01p \leq 0.01 is known).

Table 1: Lower bounds on the sample size nn that guarantee Pr⁡(∣p^−p∣≥ε)≤δ\Pr(|\hat{p} - p| \geq \varepsilon) \leq \delta

InequalityInformation used(A) δ=0.05\delta = 0.05(A) δ=10−6\delta = 10^{-6}(B) δ=0.05\delta = 0.05(B) δ=10−6\delta = 10^{-6}
Chebyshev (Section 3)Variance2,000100,000,0007,920396,000,000
Relative-error Chernoff bound (Section 4)Expectation of a Bernoulli sum1,5506,0943,68914,509
Hoeffding (Section 5)Range7382,90273,778290,174
Bernstein (Section 6)Range, variance7632,9993,40913,406
Exact (binomial distribution)The distribution itself≈ 400≈ 2,400≈ 1,600≈ 10,400

The last row gives the smallest nn such that Pr⁡(∣p^−p∣≥ε)≤δ\Pr(|\hat{p} - p| \geq \varepsilon) \leq \delta holds for every sample size at or above it. For nn such that n(p±ε)n(p \pm \varepsilon) is an integer, the event includes the boundary value with ∣p^−p∣=ε|\hat{p} - p| = \varepsilon, so the exact probability does not decrease monotonically in nn. For this reason, the row shows approximate values.

The following code plots the exact Pr⁡(∣p^−p∣≥ε)\Pr(|\hat{p} - p| \geq \varepsilon) from the binomial distribution and the bound from each inequality as functions of nn.

tail_bounds.py
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import binom

def exact_tail(n, p, eps):
    """Pr(|S/n - p| >= eps) for S ~ Bin(n, p)"""
    # 1e-9 guards against floating-point rounding errors
    upper = np.ceil(n * (p + eps) - 1e-9)
    lower = np.floor(n * (p - eps) + 1e-9)
    return binom.sf(upper - 1, n, p) + binom.cdf(lower, n, p)

def bounds(n, p, eps):
    """Upper bounds on Pr(|p_hat - p| >= eps) from each inequality"""
    var, M, eta = p * (1 - p), max(p, 1 - p), eps / p
    return {
        "Chebyshev": var / (n * eps**2),
        "Chernoff (relative)": 2 * np.exp(-eta**2 * n * p / (2 + eta)),
        "Hoeffding": 2 * np.exp(-2 * n * eps**2),
        "Bernstein": 2 * np.exp(-n * eps**2 / (2 * (var + M * eps / 3))),
    }

settings = [("A", 0.5, 0.05, 4000), ("B", 0.01, 0.005, 20000)]
fig, axes = plt.subplots(1, 2, figsize=(14, 5.6), sharey=True)
for ax, (label, p, eps, n_max) in zip(axes, settings):
    n = np.arange(10, n_max + 1, 10)
    ax.semilogy(n, exact_tail(n, p, eps), "k", lw=1.2, label="Exact (binomial)")
    for name, value in bounds(n, p, eps).items():
        ax.semilogy(n, np.minimum(value, 1), lw=2.2, label=name)
    ax.axhline(0.05, color="gray", ls="--")
    ax.set(title=rf"({label}) $p = {p}$, $\varepsilon = {eps}$",
           xlabel="$n$", xlim=(0, n_max), ylim=(1e-10, 2))
axes[0].set_ylabel(r"$\Pr(|\hat p - p| \geq \varepsilon)$")
axes[1].legend(loc="lower left")
plt.show()
Image
Figure 4: Exact error probability Pr(|p̂ − p| ≥ ε) (black) and the bound from each inequality, for setting (A) on the left and (B) on the right. The gray dashed line marks δ = 0.05. The vertical axis is logarithmic.

Table 1 and Figure 4 show three points:

  1. Growth as δ\delta decreases: Reducing δ\delta from 0.050.05 to 10−610^{-6} multiplies the nn from Chebyshev's inequality by 5×1045 \times 10^4, because it is proportional to 1/δ1/\delta. The nn from the exponential bounds (Chernoff, Hoeffding, and Bernstein) is proportional to log⁡(2/δ)\log(2/\delta) and grows only by a factor of about 3.93.9. In Figure 4, this difference appears as straight lines (exponential decay) versus a flattening curve (1/n1/n decay).
  2. Small variance: In setting (B), Bernstein's inequality, which uses the variance, and the Chernoff bound, which uses the error relative to the expectation, give an nn about 2020 times smaller than Hoeffding's inequality, which uses only the range. For δ=0.05\delta = 0.05, even Chebyshev's inequality gives a smaller nn than Hoeffding's inequality.
  3. Conservativeness: Every bound requires more samples than actually needed; even the smallest bound is about 1.21.2–1.81.8 times the exact value in setting (A) and about 1.31.3–2.12.1 times in setting (B). Concentration inequalities do not use the detailed shape of the distribution, and they are conservative to that extent.

Choosing an inequality

Table 2 summarizes the assumptions and bounds of each inequality.

Table 2: Assumptions and bounds of each inequality

InequalityMain assumptionsTargetBound
MarkovNonnegative, finite expectationNonnegative random variable XXE[X]/t\mathbb{E}[X]/t
ChebyshevFinite varianceAny random variable XXVar⁡(X)/t2\operatorname{Var}(X)/t^2
Chernoff methodFinite MGFAny random variable XXexp⁡(−sup⁡λ>0{λt−ψX(λ)})\exp(-\sup_{\lambda > 0}\{\lambda t - \psi_X(\lambda)\})
HoeffdingIndependent, boundedSum SnS_nexp⁡(−2t2/∑i(bi−ai)2)\exp(-2t^2/\sum_i (b_i - a_i)^2)
BernsteinIndependent, bounded, varianceSum SnS_nexp⁡(−t2/(2(V+Mt/3)))\exp(-t^2/(2(V + Mt/3)))
McDiarmidIndependent, bounded differencesFunction f(X1,…,Xn)f(X_1, \dots, X_n)exp⁡(−2t2/∑ici2)\exp(-2t^2/\sum_i c_i^2)

The following list gives rough guidelines for choosing an inequality:

  • Only nonnegativity and the expectation are known → Markov's inequality
  • The variance is known, but independence cannot be assumed → Chebyshev's inequality (it also applies to sample means of uncorrelated variables)
  • The MGF can be computed → the Chernoff method directly
  • A sum of independent Bernoulli random variables, with the error measured relative to the expectation → the relative-error Chernoff bound
  • A sum of independent bounded random variables, with no information on the variance → Hoeffding's inequality
  • A sum of independent bounded random variables whose variance is small compared with the range → Bernstein's inequality
  • A function that is not a sum, but on which each input has a small effect → McDiarmid's inequality

9. When the assumptions fail

Dependent random variables

Markov's and Chebyshev's inequalities do not require independence. In contrast, Hoeffding's, Bernstein's, and McDiarmid's inequalities in the forms shown in this article assume independence and do not apply as they are to dependent random variables. There are exceptions: Hoeffding (1963) showed that the same bounds as for sampling with replacement also hold for sampling without replacement from a finite population, where the samples are not independent. In addition, the Azuma–Hoeffding inequality applies to martingales with bounded increments (Azuma, 1967). The proof in the column of Section 7 is based on the same martingale argument as this inequality.

Unbounded random variables

Unbounded random variables can also concentrate. For example, a normal distribution is unbounded but, as shown in Section 4, sub-Gaussian. Sub-exponential random variables form a class that contains the sub-Gaussian ones and also allows heavier tails, and Bernstein-type bounds hold for them (Vershynin, 2018, Chapter 2). Even for distributions without a finite MGF, finite higher moments give bounds that decrease polynomially in tt, by the method of Section 2.

10. Conclusion

As Figure 5 shows, the inequalities in this article follow from Markov's inequality along two paths.

Image
Figure 5: Relationships among the inequalities in this article. The lower line in each box lists the main assumptions or information the inequality uses.
  • Markov → Chebyshev: Applying Markov's inequality to the squared deviation bounds tail probabilities by the variance.
  • Markov → Chernoff method → Hoeffding, Bernstein, McDiarmid: Applying Markov's inequality to an exponential function and bounding the MGF gives bounds that decrease exponentially. McDiarmid's inequality uses a martingale decomposition to extend these bounds to functions other than sums.

Every one of these inequalities answers the same question: how far can a quantity computed from finitely many samples deviate from its expectation? As the running example in Section 8 shows, which inequality gives the smallest bound depends on the available assumptions (variance, range, independence, and stability of the function) and on the conditions of the problem.

References

Comments