24.9 Concentration Inequalities

Whenever we report a model's test accuracy, we are reporting a measurement made on a finite sample. In Section 24.5, we attached an error bar to that measurement, ±1.96 σ^/n\pm1.96\,\hat\sigma/\sqrt n, by invoking the central limit theorem. That Gaussian approximation is convenient and often accurate, but it is exact only in the limit n→∞n\to\infty, and it relies on plugging in an estimated standard deviation σ^\hat\sigma. Earlier, in Section 24.1, we saw a bound that holds with no approximations at every finite nn, Chebyshev's inequality, yet it turned out to be painfully weak. This leaves us with a natural question: how far can a test-set error stray from the truth if we want a guarantee that holds at the sample size we actually have, and remains useful even when we demand that it almost never fail?

To make the gap concrete, consider a classifier that makes 830 mistakes on 10,000 test images, giving an observed error rate of 8.3%. Chebyshev's inequality bounds the probability that the average of nn independent draws misses its mean by tt or more by σ2/(nt2)\sigma^2/(nt^2). Because a 0/1 outcome has variance at most σ2≤14\sigma^2\leq\tfrac14, Chebyshev guarantees that the true error lies within ±2.2%\pm2.2\% of 8.3% with 95% confidence. That is already wider than the Gaussian interval, and worse still, it collapses when we demand high reliability: ask for a guarantee that fails only once in a million, and Chebyshev answers ±500%\pm500\%, which tells us nothing at all. Yet the true probability that an average of 0/1 outcomes strays far from its mean decays exponentially in nn, not like 1/n1/n. A bound that captures this exponential decay answers ±1.4%\pm1.4\% at 95% confidence and ±2.7%\pm2.7\% at one in a million.

The key trick behind these sharper bounds is surprisingly simple: apply Markov's inequality not to the average itself, but to its exponential, which turns a sum of independent terms into a product. Sergei Bernstein developed bounds of this kind in the 1920s, Herman Chernoff used the method in 1952 to measure how rapidly statistical tests become reliable, and Wassily Hoeffding gave in 1963 the clean form used throughout machine learning (Hoeffding, 1963).

Why would a practitioner ever ask for a guarantee that fails only once in a million? In practice, we rarely evaluate just one model: a learner compares many candidates and keeps the best. Guaranteeing that none of them looks good by chance requires a tiny failure probability for each one, and only an exponentially shrinking tail makes that affordable at a realistic sample size, a theme we will develop fully in Section 24.10. In this section, we first use exponential tail bounds to size a test set for a desired precision. We then apply the exact same machinery to the coordinates of a random vector in Rd\mathbb{R}^d, revealing two striking geometric facts: a standard Gaussian vector in R784\mathbb{R}^{784} almost always has length within a few percent of 28, and two independent random directions are nearly orthogonal. Both facts underpin neural network initialization and high-dimensional embeddings.

Three results from this section are worth committing to memory: the Chernoff method (24.9.1), Hoeffding's confidence interval (24.9.5), and the concentration of the Euclidean norm (24.9.10).

rng = np.random.default_rng()

24.9.1 Exponential Tail Bounds#

The Gaussian confidence interval is narrow because Gaussian tails decay like e−z2/2e^{-z^2/2}, a rate inherited from the central limit theorem and therefore guaranteed only in the limit of large nn. We want that same rapid decay combined with a guarantee that holds at every finite sample size. Before building such a bound, let us see just how far Chebyshev's inequality falls short of the truth.

24.9.1.1 Chebyshev's Rate#

Chebyshev's bound is simply Markov's inequality (Section 24.1) applied to a squared deviation. Consider the sample mean Xˉ\bar X of nn independent draws, each with mean μ\mu and finite variance σ2\sigma^2. Because the expected squared deviation is E[(Xˉ−μ)2]=Var(Xˉ)=σ2/n\mathbb{E}[(\bar X-\mu)^2]=\textrm{Var}(\bar X)=\sigma^2/n, Markov's inequality yields

P(∣Xˉ−μ∣≥t)≤σ2nt2.P\bigl(|\bar X-\mu|\geq t\bigr)\leq\frac{\sigma^2}{nt^2}.

Here the miss probability shrinks only like 1/n1/n. To push the failure probability from 11 down to 10−610^{-6} at a fixed deviation tt, we must grow the sample size a million-fold.

How small is the actual miss probability? The simplest setting where we can compute it exactly is a fair coin. Let p^\hat p denote the fraction of heads in nn independent flips, and ask for the probability that p^\hat p misses 12\tfrac12 by t=0.1t=0.1 or more. Each flip has variance 14\tfrac14, so Chebyshev's bound is 0.25/(0.01 n)=25/n0.25/(0.01\,n)=25/n. The exact probability is a sum of binomial probabilities, which we evaluate in log space so that n=5,000n=5{,}000 does not underflow to zero.

def exact_tail(n, t):
    """P(|p_hat - 1/2| >= t) for n fair flips, a binomial sum in log space."""
    k = np.arange(n + 1)
    log_pmf = n * np.log(0.5) + np.concatenate(
        ([0.0], np.cumsum(np.log((n - k[1:] + 1) / k[1:]))))
    in_tail = log_pmf[np.abs(k / n - 0.5) >= t - 1e-12]  # fp-safe boundary
    m = in_tail.max()
    return np.exp(m) * np.exp(in_tail - m).sum()  # stable log-sum-exp

At n=1,000n=1{,}000 Chebyshev allows a miss in one experiment out of forty. Before reading the table, guess how often such a miss really happens.

t = 0.1
print(f'{"n":>6} {"exact":>10} {"Chebyshev":>10}')
for n in (10, 100, 1000, 5000):
    print(f'{n:6d} {exact_tail(n, t):10.2e} {0.25 / (n * t**2):10.2e}')
     n      exact  Chebyshev
    10   7.54e-01   2.50e+00
   100   5.69e-02   2.50e-01
  1000   2.73e-10   2.50e-02
  5000   1.30e-45   5.00e-03

At n=10n=10 the exact tail is 0.750.75 while the bound, 2.52.5, is trivial. At n=100n=100 the bound drops to 0.250.25, roughly four times the exact 0.0570.057. Beyond that point the two curves part ways dramatically. At n=1,000n=1{,}000 the exact tail is 2.7×10−102.7\times10^{-10} whereas Chebyshev still allows 0.0250.025, eight orders of magnitude larger; by n=5,000n=5{,}000 the gap has widened to forty-two orders of magnitude. Every tenfold increase in nn merely divides Chebyshev's bound by ten, while the exact tail sheds a fixed number of decimal places for every hundred flips: on a logarithmic scale it descends along a straight line.

Unfortunately, Chebyshev's bound cannot be tightened without assuming more about the distribution. As we saw in Section 24.1, it holds with equality for a distribution supported on three points, so no bound relying solely on the mean and variance can improve upon it in general. A coin flip, however, has far more structure than two finite moments: its values are bounded, which keeps all of its higher moments small as well. To harness all moments at once, we turn to the moment generating function.

24.9.1.2 The Chernoff Method#

To see how to use higher moments, look at what Markov's and Chebyshev's inequalities have in common. Suppose a function gg lies everywhere above the indicator 1{x≥t}\mathbf 1\{x\geq t\}, a majorant of the indicator. Taking expectations immediately gives P(X≥t)=E[1{X≥t}]≤E[g(X)]P(X\geq t)=\mathbb{E}[\mathbf 1\{X\geq t\}]\leq\mathbb{E}[g(X)]. Markov's inequality chooses the linear majorant g(x)=x/tg(x)=x/t for a nonnegative XX, while Chebyshev's chooses the quadratic g(x)=(x/t)2g(x)=(x/t)^2 (applied to the centered deviation X−μX-\mu). Now notice that for any λ>0\lambda>0, the exponential eλ(x−t)e^{\lambda(x-t)} also lies above the indicator across the entire real line. Panel (a) of Figure 24.9.1 compares all three majorants for a nonnegative XX. Since the bound is simply the average of g(X)g(X), what determines its tightness is how small gg stays where the probability mass of XX actually sits.

Figure 24.9.1:

A tail bound is the expectation of a function lying above the indicator. (a) For a threshold t=2t=2, the indicator 1{x≥t}\mathbf{1}\{x\geq t\} (black) and three functions above it: Markov's x/tx/t, Chebyshev's (x/t)2(x/t)^2, and Chernoff's eλ(x−t)e^{\lambda(x-t)} with λ=1.5\lambda=1.5. The shaded bump marks where the mass of XX sits; each bound is the average of its function under that mass, and raising λ\lambda makes the exponential small there. (b) The Chernoff exponent −λnt+nλ2/8-\lambda nt+n\lambda^2/8 for the mean of n=100n=100 fair coins at t=0.1t=0.1. Every λ>0\lambda>0 gives a valid bound; the best, at the minimum λ=4t\lambda=4t of the parabola, is e−2e^{-2}.

The expectation of this exponential has a standard name. The moment generating function (MGF) of XX is E[eλX]\mathbb{E}[e^{\lambda X}], viewed as a function of λ\lambda wherever the expectation is finite. For a fair coin centered at zero, Z∈{−12,12}Z\in\{-\tfrac12,\tfrac12\}, it is simply 12(eλ/2+e−λ/2)=cosh⁡(λ/2)\tfrac12(e^{\lambda/2}+e^{-\lambda/2})=\cosh(\lambda/2). The MGF is finite for every λ\lambda whenever XX is bounded, but it is infinite for every λ>0\lambda>0 when the right tail decays only polynomially, as with a Student-tt variable; for such heavy-tailed variables, the exponential method below does not apply.

