Skip to content
VibeFormer
Advanced28 min

Probability Inequalities

Markov, Chebyshev, Jensen, Cauchy–Schwarz and Hoeffding bounds, and where each is used in ML theory.

Probability Inequalities

Intuition first

Often you cannot compute a probability exactly — the distribution is unknown, or the integral is intractable — but you can bound it. Inequalities give guarantees using only partial information such as the mean, or the mean and variance.

The trade-off is universality against tightness. Markov's inequality needs only the mean and holds for every non-negative variable, so it must accommodate the worst case and is usually loose. Chebyshev adds the variance and does better. Hoeffding assumes bounded variables and gives exponentially tight bounds — which is why it, not the others, underpins generalisation theory in machine learning.

These are the tools behind every statement of the form "with probability at least 1δ1 - \delta, the error is at most ϵ\epsilon".

Markov's inequality

For a non-negative random variable XX and any a>0a > 0:

P(Xa)E[X]a\Prob(X \geq a) \leq \frac{\E[X]}{a}
Proof by indicatorAdvanced

Define the indicator 1[Xa]\mathbb{1}[X \geq a]. The key observation is the pointwise inequality

X    a1[Xa]X \;\geq\; a\,\mathbb{1}[X \geq a]

Check both cases. If XaX \geq a the right side is aa and indeed XaX \geq a. If X<aX < a the right side is 0 and X0X \geq 0 by assumption — which is exactly where non-negativity is needed.

Take expectations of both sides, using monotonicity of expectation:

E[X]    aE[1[Xa]]=aP(Xa)\E[X] \;\geq\; a\,\E\big[\mathbb{1}[X \geq a]\big] = a\,\Prob(X \geq a)

Divide by a>0a > 0. Note how little was assumed: only X0X \geq 0 and a finite mean. That generality is why the bound is weak.

Chebyshev's inequality

For any random variable with finite mean μ\mu and variance σ2\sigma^2, and any k>0k > 0:

P(Xμkσ)1k2\Prob\big(\lvert X - \mu \rvert \geq k\sigma\big) \leq \frac{1}{k^2}
Chebyshev from MarkovAdvanced

Apply Markov to the non-negative variable Y=(Xμ)2Y = (X - \mu)^2 with threshold a=k2σ2a = k^2\sigma^2:

P((Xμ)2k2σ2)E[(Xμ)2]k2σ2=σ2k2σ2=1k2\Prob\big((X-\mu)^2 \geq k^2\sigma^2\big) \leq \frac{\E[(X-\mu)^2]}{k^2\sigma^2} = \frac{\sigma^2}{k^2\sigma^2} = \frac{1}{k^2}

The event (Xμ)2k2σ2(X-\mu)^2 \geq k^2\sigma^2 is identical to Xμkσ\lvert X - \mu \rvert \geq k\sigma, since squaring is monotone on non-negative values. Done.

The gain over Markov comes from squaring: it converts a one-sided statement about a non-negative variable into a two-sided statement about deviations, and the 1/k21/k^2 decay is faster than Markov's 1/k1/k.

kkChebyshev boundActual, if normal
1100%\leq 100\% (vacuous)31.7%
225%\leq 25\%4.6%
311.1%\leq 11.1\%0.27%
46.25%\leq 6.25\%0.006%

Solved problem 1 · Comparing the three bounds

Exam scores have mean 70 and standard deviation 10. Bound P(X100)\Prob(X \geq 100) using Markov, then Chebyshev, then compare with the normal answer.

Step 1 — Markov, using only the mean

Scores are non-negative, so Markov applies with a=100a = 100:

P(X100)70100=0.70\Prob(X \geq 100) \leq \frac{70}{100} = 0.70

Step 2 — Chebyshev, using mean and variance

100100 is kk standard deviations above the mean where

k=1007010=3k = \frac{100 - 70}{10} = 3

Chebyshev bounds the two-sided event:

P(X7030)190.1111\Prob\big(\lvert X - 70\rvert \geq 30\big) \leq \frac{1}{9} \approx 0.1111

We want only the upper tail. Without a symmetry assumption we cannot simply halve, so the guaranteed bound is

P(X100)0.1111\Prob(X \geq 100) \leq 0.1111

Step 3 — normal assumption, for comparison

If XN(70,100)X \sim \mathcal{N}(70, 100):

P(X100)=P(Z3)0.00135\Prob(X \geq 100) = \Prob(Z \geq 3) \approx 0.00135

Step 4 — compare

