# Hoeffding's inequality

In probability theory, Hoeffding's inequality provides an upper bound on the probability that the sum of random variables deviates from its expected value. Hoeffding's inequality was proved by Wassily Hoeffding in 1963.[1]

Hoeffding's inequality is a special case of the Azuma–Hoeffding inequality, and it is more general than the Bernstein inequality, proved by Sergei Bernstein in 1923. They are also special cases of McDiarmid's inequality.

## Special case of Bernoulli random variables

Hoeffding's inequality can be applied to the important special case of identically distributed Bernoulli random variables, and this is how the inequality is often used in combinatorics and computer science. We consider a coin that shows heads with probability p and tails with probability 1 − p. We toss the coin n times. The expected number of times the coin comes up heads is pn. Furthermore, the probability that the coin comes up heads at most k times can be exactly quantified by the following expression:

$\mathbb{P}( H(n) \leq k)= \sum_{i=0}^{k} \binom{n}{i} p^i (1-p)^{n-i},$

where H(n) is the number of heads in n coin tosses.

When k =(pε)n for some ε > 0, Hoeffding's inequality bounds this probability by a term that is exponentially small in ε2n:

$\mathbb{P}( H(n) \leq (p-\varepsilon) n)\leq\exp\left(-2\varepsilon^2 n\right).$

Similarly, when k = (p + ε)n for some ε > 0, Hoeffding's inequality bounds the probability that we see at least εn more tosses that show heads than we would expect:

$\mathbb{P}(H(n) \geq (p+\varepsilon)n)\leq\exp\left(-2\varepsilon^2 n\right).$

Hence Hoeffding's inequality implies that the number of heads that we see is concentrated around its mean, with exponentially small tail.

$\mathbb{P}\left((p-\epsilon)n \leq H(n) \leq (p+\varepsilon)n\right)\geq 1-2\exp\left(-2\varepsilon^2 n\right).$

For example, taking $\varepsilon=\sqrt{\ln{n}/n}$ gives:

$\mathbb{P}\left(|H(n)-pn| \leq \sqrt{n\ln n}\right) \geq 1-2\exp\left(-2\ln n\right) = 1-2/n^2.$

## General case

Let X1, ..., Xn be independent random variables bounded by the interval [0,1]: 0 ≤ Xi ≤ 1. We define the empirical mean of these variables by

$\overline X = \frac{1}{n}(X_1 + \cdots + X_n).$

One of the inequalities in Theorem 1 of Hoeffding (1963):

\begin{align} \mathbb{P}(\overline X - \mathrm{E}[\overline X] \geq t) \leq e^{-2nt^2} \end{align}

Theorem 2 of Hoeffding (1963) is a generalization of the above inequality when it is known that Xi are strictly bounded by the intervals [ai,bi]:

\begin{align} \mathbb{P} \left(\overline X - \mathrm{E}\left [\overline X \right] \geq t \right) &\leq \exp \left(-\frac{2n^2t^2}{\sum_{i=1}^n (b_i - a_i)^2} \right) \\ \mathbb{P} \left(\left |\overline X - \mathrm{E}\left [\overline X \right] \right | \geq t \right) &\leq 2\exp \left(-\frac{2n^2t^2}{\sum_{i=1}^n(b_i - a_i)^2} \right) \end{align}

which are valid for positive values of t. Here E[X] is the expected value of X. The inequalities can be also stated in terms of the sum

$S_{n} = X_1 + \cdots + X_n$

of the random variables:

$\mathbb{P}(S_{n} - \mathrm{E}[S_{n}] \geq t) \leq \exp \left( - \frac{2t^2}{\sum_{i=1}^n (b_i - a_i)^2} \right),$
$\mathbb{P}(|S_{n} - \mathrm{E}[S_{n}]| \geq t) \leq 2\exp \left( - \frac{2t^2}{\sum_{i=1}^n (b_i - a_i)^2} \right).$

Note that the inequalities also hold when the Xi have been obtained using sampling without replacement; in this case the random variables are not independent anymore. A proof of this statement can be found in Hoeffding's paper. For slightly better bounds in the case of sampling without replacement, see for instance the paper by Serfling (1974).

