TL;DR
- Stability principle: if the output of an algorithm changes only a little when one training point is replaced, the algorithm generalizes. Unlike capacity bounds, this looks at the actual algorithm, not the whole function class.
- is with the -th point replaced by an independent . Average stability averages the loss change on the replaced point; uniform stability . Always .
- Proposition 1: : the expected generalization gap equals the average stability.
- Theorem 2: with loss bounded by and , with probability : . The gap vanishes iff .
- Stability alone does not give consistency (a constant predictor is perfectly stable); stability plus (approximate) ERM does.
- Theorem 3: ERM with a -strongly convex, -Lipschitz loss is uniformly stable with , independent of the complexity of . Theorems 4-6: GD and SGD on convex, -smooth, -Lipschitz losses with step sizes have (non-convex: ): fewer steps, more stable.
Exam relevance
- Real exam, task type “algorithmic stability” (4 P): the bound of Theorem 2 is given together with a table of candidate rates (, , …); tick yes/no whether the bound goes to 0. Key fact: it vanishes iff . See the task and the widget.
- Mock exam, task 6: uniform stability of the averaging rule with the squared loss, then what it implies (Proposition 1). Train it with the own-number version.
- Multiple choice: vs. , stability vs. consistency, the assumptions of Theorem 3, why the plain squared loss is not strongly convex.
- Sheet 5: 1-NN is not uniformly stable at rate but is stable on average; the averaging algorithm has ; stability of one-pass SGD.
Overview: 1. Motivation and definitions, 2. Stability implies generalization, 3. ERM with strongly convex loss is stable, 4. (S)GD on smooth losses is stable.
Motivation and key definitions
Why stability?
Slides 3-6
(Literature: Hardt and Recht Sec. 6.4, Mohri Sec. 11.2, Shalev-Shwartz and Ben-David Sec. 13.2. Key original references: Bousquet and Elisseeff 2002 for the standard bound; Shalev-Shwartz, Shamir, Srebro and Sridharan 2010 for “stability is sufficient and necessary for learning”; Hardt, Recht and Singer 2016 for the stability of SGD.)
Motivation 1. The standard approach of SLT proves generalization by bounding the capacity of the function class. This is often technically challenging and gives worst-case guarantees over all functions in the class instead of looking at the actual optimizers. In the perceptron bound (Lecture 2) we already saw the stability principle: if the result of a learning algorithm changes only a little when we fiddle with the data a little, the algorithm tends to generalize well.
Motivation 2. The LLN or the CLT hold as long as no single data point has much more influence than the others: the influence of one on the empirical average is “of the order “. Stability measures, in the same spirit, the influence of single data points on the empirical risk.
Definitions
Slides 7-10
Samples and notation
Two samples drawn i.i.d. from : and . The adapted sample replaces the -th point of by the -th point of :
Shorthand: and . or is the function learned by algorithm on , and the empirical risk on (analogously , ).
Average stability
For each we compare , trained on the original sample, with , trained with replaced by , both evaluated on . Note that is a test point for but a training point for .
Uniform stability
For and that differ in exactly one point, and a completely new test point (independent of both samples):
Obviously .
Mini example: the averaging algorithm (Sheet 5)
Regression on with the squared loss, for every . Replacing one label changes the prediction by . With the two predictions and a test label : . So .
Not every algorithm is uniformly stable
1-nearest neighbour (Sheet 5): on , replacing the one training point at can flip the prediction at a test point near , so the loss changes by 1 and , not . On average, though, a single point is the nearest neighbour of a random test point only with probability .
Algorithmic stability implies generalization
The expected generalization gap
Slides 11-14
(Literature: Mohri textbook.)
Proposition 1 (expected generalization gap equals average stability)
with the expectation over the training sample .
Proof
Write both expectations as averages over equal terms.
True error. Blow it up into a sum of equal terms and write out with the independent test points :
Empirical error. By definition, with a training point, then rename: has the same distribution as , so
Subtracting gives .
Discussion
This points in an interesting direction (bounding the generalization error by stability), but average stability is hard to evaluate. The stronger notion of uniform stability is easier to bound in practice and gives a nice high-probability bound, proved with McDiarmid’s inequality (Lecture 3).
Uniformly stable algorithms generalize
Slides 15-19
Theorem 2 (generalization bound for stable algorithms)
Assume the loss is bounded by a constant and let be the uniform stability of on samples. Then with probability at least over the samples :
Proof sketch (full proof: Mohri, Sec. 11.2, p. 268)
Apply McDiarmid to .
Step 1: bounded differences. By the triangle inequality
(1): by the definition of stability.
(2): write the empirical risks as sums and split off the term :
So .
Step 2: McDiarmid. With :
Solving for : with probability at least , . Finally by Proposition 1.
Trap
On slide 16 the bound for term (2) reads ""; it should be (the loss bound), as on slide 18.
Discussion: which rates are good enough?
Slide 20
As soon as we can bound the uniform stability of an algorithm, we can plug it into Theorem 2. The key term is
and it goes to 0 if and as .
The condition to remember
The uniform stability needs to be of order to be useful. works; does not: then stays constant.
Task: which stability rates are good enough?
Exam-style task: stability rates (4 P)
Use Theorem 2 with .
bound → 0? (a) (1.5 P, easy) Fill in yes/no for each rate.
(b) (1 P, harder) Evaluate the gap for , and .
(c) (1.5 P, transfer) GD with constant step size has after steps (Theorem 4). How may the number of steps grow so that Theorem 2 still gives a vanishing gap?
Solution
(a) Check : yes (), no (constant 1), yes (), yes (), no (), no (). (0.25 P each)
(b) , , . Gap . (1 P)
(c) iff . For example works, (one step per training point) does not. More steps make GD less stable: an argument for early stopping. (1.5 P)
Stability does not immediately imply consistency
Slides 21-22
Theorem 2 only says that for the function picked by the algorithm, . We do not (yet) know whether this function is anywhere close to the best in , nor to the Bayes predictor.
Counterexample
A naive algorithm that always predicts 0 is perfectly stable () and satisfies , but it is not the best in . For consistency we need a separate condition about the (empirical) risk of the classifier.
Stability + approximate ERM ⇒ consistency
Run ERM on a huge class ; if the ERM solution is uniformly stable, we get consistency:
Task: stability of an averaging rule
Exam-style task: an averaging rule with the absolute loss (4 P)
Labels , the algorithm predicts the mean label for every , and the loss is the absolute loss .
(a) (1 P, easy) Show that and differ pointwise by at most .
(b) (1.5 P, harder) Show and give the loss bound .
(c) (1.5 P, transfer) Evaluate the gap of Theorem 2 for , . What does the result say about , and what does it not say?
Solution
(a) Only the -th label changes: . (1 P)
(b) The absolute loss is 1-Lipschitz in the prediction: for every test point, so . Predictions and labels lie in , so . (1.5 P)
(c) , , : gap . With probability 0.95 the true risk is at most the training risk plus , and the gap tends to 0 because : no overfitting. It does not say that the risk is small: a constant predictor can be far from the regression function (large approximation error). (1.5 P)
ERM with strongly convex loss function is stable
Motivation and strongly convex functions
Slides 23-27
(Literature: Hardt and Recht, Chapter 6, p. 111, Theorem 4.) Machine learning often minimizes a loss on training data (ERM). For small classes we can prove uniform convergence; if the class is too large for SLT, uniform stability might help. Question: is ERM uniformly stable? Answer: only under very strong assumptions on the loss.
-strongly convex
A differentiable on a convex domain is -strongly convex () if for all
In 1d with twice differentiable: convex iff , strongly convex if everywhere (a lower bound on the curvature). In : the smallest eigenvalue of the Hessian is at least .


