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.
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 means cross-validation tracks truth tightly, while an SGD gap of 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 and differing in example , where is the full sample and is with example swapped, plus outputs and , where is the trained predictor. Loss 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 , where the supremum runs over all datasets, swaps, and test points , and is the stability number. Hypothesis stability takes expectation over the swap. Leave-one-out stability bounds on the held-out point . On-average stability bounds the mean over .
Standard rates, where is the Lipschitz constant bounding loss slope, is the strong-convexity from regularization, is sample size, is learning rate, and is step count: -strongly convex regularised ERM has uniform , and smooth convex SGD has uniform with the Lipschitz constant, up to logs. Halve the steps and stability halves, and double the rate and it doubles.
Worked example
Ridge with , , and gives uniform . Its leave-one-out error then estimates test error within in expectation, so -fold cross-validation at per fold tracks truth tightly. Training at allows test up to about from stability alone.
SGD on a smooth convex loss with , , , and gives . Train at and the stability gap alone allows test up to . Train for steps and grows toward , which is vacuous: the bound itself recommends early stopping, which matches practice.
Code
The point is the check: the same and 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.2Ridge holds every swap to on samples, while SGD steps at on samples hold to . Training at plus gives the 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 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 , so the bound at step with says nothing about step where heads toward . Reporting the early beside final-epoch accuracy borrows a guarantee the run already spent.
Fix by stating 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 , which is for ridge at samples.
- Smooth SGD gets about , which is at steps of on samples.
- Early stopping is a stability decision because fewer steps mean smaller .
- Training at with allows test up to .
- Always state steps and variant, since uniform, average, and SGD numbers are not interchangeable.