Skip to content
AI360XpertBeta

Algorithmic Stability

A stable algorithm barely changes its predictions when one training example is swapped. That insensitivity is what lets test error track training error, with tighter numbers for ridge and early-stopped SGD.

Uniform stability caps every swap at 0.001 while SGD stability grows with steps to 0.05 after 500 updates
Uniform stability caps every swap at 0.001 while SGD stability grows with steps to 0.05 after 500 updates

Why Does This Exist?

Test error is what you pay and training error is what you see, and the gap between them needs a guarantee. On 2,000 samples a ridge gap of 0.0010.001 means cross-validation tracks truth tightly, while an SGD gap of 0.050.05 after 500 steps means early stopping is not folklore but arithmetic. Without a stability number you cannot tell which regime you are in.

Stability is not one definition. Uniform stability controls the worst test point under the worst swap and gives high-probability bounds. Hypothesis stability averages over the swap and suits squared error. Leave-one-out stability tracks retraining without each point and connects to cross-validation. SGD stability grows with steps and learning rate, which explains early stopping.

This page separates the four variants with their standard rates. Sampling background lives in sampling distributions, resampling in bootstrap and resampling, the SGD loop in stochastic gradient descent variants, and neighbouring guarantees in bias variance decomposition and PAC Bayes bounds.

The one idea you need first

You need training sets SS and SiS^i differing in example ii, where SS is the full sample and SiS^i is SS with example ii swapped, plus outputs fSf_S and fSif_{S^i}, where ff is the trained predictor. Loss ℓ\ell measures one prediction error. Background is in sampling distributions and stochastic gradient descent variants.

Think of It Like This

Four ways to test a recipe

Uniform stability tastes every dish after swapping any ingredient: the worst change anywhere must be small. Hypothesis stability tastes the average dish after an average swap. Leave-one-out recooks the meal missing each ingredient in turn and compares. SGD stability watches the cook stir, where each extra stir lets one ingredient spread further.

All four test insensitivity, but strictness differs wildly. The uniform taste test fails recipes the average test passes, and the stir count explains why a briefly stirred soup is stable while an overnight stew is not.

Where it stops: recipes mix physically while algorithms mix through optimisation geometry. Only convexity or step limits make the stir count quantitative.

How It Actually Works

Uniform stability requires sup⁡S,Si,z∣ℓ(fS,z)−ℓ(fSi,z)∣≤β\sup_{S, S^i, z} \lvert \ell(f_S, z) - \ell(f_{S^i}, z) \rvert \le \beta, where the supremum runs over all datasets, swaps, and test points zz, and β\beta is the stability number. Hypothesis stability takes expectation over the swap. Leave-one-out stability bounds ∣ℓ(fS,zi)−ℓ(fSi,zi)∣\lvert \ell(f_S, z_i) - \ell(f_{S^i}, z_i) \rvert on the held-out point ziz_i. On-average stability bounds the mean over ii.

Standard rates, where GG is the Lipschitz constant bounding loss slope, λ\lambda is the strong-convexity from regularization, nn is sample size, η\eta is learning rate, and TT is step count: λ\lambda-strongly convex regularised ERM has uniform β≤2G2/λn\beta \le 2G^2/\lambda n, and smooth convex SGD has uniform β≲2L2ηT/n\beta \lesssim 2L^2\eta T/n with LL the Lipschitz constant, up to logs. Halve the steps and stability halves, and double the rate and it doubles.

Worked example

Ridge with G=1G = 1, λ=1\lambda = 1, and n=2000n = 2000 gives uniform β=2×1/(1×2000)=0.001\beta = 2 \times 1/(1 \times 2000) = 0.001. Its leave-one-out error then estimates test error within 0.0010.001 in expectation, so 55-fold cross-validation at 400400 per fold tracks truth tightly. Training at 0.1500.150 allows test up to about 0.1510.151 from stability alone.

SGD on a smooth convex loss with L=1L = 1, η=0.01\eta = 0.01, T=500T = 500, and n=200n = 200 gives β≤2×0.01×500/200=10/200=0.05\beta \le 2 \times 0.01 \times 500/200 = 10/200 = 0.05. Train at 0.150.15 and the stability gap alone allows test up to 0.200.20. Train for 5,0005{,}000 steps and β\beta grows toward 0.50.5, which is vacuous: the bound itself recommends early stopping, which matches practice.

Code

The point is the check: the same 0.0010.001 and 0.050.05 numbers, in plain Python.

def beta_ridge(G: float, lam: float, n: int) -> float:    return 2.0 * G * G / (lam * n)

def beta_sgd(eta: float, T: int, n: int) -> float:    return 2.0 * eta * T / n

b_ridge: float = beta_ridge(1.0, 1.0, 2000)b_sgd: float = beta_sgd(0.01, 500, 200)print((round(b_ridge, 4), round(b_sgd, 4)))  # -> (0.001, 0.05)print(round(0.15 + b_sgd, 2))  # -> 0.2

Ridge holds every swap to 0.0010.001 on 2,0002{,}000 samples, while 500500 SGD steps at 0.010.01 on 200200 samples hold to 0.050.05. Training at 0.150.15 plus 0.050.05 gives the 0.200.20 test ceiling above.

Watch Out For

Quoting uniform rates for a hypothesis-stable algorithm

Nearest neighbours have good hypothesis stability but poor uniform stability: one swap can flip a neighbourhood and move one test loss a lot while the average barely moves. The uniform bound goes vacuous while the hypothesis bound stays meaningful.

Symptom is rejecting an algorithm that generalises fine on average because its worst-swap β\beta looks large. Match variant to loss: bounded regression can use hypothesis stability, while high-probability claims need uniform.

Ignoring the step count in SGD stability

SGD stability grows with TT, so the bound at step 500500 with β=0.05\beta = 0.05 says nothing about step 50,00050{,}000 where β\beta heads toward 0.50.5. Reporting the early 0.050.05 beside final-epoch accuracy borrows a guarantee the run already spent.

Fix by stating (T,η,n)(T, \eta, n) with every SGD stability number. No steps, no claim.

The Quick Version

  • Uniform stability caps the worst swap on the worst test point, while hypothesis and leave-one-out average instead.
  • Strongly convex ERM gets uniform 2G2/λn2G^2/\lambda n, which is 0.0010.001 for ridge at 20002000 samples.
  • Smooth SGD gets about 2ηT/n2\eta T/n, which is 0.050.05 at 500500 steps of 0.010.01 on 200200 samples.
  • Early stopping is a stability decision because fewer steps mean smaller β\beta.
  • Training at 0.150.15 with β=0.05\beta = 0.05 allows test up to 0.200.20.
  • Always state steps and variant, since uniform, average, and SGD numbers are not interchangeable.