Applying Markov's inequality to the nonnegative random variable eλXe^{\lambda X} gives the bound in one line. Because x↦eλxx\mapsto e^{\lambda x} is strictly increasing for λ>0\lambda>0, the event {X≥t}\{X\geq t\} is identical to {eλX≥eλt}\{e^{\lambda X}\geq e^{\lambda t}\}, so

P(X≥t)=P(eλX≥eλt)≤e−λt E[eλX],henceP(X≥t)≤inf⁡λ>0 e−λt E[eλX].(24.9.1)P(X \geq t) = P\bigl(e^{\lambda X} \geq e^{\lambda t}\bigr) \leq e^{-\lambda t}\,\mathbb{E}\bigl[e^{\lambda X}\bigr], \qquad\textrm{hence}\qquad P(X \geq t) \leq \inf_{\lambda > 0}\, e^{-\lambda t}\, \mathbb{E}\bigl[e^{\lambda X}\bigr]. \tag{24.9.1}

Every choice of λ>0\lambda>0 yields a valid upper bound; taking the infimum simply keeps the tightest one. This two-step recipe is the Chernoff method.

There is a second, equally decisive reason why the exponential is the right majorant. When S=X1+⋯+XnS=X_1+\cdots+X_n is a sum of independent random variables, eλS=∏i=1neλXie^{\lambda S}=\prod_{i=1}^n e^{\lambda X_i} becomes a product of independent factors, and the expectation of a product of independent variables is the product of their expectations:

E[eλS]=∏i=1nE[eλXi].\mathbb{E}\bigl[e^{\lambda S}\bigr]=\prod_{i=1}^n\mathbb{E}\bigl[e^{\lambda X_i}\bigr].

Thus the moment generating function of a sum factorizes into the product of the MGFs of its terms, so the logarithm of the Chernoff bound splits into a sum of nn pieces and scales linearly with nn. No polynomial majorant enjoys this property: E[S4]\mathbb{E}[S^4] does not factor into a product of fourth moments. All that remains is to bound the MGF of a single summand.

24.9.1.3 The Fair Coin#

Let us work through the fair coin all the way to the end, since this simplest case already contains every step of the general proof. A centered flip Z=X−12Z=X-\tfrac12 takes the values ±12\pm\tfrac12 with equal probability, so its MGF is E[eλZ]=cosh⁡(λ/2)\mathbb{E}[e^{\lambda Z}]=\cosh(\lambda/2). Comparing the Taylor series of cosh⁡u\cosh u and eu2/2e^{u^2/2} term by term gives

cosh⁡u=∑k≥0u2k(2k)!≤∑k≥0(u2/2)kk!=eu2/2,\cosh u=\sum_{k\geq0}\frac{u^{2k}}{(2k)!} \leq\sum_{k\geq0}\frac{(u^2/2)^k}{k!}=e^{u^2/2},

because (2k)!≥2⋅4⋯(2k)=2kk!(2k)!\geq2\cdot4\cdots(2k)=2^kk!: the even factors of (2k)!(2k)! alone already produce 2kk!2^kk!, and every odd factor is at least 11. Setting u=λ/2u=\lambda/2, we see that a single centered flip satisfies E[eλZ]≤eλ2/8\mathbb{E}[e^{\lambda Z}]\leq e^{\lambda^2/8} for every λ\lambda. By comparison, a Gaussian N(0,σ2)\mathcal N(0,\sigma^2) has E[eλX]=eλ2σ2/2\mathbb{E}[e^{\lambda X}]=e^{\lambda^2\sigma^2/2} (found by completing the square in the integral), so a centered coin's MGF is never larger than that of a Gaussian with standard deviation 12\tfrac12.

Now consider nn independent flips. The event p^−12≥t\hat p-\tfrac12\geq t is the same as ∑i=1nZi≥nt\sum_{i=1}^n Z_i\geq nt, so the Chernoff method and the product rule give

P(p^−12≥t)≤e−λnt∏i=1nE[eλZi]≤exp⁡(−λnt+nλ28).P\bigl(\hat p-\tfrac12\geq t\bigr) \leq e^{-\lambda nt}\prod_{i=1}^n\mathbb{E}\bigl[e^{\lambda Z_i}\bigr] \leq\exp\Bigl(-\lambda nt+\frac{n\lambda^2}{8}\Bigr).

The exponent is a simple parabola in λ\lambda. Panel (b) of Figure 24.9.1 plots it for n=100n=100 and t=0.1t=0.1, where it equals −10λ+12.5λ2-10\lambda+12.5\lambda^2. Any λ>0\lambda>0 gives a valid bound, for example e−0.875≈0.42e^{-0.875}\approx0.42 at λ=0.1\lambda=0.1. The tightest bound sits at the vertex of the parabola, λ=4t\lambda=4t, where the exponent simplifies to −4nt2+2nt2=−2nt2-4nt^2+2nt^2=-2nt^2. By symmetry the lower tail obeys the same bound, and adding the two tails yields

P(∣p^−12∣≥t)≤2e−2nt2.P\bigl(|\hat p-\tfrac12|\geq t\bigr)\leq2e^{-2nt^2}.

The probability of straying by tt now decays exponentially in nt2nt^2. At n=100n=100 and t=0.1t=0.1 this gives 2e−2≈0.272e^{-2}\approx0.27, and at n=1,000n=1{,}000 it drops to 2e−20≈4.1×10−92e^{-20}\approx4.1\times10^{-9}, a dramatic improvement over Chebyshev's 0.0250.025.

Why does the exponential majorant work so well? At the threshold S=ntS=nt, the function eλ(S−nt)e^{\lambda(S-nt)} equals 11, while at the mean S=0S=0, where almost all the probability mass sits, it shrinks to e−λnte^{-\lambda nt}, exponentially small in nn. What prevents us from pushing λ\lambda to infinity is that the function grows steeply for S>0S>0, so upward fluctuations carry disproportionate weight. The product of the MGFs, bounded by enλ2/8e^{n\lambda^2/8}, measures that penalty, and the optimal λ=4t\lambda=4t strikes the exact balance between the two.

Notice that the entire derivation relied on just one property of the coin: the MGF of a centered flip is bounded by eλ2/8e^{\lambda^2/8}, the MGF of a Gaussian with standard deviation 12\tfrac12, which is half the coin's range. Hoeffding's lemma generalizes this single step, showing that every random variable confined to an interval [a,b][a,b] obeys the same bound with (b−a)/2(b-a)/2 in place of 12\tfrac12.

24.9.1.4 Hoeffding's Lemma and Hoeffding's Inequality#

A test-set loss is rarely a fair coin. An error rate of 8.3% behaves like a heavily biased coin, and a clipped loss takes a continuum of values rather than just 00 and 11. We would like the fair coin's exponential bound to hold for any bounded random variable. The lemma that delivers this is the main technical step of the section, and its proof rests on one elementary fact about variances.

Proposition (variance of a bounded variable). If YY takes values in [a,b][a,b], then Var(Y)≤(b−a)2/4\textrm{Var}(Y)\leq(b-a)^2/4, with equality when YY takes the values aa and bb with probability 12\tfrac12 each.

Proof. The mean minimizes the expected squared deviation, since E[(Y−c)2]=Var(Y)+(E[Y]−c)2\mathbb{E}[(Y-c)^2]=\textrm{Var}(Y)+(\mathbb{E}[Y]-c)^2 for every choice of center cc. Taking c=(a+b)/2c=(a+b)/2, every point of [a,b][a,b] lies within (b−a)/2(b-a)/2 of the midpoint, so

Var(Y)≤E[(Y−a+b2)2]≤(b−a2)2.\textrm{Var}(Y)\leq\mathbb{E}\Bigl[\Bigl(Y-\frac{a+b}{2}\Bigr)^2\Bigr] \leq\Bigl(\frac{b-a}{2}\Bigr)^2.

Both inequalities become equalities when YY places equal mass at the two endpoints aa and bb. ■\blacksquare

The fair coin on [0,1][0,1] is precisely this extreme case, with variance 14\tfrac14. With this variance bound in hand, we can prove Hoeffding's lemma.

