TExcelTAD
Home › Randomized Algorithms & Probabilistic Analysis › Chernoff Bounds and Their Proofs

Chernoff Bounds and Their Proofs

Chebyshev's inequality knows only the variance, so for a sum of nn coin flips it bounds a 10% deviation by O(1/n)O(1/n). The truth is exponentially small, and the Chernoff bounds prove it. They apply to a sum of independent variables with values in [0,1][0, 1] and give tails of the form e−cδ2μe^{-c\delta^2\mu}. Almost every with-high-probability statement in this course (maximum loads, randomized rounding, set balancing, sampling, amplification) is a Chernoff bound followed by a union bound. This lesson proves the standard multiplicative forms for both tails from moment-generating functions.

Setting

Let X1,…,XnX_1, \ldots, X_n be independent random variables with Pr⁡[Xi=1]=pi\Pr[X_i = 1] = p_i and Pr⁡[Xi=0]=1−pi\Pr[X_i = 0] = 1 - p_i (Bernoulli variables with possibly different pip_i, often called Poisson trials). Let

X=∑i=1nXi,μ=E[X]=∑i=1npi.X = \sum_{i=1}^n X_i, \qquad \mu = \mathbb{E}[X] = \sum_{i=1}^n p_i .

The bounds are named after Herman Chernoff (1952), whose paper treated the optimised exponential bound for sums of identically distributed variables; the forms below are the ones used in algorithms, as in Motwani and Raghavan (1995) and Mitzenmacher and Upfal (2005). The same exponential-moment technique goes back to Bernstein in the 1920s.

The moment-generating-function method

The trick is Markov's inequality applied to etXe^{tX} for a parameter t>0t > 0, which is increasing in XX:

Pr⁡[X≥a]=Pr⁡[etX≥eta]≤E[etX]eta.\Pr[X \ge a] = \Pr\bigl[e^{tX} \ge e^{ta}\bigr] \le \frac{\mathbb{E}[e^{tX}]}{e^{ta}} .

E[etX]\mathbb{E}[e^{tX}] is the moment-generating function of XX (Moment Generating Functions). Independence makes it factor into a product, and each factor is easy:

E[etX]=∏i=1nE[etXi]independence=∏i=1n(1+pi(et−1))≤∏i=1nepi(et−1)=eμ(et−1)1+x≤ex\begin{aligned} \mathbb{E}\bigl[e^{tX}\bigr] &= \prod_{i=1}^n \mathbb{E}\bigl[e^{tX_i}\bigr] && \text{independence} \\ &= \prod_{i=1}^n \bigl(1 + p_i(e^t - 1)\bigr) \\ &\le \prod_{i=1}^n e^{p_i(e^t - 1)} = e^{\mu(e^t - 1)} && 1 + x \le e^x \end{aligned}

Independence is used exactly once, in the first line, and it is essential: for dependent summands the MGF of the sum is not the product of the MGFs.

The upper tail

Theorem (upper tail). For every δ>0\delta > 0,

Pr⁡[X≥(1+δ)μ]≤(eδ(1+δ)1+δ)μ.\Pr\bigl[X \ge (1 + \delta)\mu\bigr] \le \left(\frac{e^{\delta}}{(1 + \delta)^{1 + \delta}}\right)^{\mu} .

Proof. With a=(1+δ)μa = (1 + \delta)\mu the method gives Pr⁡[X≥a]≤eμ(et−1)−t(1+δ)μ\Pr[X \ge a] \le e^{\mu(e^t - 1) - t(1 + \delta)\mu} for every t>0t > 0. The exponent is minimised at t=ln⁡(1+δ)>0t = \ln(1 + \delta) > 0, where et−1=δe^t - 1 = \delta, and the bound becomes eμδ(1+δ)−(1+δ)μe^{\mu\delta}(1 + \delta)^{-(1 + \delta)\mu}. □\square

The exact form is the strongest, but simpler corollaries are easier to use.