Markov:0.70Chebyshev:0.111Normal:0.00135\text{Markov}: 0.70 \qquad \text{Chebyshev}: 0.111 \qquad \text{Normal}: 0.00135

Markov is 500 times too large, Chebyshev 82 times too large. Each additional piece of information — first the variance, then the full shape — tightens the bound by roughly two orders of magnitude.

Answer

Markov 0.70\leq 0.70; Chebyshev 0.111\leq 0.111; normal gives 0.001350.00135. The bounds are correct but weak, which is the price of assuming almost nothing.

Jensen's inequality

For a convex function gg:

E[g(X)]g(E[X])\E[g(X)] \geq g\big(\E[X]\big)

with the inequality reversed for concave gg, and equality only when XX is constant or gg is linear.

Proof via the supporting lineAdvanced

Convexity means the graph of gg lies above every tangent line. At the point μ=E[X]\mu = \E[X] there is a supporting line with some slope cc:

g(x)    g(μ)+c(xμ)for all xg(x) \;\geq\; g(\mu) + c\,(x - \mu) \qquad \text{for all } x

Take expectations of both sides:

E[g(X)]    g(μ)+c(E[X]μ)=g(μ)+c0=g(μ)\E[g(X)] \;\geq\; g(\mu) + c\,\big(\E[X] - \mu\big) = g(\mu) + c \cdot 0 = g(\mu)

The linear term vanishes precisely because we expanded about the mean.

Two instances used repeatedly in this curriculum: g(x)=x2g(x) = x^2 gives E[X2](E[X])2\E[X^2] \geq (\E[X])^2, which is variance non-negativity; and g(x)=logxg(x) = -\log x gives E[logX]logE[X]\E[-\log X] \geq -\log \E[X], which is the step that produces the ELBO in variational inference.

Hoeffding's inequality

For independent X1,,XnX_1, \dots, X_n with Xi[ai,bi]X_i \in [a_i, b_i], and Xˉ\bar{X} their mean:

P(XˉE[Xˉ]t)    2exp(2n2t2i(biai)2)\Prob\big(\lvert \bar{X} - \E[\bar{X}] \rvert \geq t\big) \;\leq\; 2\exp\left(-\frac{2n^2t^2}{\sum_i (b_i - a_i)^2}\right)

For the common case Xi[0,1]X_i \in [0,1] this simplifies to

P(Xˉμt)    2e2nt2\Prob\big(\lvert \bar{X} - \mu \rvert \geq t\big) \;\leq\; 2e^{-2nt^2}

Solved problem 2 · Sample size from Hoeffding

You estimate a classifier's accuracy on nn held-out examples. How large must nn be so that the estimate is within 0.020.02 of the true accuracy with probability at least 0.990.99?

Step 1 — set up

Each example contributes a 0/10/1 correctness indicator, so Xi[0,1]X_i \in [0,1] and Hoeffding applies in its simplified form. We need

2e2nt2δwith t=0.02,  δ=0.012e^{-2nt^2} \leq \delta \qquad \text{with } t = 0.02, \; \delta = 0.01

Step 2 — solve for n

e2nt2δ22nt2lnδ2nln(2/δ)2t2e^{-2nt^2} \leq \frac{\delta}{2} \quad\Longrightarrow\quad -2nt^2 \leq \ln\frac{\delta}{2} \quad\Longrightarrow\quad n \geq \frac{\ln(2/\delta)}{2t^2}

Step 3 — substitute

ln20.01=ln2005.2983\ln\frac{2}{0.01} = \ln 200 \approx 5.29832t2=2(0.02)2=2×0.0004=0.00082t^2 = 2(0.02)^2 = 2 \times 0.0004 = 0.0008n5.29830.0008=6622.9n6623n \geq \frac{5.2983}{0.0008} = 6622.9 \quad\Longrightarrow\quad n \geq 6623

Step 4 — compare with Chebyshev

Chebyshev needs Var(Xˉ)=σ2/n\Var(\bar X) = \sigma^2/n with σ20.25\sigma^2 \leq 0.25 for a [0,1][0,1] variable:

P(Xˉμt)σ2nt20.25n(0.0004)\Prob(\lvert \bar X - \mu\rvert \geq t) \leq \frac{\sigma^2}{nt^2} \leq \frac{0.25}{n(0.0004)}

Setting this to 0.010.01:

n0.250.01×0.0004=0.254×106=62,500n \geq \frac{0.25}{0.01 \times 0.0004} = \frac{0.25}{4\times10^{-6}} = 62{,}500

