Probability Theory Module

Concentration Inequalities & Tail Bounds

Non-asymptotic tail bounds in computer science: Markov's inequality, Chebyshev's inequality, Chernoff bounds, Hoeffding's inequality, and PAC learning sample complexity.

1. The Need for Concentration Bounds

In theoretical computer science, machine learning generalization theory, and distributed systems, we frequently face the question: What is the probability that a random metric deviates significantly from its expected value?
While the Central Limit Theorem describes asymptotic behavior as $n \to \infty$, it provides no non-asymptotic guarantees for finite samples $n$. Concentration inequalities provide rigorous, non-asymptotic upper bounds on tail probabilities:
$$P(|X - E[X]| \ge \epsilon) \le \delta$$
text
+-----------------------------------------------------------------------------------------+
|                         THE CONCENTRATION INEQUALITY HIERARCHY                          |
+-----------------------------------------------------------------------------------------+
|                                                                                         |
|  MARKOV'S INEQUALITY                                                                    |
|  Assumes: X >= 0, knows only E[X].                         Decay rate: O(1 / a)          |
|         |                                                                               |
|         v (Apply to (X - mu)^2)                                                         |
|  CHEBYSHEV'S INEQUALITY                                                                 |
|  Assumes: Knows E[X] and Var(X).                           Decay rate: O(1 / a^2)        |
|         |                                                                               |
|         v (Apply to e^{tX} and optimize over t > 0)                                     |
|  CHERNOFF & HOEFFDING BOUNDS                                                            |
|  Assumes: Independent bounded variables or known MGF.      Decay rate: exp(-c * a^2)     |
|                                                            (Exponential tail decay!)     |
+-----------------------------------------------------------------------------------------+

2. Markov's Inequality

Markov's inequality is the parent of almost all concentration inequalities. It requires only that the random variable is non-negative and has a finite mean.

Theorem

Let $X$ be a non-negative random variable ($X \ge 0$) with finite mean $E[X]$. For any constant $a > 0$:
$$P(X \ge a) \le \frac{E[X]}{a}$$

Mathematical Proof:

Define the indicator variable $I_{X \ge a} = 1$ if $X \ge a$, and $0$ otherwise. Notice that for all values of $X \ge 0$: $$X \ge a \cdot I_{X \ge a}$$
  • If $X < a$: Left side is $\ge 0$, right side is $0$. Inequality holds.
  • If $X \ge a$: Left side is $\ge a$, right side is $a \cdot 1 = a$. Inequality holds.
Taking expectations on both sides: $$E[X] \ge E[a \cdot I_{X \ge a}] = a \cdot E[I_{X \ge a}] = a \cdot P(X \ge a)$$ Dividing both sides by $a$: $$P(X \ge a) \le \frac{E[X]}{a} \quad \blacksquare$$

Intuition & Limitations:

If average cloud bill is $$1,000$, what is the probability the bill exceeds $$5,000$? $$P(X \ge 5000) \le \frac{1000}{5000} = 0.20 \quad (20%)$$ At most $20%$ of users can spend more than $5 \times$ the average. Markov's bound decays only linearly ($1/a$), making it relatively loose.

3. Chebyshev's Inequality

Chebyshev incorporates variance information to achieve quadratic decay ($1/a^2$).

Theorem

Let $X$ be any random variable with mean $\mu = E[X]$ and finite variance $\sigma^2 = \text{Var}(X)$. For any $k > 0$:
$$P(|X - \mu| \ge k\sigma) \le \frac{1}{k^2}$$
Equivalently, for any deviation $\epsilon > 0$:
$$P(|X - \mu| \ge \epsilon) \le \frac{\text{Var}(X)}{\epsilon^2}$$

Mathematical Proof:

The event $|X - \mu| \ge \epsilon$ is identical to $(X - \mu)^2 \ge \epsilon^2$. Notice that $(X - \mu)^2$ is a non-negative random variable with expectation $E[(X - \mu)^2] = \text{Var}(X)$. Applying Markov's inequality directly to $(X - \mu)^2$: $$P((X - \mu)^2 \ge \epsilon^2) \le \frac{E[(X - \mu)^2]}{\epsilon^2} = \frac{\text{Var}(X)}{\epsilon^2} \quad \blacksquare$$