Corollary. For XX and μ\mu as above:

  1. Pr⁡[X≥(1+δ)μ]≤e−δ2μ/(2+δ)\Pr[X \ge (1 + \delta)\mu] \le e^{-\delta^2 \mu / (2 + \delta)} for every δ>0\delta > 0;
  2. Pr⁡[X≥(1+δ)μ]≤e−δ2μ/3\Pr[X \ge (1 + \delta)\mu] \le e^{-\delta^2 \mu / 3} for 0<δ≤10 < \delta \le 1;
  3. Pr⁡[X≥R]≤2−R\Pr[X \ge R] \le 2^{-R} for every R≥6μR \ge 6\mu.
Proof of the corollary

Take logarithms: the theorem says ln⁡Pr⁡[X≥(1+δ)μ]≤μ(δ−(1+δ)ln⁡(1+δ))\ln \Pr[X \ge (1 + \delta)\mu] \le \mu\bigl(\delta - (1 + \delta)\ln(1 + \delta)\bigr).

(1) The inequality ln⁡(1+δ)≥2δ2+δ\ln(1 + \delta) \ge \frac{2\delta}{2 + \delta} holds for δ≥0\delta \ge 0 (both sides vanish at 0, and the derivative of the left side, 11+δ\frac{1}{1 + \delta}, is at least that of the right side, 4(2+δ)2\frac{4}{(2 + \delta)^2}, because (2+δ)2≥4(1+δ)(2 + \delta)^2 \ge 4(1 + \delta)). Hence

δ−(1+δ)ln⁡(1+δ)≤δ−2δ(1+δ)2+δ=−δ22+δ.\delta - (1 + \delta)\ln(1 + \delta) \le \delta - \frac{2\delta(1 + \delta)}{2 + \delta} = -\frac{\delta^2}{2 + \delta}.

(2) For 0<δ≤10 < \delta \le 1, 2+δ≤32 + \delta \le 3, so (1) gives (2).

(3) Let R=(1+δ)μ≥6μR = (1 + \delta)\mu \ge 6\mu, so 1+δ≥61 + \delta \ge 6. Then eδ(1+δ)1+δ≤e1+δ(1+δ)1+δ\frac{e^\delta}{(1 + \delta)^{1 + \delta}} \le \frac{e^{1 + \delta}}{(1 + \delta)^{1 + \delta}}, and the bound is at most (e1+δ)(1+δ)μ≤(e6)R≤2−R\left(\frac{e}{1 + \delta}\right)^{(1 + \delta)\mu} \le \left(\frac{e}{6}\right)^R \le 2^{-R}.

The lower tail

For the lower tail, apply the same method to −X-X, that is, use t<0t < 0:

Pr⁡[X≤a]=Pr⁡[etX≥eta]≤eμ(et−1)−ta(t<0).\Pr[X \le a] = \Pr\bigl[e^{tX} \ge e^{ta}\bigr] \le e^{\mu(e^t - 1) - ta} \qquad (t < 0).

Theorem (lower tail). For 0<δ<10 < \delta < 1,

Pr⁡[X≤(1−δ)μ]≤(e−δ(1−δ)1−δ)μ≤e−δ2μ/2.\Pr\bigl[X \le (1 - \delta)\mu\bigr] \le \left(\frac{e^{-\delta}}{(1 - \delta)^{1 - \delta}}\right)^{\mu} \le e^{-\delta^2 \mu / 2} .

Proof. Choose t=ln⁡(1−δ)<0t = \ln(1 - \delta) < 0, so et−1=−δe^t - 1 = -\delta, and the bound is e−δμ(1−δ)−(1−δ)μe^{-\delta\mu}(1 - \delta)^{-(1 - \delta)\mu}. For the simpler form, (1−δ)ln⁡(1−δ)≥−δ+δ22(1 - \delta)\ln(1 - \delta) \ge -\delta + \frac{\delta^2}{2} on [0,1)[0, 1) (equal at 0; the derivative of the difference is −ln⁡(1−δ)−δ≥0-\ln(1 - \delta) - \delta \ge 0), so the exponent −δμ−(1−δ)ln⁡(1−δ)μ-\delta\mu - (1 - \delta)\ln(1 - \delta)\mu is at most −δ2μ2-\frac{\delta^2\mu}{2}. □\square