## Proof

In this section, we give a proof of Hoeffding's inequality.[2] The proof uses Hoeffding's Lemma:

Suppose X is a real random variable with mean zero such that $\textstyle\mathbb{P}\left(X\in\left[a,b\right]\right)=1$. Then
$\mathrm{E} \left [e^{sX} \right ]\leq \exp\left(\tfrac{1}{8} s^2 (b-a)^2\right).$

Using this lemma, we can prove Hoeffding's inequality. Suppose X1, ..., Xn are n independent random variables such that

$\mathbb{P}\left (X_{i}\in [a_{i},b_{i}] \right)=1, \qquad 1\leq i\leq n.$

Let

$S_n = X_1 + \cdots + X_n.$

Then for s, t ≥ 0, Markov's inequality and the independence of Xi implies:

\begin{align} \mathbb{P}\left(S_{n}-\mathrm{E}\left [S_n \right ]\geq t \right) &= \mathbb{P} \left (e^{s(S_n-\mathrm{E}\left [S_n \right ])} \geq e^{st} \right)\\ &\leq e^{-st} \mathrm{E} \left [e^{s(S_{n}-\mathrm{E}\left [S_n \right ])} \right ]\\ &= e^{-st} \prod_{i=1}^{n}\mathrm{E} \left [e^{s(X_i-\mathrm{E}\left [X_{i}\right])} \right ]\\ &\leq e^{-st} \prod_{i=1}^{n} e^{\frac{s^2 (b_i-a_i)^2}{8} } \\ &= \exp\left(-st+\tfrac{1}{8} s^2 \sum_{i=1}^{n}(b_{i}-a_{i})^{2}\right) \end{align}

To get the best possible upper bound, we find the minimum of the right hand side of the last inequality as a function of s. Define

$\begin{cases} g: \mathbf{R_{+}} \to \mathbf{R} \\ g(s)=-st+\frac{s^{2}}{8}\sum_{i=1}^{n}(b_{i}-a_{i})^2 \end{cases}$

Note that g is a quadratic function and achieves its minimum at

$s=\frac{4t}{\sum_{i=1}^{n}(b_{i}-a_{i})^{2}}.$

Thus we get

$\mathbb{P} \left(S_{n}-\mathrm{E}\left [S_{n} \right ]\geq t \right)\leq \exp\left(-\frac{2t^{2}}{\sum_{i=1}^{n}(b_{i}-a_{i})^{2}}\right).$

## Usage

### Confidence Intervals

Hoeffding's inequality is useful to analyse the number of required samples needed to obtain a confidence interval by solving the inequality in Theorem 1:

$\mathbb{P}(\overline X - \mathrm{E}[\overline X] \geq t) \leq e^{-2nt^2}$

The inequality states that the probability that the estimated and true values differ by more than t is bounded by e−2nt2. Symmetrically, the inequality is also valid for another side of the difference:

$\mathbb{P}(-\overline X + \mathrm{E}[\overline X] \geq t) \leq e^{-2nt^2}$

By adding them both up, we can obtain two-sided variant of this inequality:

$\mathbb{P}(|\overline X - \mathrm{E}[\overline X]| \geq t) \leq 2e^{-2nt^2}$

This probability can be interpreted as the level of significance $\alpha$ (probability of making an error) for a confidence interval around $\mathrm{E}[\overline X]$ of size 2t:

$\alpha=\mathbb{P}(\overline X \notin [\mathrm{E}[\overline X]-t, \mathrm{E}[\overline X]+t]) \leq 2e^{-2nt^2}$

Solving the above for n gives us the following:

$n\geq-\frac{\log(\alpha/2)}{2t^2}$

Therefore, we require at least $\textstyle -\frac{\log(\alpha/2)}{2t^2}$ samples to acquire $\textstyle (1-\alpha)$-confidence interval $\textstyle \mathrm{E}[\overline X]\pm t$.

Hence, the cost of acquiring the confidence interval is sublinear in terms of confidence level and quadratic in terms of precision.

Note that this inequality is the most conservative of the three in Theorem 1, and there are more efficient methods of estimating a confidence interval.