If the loss is strongly convex, the empirical risk is strongly convex with the same . Then there always is a global optimum and it is not “hidden” in flat parts; GD and SGD easily find it.
Theorem 3: ERM is stable for strongly convex losses
Slides 28-33
Theorem 3 (ERM for strongly convex loss functions is stable)
Let each function in be parameterized by . Assume the loss is -strongly convex in and -Lipschitz in , for every . Then the empirical risk minimizer is uniformly stable with
First discussion
- The theorem is about the empirical risk minimizer itself, not about an algorithm that tries to find it.
- The complexity of does not show up anywhere. This is great.
- scales as , so Theorem 2 gives a vanishing gap and, with the ERM argument above, consistency.
- The assumptions are really strong. Promising, but not yet a solution for more complex losses.
Proof of Theorem 3
Fix , and a test point . Let , be the ERM minimizers. Because is -Lipschitz, , so it suffices to show .
Step 1. A -strongly convex with minimizer satisfies (definition plus ). The empirical risk is -strongly convex with minimizer , so
Step 2. Write as a sum, split off the term , add and subtract the terms with and use that minimizes :
Step 3. Combine: , so and .
Two small slips on the slides
Slide 31 writes on the right of step 1; since minimizes , the non-negative difference is . Slide 33 ends with ; the Lipschitz step adds a factor , giving as in the theorem.
Discussing the assumption
Slide 34
The squared loss of a linear model is not strongly convex
has gradient and Hessian . The Hessian has rank 1, so its smallest eigenvalue is 0 (for ): not strongly convex. Adding regularization makes it strongly convex, and this is the main use case of Theorem 3 (Lecture 5).
Task: applying Theorem 3
Exam-style task: stability of ERM from strong convexity (4 P)
One-dimensional parameter , labels , loss . ERM returns the mean label.
(a) (1 P, easy) Determine the strong convexity constant and a Lipschitz constant of the loss in on .
(b) (1.5 P, harder) What bound on does Theorem 3 give?
(c) (1.5 P, transfer) Compute directly as in the averaging example. How tight is Theorem 3 here? What changes for linear regression with parameters?
Solution
(a) , so . , so . (1 P)
(b) . (1.5 P)
(c) Means differ by at most , and . Theorem 3 is 4 times too large here but has the right order . For the squared loss has the rank-1 Hessian and is not strongly convex; one needs a regularizer , which gives . (1.5 P)
SGD is stable
Motivation: is SGD always stable?
Slides 35-39
(Literature: Hardt and Recht, Chapter 6, Theorem 6, p. 120; original paper: Hardt, Recht and Singer, “Train faster, generalize better: Stability of stochastic gradient descent”, ICML 2016.)
- ERM is stable, but only under super-strong assumptions (strongly convex loss, a lower bound on the curvature), and the result is about the perfect minimizer, ignoring how to find it.
- Now we look at a specific algorithm and the stability of its solutions: SGD.
- We want uniform stability of order . SGD won’t be stable if it makes super-large steps that cannot be controlled, or if the loss landscape is super-fragmented so we cannot control where we jump. So we need assumptions.
Beta-smooth functions
Slides 40-41
-smooth
A differentiable is -smooth if its gradient is -Lipschitz:
Smoothness is good for gradient methods: the gradient changes slowly, so after a small step it does not point in a completely different direction. While -strong convexity is a lower bound on the curvature, -smoothness is more like an upper bound.
Smooth losses
- Squared loss for linear regression : convex and smooth with ; if it is -smooth. (The slide says “-smoothness”; with the constant is .)
- Logistic loss : the Hessian satisfies , so it is smooth if is bounded.
Stability of gradient descent
Slides 42-47
To minimize : GD uses the full gradient, ; SGD samples one point per step, .
Theorem 4 (stability of GD)
Let the loss be continuously differentiable, convex, -smooth and -Lipschitz. Run GD with step sizes for steps from a fixed . Then the solution is uniformly stable with
Proof sketch
Step 1. Compare the trajectories on and : and . Add and subtract :
Step 2 (blue). and differ in one point: only one summand changes, and a gradient at one point changes by at most , so .
Step 3 (green). A gradient step with step size on a convex -smooth function is non-expansive: . This is where the assumptions are used.
Step 4. So . Sum from to with the same start (the terms telescope): .
Step 5. Lipschitz: .
Stability of SGD
Slides 48-51
Theorem 5 (stability of SGD, convex case)
Same assumptions (continuously differentiable, convex, -smooth, -Lipschitz), SGD with step sizes for steps:
The proof goes along similar lines but is more complicated because of the randomness: GD introduces a small bias at every step; SGD only seldom (when it updates on the changed sample), but then a larger change happens. Details: Hardt, Recht and Singer (and the assignments).
Theorem 6 (stability of SGD, non-convex case)
Assume the loss is -Lipschitz and -smooth (not necessarily convex), and run SGD for steps with decreasing step sizes . Then
Ignoring constants:
Depending on , this can be combined with Theorem 2 to get generalization (but not necessarily consistency).
- These bounds are about stability; they do not yet guarantee consistency (how many steps ? convergence to an ERM minimizer?). Hardt, Recht and Singer give some guarantees for the convex setting.
Discussion and more results
Slides 52-53
- The theorems on GD / SGD are the first results about an actual learning algorithm, not just an abstract empirical risk minimizer.
- Depending on the number of steps we might or might not get stability of order , as needed in the generalization bound.
- From the point of view of stability, fewer steps are better (a smaller generalization gap), but this ignores whether we get close enough to the actual minimizer. We revisit this with regularization (Lecture 5).
- Stability has been proved for many algorithms: regularization, many kernel algorithms, GD / SGD in various (also non-convex) scenarios: SGD for deep networks (Hardt, Recht and Singer, ICML 2016), noisy SGD (Pensia, Jog and Loh, 2018), early stopping (Hardt, Ma and Recht, ICLR 2020), sharp vs. flat minima (Wu, Zhu et al., NeurIPS 2020).
Summary
| Result | Statement | Assumptions |
|---|---|---|
| Proposition 1 | none | |
| Theorem 2 | loss ; useful iff | |
| Stability + ERM | consistency | ERM solution uniformly stable |
| Theorem 3 (ERM) | -strongly convex, -Lipschitz; no complexity of | |
| Theorems 4, 5 (GD, SGD) | convex, -smooth, -Lipschitz, | |
| Theorem 6 (SGD) | non-convex, |
Self-Test
Question cards (12)
What is the stability principle, and why is it an alternative to capacity bounds?
Answer
If the output of an algorithm changes only a little when one training point is replaced, the algorithm generalizes. It analyses the actual algorithm instead of giving worst-case guarantees over all functions of a class.
Define , average stability and uniform stability.
Answer
is with replaced by an independent . . . Always .
State and prove Proposition 1.
Answer
. Write with test points , and by exchanging and ; subtract.
State Theorem 2 and the tool used in its proof.
Answer
For loss bounded by and : w.p. , . McDiarmid applied to with bounded differences , plus .
Which uniform stability rates make Theorem 2 useful, and why?
Answer
: the term behaves like . works, gives a constant gap.
Why does stability alone not give consistency, and what does?
Answer
A constant predictor is perfectly stable but not the best in . With ERM: : small by stability, by minimization, small by the LLN.
Define -strong convexity and give the 1d intuition.
Answer
. In 1d: , a lower bound on the curvature; in the smallest Hessian eigenvalue is .
State Theorem 3 and sketch its proof.
Answer
-strongly convex and -Lipschitz loss: . Strong convexity gives , so ; Lipschitz gives another factor .
Why is the squared loss of a linear model not strongly convex, and how is this fixed?
Answer
Its Hessian has rank 1, so for the smallest eigenvalue is 0. Adding makes it -strongly convex (ridge regression).
Define -smoothness and compare it with strong convexity.
Answer
: the gradient is -Lipschitz, an upper bound on the curvature; strong convexity is a lower bound.
State the stability bound for GD and the key steps of its proof.
Answer
Convex, -smooth, -Lipschitz, : . The gradients on and differ by at most ; a gradient step is non-expansive; so the distance grows by at most per step; sum and apply Lipschitz.
What does the SGD stability bound say about the number of training steps?
Answer
The bound grows with (convex) or (non-convex): fewer steps give more stability and a smaller generalization gap, but maybe not a good minimizer. With constant step size, Theorem 2 needs .
Multiple Choice
Multiple choice (7)
Which relation between the two stability notions always holds?
they are unrelated
Explanation
An average of loss differences is at most their supremum (slide 10).
Proposition 1 states that the expected generalization gap
is at most for every algorithm
equals the average stability
equals the uniform stability
is 0 for ERM
Explanation
Exactly , which is at most . ERM usually has a positive gap (the training error is optimistic).
An algorithm has uniform stability and loss bound . What does Theorem 2 give?
a gap of order
a gap of order
a gap that does not go to 0
consistency
Explanation
is a constant; one needs .
Which statement about stability and consistency is true?
Every uniformly stable algorithm is consistent.
A constant predictor is perfectly stable but in general not consistent.
Consistent algorithms are always uniformly stable at rate .
Stability implies that the approximation error is 0.
Explanation
Slide 21. Stability controls the gap between training and test error; consistency needs in addition that the empirical risk is (approximately) minimized.
Which assumptions does Theorem 3 ( ) need?
finite VC dimension of
a loss that is -strongly convex and -Lipschitz in the parameters
a -smooth loss and step sizes
linearly separable data
Explanation
The complexity of does not appear at all. Smoothness and step sizes are the assumptions of the GD/SGD theorems.
For GD on a convex, -smooth, -Lipschitz loss, the stability bound suggests that
running fewer steps (or with smaller steps) makes the solution more stable
running more steps always improves generalization
the step size does not matter
the bound is independent of
Explanation
The bound grows with the total step length; this supports early stopping, at the price of possibly not reaching a good minimizer.
Why is 1-nearest neighbour not uniformly stable at rate ?
because it has infinite VC dimension
because replacing a single training point can flip the prediction at a test point, changing the loss by 1
because its loss is not bounded
because it is not an ERM algorithm
Explanation
Sheet 5: uniform stability is a supremum over all samples and test points, and one point can be the nearest neighbour of the test point. On average the effect is only .
References
All sources cited on the slides, in slide order (13 entries)
Slide Source Key point 3 Hardt and Recht, Patterns, Predictions, and Actions, Sec. 6.4 (online) stability 3 Mohri, Rostamizadeh and Talwalkar, Foundations of Machine Learning, Sec. 11.2 stability bounds (full proof of Theorem 2, p. 268) 3 Shalev-Shwartz and Ben-David, Understanding Machine Learning, Sec. 13.2 (online) stability and regularization 3 Bousquet and Elisseeff, “Stability and generalization”, JMLR, 2002 the standard uniform stability bound 3 Shalev-Shwartz, Shamir, Srebro and Sridharan, “Learnability, Stability and Uniform Convergence”, JMLR, 2010 stability is sufficient and necessary for learning 3, 36, 53 Hardt, Recht and Singer, “Train faster, generalize better: Stability of stochastic gradient descent”, ICML 2016 stability of SGD 11 Mohri textbook stability implies generalization 23 Hardt and Recht, Chapter 6, p. 111, Theorem 4 ERM with strongly convex loss is stable 36 Hardt and Recht, Chapter 6, Theorem 6, p. 120 stability of (S)GD 38 Li et al., “Visualizing the loss landscape of neural nets”, NeurIPS 2018 loss landscape figure 53 Pensia, Jog and Loh, “Stability of stochastic gradient descent on non-convex losses”, arXiv 2018 noisy SGD 53 Hardt, Ma and Recht, “Identity matters in deep learning”, ICLR 2020 stability and early stopping 53 Wu, Zhu et al., “Understanding SGD generalization in deep learning via stability”, NeurIPS 2020 sharp vs. flat minima
Related
- Previous: Lecture 3: Statistical Learning Theory · Course: Overview
- Concepts: Algorithmic Stability, Strong Convexity, Smoothness, Stochastic Gradient Descent, Hoeffding Inequality (McDiarmid), Leave-One-Out Error
- Exercises: Sheet 5 (stability of 1-NN, the averaging algorithm, one-pass SGD)