Engineering Consequence:

For any arbitrary distribution (regardless of shape or skew):
  • At least $75%$ of values lie within $2\sigma$ ($k=2 \implies P \le 1/4$).
  • At least $88.8%$ of values lie within $3\sigma$ ($k=3 \implies P \le 1/9$).
  • At least $96%$ of values lie within $5\sigma$ ($k=5 \implies P \le 1/25$).

4. The Chernoff Bound Method

Can we achieve exponential decay? Yes, by applying Markov's inequality to the exponential transform $e^{tX}$.

The Generic Chernoff Technique

For any $t > 0$, the event $X \ge a$ is equivalent to $e^{tX} \ge e^{ta}$. Since $e^{tX} > 0$, we apply Markov's inequality:
$$P(X \ge a) = P(e^{tX} \ge e^{ta}) \le \frac{E[e^{tX}]}{e^{ta}} = e^{-ta} M_X(t)$$
Since this inequality holds for every choice of $t > 0$, we choose the optimal $t$ that minimizes the right-hand side:
$$P(X \ge a) \le \inf_{t > 0} \left[ e^{-ta} M_X(t) \right]$$

Chernoff Bounds for Sums of Independent Bernoulli Variables

Let $X_1, X_2, \dots, X_n$ be independent Bernoulli random variables with $P(X_i = 1) = p_i$. Let $S_n = \sum_{i=1}^n X_i$, and $\mu = E[S_n] = \sum_{i=1}^n p_i$.
For any $\delta > 0$:
$$P(S_n \ge (1 + \delta)\mu) \le \left( \frac{e^\delta}{(1 + \delta)^{1 + \delta}} \right)^\mu \le \exp\left( -\frac{\mu \delta^2}{2 + \delta} \right) \le \exp\left( -\frac{\mu \delta^2}{3} \right)$$
For the lower tail ($0 < \delta < 1$):
$$P(S_n \le (1 - \delta)\mu) \le \exp\left( -\frac{\mu \delta^2}{2} \right)$$
text
Decay Comparison:
Deviation delta = 100% (2x average load), mu = 100 requests
- Markov:     P(X >= 200) <= 100 / 200 = 0.50 (50%)
- Chebyshev:  P(X >= 200) <= 100 / (100)^2 = 0.01 (1%)
- Chernoff:   P(X >= 200) <= exp(-100 * 1^2 / 3) = exp(-33.3) ≈ 3.3 x 10^-15 !

5. Hoeffding's Inequality

Hoeffding's inequality generalizes Chernoff bounds to any independent random variables bounded in arbitrary real intervals.

Theorem (Hoeffding)

Let $X_1, X_2, \dots, X_n$ be independent random variables such that $X_i \in [a_i, b_i]$ with probability $1$. Let $\bar{X} = \frac{1}{n} \sum_{i=1}^n X_i$. For any $\epsilon > 0$:
$$P(\bar{X} - E[\bar{X}] \ge \epsilon) \le \exp\left( -\frac{2 n^2 \epsilon^2}{\sum_{i=1}^n (b_i - a_i)^2} \right)$$
For identical ranges $[a, b]$ with range width $R = b - a$:
$$P(|\bar{X} - E[\bar{X}]| \ge \epsilon) \le 2 \exp\left( -\frac{2 n \epsilon^2}{R^2} \right)$$

6. Machine Learning Application: PAC Learning Sample Complexity

In PAC Learning (Probably Approximately Correct), we want to guarantee with high probability ($1 - \delta$) that a trained machine learning model's empirical training error $\hat{R}(h)$ differs from its true test error $R(h)$ by at most $\epsilon$:
$$P(\exists h \in \mathcal{H} : |R(h) - \hat{R}(h)| \ge \epsilon) \le \delta$$

