Chernoff Bounds and Their Proofs
Chebyshev's inequality knows only the variance, so for a sum of coin flips it bounds a 10% deviation by . The truth is exponentially small, and the Chernoff bounds prove it. They apply to a sum of independent variables with values in and give tails of the form . 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 be independent random variables with and (Bernoulli variables with possibly different , often called Poisson trials). Let
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 for a parameter , which is increasing in :
is the moment-generating function of (Moment Generating Functions). Independence makes it factor into a product, and each factor is easy:
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 ,
Proof. With the method gives for every . The exponent is minimised at , where , and the bound becomes .
The exact form is the strongest, but simpler corollaries are easier to use.
Corollary. For and as above:
- for every ;
- for ;
- for every .
Proof of the corollary
Take logarithms: the theorem says .
(1) The inequality holds for (both sides vanish at 0, and the derivative of the left side, , is at least that of the right side, , because ). Hence
(2) For , , so (1) gives (2).
(3) Let , so . Then , and the bound is at most .
The lower tail
For the lower tail, apply the same method to , that is, use :
Theorem (lower tail). For ,
Proof. Choose , so , and the bound is . For the simpler form, on (equal at 0; the derivative of the difference is ), so the exponent is at most .
The lower tail is slightly better (constant instead of ). Combining both with gives the two-sided form used most often:
Two practical remarks. First, the bounds still hold if is replaced by an upper bound in the upper tail (or a lower bound in the lower tail), because the MGF estimate grows with for . That is handy when only an estimate of the mean is available. Second, the proofs use only , which holds for any variable with values in and mean (by convexity of ), so the same bounds apply to bounded, not just 0/1, summands.
How tight are they?
The program compares the exact binomial tails for fair coins with the exact Chernoff form and its simplified versions, and also minimises over numerically to confirm that is the best choice.
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 ) that the bound ignores, and a factor caused by approximating by , which is noticeable for fair coins and negligible for small . For fair coins in particular there is a sharper form, proved with for : if are independent and uniform on , then . That version is used for set balancing in The Union Bound at Work.
The lab draws the same comparison for any , and ; its Chernoff bar is corollary (1). With 200 flips, and the exact tail is about , Chernoff gives about , Chebyshev and Markov .
A first application: how many samples?
An unknown fraction of a population has some property. Sample members independently and output the sample fraction . How large must be for to be within a factor of with probability at least ? With the two-sided bound gives failure probability at most , so
suffices. Chebyshev would require , linear instead of logarithmic in . The program checks the Chernoff sample size by simulation.
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 .
Test yourself
Where is independence used in the proof of the Chernoff bound?
- In Markov's inequality
- To write as the product of the
- In the inequality
- In choosing
is a sum of independent Bernoulli variables with . Which bound does Chernoff give for ?
Which value of minimises ?
To estimate a fraction within a factor with failure probability , how does the Chernoff sample size depend on ?
- Like
- Like
- Like
- It does not depend on