Nearly ten times more data for the same guarantee.

Step 5 — and the normal approximation

Assuming normality, t=zσ/nt = z\sigma/\sqrt{n} with z=2.576z = 2.576 for 99% and σ0.5\sigma \leq 0.5:

n(2.576×0.50.02)2=(64.4)24148n \geq \left(\frac{2.576 \times 0.5}{0.02}\right)^2 = (64.4)^2 \approx 4148

Answer

Hoeffding requires n6,623n \geq 6{,}623; Chebyshev 62,50062{,}500; the normal approximation 4,1484{,}148.

Hoeffding is only 60% more conservative than the normal approximation while requiring no distributional assumption at all — which is why it is the tool of choice for guarantees.

Summary

InequalityNeedsBoundTightness
MarkovX0X \geq 0, meanE[X]/a\E[X]/aVery loose
ChebyshevMean, variance1/k21/k^2Loose
JensenConvexityDirectionalExact tool, not a tail bound
HoeffdingIndependence, bounded2e2nt22e^{-2nt^2}Tight
ChernoffIndependence, MGF existsExponentialTightest
python
import numpy as np
from scipy import stats

mu, sigma = 70, 10

print(f"Markov     P(X>=100) <= {mu/100:.5f}")
print(f"Chebyshev  P(X>=100) <= {1/3**2:.5f}")
print(f"Normal     P(X>=100)  = {stats.norm.sf(100, mu, sigma):.5f}")

# Sample size for |X̄ - μ| <= 0.02 with 99% confidence.
t, delta = 0.02, 0.01
n_hoeff = np.ceil(np.log(2/delta) / (2 * t**2))
n_cheb = np.ceil(0.25 / (delta * t**2))
n_norm = np.ceil((stats.norm.ppf(1 - delta/2) * 0.5 / t) ** 2)
print(f"\nn needed — Hoeffding {n_hoeff:.0f}  Chebyshev {n_cheb:.0f}  normal {n_norm:.0f}")

# Check Hoeffding empirically at n = 6623.
rng = np.random.default_rng(0)
n = int(n_hoeff)
means = rng.binomial(1, 0.85, size=(20_000, n)).mean(axis=1)
violations = np.mean(np.abs(means - 0.85) >= t)
print(f"observed violation rate {violations:.5f}  <= bound {2*np.exp(-2*n*t**2):.5f}")

Exercise 1

A non-negative variable has mean 5. Bound P(X20)\Prob(X \geq 20). Then, told additionally that σ=2\sigma = 2, improve it.

Show solution

Markov:

P(X20)520=0.25\Prob(X \geq 20) \leq \frac{5}{20} = 0.25

Chebyshev. The threshold is kk standard deviations above the mean with

k=2052=7.5k = \frac{20 - 5}{2} = 7.5P(X515)17.52=156.250.01778\Prob\big(\lvert X - 5\rvert \geq 15\big) \leq \frac{1}{7.5^2} = \frac{1}{56.25} \approx 0.01778

Adding the variance tightened the bound from 0.250.25 to 0.01780.0178 — a fourteen-fold improvement, for one extra number.

Exercise 2

Use Jensen's inequality to show that the arithmetic mean is at least the geometric mean for positive numbers.

Show solution

Let XX take the values x1,,xn>0x_1, \dots, x_n > 0 each with probability 1/n1/n. Apply Jensen to the concave function g(x)=logxg(x) = \log x, which reverses the inequality:

E[logX]    logE[X]\E[\log X] \;\leq\; \log \E[X]

The left side is

E[logX]=1ni=1nlogxi=log(i=1nxi)1/n\E[\log X] = \frac{1}{n}\sum_{i=1}^n \log x_i = \log\left(\prod_{i=1}^n x_i\right)^{1/n}

the log of the geometric mean. The right side is log\log of the arithmetic mean. Since log\log is strictly increasing, the inequality passes through:

(i=1nxi)1/n    1ni=1nxi\left(\prod_{i=1}^n x_i\right)^{1/n} \;\leq\; \frac{1}{n}\sum_{i=1}^n x_i

which is AM–GM. Equality holds exactly when XX is constant, that is when all xix_i are equal — matching the equality condition in Jensen.

This is why the geometric mean is the right average for multiplicative quantities such as growth rates: the arithmetic mean of returns systematically overstates the compounded result.


Next: Laws of Large Numbers, which Chebyshev proves in three lines.