The lower tail is slightly better (constant 1/21/2 instead of 1/31/3). Combining both with δ≤1\delta \le 1 gives the two-sided form used most often:

Pr⁡[∣X−μ∣≥δμ]≤2e−δ2μ/3,0<δ<1.\Pr\bigl[\lvert X - \mu \rvert \ge \delta\mu\bigr] \le 2e^{-\delta^2\mu/3}, \qquad 0 < \delta < 1 .

Two practical remarks. First, the bounds still hold if μ\mu is replaced by an upper bound μH≥E[X]\mu_H \ge \mathbb{E}[X] in the upper tail (or a lower bound μL≤E[X]\mu_L \le \mathbb{E}[X] in the lower tail), because the MGF estimate eμ(et−1)e^{\mu(e^t - 1)} grows with μ\mu for t>0t > 0. That is handy when only an estimate of the mean is available. Second, the proofs use only E[etXi]≤epi(et−1)\mathbb{E}[e^{tX_i}] \le e^{p_i(e^t - 1)}, which holds for any variable with values in [0,1][0, 1] and mean pip_i (by convexity of etxe^{tx}), so the same bounds apply to bounded, not just 0/1, summands.

How tight are they?

The program compares the exact binomial tails for n=1000n = 1000 fair coins with the exact Chernoff form and its simplified versions, and also minimises eμ(et−1)−tae^{\mu(e^t - 1) - ta} over tt numerically to confirm that t=ln⁡(1+δ)t = \ln(1 + \delta) is the best choice.

python · try it yourself
from math import comb, exp, log

n, p = 1000, 0.5
mu = n * p
pmf = [comb(n, k) * p ** k * (1 - p) ** (n - k) for k in range(n + 1)]

