Tutorials › Statistical Learning (Graduate) › High-Probability Generalization from Stability

Localized Complexity and Stability · Tutorial 189 of 989

High-Probability Generalization from Stability

Learn to turn uniform stability into a high-probability generalization guarantee by combining an expected-gap bound with bounded-differences concentration.

Advanced 10 min read

What You'll Learn

  • Define uniform stability for an algorithm and a bounded loss
  • Derive the expected generalization-gap bound from leave-one-out replacement
  • Apply bounded-differences concentration to obtain a high-probability guarantee
  • Separate the contribution of algorithmic stability from sampling fluctuation
  • Calculate the bound in numerical examples and recognize when it is vacuous

From Expected Generalization to a Probability Guarantee

An algorithm can have a small expected difference between population risk and training risk without that difference being small on every sample. A high-probability statement addresses the sample-to-sample fluctuation: it says that, except on an event of specified probability, the population risk is no more than the observed training risk plus an explicit allowance. Uniform stability supplies one part of that allowance; concentration of the sample-dependent gap supplies the other.

We consider a fixed learning algorithm and independent observations. The loss is bounded, so changing a single observation cannot cause an arbitrarily large direct change in the training loss. Stability also controls how much the fitted rule changes when one observation is replaced. Together these facts make the generalization gap concentrate around its expectation.

Setup and Uniform Stability

Let \(Z_1,\ldots,Z_n\) be independent observations with common distribution \(P\), and write \(S=(Z_1,\ldots,Z_n)\). A deterministic learning algorithm \(A\) maps a sample to a prediction rule \(A(S)\). Let \(\ell(h,z)\) be the loss of rule \(h\) on observation \(z\), and suppose it is measurable and takes values in \([0,1]\). Define the population and empirical risks by

$$ R(h)=E_{Z\sim P}[\ell(h,Z)], \qquad \widehat R_S(h)=\frac{1}{n}\sum_{i=1}^n \ell(h,Z_i). $$

The generalization gap of the fitted rule is \(G(S)=R(A(S))-\widehat R_S(A(S))\). A positive gap means the population risk exceeds the training risk. The expectation in \(R(A(S))\) is over a fresh observation \(Z\) independent of the training sample, while \(A(S)\) is held fixed.

Definition: The algorithm \(A\) has uniform stability \(\beta\geq 0\) with respect to \(\ell\) if, for every pair of samples \(S,S'\) that differ in at most one coordinate and every observation \(z\), $$ |\ell(A(S),z)-\ell(A(S'),z)|\leq \beta. $$

The bound is uniform over both the replaced sample coordinate and the test observation. Stability controls the change in loss caused by changing the fitted rule; it does not say that the loss itself is small. We assume throughout that the risks and random quantities used below are measurable and integrable. For the concentration argument, the observations are independent as stated above.

Worked Example: A Direct Risk Bound at a Given Confidence Level

Suppose \(n=1000\), the loss lies in \([0,1]\), and the algorithm has uniform stability \(\beta=0.001\). The observed training risk is \(0.20\). Calculate the bound at confidence level \(95\%\), so \(\delta=0.05\).

The theorem below gives the gap allowance \[ \beta+(2n\beta+1)\sqrt{\frac{\log(1/\delta)}{2n}}. \] Here \(2n\beta+1=2(1000)(0.001)+1=3\), and \(\log(1/0.05)=\log(20)\approx 2.9957\). Thus \[ \sqrt{\frac{\log(20)}{2000}}\approx \sqrt{0.0014979}\approx 0.03870, \] so the allowance is \(0.001+3(0.03870)\approx 0.1171\). With probability at least \(0.95\), the population risk is at most \(0.20+0.1171=0.3171\).

This is an upper bound, not a prediction that the population risk equals \(0.3171\). It can be conservative, but it explicitly separates the stability contribution from a confidence-dependent fluctuation term.

Expected Generalization Gap

First, stability bounds the expected signed gap. The argument compares a training observation with an independent replacement and uses the fact that the replaced sample has the same distribution as the original sample.

Result: Under the setup above, if \(A\) has uniform stability \(\beta\), then $$ |E[G(S)]|\leq \beta. $$

