Hoeffding's Inequality
The Chernoff bounds of the previous lesson are multiplicative: they bound deviations of in terms of the mean . Often the natural question is additive: is the average of bounded measurements within of its expectation? Hoeffding's inequality (Wassily Hoeffding, 1963) answers it for any independent variables with bounded ranges, whatever their distributions. This lesson proves it through Hoeffding's lemma, compares it with Chernoff, and uses it to settle the majority-vote bound promised in Amplification by Repetition.
The statement
Theorem (Hoeffding). Let be independent with , and let . For every ,
and the same bound holds for . In particular, if every and , then
The bound depends only on the ranges, not on the means or variances. That makes it the default tool for "average of bounded samples" questions, such as Monte Carlo estimation of an integral or a probability, and the sample-complexity bounds of learning theory.
Hoeffding's lemma
The proof follows the MGF method of Chernoff Bounds and Their Proofs. The one new ingredient bounds the MGF of a single bounded, centred variable.
Lemma (Hoeffding). If and , then for every real
Proof of the lemma
Since (the mean is 0) and is convex, on it lies below its chord:
Take expectations and use : . Put and . The right-hand side equals with
Now , , and with , so . By Taylor's theorem with remainder, .
Proof of the theorem. For , Markov's inequality and independence give
The exponent is smallest at , which gives the theorem. The lower tail follows by applying this to .
The program checks the lemma numerically for a few centred distributions on and a range of away from 0 (at both sides equal 1): the ratio of the true MGF to the bound stays below 1.
from math import exp
dists = {
"fair +-1": [(-1, 0.5), (1, 0.5)],
"Bernoulli(0.1)-0.1": [(-0.1, 0.9), (0.9, 0.1)],
"three-point": [(-1, 0.25), (0, 0.25), (0.5, 0.5)],
}
for name, d in dists.items():
assert abs(sum(v * p for v, p in d)) < 1e-12 # centred
a, b = min(v for v, _ in d), max(v for v, _ in d)
worst = max(sum(p * exp(lam * v) for v, p in d) / exp(lam ** 2 * (b - a) ** 2 / 8)
for lam in [i / 10 for i in range(-50, 51) if abs(i) >= 5])
print(f"{name:20} range [{a:.2f}, {b:.2f}]: max of MGF / bound for 0.5 <= |lambda| <= 5: {worst:.4f}")fair +-1 range [-1.00, 1.00]: max of MGF / bound for 0.5 <= |lambda| <= 5: 0.9951
Bernoulli(0.1)-0.1 range [-0.10, 0.90]: max of MGF / bound for 0.5 <= |lambda| <= 5: 0.9818
three-point range [-1.00, 0.50]: max of MGF / bound for 0.5 <= |lambda| <= 5: 0.9802
The fair variable comes closest: it is the extreme case of the lemma, with , and the ratio tends to 1 as .
Majority votes, settled
In Amplification by Repetition, independent runs each answer correctly with probability , and the majority is taken. Let indicate that run is correct, so . The majority is wrong only if , a deviation of below the mean, and the ranges are :
Hoeffding or Chernoff?
For 0/1 variables both bounds apply, and they are good at different things. Hoeffding's exponent is , which ignores the mean. Chernoff's exponent for a deviation is about , which is much larger when is small compared with , that is, for rare events. For fair coins the two are comparable, and Hoeffding's constant is better.
from math import exp, lgamma, log
def exact_upper(n, p, k):
# binomial terms in log space, so that large n does not overflow
return sum(exp(lgamma(n + 1) - lgamma(j + 1) - lgamma(n - j + 1) + j * log(p) + (n - j) * log(1 - p))
for j in range(k, n + 1))
print(" n p mu threshold exact Hoeffding Chernoff (2+delta)")
for n, p, k in [(1000, 0.5, 550), (1000, 0.5, 600), (10000, 0.01, 130), (10000, 0.01, 200)]:
mu = n * p
t = k - mu
d = t / mu
hoeff = exp(-2 * t * t / n)
chern = exp(-d * d * mu / (2 + d))
print(f"{n:5} {p:5} {mu:4.0f} {k:11} {exact_upper(n, p, k):9.2e} {hoeff:10.2e} {chern:12.2e}") n p mu threshold exact Hoeffding Chernoff (2+delta)
1000 0.5 500 550 8.65e-04 6.74e-03 9.25e-02
1000 0.5 500 600 1.36e-10 2.06e-09 1.13e-04
10000 0.01 100 130 2.18e-03 8.35e-01 2.00e-02
10000 0.01 100 200 5.63e-19 1.35e-01 3.34e-15
With and , reaching 200 successes instead of the expected 100 is astronomically unlikely, which Chernoff sees and Hoeffding does not. For balls into bins, where each bin's load is a sum of many indicators with tiny means, Chernoff is therefore the right choice (The Union Bound at Work).
Estimating an average by sampling
To estimate the mean of a function with values in over a large domain, average at independent uniform samples. Hoeffding says samples make the estimate -accurate with probability at least , independently of the domain size and of . The program estimates the fraction of pairs in that are coprime (close to ) and records how often the estimate misses by more than .
import random
from math import ceil, gcd, log
N = 300
true = sum(gcd(x, y) == 1 for x in range(1, N + 1) for y in range(1, N + 1)) / N ** 2
eps, eta = 0.05, 0.05
n = ceil(log(2 / eta) / (2 * eps ** 2))
rng = random.Random(6)
trials, misses = 150, 0
for _ in range(trials):
hits = sum(gcd(rng.randint(1, N), rng.randint(1, N)) == 1 for _ in range(n))
misses += abs(hits / n - true) > eps
print(f"true fraction {true:.5f}; Hoeffding sample size for eps = {eps}, eta = {eta}: n = {n}")
print(f"{trials} estimates: {misses} missed by more than eps (allowed about {eta * trials:.1f})")true fraction 0.60883; Hoeffding sample size for eps = 0.05, eta = 0.05: n = 738
150 estimates: 1 missed by more than eps (allowed about 7.5)
Beyond independence
Hoeffding's proof extends almost word for word to martingales with bounded increments: if is a martingale with , then (the Azuma-Hoeffding inequality, Azuma 1967). A consequence, McDiarmid's bounded-differences inequality (1989), says that any function of independent variables that changes by at most when alone changes satisfies . It proves, for example, that the number of empty bins or the chromatic number of a random graph is concentrated, even though these are not sums of independent variables. Both are stated here without proof; see the martingale chapter of Mitzenmacher and Upfal.
Test yourself
Hoeffding's inequality for with depends on which quantities?
- Only the means of the
- Only the deviation and the ranges
- The variances of the
- The number of distinct values
Hoeffding's lemma bounds for a centred by what?
How many samples of a -valued function does Hoeffding require to estimate its mean within with failure probability ?
- About 185
- About 18 445
- About 200 000
- It depends on the domain size
For a sum of 10 000 Bernoulli(0.01) variables, why is Chernoff much stronger than Hoeffding for ?
- Hoeffding needs identical distributions
- Chernoff's exponent scales with while Hoeffding's scales with , and here is tiny compared with
- Hoeffding applies only to the lower tail
- They give the same bound