def upper_exact(a):
    return sum(pmf[k] for k in range(int(-(-a // 1)), n + 1))

def lower_exact(a):
    return sum(pmf[k] for k in range(0, int(a // 1) + 1))

print("delta   exact upper   Chernoff exact   e^(-d^2 mu/3)   numeric best t   exact lower   e^(-d^2 mu/2)")
for d in [0.05, 0.1, 0.15, 0.2]:
    a = (1 + d) * mu
    exact_form = (exp(d) / (1 + d) ** (1 + d)) ** mu
    best = min(exp(mu * (exp(t) - 1) - t * a) for t in [i / 10000 for i in range(1, 5000)])
    print(f"{d:5}   {upper_exact(a):11.3e}   {exact_form:14.3e}   {exp(-d * d * mu / 3):13.3e}"
          f"   {best:14.3e}   {lower_exact((1 - d) * mu):11.3e}   {exp(-d * d * mu / 2):13.3e}")
print(f"optimal t for delta = 0.2: ln(1.2) = {log(1.2):.4f}")
delta   exact upper   Chernoff exact   e^(-d^2 mu/3)   numeric best t   exact lower   e^(-d^2 mu/2)
 0.05     6.061e-02        5.407e-01       6.592e-01        5.407e-01     6.061e-02       5.353e-01
  0.1     8.653e-04        8.887e-02       1.889e-01        8.887e-02     8.653e-04       8.208e-02
 0.15     1.178e-06        4.686e-03       2.352e-02        4.686e-03     1.178e-06       3.607e-03
  0.2     1.364e-10        8.331e-05       1.273e-03        8.331e-05     1.364e-10       4.540e-05
optimal t for delta = 0.2: ln(1.2) = 0.1823

The exponent of the bound is within a constant factor of the true exponent; the gap is the polynomial factor in front (roughly 1/μ1/\sqrt{\mu}) that the bound ignores, and a factor caused by approximating 1+pi(et−1)1 + p_i(e^t - 1) by epi(et−1)e^{p_i(e^t - 1)}, which is noticeable for fair coins and negligible for small pip_i. For fair coins in particular there is a sharper form, proved with E[etY]=cosh⁡t≤et2/2\mathbb{E}[e^{tY}] = \cosh t \le e^{t^2/2} for Y=±1Y = \pm 1: if Y1,…,YnY_1, \ldots, Y_n are independent and uniform on {−1,+1}\{-1, +1\}, then Pr⁡[∑iYi≥a]≤e−a2/(2n)\Pr\bigl[\sum_i Y_i \ge a\bigr] \le e^{-a^2/(2n)}. That version is used for set balancing in The Union Bound at Work.

The lab draws the same comparison for any nn, pp and δ\delta; its Chernoff bar is corollary (1). With 200 flips, p=0.1p = 0.1 and δ=1\delta = 1 the exact tail Pr⁡[X≥40]\Pr[X \ge 40] is about 1.7⋅10−51.7 \cdot 10^{-5}, Chernoff gives about 1.3⋅10−31.3 \cdot 10^{-3}, Chebyshev 0.0450.045 and Markov 0.50.5.

00.0940μ = 20200heads kP(X = k)a = 40P(X ≥ a) vs bounds, log scaleexact1.70e-5Chernoff0.0013Chebyshev0.0450Markov0.5000

A first application: how many samples?

An unknown fraction pp of a population has some property. Sample ss members independently and output the sample fraction p^=X/s\hat p = X/s. How large must ss be for p^\hat p to be within a factor 1±ε1 \pm \varepsilon of pp with probability at least 1−η1 - \eta? With μ=sp\mu = sp the two-sided bound gives failure probability at most 2e−ε2sp/32e^{-\varepsilon^2 sp/3}, so

s≥3ln⁡(2/η)ε2ps \ge \frac{3 \ln(2/\eta)}{\varepsilon^2 p}

suffices. Chebyshev would require s≥1−pε2pηs \ge \frac{1 - p}{\varepsilon^2 p \eta}, linear instead of logarithmic in 1/η1/\eta. The program checks the Chernoff sample size by simulation.

python · try it yourself
import random
from math import ceil, log

p, eps, eta = 0.2, 0.2, 0.01
s = ceil(3 * log(2 / eta) / (eps ** 2 * p))
s_cheb = ceil((1 - p) / (eps ** 2 * p * eta))
print(f"samples needed: Chernoff {s}, Chebyshev {s_cheb}")

rng = random.Random(9)
trials, bad = 200, 0
for _ in range(trials):
    x = sum(rng.random() < p for _ in range(s))
    if abs(x / s - p) > eps * p:
        bad += 1
print(f"{trials} trials with s = {s}: {bad} estimates outside p(1 +- eps), allowed rate {eta}")
samples needed: Chernoff 1987, Chebyshev 10000
200 trials with s = 1987: 0 estimates outside p(1 +- eps), allowed rate 0.01

None of the runs fails, as expected: the bound is conservative. Recall what was assumed: independent samples. With pairwise independent samples only Chebyshev applies, and the median trick is the way to recover a logarithmic dependence on 1/η1/\eta.

Test yourself

Where is independence used in the proof of the Chernoff bound?

  1. In Markov's inequality
  2. To write E[etX]\mathbb{E}[e^{tX}] as the product of the E[etXi]\mathbb{E}[e^{tX_i}]
  3. In the inequality 1+x≤ex1 + x \le e^x
  4. In choosing tt

XX is a sum of independent Bernoulli variables with μ=60\mu = 60. Which bound does Chernoff give for Pr⁡[X≥90]\Pr[X \ge 90]?

  1. e−1.25e^{-1.25}
  2. e−5e^{-5}
  3. e−15e^{-15}
  4. 1/31/3

Which value of tt minimises eμ(et−1)−t(1+δ)μe^{\mu(e^t - 1) - t(1+\delta)\mu}?

  1. t=δt = \delta
  2. t=ln⁡(1+δ)t = \ln(1 + \delta)
  3. t=1t = 1
  4. t=δ2/3t = \delta^2/3

To estimate a fraction pp within a factor 1±ε1 \pm \varepsilon with failure probability η\eta, how does the Chernoff sample size depend on η\eta?

  1. Like 1/η1/\eta
  2. Like ln⁡(1/η)\ln(1/\eta)
  3. Like 1/η21/\eta^2
  4. It does not depend on η\eta