To verify the result, let \(Z_i'\) be an independent draw from \(P\), and let \(S^{(i)}\) be \(S\) with coordinate \(i\) replaced by \(Z_i'\). By independence and identical distributions, the pair consisting of \(S^{(i)}\) and \(Z_i\) has the same distribution as the pair consisting of \(S\) and a fresh test observation. Therefore,

$$ E[G(S)] =\frac{1}{n}\sum_{i=1}^n E\!\left[\ell(A(S^{(i)}),Z_i)-\ell(A(S),Z_i)\right]. $$

The samples \(S^{(i)}\) and \(S\) differ in at most one coordinate. Uniform stability bounds the absolute value of each difference inside the expectation by \(\beta\). Hence each expectation has absolute value at most \(\beta\), and the absolute value of their average is also at most \(\beta\). This proves the result. \(\square\)

The expected-gap result alone is not a high-probability guarantee: a random variable can have a small expectation while still taking relatively large values on some samples. The next step controls how much \(G(S)\) can change when one input observation changes.

Bounded Differences and the High-Probability Bound

We use the bounded-differences inequality, also called McDiarmid’s inequality. If \(W_1,\ldots,W_n\) are independent and a measurable function \(F(W_1,\ldots,W_n)\) changes by at most \(c_i\) whenever only coordinate \(i\) is replaced, then, for \(t>0\),

$$ P\!\left(F-E[F]\geq t\right) \leq \exp\!\left(-\frac{2t^2}{\sum_{i=1}^n c_i^2}\right). $$

For the generalization gap, replace coordinate \(i\) of \(S\) to obtain \(S'\). The population-risk term changes by at most \(\beta\): for every test observation the losses differ by at most \(\beta\), and taking expectations preserves that bound. For the empirical-risk term, each of the \(n-1\) unchanged observations contributes a loss change of at most \(\beta\). The remaining observation can change both its value and the fitted rule, but both losses are in \([0,1]\), so their difference is at most \(1\). Consequently,

$$ |\widehat R_S(A(S))-\widehat R_{S'}(A(S'))| \leq \frac{(n-1)\beta+1}{n}. $$

Combining the two changes gives a coordinate bound for \(G\):

$$ |G(S)-G(S')| \leq \beta+\frac{(n-1)\beta+1}{n} =2\beta+\frac{1-\beta}{n} \leq 2\beta+\frac{1}{n}. $$

Thus we can use \(c_i=2\beta+1/n\) for each coordinate. Applying the bounded-differences inequality and the expected-gap result gives the following theorem.

Theorem: Suppose \(Z_1,\ldots,Z_n\) are independent and identically distributed, the loss is measurable and lies in \([0,1]\), and the deterministic algorithm \(A\) has uniform stability \(\beta\). For every \(0<\delta<1\), with probability at least \(1-\delta\) over the training sample, $$ R(A(S)) \leq \widehat R_S(A(S)) +\beta+(2n\beta+1)\sqrt{\frac{\log(1/\delta)}{2n}}. $$

Indeed, \(\sum_i c_i^2=n(2\beta+1/n)^2=(2n\beta+1)^2/n\). Set \[ t=(2n\beta+1)\sqrt{\frac{\log(1/\delta)}{2n}}. \] The bounded-differences inequality then gives \(P(G-EG\geq t)\leq\delta\). Since \(E[G]\leq\beta\), outside an event of probability at most \(\delta\), \(G\leq\beta+t\). Substituting \(G=R(A(S))-\widehat R_S(A(S))\) proves the stated risk bound. \(\square\)

The first term, \(\beta\), comes from the expected generalization gap. The remaining term is the sampling fluctuation allowed at confidence level \(1-\delta\). In particular, decreasing \(\delta\) makes the guarantee more conservative. Since a population risk is at most \(1\), the right-hand side can always be capped at \(1\); if the displayed bound exceeds \(1\), it is valid but may not be informative.

Worked Example: A Stability Level That Decreases With Sample Size

Suppose \(n=2500\), \(\beta=1/n=0.0004\), and \(\delta=0.05\). If the training risk is \(0.18\), calculate the resulting population-risk bound.

The factor multiplying the square root is \(2n\beta+1=2(2500)(0.0004)+1=3\). Also, \[ \sqrt{\frac{\log(20)}{2(2500)}} =\sqrt{\frac{2.9957}{5000}} \approx 0.02447. \] The full allowance is therefore \(0.0004+3(0.02447)\approx 0.0738\), giving \(R(A(S))\leq 0.18+0.0738=0.2538\) with probability at least \(0.95\).

This calculation illustrates why the two contributions should be kept distinct. Here the stability contribution is \(0.0004\), while the confidence-dependent fluctuation contributes about \(0.0734\).

Worked Example: Stability of the Sample-Mean Predictor

Let \(Y_1,\ldots,Y_{100}\) be independent Bernoulli observations with success probability \(p=0.3\). The algorithm predicts with the sample mean, \(A(S)=\bar Y\), and uses squared-error loss \(\ell(a,y)=(a-y)^2\). Since \(a,y\in[0,1]\), this loss lies in \([0,1]\). Verify a stability value and calculate the bound for a sample with 30 ones and 70 zeros.

If one observation is replaced, the sample mean changes by at most \(1/100\), so \(|\bar Y-\bar Y'|\leq 0.01\). For any \(y\in[0,1]\), \[ |(\bar Y-y)^2-(\bar Y'-y)^2| =|\bar Y-\bar Y'|\,|\bar Y+\bar Y'-2y| \leq 0.01(2)=0.02. \] Thus \(\beta=0.02\) is a valid uniform-stability bound.