Derivation:

  1. For a single hypothesis $h$, training losses are independent bounded variables $L_i \in [0, 1]$. By Hoeffding's inequality: $$P(|R(h) - \hat{R}(h)| \ge \epsilon) \le 2 e^{-2n\epsilon^2}$$
  2. For a finite hypothesis class $\mathcal{H}$ of size $|\mathcal{H}|$, applying Boole's union bound: $$P(\exists h \in \mathcal{H} : |R(h) - \hat{R}(h)| \ge \epsilon) \le \sum_{h \in \mathcal{H}} 2 e^{-2n\epsilon^2} = 2|\mathcal{H}| e^{-2n\epsilon^2}$$
  3. Setting the error probability to at most $\delta$: $$2|\mathcal{H}| e^{-2n\epsilon^2} \le \delta \implies e^{-2n\epsilon^2} \le \frac{\delta}{2|\mathcal{H}|}$$ Taking natural logs and solving for $n$: $$-2n\epsilon^2 \le \ln\left(\frac{\delta}{2|\mathcal{H}|}\right) \implies n \ge \frac{1}{2\epsilon^2} \ln\left( \frac{2|\mathcal{H}|}{\delta} \right)$$
This foundational theorem proves that the number of training samples required scales only logarithmically with the model's complexity $|\mathcal{H}|$.

7. Comparative Hierarchy of Concentration Bounds

BoundRequired KnowledgeUnderlying AssumptionsDecay RateUse Case
Markov$E[X]$ only$X \ge 0$$O(1/\epsilon)$Zero variance info available
Chebyshev$E[X], \text{Var}(X)$Finite variance$O(1/\epsilon^2)$Distribution shape unknown
ChernoffMGF $M_X(t)$Independent random variables$\exp(-c \epsilon^2)$Sums of independent Bernoulli / indicators
HoeffdingBound intervals $[a_i, b_i]$Independent bounded variables$\exp(-2n\epsilon^2)$Generalization theory, PAC learning

8. Python Implementation: Empirical Comparison of Bounds

python
import numpy as np

def compare_concentration_bounds():
    """
    Empirically compare Markov, Chebyshev, and Chernoff bounds
    against the true tail probability of a sum of Bernoulli trials.
    """
    n = 100
    p = 0.2
    mu = n * p               # Mean = 20.0
    var = n * p * (1 - p)    # Var  = 16.0
    sigma = np.sqrt(var)     # Std  = 4.0

    delta = 0.5              # 50% deviation above the mean
    threshold = (1 + delta) * mu  # X >= 30

    # 1. Markov's Bound: P(X >= a) <= E[X] / a
    markov_bound = mu / threshold

    # 2. Chebyshev's One-Sided Bound (Cantelli's inequality):
    # P(X - mu >= k*sigma) <= 1 / (1 + k^2) where k*sigma = threshold - mu
    k = (threshold - mu) / sigma
    cantelli_chebyshev = 1.0 / (1.0 + k**2)

    # 3. Chernoff Bound: exp(-mu * delta^2 / 3)
    chernoff_bound = np.exp(-mu * (delta ** 2) / 3.0)

    # 4. True Monte Carlo probability
    rng = np.random.default_rng(42)
    trials = 1_000_000
    samples = rng.binomial(n, p, size=trials)
    empirical_prob = np.mean(samples >= threshold)

    print(f"Sum of {n} Bernoullis(p={p}): Mean={mu}, Threshold={threshold}")
    print("-----------------------------------------------------------------")
    print(f"Markov Upper Bound:     {markov_bound:.6f}  (Ratio: {markov_bound / empirical_prob:.1f}x)")
    print(f"Chebyshev Upper Bound:  {cantelli_chebyshev:.6f}  (Ratio: {cantelli_chebyshev / empirical_prob:.1f}x)")
    print(f"Chernoff Upper Bound:   {chernoff_bound:.6f}  (Ratio: {chernoff_bound / empirical_prob:.1f}x)")
    print(f"True Empirical Prob:    {empirical_prob:.6f}")

    assert empirical_prob <= chernoff_bound <= cantelli_chebyshev <= markov_bound

if __name__ == "__main__":
    compare_concentration_bounds()

9. Key Takeaways

  1. Markov is Universal but Loose: $P(X \ge a) \le E[X]/a$ requires only non-negativity, decaying as $O(1/a)$.
  2. Chebyshev Exploits Variance: Bounding $|X - \mu| \ge \epsilon$ by $\text{Var}(X)/\epsilon^2$ achieves quadratic decay.
  3. Chernoff & Hoeffding Provide Exponential Tightness: Sums of independent bounded variables decay exponentially fast ($\exp(-c n \epsilon^2)$), enabling modern PAC learning and randomized algorithmic guarantees.