Proposition (Hoeffding's lemma). Let XX be a random variable with E[X]=0\mathbb{E}[X]=0 taking values in [a,b][a,b]. Then for every λ∈R\lambda\in\mathbb{R},

E[eλX]≤exp⁡ ⁣(λ2(b−a)28).(24.9.2)\mathbb{E}\bigl[e^{\lambda X}\bigr] \leq \exp\!\left(\frac{\lambda^2 (b-a)^2}{8}\right). \tag{24.9.2}

Proof. We want to show that the log-MGF ψ(λ)=log⁡E[eλX]\psi(\lambda)=\log\mathbb{E}[e^{\lambda X}] grows no faster than the parabola λ2(b−a)2/8\lambda^2(b-a)^2/8. Because XX is bounded, ψ\psi is finite and smooth everywhere, allowing us to differentiate under the expectation. At λ=0\lambda=0, we have ψ(0)=log⁡1=0\psi(0)=\log 1=0 and

ψ′(λ)=E[XeλX]E[eλX],soψ′(0)=E[X]=0.\psi'(\lambda) = \frac{\mathbb{E}[X e^{\lambda X}]}{\mathbb{E}[e^{\lambda X}]}, \qquad\textrm{so}\qquad \psi'(0) = \mathbb{E}[X] = 0 .

Just as for the log-partition function of an exponential family (Section 24.4), the second derivative of ψ\psi is a variance. Define the tilted distribution qλq_\lambda by reweighting the distribution of XX by eλxe^{\lambda x} and normalizing. Under qλq_\lambda, ψ′(λ)\psi'(\lambda) is the mean of XX, and differentiating once more gives

ψ′′(λ)=E[X2eλX]E[eλX]−(E[XeλX]E[eλX]) ⁣2=Varqλ(X).\psi''(\lambda) = \frac{\mathbb{E}[X^2 e^{\lambda X}]}{\mathbb{E}[e^{\lambda X}]} - \left(\frac{\mathbb{E}[X e^{\lambda X}]}{\mathbb{E}[e^{\lambda X}]}\right)^{\!2} = \textrm{Var}_{q_\lambda}(X).

Crucially, exponential tilting only reweights points; it never moves mass outside [a,b][a,b]. Our variance bound therefore holds for qλq_\lambda at every λ\lambda, giving ψ′′(λ)≤(b−a)2/4\psi''(\lambda)\leq(b-a)^2/4. Taylor's theorem with the Lagrange remainder now finishes the proof: for some ξ\xi between 00 and λ\lambda,

ψ(λ)=ψ(0)+λ ψ′(0)+λ22 ψ′′(ξ)≤λ2(b−a)28,\psi(\lambda) = \psi(0) + \lambda\,\psi'(0) + \frac{\lambda^2}{2}\,\psi''(\xi) \leq \frac{\lambda^2 (b-a)^2}{8},

and exponentiating both sides yields (24.9.2). ■\blacksquare

In words, any bounded, centered random variable has a moment generating function no larger than that of a Gaussian with standard deviation (b−a)/2(b-a)/2. For a centered coin, b−a=1b-a=1, so the lemma immediately recovers the bound cosh⁡(λ/2)≤eλ2/8\cosh(\lambda/2)\leq e^{\lambda^2/8} that we proved by Taylor series. With that single ingredient in place, our coin proof carries over verbatim to any average of independent bounded variables.

Proposition (Hoeffding's inequality). Let X1,…,XnX_1,\ldots,X_n be independent random variables with Xi∈[a,b]X_i\in[a,b], and let Xˉ=1n∑iXi\bar X = \frac1n\sum_i X_i. Then for every t>0t>0,

P(∣Xˉ−E[Xˉ]∣≥t)≤2exp⁡ ⁣(−2nt2(b−a)2).(24.9.3)P\bigl(|\bar X - \mathbb{E}[\bar X]| \geq t\bigr) \leq 2\exp\!\left(-\frac{2 n t^2}{(b-a)^2}\right). \tag{24.9.3}

Proof. Let Zi=Xi−E[Xi]Z_i = X_i - \mathbb{E}[X_i]. Each ZiZ_i has mean zero and lies in an interval of length b−ab-a, so Hoeffding's lemma applies to every term. For any λ>0\lambda>0, the Chernoff method (24.9.1) and the product rule give

P(Xˉ−E[Xˉ]≥t)=P(∑iZi≥nt)≤e−λnt∏i=1nE[eλZi]≤exp⁡ ⁣(−λnt+nλ2(b−a)28).\begin{aligned} P(\bar X - \mathbb{E}[\bar X] \geq t) &= P\Bigl(\sum_i Z_i \geq nt\Bigr) \leq e^{-\lambda n t} \prod_{i=1}^n \mathbb{E}\bigl[e^{\lambda Z_i}\bigr] \\ &\leq \exp\!\left(-\lambda n t + \frac{n\lambda^2 (b-a)^2}{8}\right). \end{aligned}

This is the same parabola we minimized for the coin, with (b−a)2(b-a)^2 in place of 11. Its minimum occurs at λ=4t/(b−a)2\lambda = 4t/(b-a)^2, where the exponent equals −2nt2/(b−a)2-2nt^2/(b-a)^2. Applying the same argument to −Zi-Z_i bounds the lower tail by the same quantity, and adding the two tails produces the factor of 22. ■\blacksquare

Thus the sample mean of nn independent bounded variables strays from its expectation by tt with a probability that decays exponentially in nt2nt^2, where tt is measured in units of the range b−ab-a. Notice what the bound does not require: no Gaussianity, no variance estimate, and no asymptotic limit. It asks only for boundedness and independence, and it holds at every finite nn. Independence, however, is a genuine requirement: the bound does not apply to the correlated samples of a Markov chain.

Look back at the proof and you will notice we never actually needed all the intervals to have the same length. If the independent centered variables satisfy Yi∈[ai,bi]Y_i\in[a_i,b_i], the product of Hoeffding's lemma bounds replaces n(b−a)2n(b-a)^2 by ∑i(bi−ai)2\sum_i(b_i-a_i)^2, and the same quadratic minimization gives

P(∣∑iYi∣≥s)≤2exp⁡(−2s2∑i(bi−ai)2).(24.9.4)P\Bigl(\Bigl|\sum_iY_i\Bigr|\geq s\Bigr) \leq2\exp\Bigl(-\frac{2s^2}{\sum_i(b_i-a_i)^2}\Bigr). \tag{24.9.4}

We will put this unequal-range version to work shortly when we analyze random directions in high dimensions.

Let us translate Hoeffding's inequality into a practical test-set size. For losses in [0,1][0,1], we have b−a=1b-a=1, so the failure probability is at most δ\delta once n≥log⁡(2/δ)/(2t2)n\geq\log(2/\delta)/(2t^2). To estimate an error rate within t=0.01t=0.01 with failure probability δ=0.05\delta=0.05, we need n≥log⁡40/(2⋅10−4)=18,444.4n\geq\log 40/(2\cdot10^{-4})=18{,}444.4, or 18,44518{,}445 test examples. This is the figure quoted in Section 3.5, roughly twice the 9,604 examples suggested by the asymptotic Gaussian approximation.

Equivalently, setting the right-hand side of (24.9.3) equal to δ\delta and solving for tt gives the confidence-interval form used in practice: with probability at least 1−δ1-\delta,

∣Xˉ−E[Xˉ]∣≤(b−a)log⁡(2/δ)2n.(24.9.5)\bigl|\bar X - \mathbb{E}[\bar X]\bigr| \leq (b-a)\sqrt{\frac{\log(2/\delta)}{2n}} . \tag{24.9.5}

Just like the Gaussian interval μ^±1.96 σ^/n\hat\mu\pm1.96\,\hat\sigma/\sqrt n, the half-width shrinks at the 1/n1/\sqrt n rate, but it comes with a strict finite-sample guarantee.

Returning to our classifier with 830 errors on 10,000 images at δ=0.05\delta=0.05, Hoeffding gives ±1.36%\pm1.36\%, compared with the Gaussian interval ±1.960.083⋅0.917/104=±0.54%\pm1.96\sqrt{0.083\cdot0.917/10^4}=\pm0.54\%. The two differ only in their constants: Hoeffding replaces the empirical standard deviation σ^=0.28\hat\sigma=0.28 by its worst-case value (b−a)/2=0.5(b-a)/2=0.5, and replaces the Gaussian quantile 1.961.96 by 2log⁡(2/δ)=2.72\sqrt{2\log(2/\delta)}=2.72, making the interval 2.52.5 times wider. Whenever the actual spread of the data is much smaller than their range, Hoeffding is inevitably conservative, a gap that Bernstein's inequality will close below.

One might wonder whether the constant 18\tfrac18 in Hoeffding's lemma can be sharpened. It cannot: a variable placing probability 12\tfrac12 at each endpoint of [a,b][a,b] attains 18\tfrac18 to second order in λ\lambda (Exercise 1).

24.9.1.5 The Fair Coin in Numbers#

Let us see how close Hoeffding's bound 2e−2nt22e^{-2nt^2} comes to the exact tail of the fair coin at t=0.1t=0.1. We print both alongside their ratio, and plot them together with Chebyshev's bound against nn on a logarithmic scale.

print(f'{"n":>6} {"exact":>10} {"Hoeffding":>10} {"ratio":>8}')
for n in (10, 100, 1000, 5000):
    hoeffding = 2 * np.exp(-2 * n * t**2)
    print(f'{n:6d} {exact_tail(n, t):10.2e} {hoeffding:10.2e} '
          f'{hoeffding / exact_tail(n, t):8.1f}')

ns = np.arange(10, 701, 10)
d2l.plot(ns, [np.array([exact_tail(n, t) for n in ns]),
              0.25 / (ns * t**2), 2 * np.exp(-2 * ns * t**2)],
         'n', 'P(|p_hat - 1/2| >= 0.1)',
         legend=['exact', 'Chebyshev', 'Hoeffding'], yscale='log')
     n      exact  Hoeffding    ratio
    10   7.54e-01   1.64e+00      2.2
   100   5.69e-02   2.71e-01      4.8
  1000   2.73e-10   4.12e-09     15.1
  5000   1.30e-45   7.44e-44     57.2

At n=10n=10 both bounds exceed 11 and are uninformative. At n=100n=100, Chebyshev's 0.250.25 is actually a touch tighter than Hoeffding's 0.270.27: at small sample sizes the leading constants decide, and Chebyshev benefits from knowing the exact variance 14\tfrac14. Once nn grows, however, the exponential rate takes over completely. Hoeffding stays within a factor of 15 of the exact tail at n=1,000n=1{,}000 and within a factor of 57 at n=5,000n=5{,}000.

On the logarithmic plot, the exact tail and Hoeffding's bound trace nearly parallel straight lines. The logarithm of Hoeffding's bound drops by 2t2=0.022t^2=0.02 per flip, while the exact tail drops by roughly 0.02010.0201 per flip. That sharper slope is the Kullback–Leibler divergence DKL(0.6∥0.5)=0.6log⁡1.2+0.4log⁡0.8D_{\textrm{KL}}(0.6\|0.5)=0.6\log1.2+0.4\log0.8 between a biased coin with probability 0.60.6 and a fair coin (Section 25.3). Applying the Chernoff method with the exact MGF of a Bernoulli variable recovers this exact rate (Exercise 3).

Of course, when nn is tiny, no inequality can create evidence that is not there. Recall the coin from the chapter introduction that landed heads 9 times in 13 flips, a deviation of t=2.5/13t=2.5/13 from 12\tfrac12. Hoeffding's bound on such a deviation is 2e−2⋅13⋅(2.5/13)2=2e−0.96≈0.772e^{-2\cdot13\cdot(2.5/13)^2}=2e^{-0.96}\approx0.77, which rules out nothing. Even the exact two-sided binomial probability is 0.270.27: thirteen flips simply cannot rule out a fair coin.

24.9.1.6 Sub-Gaussian and Sub-Exponential Variables#

Hoeffding's interval for our 8.3% classifier was 2.5 times wider than the Gaussian interval because it knows only the range of a 0/1 loss and ignores its small variance. Bernstein's inequality incorporates both.

Proposition (Bernstein's inequality). Let X1,…,XnX_1,\ldots,X_n be independent with Var(Xi)≤σ2\textrm{Var}(X_i)\leq\sigma^2 and ∣Xi−E[Xi]∣≤M|X_i-\mathbb{E}[X_i]|\leq M. Then for every t>0t>0,

P(∣Xˉ−E[Xˉ]∣≥t)≤2exp⁡ ⁣(−nt22(σ2+Mt/3)).(24.9.6)P\bigl(|\bar X - \mathbb{E}[\bar X]| \geq t\bigr) \leq 2\exp\!\left(-\frac{n t^2}{2\bigl(\sigma^2 + M t/3\bigr)}\right). \tag{24.9.6}

Once again, the proof is the Chernoff method (Boucheron et al., 2013), paired with an MGF bound that tracks both the variance and the range (worked out in Exercise 7). Look at the two regimes in the denominator. When tt is small, σ2\sigma^2 dominates Mt/3Mt/3 and the bound behaves like a Gaussian tail with the true variance σ2\sigma^2. When tt is large, the linear term Mt/3Mt/3 takes over and the tail decays only exponentially in tt rather than as a Gaussian in t2t^2.

How much does accounting for the variance help in practice? Consider a classifier with a 2% error rate on n=10,000n=10{,}000 test examples: each 0/1 loss has variance σ2=0.02⋅0.98\sigma^2=0.02\cdot0.98, while its centered deviation satisfies M=1M=1. Setting the right-hand side of (24.9.6) equal to δ\delta produces a quadratic equation in tt, namely nt2/(2(σ2+t/3))=log⁡(2/δ)nt^2/(2(\sigma^2+t/3))=\log(2/\delta). Below, we solve this quadratic at δ=0.05\delta=0.05 for both our 8.3% and 2% error rates alongside Hoeffding and the Gaussian interval, computing both the plug-in estimate (using the observed rate in the variance) and a fully guaranteed version that we explain right after the output.

def half_widths(p, n, delta=0.05, z=1.96):
    """Hoeffding, Bernstein (plug-in, guaranteed), Gaussian half-widths."""
    L = np.log(2 / delta)
    hoeffding = np.sqrt(L / (2 * n))
    c = 2 * L / 3  # Bernstein with M = 1: n t^2 - c t - 2 L var = 0
    bernstein = lambda var: (c + np.sqrt(c**2 + 8 * n * L * var)) / (2 * n)
    plug_in = t = bernstein(p * (1 - p))
    for _ in range(20):  # true rate at most p + t: a fixed point in t
        t = bernstein((p + t) * (1 - p - t))
    return hoeffding, plug_in, t, z * np.sqrt(p * (1 - p) / n)

Evaluating half_widths(p, 10000) at both the 8.3%8.3\% and 2.0%2.0\% error rates compares the resulting 95% confidence half-widths across all four methods:

for p in (0.083, 0.02):
    hoeffding, plug_in, bernstein, gauss = half_widths(p, 10000)
    print(f'error {p:.1%}: Hoeffding ±{hoeffding:.2%}, Bernstein '
          f'±{plug_in:.2%} (plug-in) ±{bernstein:.2%} (guaranteed), '
          f'Gaussian ±{gauss:.2%}')
error 8.3%: Hoeffding ±1.36%, Bernstein ±0.76% (plug-in) ±0.79% (guaranteed), Gaussian ±0.54%
error 2.0%: Hoeffding ±1.36%, Bernstein ±0.39% (plug-in) ±0.43% (guaranteed), Gaussian ±0.27%

At a 2% error rate, Bernstein's plug-in half-width shrinks to ±0.39%\pm0.39\%, compared with Hoeffding's ±1.36%\pm1.36\%: roughly three and a half times tighter, and within a factor of 1.41.4 of the asymptotic Gaussian ±0.27%\pm0.27\%. At 8.3% error the improvement is smaller but still substantial, narrowing ±1.36%\pm1.36\% down to ±0.76%\pm0.76\%.

Strictly speaking, those two plug-in numbers (±0.39%\pm0.39\% and ±0.76%\pm0.76\%) are not yet true finite-sample guarantees. The code substituted the observed rate p^\hat p into the variance p(1−p)p(1-p), whereas Bernstein's inequality requires an upper bound on the true variance, the exact same plug-in objection we raised against the Gaussian interval. Fortunately, fixing this is inexpensive. Whenever the bound holds, the true error rate is at most p^+t\hat p+t, so we simply solve the same equation with the worst-case variance (p^+t)(1−p^−t)(\hat p+t)(1-\hat p-t). Iterating this fixed-point equation (as the cell does) nudges the half-widths only slightly, to the fully guaranteed ±0.43%\pm0.43\% and ±0.79%\pm0.79\%. This gives a sharp answer to our opening question: for the classifier with 830 errors on 10,000 images, its true error rate lies within about 0.8%0.8\% of 8.3% with 95% confidence. Because practical models typically operate at error rates of a few percent, variance-aware bounds make a real difference.

Stepping back, Hoeffding's proof relied on just one property of the summands: their moment generating functions were bounded by that of a Gaussian. Naming this property lets us extend the same proof to unbounded random variables, and clarifies exactly where it stops working. A random variable XX is sub-Gaussian with variance proxy σ2\sigma^2 if its centered MGF never exceeds that of N(0,σ2)\mathcal N(0,\sigma^2):

E[eλ(X−E[X])]≤exp⁡ ⁣(λ2σ22)for all λ∈R.(24.9.7)\mathbb{E}\bigl[e^{\lambda (X - \mathbb{E}[X])}\bigr] \leq \exp\!\left(\frac{\lambda^2\sigma^2}{2}\right) \qquad\textrm{for all } \lambda\in\mathbb{R}. \tag{24.9.7}

Any sub-Gaussian variable has tails at least as light as a Gaussian's: applying the Chernoff method with λ=t/σ2\lambda=t/\sigma^2 yields P(∣X−E[X]∣≥t)≤2e−t2/(2σ2)P(|X-\mathbb{E}[X]|\geq t)\leq2e^{-t^2/(2\sigma^2)}. Keep in mind that σ2\sigma^2 here is a proxy, not necessarily the true variance. Comparing both sides of (24.9.7) to second order in λ\lambda shows that the proxy is never smaller than Var(X)\textrm{Var}(X), and it can be far larger: a 0/1 outcome with 2% error has variance 0.01960.0196, yet Hoeffding's lemma supplies the proxy 14\tfrac14, which is precisely why Hoeffding's interval was so wide.

Three standard families are sub-Gaussian. A Gaussian N(μ,σ2)\mathcal N(\mu,\sigma^2) has proxy σ2\sigma^2 with equality; any variable on [a,b][a,b] has proxy (b−a)2/4(b-a)^2/4 by Hoeffding's lemma; and a uniform random sign ξ∈{−1,+1}\xi\in\{-1,+1\} has proxy 11, since E[eλξ]=cosh⁡λ≤eλ2/2\mathbb{E}[e^{\lambda\xi}]=\cosh\lambda\leq e^{\lambda^2/2} by our earlier series comparison. Best of all, sub-Gaussianity is preserved by averaging: if X1,…,XnX_1,\ldots,X_n are independent with proxy σ2\sigma^2, the product rule gives Xˉ\bar X the proxy σ2/n\sigma^2/n, and therefore P(∣Xˉ−EXˉ∣≥t)≤2e−nt2/(2σ2)P(|\bar X-\mathbb{E}\bar X|\geq t)\leq2e^{-nt^2/(2\sigma^2)}.

Not every well-behaved random variable is sub-Gaussian, however, and the very next quantity we need is not. The squared length of a Gaussian vector is a sum of squares of standard Gaussians, and for a single standard Gaussian xx, completing the square gives

E[eλ(x2−1)]=e−λ1−2λfor λ<12,\mathbb{E}\bigl[e^{\lambda(x^2-1)}\bigr]=\frac{e^{-\lambda}}{\sqrt{1-2\lambda}} \qquad\textrm{for }\lambda\lt \tfrac12,

while the expectation diverges to infinity for every λ≥12\lambda\geq\tfrac12. Because the MGF blows up at λ=12\lambda=\tfrac12, (24.9.7) cannot hold for x2x^2 at any variance proxy: its right tail decays like e−t/2e^{-t/2}, too slowly for a Gaussian bound.

Even so, a Gaussian-shaped MGF bound does hold on a restricted window around λ=0\lambda=0. We say that a random variable XX is sub-exponential with parameters (ν,α)(\nu,\alpha) if

E[eλ(X−E[X])]≤exp⁡ ⁣(λ2ν22)for ∣λ∣≤1α.(24.9.8)\mathbb{E}\bigl[e^{\lambda (X - \mathbb{E}[X])}\bigr] \leq \exp\!\left(\frac{\lambda^2\nu^2}{2}\right) \qquad\textrm{for } |\lambda| \leq \frac{1}{\alpha}. \tag{24.9.8}

Here ν2\nu^2 acts as a local variance proxy near λ=0\lambda=0, while 1/α1/\alpha sets the half-width of the admissible window, capping how large a λ\lambda the Chernoff method may choose. In Section 24.9.2.1 we will see that x2x^2 is sub-exponential with ν=2\nu=2 and α=4\alpha=4. When we apply the Chernoff method to an average of sub-exponential variables, the optimization naturally splits at the boundary of this window. You may skip the proof on a first reading; the next subsection uses only the statement.

Proposition (sub-exponential tail bound). Let X1,…,XnX_1,\ldots,X_n be independent and (ν,α)(\nu,\alpha)-sub-exponential. Then for every t>0t>0,

P(∣Xˉ−E[Xˉ]∣≥t)≤2exp⁡ ⁣(−n2min⁡(t2ν2, tα)).(24.9.9)P\bigl(|\bar X-\mathbb{E}[\bar X]|\geq t\bigr) \leq2\exp\!\left(-\frac n2\min\Bigl(\frac{t^2}{\nu^2},\,\frac{t}{\alpha}\Bigr)\right). \tag{24.9.9}

Proof. For any 0<λ≤1/α0\lt \lambda\leq1/\alpha, the Chernoff method and the product rule bound P(Xˉ−E[Xˉ]≥t)P(\bar X-\mathbb{E}[\bar X]\geq t) by exp⁡(−λnt+nλ2ν2/2)\exp(-\lambda nt+n\lambda^2\nu^2/2). When t≤ν2/αt\leq\nu^2/\alpha, the unconstrained minimizer λ=t/ν2\lambda=t/\nu^2 falls inside the window and yields e−nt2/(2ν2)e^{-nt^2/(2\nu^2)}. When t>ν2/αt>\nu^2/\alpha, that minimizer lies outside the window, so we clamp λ\lambda to the largest admissible value, λ=1/α\lambda=1/\alpha. The exponent becomes −nt/α+nν2/(2α2)-nt/\alpha+n\nu^2/(2\alpha^2), which is at most −nt/α+nt/(2α)=−nt/(2α)-nt/\alpha+nt/(2\alpha)=-nt/(2\alpha) because ν2/α<t\nu^2/\alpha\lt t. Combining both regimes gives an exponent of at most −n2min⁡(t2/ν2,t/α)-\tfrac n2\min(t^2/\nu^2,t/\alpha). The lower tail follows identically using λ∈[−1/α,0)\lambda\in[-1/\alpha,0). ■\blacksquare

The contrast with sub-Gaussian averages is now crystal clear. Averages of bounded or sub-Gaussian variables enjoy Gaussian-type tails e−ct2e^{-ct^2} at every scale. A sub-exponential average has that same Gaussian tail for moderate deviations below ν2/α\nu^2/\alpha, and then transitions to a slower exponential tail e−nt/(2α)e^{-nt/(2\alpha)} farther out.

24.9.2 Probability in High Dimension#

Up to now, our bounds have protected a single sample average. Now consider a random vector in Rd\mathbb{R}^d with dd independent coordinates: both its squared length and its inner products with other vectors are sums over those dd coordinates. Concentration inequalities therefore govern the geometry of high-dimensional space. If you are jumping in here, you only need two results from the first half of the section: the sub-exponential tail bound (24.9.9) for squared lengths, and the unequal-range Hoeffding bound (24.9.4) for inner products.

24.9.2.1 The Thin Shell#

Draw a standard Gaussian vector x∼N(0,I784)\mathbf x\sim\mathcal N(\mathbf 0,\mathbf I_{784}), which has as many coordinates as a 28×2828\times28 image. Its probability density is highest at the origin. Surprisingly, however, the probability that x\mathbf x lands within distance 14 of the origin (half its typical length) is roughly 10−11010^{-110}, the chance that a sum of 784 squared standard Gaussians is at most 196. No sample you could ever draw on a computer will contain a point anywhere near the mode. Instead, a typical draw has norm 28.0±0.728.0\pm0.7.

The explanation is that ∥x∥2=∑i=1dxi2\|\mathbf x\|^2=\sum_{i=1}^d x_i^2 is a sum of dd independent terms, each with mean 11, so ∥x∥2/d\|\mathbf x\|^2/d is simply a sample mean. Because xi2x_i^2 is unbounded, Hoeffding's inequality does not apply, but our sub-exponential bound handles it cleanly.

Proposition (norm concentration). Let x∼N(0,Id)\mathbf x\sim\mathcal N(\mathbf 0,\mathbf I_d). For every 0<ε≤10\lt \varepsilon\leq 1,

P ⁣(∣∥x∥d−1∣≥ε)≤2exp⁡ ⁣(−d ε28).(24.9.10)P\!\left(\Bigl|\frac{\|\mathbf x\|}{\sqrt d} - 1\Bigr| \geq \varepsilon\right) \leq 2\exp\!\left(-\frac{d\,\varepsilon^2}{8}\right). \tag{24.9.10}

Proof. The argument proceeds in three short steps. First, a power-series comparison (Exercise 4) shows that the MGF of a centered square, e−λ/1−2λe^{-\lambda}/\sqrt{1-2\lambda}, satisfies

E[eλ(xi2−1)]≤e2λ2for ∣λ∣≤14.(24.9.11)\mathbb{E}\bigl[e^{\lambda (x_i^2 - 1)}\bigr] \leq e^{2\lambda^2} \qquad\textrm{for } |\lambda| \leq \tfrac14 . \tag{24.9.11}

In the terminology of (24.9.8), xi2x_i^2 is sub-exponential with ν=2\nu=2 and α=4\alpha=4. Second, applying the sub-exponential tail bound (24.9.9) with n=dn=d and t=εt=\varepsilon gives

P(∣∥x∥2d−1∣≥ε)≤2exp⁡(−d2min⁡(ε24,ε4))=2e−dε2/8for ε≤1.P\Bigl(\Bigl|\frac{\|\mathbf x\|^2}{d}-1\Bigr|\geq\varepsilon\Bigr) \leq2\exp\Bigl(-\frac d2\min\Bigl(\frac{\varepsilon^2}{4},\frac{\varepsilon}{4}\Bigr)\Bigr) =2e^{-d\varepsilon^2/8} \qquad\textrm{for }\varepsilon\leq1.

Third, we pass from the squared norm to the norm itself. Let z=∥x∥/d≥0z=\|\mathbf x\|/\sqrt d\geq0. Whenever ∣z−1∣≥ε|z-1|\geq\varepsilon, we also have ∣z2−1∣=∣z−1∣ (z+1)≥ε|z^2-1|=|z-1|\,(z+1)\geq\varepsilon, since z+1≥1z+1\geq1. Thus the event for the norm is contained in the event for the squared norm and inherits its upper bound. ■\blacksquare

In short, the probability that the length of a standard Gaussian vector misses d\sqrt d by a fixed fraction decays exponentially in the dimension dd. Note that the restriction ε≤1\varepsilon\leq1 is an artifact of bounding the squared norm, whose upper tail beyond ε=1\varepsilon=1 decays only exponentially as e−dε/8e^{-d\varepsilon/8} (Exercise 4). The norm itself keeps a Gaussian tail at every scale: exceeding (1+ε)d(1+\varepsilon)\sqrt d forces the squared norm above (1+2ε+ε2)d(1+2\varepsilon+\varepsilon^2)d, whose probability is at most e−dmin⁡(s,s2)/8e^{-d\min(s,s^2)/8} with s=2ε+ε2s=2\varepsilon+\varepsilon^2; since s≥ε2s\geq\varepsilon^2 and s2≥4ε2s^2\geq4\varepsilon^2, this is at most e−dε2/8e^{-d\varepsilon^2/8}.

How thick is this shell of typical norms? Since E[x4]=3\mathbb{E}[x^4]=3, each coordinate square has Var(x2)=3−1=2\textrm{Var}(x^2)=3-1=2, giving Var(∥x∥2)=2d\textrm{Var}(\|\mathbf x\|^2)=2d. Linearizing the square root around dd gives ∥x∥≈d+(∥x∥2−d)/(2d)\|\mathbf x\|\approx\sqrt d+(\|\mathbf x\|^2-d)/(2\sqrt d), so the standard deviation of ∥x∥\|\mathbf x\| is approximately 2d/(2d)=1/2≈0.71\sqrt{2d}/(2\sqrt d)=1/\sqrt2 \approx0.71, independent of the dimension. Remarkably, a standard Gaussian in Rd\mathbb{R}^d concentrates on a thin shell of radius d\sqrt d whose thickness stays of order one no matter how large dd becomes.

Why does all the probability mass sit so far from the mode? The joint density (2π)−d/2e−∥x∥2/2(2\pi)^{-d/2}e^{-\|\mathbf x\|^2/2} depends on x\mathbf x solely through its radius r=∥x∥r=\|\mathbf x\|, while the surface area of a sphere of radius rr grows like rd−1r^{d-1}. Multiplying density by surface area, the distribution of the radius ∥x∥\|\mathbf x\| is proportional to rd−1e−r2/2r^{d-1}e^{-r^2/2}. As rr grows, the volume factor rd−1r^{d-1} explodes while the density e−r2/2e^{-r^2/2} plummets; their product peaks where the derivative of (d−1)log⁡r−r2/2(d-1)\log r-r^2/2 vanishes, namely at r=d−1r=\sqrt{d-1}. Panel (a) of Figure 24.9.2 illustrates this competition between volume and density at d=20d=20.

At a typical point of norm d\sqrt d, the pointwise density is e−d/2e^{-d/2} times its value at the origin (a tiny 10−17010^{-170} when d=784d=784), yet there is so much more surface area at radius d\sqrt d that virtually all the mass lives there. Panel (b) displays the exact density of ∥x∥\|\mathbf x\| from d=2d=2 to d=512d=512: the peaks march outward like d\sqrt d while their widths stay pinned near 1/21/\sqrt2.

Figure 24.9.2:

The thin shell. (a) At d=20d=20 the Gaussian density e−r2/2e^{-r^2/2} falls with the radius rr, the volume rd−1r^{d-1} of the shell at radius rr grows, and their product, the density of ∥x∥\|\mathbf{x}\|, peaks at d−1\sqrt{d-1}, far from the origin where the density is largest; each curve is scaled to maximum 1. (b) The exact density of ∥x∥\|\mathbf{x}\| for x∼N(0,Id)\mathbf{x}\sim\mathcal{N}(\mathbf{0},\mathbf{I}_d) and d=2,8,32,128,512d=2,8,32,128,512. The centers move out like d\sqrt{d}; the widths stay near 1/21/\sqrt{2}.

Notice that our bound captures the exponential scaling in dd, though not the exact numerical value. A norm below 14 at d=784d=784 corresponds to ε=12\varepsilon=\tfrac12, for which (24.9.10) gives 2e−784/32=2e−24.5≈5×10−112e^{-784/32}=2e^{-24.5}\approx5\times10^{-11}, compared with the exact 10−11010^{-110}. The constant 88 in the denominator is loose, but the qualitative conclusion, exponential decay in dd, is right on target.

24.9.2.2 Near-Orthogonality of Random Directions#

In Section 21.1, we saw that the cosine of the angle between a fixed unit vector and a random direction in Rd\mathbb{R}^d has variance 1/d1/d. Paired with Chebyshev's inequality, that gave a weak tail of order 1/(dε2)1/(d\varepsilon^2). Concentration sharpens this to an exponential tail, which in turn lets us count how many random directions can be simultaneously nearly orthogonal.

Random sign vectors provide the cleanest calculation. Fix any unit vector u\mathbf u and draw independent uniform signs xi∈{−1,+1}x_i\in\{-1,+1\}. Each term uixiu_ix_i of the inner product ⟨x,u⟩\langle\mathbf x,\mathbf u\rangle has mean zero and lies in [−∣ui∣,∣ui∣][-|u_i|,|u_i|], an interval of length 2∣ui∣2|u_i|. Substituting these ranges into our unequal-range Hoeffding bound (24.9.4), the denominator becomes 4∑iui2=44\sum_i u_i^2=4, leaving

P(∣⟨x,u⟩∣≥s)≤2e−s2/2.(24.9.12)P\bigl(|\langle\mathbf x,\mathbf u\rangle| \geq s\bigr) \leq 2 e^{-s^2/2}. \tag{24.9.12}

The inner product of a random sign vector with any fixed unit vector stays of order one with a Gaussian tail, because the ±∣ui∣\pm|u_i| contributions largely cancel. Meanwhile, the norm of x\mathbf x is d\sqrt d. Setting s=εds=\varepsilon\sqrt d immediately gives P(∣cos⁡(x,u)∣≥ε)≤2e−dε2/2P(|\cos(\mathbf x,\mathbf u)|\geq\varepsilon)\leq2e^{-d\varepsilon^2/2}. For a standard Gaussian vector x\mathbf x, the same behavior holds: the inner product ⟨x,u⟩\langle\mathbf x,\mathbf u\rangle is itself a standard Gaussian for every unit vector u\mathbf u, so it obeys the exact same tail 2e−s2/22e^{-s^2/2}, and the thin shell keeps ∥x∥\|\mathbf x\| within a few percent of d\sqrt d.

With an exponential tail in hand, we can control many pairs at once using one extra tool: the union bound, which states that the probability that at least one of several events occurs is at most the sum of their individual probabilities, regardless of whether those events are independent. Take mm independent random sign vectors. They form m(m−1)/2<m2/2m(m-1)/2\lt m^2/2 distinct pairs, and any single pair has ∣cos⁡∣≥ε|\cos|\geq\varepsilon with probability at most 2e−dε2/22e^{-d\varepsilon^2/2}. By the union bound, the probability that any pair exceeds ε\varepsilon is at most m2e−dε2/2m^2e^{-d\varepsilon^2/2}. Consequently, with probability at least 1−δ1-\delta, all pairwise cosines stay below ε\varepsilon whenever m≤δ edε2/4m\leq\sqrt\delta\,e^{d\varepsilon^2/4}. In high dimensions, you can pack exponentially many nearly orthogonal vectors into Rd\mathbb{R}^d.

Let us plug in d=784d=784 and δ=0.05\delta=0.05. Even this loose bound guarantees roughly 570 directions with all pairwise ∣cos⁡∣<0.2|\cos|\lt 0.2, and roughly 10710^7 directions with all pairwise ∣cos⁡∣<0.3|\cos|\lt 0.3. And those are worst-case guarantees over all pairs; a single typical pair has ∣cos⁡∣|\cos| much smaller, around 2/(πd)≈0.028\sqrt{2/(\pi d)}\approx0.028, the mean absolute value of a Gaussian with standard deviation 1/d1/\sqrt d.

Of course, learned neural network embeddings are not independent random vectors, and that is precisely why this calculation is useful. At d=784d=784, a cosine similarity of 0.30.3 sits more than eight standard deviations (1/784=0.0361/\sqrt{784}=0.036) above what independent random directions produce. Random directions thus serve as the null model against which genuine geometric structure in trained embeddings is measured.

24.9.2.3 The Thin Shell in Numbers#

Because our theoretical bounds have loose constants, let us measure the true numbers directly. Our tangent-line argument predicts that the standard deviation of ∥x∥\|\mathbf x\| stays near 1/2≈0.711/\sqrt2\approx0.71 at every dimension dd, while the Gaussian approximation predicts a mean ∣cos⁡∣|\cos| of 2/(πd)\sqrt{2/(\pi d)}. Below, we draw 10,000 pairs of standard Gaussian vectors at d=2,20,200,2000d=2,20,200,2000 to test both predictions; notice that one row will not match.

for d in (2, 20, 200, 2000):
    x, y = rng.standard_normal((2, 10000, d))
    nx = np.linalg.norm(x, axis=1)
    cos = (x * y).sum(1) / (nx * np.linalg.norm(y, axis=1))
    print(f'd = {d:4d}: mean ||x||/sqrt(d) = {(nx / np.sqrt(d)).mean():.3f}, '
          f'sd ||x|| = {nx.std():.2f}, mean |cos| = {np.abs(cos).mean():.4f}'
          f' vs {np.sqrt(2 / (np.pi * d)):.4f}')
d =    2: mean ||x||/sqrt(d) = 0.886, sd ||x|| = 0.65, mean |cos| = 0.6377 vs 0.5642
d =   20: mean ||x||/sqrt(d) = 0.986, sd ||x|| = 0.71, mean |cos| = 0.1827 vs 0.1784
d =  200: mean ||x||/sqrt(d) = 0.999, sd ||x|| = 0.70, mean |cos| = 0.0560 vs 0.0564
d = 2000: mean ||x||/sqrt(d) = 1.000, sd ||x|| = 0.71, mean |cos| = 0.0179 vs 0.0178

As predicted, the standard deviation of the norm sits near 0.650.65 at d=2d=2 and settles right around 0.70.7 thereafter, even as the norm itself climbs from roughly 1.3 to 45. The one row that does not match the asymptotic formula is d=2d=2, where the mean ∣cos⁡∣|\cos| is about 0.640.64: in the plane, the angle between two isotropic vectors is uniform, giving E∣cos⁡θ∣=2/π\mathbb{E}|\cos\theta|=2/\pi, whereas 2/(πd)\sqrt{2/(\pi d)} is a high-dimensional approximation. From d=20d=20 onward, the measured values (about 0.180.18, 0.0570.057, and 0.0180.018) agree with the formula to within a few percent.

Two follow-up questions make the geometry even more vivid. First, what fraction of the probability mass lies within 10% of the typical norm, inside the shell (1±0.1)d(1\pm0.1)\sqrt d? Second, do Euclidean distances still separate nearby points from distant ones? To measure separation, we compute the contrast of a query point, (dmax⁡−dmin⁡)/dmin⁡(d_{\max}-d_{\min})/d_{\min} across its distances to 200 random points, and report the median contrast over 100 queries.

eps = 0.1
for d in (2, 20, 200, 2000):
    x = rng.standard_normal((10000, d))
    ratio = np.linalg.norm(x, axis=1) / np.sqrt(d)
    shell = np.mean(np.abs(ratio - 1) <= eps)          # mass in the 10% shell
    query, points = x[:100], x[100:300]                # 100 queries, 200 points
    dist = np.linalg.norm(query[:, None] - points[None], axis=2)  # (100, 200)
    contrast = (dist.max(1) - dist.min(1)) / dist.min(1)
    print(f'd = {d:4d}: mass in (1 ± 0.1) sqrt(d) = {shell:6.1%}, '
          f'median contrast = {np.median(contrast):.3f}')
d =    2: mass in (1 ± 0.1) sqrt(d) =  14.5%, median contrast = 30.417
d =   20: mass in (1 ± 0.1) sqrt(d) =  46.7%, median contrast = 1.179
d =  200: mass in (1 ± 0.1) sqrt(d) =  95.6%, median contrast = 0.270
d = 2000: mass in (1 ± 0.1) sqrt(d) = 100.0%, median contrast = 0.079

At d=2d=2, the 10% shell captures only about 15% of the mass; by d=20d=20 it captures roughly 47%, and by d=200d=200 roughly 95%. That 95% matches our tangent-line estimate: at d=200d=200, the ratio ∥x∥/d\|\mathbf x\|/\sqrt d has standard deviation 1/2d=0.051/\sqrt{2d}=0.05, so ±0.1\pm0.1 spans two standard deviations on either side of the mean. By d=2000d=2000, all 10,000 draws land inside the shell. Meanwhile, the median distance contrast collapses from around 30 at d=2d=2 (fluctuating between roughly 25 and 40 from run to run) down to about 1.2, 0.27, and finally 0.08. At d=2000d=2000, for a typical query, the farthest of 200 random points is less than 10% farther away than the nearest.

24.9.2.4 Consequences for Deep Learning#

Three standard practices in deep learning rest directly on this high-dimensional geometry.

Initialization. LeCun initialization (LeCun et al., 1998) samples the entries of a d×dd\times d weight matrix independently with variance 1/d1/d, and He initialization (He et al., 2015) uses variance 2/d2/d for ReLU networks (Section 4.4). The classical derivation of these scales works in expectation over all random draws of the weights: at LeCun's scale, each pre-activation ⟨w,x⟩\langle\mathbf w,\mathbf x\rangle has variance ∥x∥2/d\|\mathbf x\|^2/d, which norm concentration keeps close to 11 for inputs with unit-variance coordinates. In practice, however, we initialize and train a single network, not an average over infinitely many. Concentration tells us when that expectation actually describes our one draw.

For a single He-initialized ReLU layer of width dd, the ratio ρ=∥hk∥2/∥hk−1∥2\rho=\|\mathbf h_k\|^2/\|\mathbf h_{k-1}\|^2 of squared activation norms has mean 11 and variance 5/d5/d (Exercise 5), so one layer perturbs the squared norm by roughly 5/d\sqrt{5/d}, or about 10% at d=512d=512. Across KK layers, these multiplicative fluctuations add on a logarithmic scale, giving log⁡(∥hK∥2/∥h0∥2)\log(\|\mathbf h_K\|^2/\|\mathbf h_0\|^2) a variance of roughly 5K/d5K/d. The expected-variance heuristic therefore describes a typical network only while K≪dK\ll d. At K=50K=50 and d=512d=512, the log-variance reaches about 0.50.5, meaning the squared norm of a typical initialized network is already off by a factor of two in either direction.

Distances and nearest neighbors. For two independent standard Gaussian draws, the difference satisfies x−y∼N(0,2I)\mathbf x-\mathbf y\sim\mathcal N(\mathbf 0,2\mathbf I), so norm concentration applies directly to (x−y)/2(\mathbf x-\mathbf y)/\sqrt2: each pairwise distance falls in (1±ε)2d(1\pm\varepsilon)\sqrt{2d} except with probability 2e−dε2/82e^{-d\varepsilon^2/8}. Applying the same union bound we used for directions places all pairwise distances among nn points inside that narrow band simultaneously once d≥(8/ε2)log⁡(n2/δ)d\geq(8/\varepsilon^2)\log(n^2/\delta), a threshold that grows only logarithmically with nn. When every distance is nearly the same, nearest and farthest neighbors differ by only a small relative margin, just as our contrast experiment showed. Real learned embeddings retain meaningful distance contrast only because real data lie near a much lower-dimensional structure. On the flip side, this same calculation yields a powerful tool: a random projection down to kk dimensions preserves all pairwise distances among nn points once kk is of order log⁡n\log n, regardless of the ambient dimension (Exercise 6).

Latent codes. A generative decoder trained on latent codes z∼N(0,Id)\mathbf z\sim\mathcal N(\mathbf 0,\mathbf I_d) almost exclusively sees inputs whose norm is close to d\sqrt d. Both the prior mean (norm 00) and the midpoint of the straight chord connecting two independent codes (norm close to d/2\sqrt{d/2}) lie deep in the empty interior where the decoder was never trained. For this reason, practitioners typically interpolate between latent codes along a spherical arc rather than a straight line, as Figure 24.9.3 illustrates (Exercise 2).

Figure 24.9.3:

Two ways to interpolate between latent codes z1,z2∼N(0,Id)\mathbf{z}_1,\mathbf{z}_2\sim\mathcal{N}(\mathbf{0},\mathbf{I}_d). (a) Both codes lie in the thin shell of radius d\sqrt d (shaded) and are nearly orthogonal. The straight chord (lerp) cuts through the interior, and its midpoint has norm about d/2\sqrt{d/2}; the spherical arc (slerp) stays in the shell. (b) The norm along each path, divided by d\sqrt d, for one random pair at d=512d=512.

One crucial limitation remains. Every bound in this section protects a single quantity fixed before the data are drawn. A learning algorithm, by contrast, inspects the data and picks the best model among many candidates after the fact, and the best of many fair coins will always look biased. In Section 24.10, we show how to extend concentration inequalities to account for that selection.

24.9.3 Summary#

How far can an average of nn independent terms stray from its expectation at a finite sample size nn? Chebyshev's inequality gives a tail probability that decays only like 1/n1/n, far too slowly when we need a guarantee that almost never fails. The Chernoff method applies Markov's inequality to eλXe^{\lambda X}, turning the moment generating function of an independent sum into a product, and then optimizes over λ\lambda. Combined with Hoeffding's lemma, this yields the exponential tail 2e−2nt22e^{-2nt^2} for losses in [0,1][0,1] and a finite-sample confidence interval of half-width log⁡(2/δ)/(2n)\sqrt{\log(2/\delta)/(2n)}; Bernstein's inequality tightens this interval substantially whenever the variance is small relative to the range. Applied to the dd coordinates of a random vector, the same ideas show that a standard Gaussian concentrates on a thin shell of radius d\sqrt d and thickness about 1/21/\sqrt2, and that exponentially many random directions are pairwise nearly orthogonal. Together, these results tell us how to size test sets, when initialization heuristics hold for a single trained network, and how to judge cosine similarities and distances in high-dimensional embeddings.

24.9.4 Exercises#

  1. Sub-Gaussian random signs. A random sign ξ\xi takes the values −1-1 and +1+1 with probability 12\tfrac12 each, so that E[eλξ]=cosh⁡λ≤eλ2/2\mathbb{E}[e^{\lambda\xi}]=\cosh\lambda\leq e^{\lambda^2/2}.

    1. Conclude with the Chernoff method (24.9.1) that the average ξˉ\bar\xi of nn independent random signs satisfies P(∣ξˉ∣≥t)≤2e−nt2/2P(|\bar\xi|\geq t)\leq 2e^{-nt^2/2}.
    2. Hoeffding's lemma (24.9.2) with [a,b]=[−1,1][a,b]=[-1,1] also gives a variance proxy for ξ\xi. Compare it with the bound cosh⁡λ≤eλ2/2\cosh\lambda\leq e^{\lambda^2/2}. Expand log⁡cosh⁡λ=λ2/2−λ4/12+⋯\log\cosh\lambda=\lambda^2/2-\lambda^4/12+\cdots around λ=0\lambda=0, and explain why no constant smaller than 18\tfrac18 can replace the 18\tfrac18 in (24.9.2) for all bounded variables.
  2. Latent interpolation. A generative model decodes latent codes z∼N(0,Id)\mathbf z\sim\mathcal N(\mathbf 0,\mathbf I_d) with d=512d=512. Let z1,z2\mathbf z_1,\mathbf z_2 be two independent codes and z(γ)=(1−γ)z1+γz2\mathbf z(\gamma)=(1-\gamma)\mathbf z_1+\gamma\mathbf z_2 for γ∈[0,1]\gamma\in[0,1] their linear interpolation.

    1. Find the distribution of z(γ)\mathbf z(\gamma) and the approximate value of ∥z(γ)∥\|\mathbf z(\gamma)\|. At which γ\gamma is the norm smallest?
    2. Use (24.9.10) to bound the probability that the midpoint z(12)\mathbf z(\tfrac12) has norm at least 0.9d0.9\sqrt d, that is, reaches the shell (1±0.1)d(1\pm 0.1)\sqrt d in which typical codes lie. Then compute the exact probability, which is P(χ5122≥2⋅0.81⋅512)P(\chi^2_{512}\geq 2\cdot0.81\cdot512) for a chi-square variable with 512 degrees of freedom (scipy.stats.chi2.sf). By how many orders of magnitude is the bound loose?
    3. Spherical interpolation (White, 2016) replaces the chord by the arc
z~(γ)=sin⁡((1−γ)θ)sin⁡θ z1+sin⁡(γθ)sin⁡θ z2,\tilde{\mathbf z}(\gamma)=\frac{\sin((1-\gamma)\theta)}{\sin\theta}\,\mathbf z_1+\frac{\sin(\gamma\theta)}{\sin\theta}\,\mathbf z_2,

where θ\theta is the angle between z1\mathbf z_1 and z2\mathbf z_2. Show that ∥z~(γ)∥=r\|\tilde{\mathbf z}(\gamma)\|=r for all γ\gamma when ∥z1∥=∥z2∥=r\|\mathbf z_1\|=\|\mathbf z_2\|=r. Which value does θ\theta take approximately for d=512d=512, and why?

  1. [code] Chernoff bound for coins. ● Let p^\hat p be the fraction of heads in nn independent flips of a coin with bias pp, and let a>pa>p.

    1. Apply the Chernoff method (24.9.1) to np^n\hat p, whose moment generating function is (1−p+peλ)n(1-p+pe^\lambda)^n. Optimize over λ\lambda and show that P(p^≥a)≤e−n DKL(a∥p)P(\hat p\geq a)\leq e^{-n\,D_{\textrm{KL}}(a\|p)}, where DKL(a∥p)=alog⁡ap+(1−a)log⁡1−a1−pD_{\textrm{KL}}(a\|p)=a\log\frac ap+(1-a)\log\frac{1-a}{1-p}.
    2. Show that DKL(a∥p)≥2(a−p)2D_{\textrm{KL}}(a\|p)\geq 2(a-p)^2 by examining the second derivative in aa, so that the bound of (a) is never weaker than one side of Hoeffding's bound. Evaluate both exponents for p=12p=\tfrac12 and a=0.6a=0.6.
    3. Add the two-sided bound 2e−n DKL(0.6∥0.5)2e^{-n\,D_{\textrm{KL}}(0.6\|0.5)} as a column to the table of Section 24.9.1.5, for n∈{10,100,1000,5000}n\in\{10,100,1000,5000\}. The ratio of the exact tail to this bound still decreases with nn. How does it scale with nn, and what does the scaling say about the factor that the Chernoff method loses?
  2. Chi-square tail. ● The proof of (24.9.10) rests on the bound (24.9.11) for x2−1x^2-1 with x∼N(0,1)x\sim\mathcal N(0,1), which the proof states without derivation.

    1. Show that E[eλ(x2−1)]=e−λ/1−2λ\mathbb{E}[e^{\lambda(x^2-1)}]=e^{-\lambda}/\sqrt{1-2\lambda} for λ<12\lambda\lt \tfrac12 by completing the square in the Gaussian integral.
    2. Expand log⁡E[eλ(x2−1)]\log\mathbb{E}[e^{\lambda(x^2-1)}] into a power series in 2λ2\lambda and prove (24.9.11). The series starts at the quadratic term.
    3. The proof of (24.9.10) takes λ=ε/4\lambda=\varepsilon/4, which is admissible only for ε≤1\varepsilon\leq 1. For ε>1\varepsilon>1, set λ=14\lambda=\tfrac14 and bound P(∥x∥2≥(1+ε)d)P(\|\mathbf x\|^2\geq(1+\varepsilon)d). Does the result decay like e−cε2e^{-c\varepsilon^2} or like e−cεe^{-c\varepsilon} in ε\varepsilon, and which regime of (24.9.9) does it belong to?
  3. [code] Activation norms through depth. ● Consider a ReLU network of width dd and depth KK without biases, hk=ReLU(Wkhk−1)\mathbf h_k=\mathrm{ReLU}(\mathbf W_k\mathbf h_{k-1}), whose weights are independent draws from N(0,2/d)\mathcal N(0,2/d) (He initialization, Section 4.4). Let ρk=∥hk∥2/∥hk−1∥2\rho_k=\|\mathbf h_k\|^2/\|\mathbf h_{k-1}\|^2. How such norms fluctuate with depth and width was analyzed by Hanin and Nica (2020).

    1. Show that, given hk−1≠0\mathbf h_{k-1}\ne\mathbf 0, the ratio ρk\rho_k is distributed as 2d∑j=1dReLU(gj)2\frac2d\sum_{j=1}^d\mathrm{ReLU}(g_j)^2 with independent gj∼N(0,1)g_j\sim\mathcal N(0,1), whatever the direction of hk−1\mathbf h_{k-1}. Conclude that E[ρk]=1\mathbb{E}[\rho_k]=1 and Var(ρk)=5/d\textrm{Var}(\rho_k)=5/d, using E[g2]=1\mathbb{E}[g^2]=1 and E[g4]=3\mathbb{E}[g^4]=3.
    2. Write log⁡(∥hK∥2/∥h0∥2)\log(\|\mathbf h_K\|^2/\|\mathbf h_0\|^2) as a sum of KK independent terms (ρk=0\rho_k=0 has probability 2−d2^{-d} per layer; ignore it). Expand log⁡ρ\log\rho to second order around 11 and predict the mean and variance of this sum in terms of K/dK/d.
    3. Simulate 1,0001{,}000 networks for each width d∈{32,128}d\in\{32,128\} and depth K∈{1,10,50}K\in\{1,10,50\}, each with a fresh standard Gaussian input. Compare the mean and variance of log⁡(∥hK∥2/∥h0∥2)\log(\|\mathbf h_K\|^2/\|\mathbf h_0\|^2) with (b), and report the mean and the median of the ratio ∥hK∥2/∥h0∥2\|\mathbf h_K\|^2/\|\mathbf h_0\|^2 itself. The variance calculation of Section 4.4 gives E[∥hK∥2/∥h0∥2]=1\mathbb{E}[\|\mathbf h_K\|^2/\|\mathbf h_0\|^2]=1 at every depth. Repeat the run at K=50K=50 and d=32d=32 several times. Why does the sample mean over 1,0001{,}000 networks scatter so widely around 11? Why does the expectation not describe a typical network there?
  4. [code] Random projections preserve distances. ● Let A∈Rk×d\mathbf A\in\mathbb{R}^{k\times d} have independent N(0,1/k)\mathcal N(0,1/k) entries.

    1. Show that for a fixed v≠0\mathbf v\neq\mathbf 0 the ratio ∥Av∥2/∥v∥2\|\mathbf A\mathbf v\|^2/\|\mathbf v\|^2 has the distribution of ∥g∥2/k\|\mathbf g\|^2/k with g∼N(0,Ik)\mathbf g\sim\mathcal N(\mathbf 0,\mathbf I_k), so that by (24.9.10) P(∣∥Av∥/∥v∥−1∣≥ε)≤2e−kε2/8P(|\|\mathbf A\mathbf v\|/\|\mathbf v\|-1|\geq\varepsilon)\leq 2e^{-k\varepsilon^2/8}. Hint: rotate so that v\mathbf v lies along the first axis.
    2. For nn points, apply (a) to the n(n−1)/2n(n-1)/2 differences and a union bound. Show that all pairwise distances are preserved within a factor 1±ε1\pm\varepsilon with probability at least 1−δ1-\delta once k≥(8/ε2)log⁡(n2/δ)k\geq(8/\varepsilon^2)\log(n^2/\delta), a bound that does not depend on dd. This is the Johnson–Lindenstrauss lemma. Evaluate it for n=1,000n=1{,}000, ε=0.3\varepsilon=0.3 and δ=0.05\delta=0.05.
    3. Verify it on 1,0001{,}000 standard Gaussian points in d=2,000d=2{,}000. Project to k∈{50,200,800}k\in\{50,200,800\} and report the largest distortion ∣∥A(xi−xj)∥/∥xi−xj∥−1∣|\|\mathbf A(\mathbf x_i-\mathbf x_j)\|/\|\mathbf x_i-\mathbf x_j\|-1| over all pairs, together with the typical fluctuation 1/2k1/\sqrt{2k}. Compute the pairwise distances from the Gram matrix, ∥xi−xj∥2=∥xi∥2+∥xj∥2−2 xi⊤xj\|\mathbf x_i-\mathbf x_j\|^2=\|\mathbf x_i\|^2+\|\mathbf x_j\|^2-2\, \mathbf x_i^\top\mathbf x_j, not by broadcasting a 1,000×1,000×2,0001{,}000\times1{,}000\times2{,}000 array. Explain the ratio between the two numbers from the number of pairs. Already at k=200k=200 the largest distortion is below ε=0.3\varepsilon=0.3, while (b) asked for a much larger kk. Which part of the bound is loose: the constant 8 or the log⁡n\log n?
  5. Bernstein's inequality. ● Let XX be centered with ∣X∣≤M|X|\leq M and Var(X)=σ2\textrm{Var}(X)=\sigma^2.

    1. Show that E[Xk]≤σ2Mk−2\mathbb{E}[X^k]\leq\sigma^2M^{k-2} for k≥2k\geq2, and hence that E[eλX]≤1+σ2(eλM−1−λM)/M2\mathbb{E}[e^{\lambda X}]\leq1+\sigma^2(e^{\lambda M}-1-\lambda M)/M^2 for λ>0\lambda>0.
    2. Show that eu−1−u≤u2/(2(1−u/3))e^u-1-u\leq u^2/(2(1-u/3)) for 0≤u<30\leq u\lt 3 by comparing uk/k!u^k/k! with (u2/2)(u/3)k−2(u^2/2)(u/3)^{k-2}, that is, by using k!≥2⋅3k−2k!\geq2\cdot3^{k-2}. Conclude with 1+y≤ey1+y\leq e^y that E[eλX]≤exp⁡(λ2σ2/(2(1−λM/3)))\mathbb{E}[e^{\lambda X}]\leq\exp(\lambda^2\sigma^2/(2(1-\lambda M/3))) for 0<λ<3/M0\lt \lambda\lt 3/M.
    3. Apply the Chernoff method to an average of nn such variables with λ=t/c\lambda=t/c, where c=σ2+Mt/3c=\sigma^2+Mt/3. Check that λ<3/M\lambda\lt 3/M and that 1−λM/3=σ2/c1-\lambda M/3=\sigma^2/c, and conclude that the exponent is exactly −nt2/(2c)-nt^2/(2c), which proves (24.9.6).
    4. Show that (b) makes XX sub-exponential in the sense of (24.9.8) with ν2=2σ2\nu^2=2\sigma^2 and α=2M/3\alpha=2M/3.
    5. With n=10,000n=10{,}000 and δ=0.05\delta=0.05, show that Bernstein's bound is weaker than Hoeffding's at the worst-case variance σ2=14\sigma^2=\tfrac14 of a 0/1 outcome. Below which variance does it win, and which error rates does that correspond to?

Discussions