For the specified sample, \(\bar Y=0.3\). Its empirical squared-error risk is \[ \widehat R_S(A(S)) =\frac{30(1-0.3)^2+70(0-0.3)^2}{100} =\frac{30(0.49)+70(0.09)}{100} =\frac{14.7+6.3}{100} =0.21. \] The population risk at prediction \(0.3\) is \[ R(0.3)=0.3(1-0.3)^2+0.7(0-0.3)^2 =0.3(0.49)+0.7(0.09) =0.21. \]

At \(\delta=0.05\), the theorem’s allowance is \[ 0.02+(2(100)(0.02)+1)\sqrt{\frac{\log(20)}{200}} =0.02+5\sqrt{\frac{2.9957}{200}} \approx 0.02+5(0.1224) \approx 0.632. \] The resulting upper bound is about \(0.842\), which is valid but loose compared with the actual population risk \(0.21\). This example shows that bounded loss and stability give a guarantee, but do not ensure that the numerical guarantee is sharp at a particular sample size.

Common Pitfall and Interpretation

A common mistake is to treat \(\beta\) as a high-probability bound on the generalization gap. That reasoning confuses the expected-gap result with concentration: \(|E[G]|\leq\beta\) controls an expectation, not the realized value of \(G(S)\) for most samples. The correction is to add a fluctuation term obtained from bounded differences, as in the theorem. Conversely, using only the fluctuation term and dropping \(\beta\) also needs justification; the theorem’s proof controls deviations around \(E[G]\), so the expected-gap contribution must be included.

The result concerns the generalization gap of the algorithm’s output, not a bound on excess risk relative to an optimal rule. Its usefulness depends on the size of both terms. If stability is weak, or the sample is small, the confidence allowance can be large—even when the observed training risk is small. For losses bounded by a constant other than \(1\), one can rescale the loss to \([0,1]\), apply the theorem, and scale the resulting risk bound back.

Check Your Understanding

Use the assumptions and bound stated above to answer these questions.

  1. In the theorem, which term accounts for the expected generalization gap, and which term depends on the confidence level?
  2. Why does replacing one observation change the empirical risk by at most \(((n-1)\beta+1)/n\)?
  3. If \(\beta=0\), what fluctuation term remains in the bound, and why does a sampling term remain?
  4. For fixed \(n\) and \(\beta\), what happens to the displayed allowance as \(\delta\) decreases?
  5. Why does a small expected generalization gap by itself not establish a high-probability guarantee?
Clinical Biostats