Documentation

CslibFrontier.MachineLearning.LossMinimization.Stability

Replace-one stability #

A learning rule A : (Fin m → Z) → W overfits when the risk of A S on the training sample S is much smaller than its true risk. Replace-one stability measures how much the loss of A S on a training example S i grows when that example is replaced by a fresh one z' [ShalevShwartzBenDavid2014, Chapter 13]. This file proves that the two quantities agree in expectation, and that a rule that is stable at rate ε generalizes at rate ε.

The fresh example and the sample are drawn together from (Measure.pi fun _ => D).prod D; a pair p consists of the sample p.1 and the replacement p.2, and Function.update p.1 i p.2 is the sample S⁽ⁱ⁾ of [ShalevShwartzBenDavid2014, Section 13.2].

Main definitions #

Main results #

References #

The replace-one gap #

noncomputable def Cslib.MachineLearning.replaceOneGap {W : Type u_1} {Z : Type u_2} [MeasurableSpace Z] (ℓ : W → Z → ℝ) (D : MeasureTheory.Measure Z) {m : ℕ} (A : (Fin m → Z) → W) :

The expected replace-one gap of a learning rule A on m examples from D: the expected increase 𝔼_{(S, z'), i} [ℓ(A(S⁽ⁱ⁾), z_i) - ℓ(A S, z_i)] of the loss on the i-th example when it is replaced by an independent example z', for a uniformly random index i [ShalevShwartzBenDavid2014, Theorem 13.2]. Here S⁽ⁱ⁾ is Function.update S i z'.

Both terms are Bochner integrals, which are 0 for non-integrable integrands. So a rule whose losses are not integrable under D has gap 0, and the gap, and stability defined from it, carry information only for integrable losses; the results below assume integrability.

theorem Cslib.MachineLearning.replaceOneGap_def {W : Type u_1} {Z : Type u_2} [MeasurableSpace Z] (ℓ : W → Z → ℝ) (D : MeasureTheory.Measure Z) {m : ℕ} (A : (Fin m → Z) → W) :
replaceOneGap ℓ D A = Finset.univ.expect fun (i : Fin m) => ∫ (p : (Fin m → Z) × Z), ℓ (A (Function.update p.1 i p.2)) (p.1 i) - ℓ (A p.1) (p.1 i) ∂(MeasureTheory.Measure.pi fun (x : Fin m) => D).prod D
theorem Cslib.MachineLearning.integral_update_eval {Z : Type u_2} [MeasurableSpace Z] (D : MeasureTheory.Measure Z) [MeasureTheory.IsProbabilityMeasure D] {m : ℕ} (i : Fin m) (g : (Fin m → Z) × Z → ℝ) :
∫ (p : (Fin m → Z) × Z), g (Function.update p.1 i p.2, p.1 i) ∂(MeasureTheory.Measure.pi fun (x : Fin m) => D).prod D = ∫ (p : (Fin m → Z) × Z), g p ∂(MeasureTheory.Measure.pi fun (x : Fin m) => D).prod D

Replacing one example by a fresh one preserves expectations: for m i.i.d. examples and an independent example z' from D, 𝔼 [g(S⁽ⁱ⁾, z_i)] = 𝔼 [g(S, z')], where S⁽ⁱ⁾ is Function.update S i z'.

theorem Cslib.MachineLearning.integrable_update_eval {Z : Type u_2} [MeasurableSpace Z] {D : MeasureTheory.Measure Z} [MeasureTheory.IsProbabilityMeasure D] {m : ℕ} (i : Fin m) {g : (Fin m → Z) × Z → ℝ} (hg : MeasureTheory.Integrable g ((MeasureTheory.Measure.pi fun (x : Fin m) => D).prod D)) :
MeasureTheory.Integrable (fun (p : (Fin m → Z) × Z) => g (Function.update p.1 i p.2, p.1 i)) ((MeasureTheory.Measure.pi fun (x : Fin m) => D).prod D)

The integrability counterpart of Cslib.MachineLearning.integral_update_eval.

theorem Cslib.MachineLearning.integral_trueRisk_sub_empiricalRisk {W : Type u_1} {Z : Type u_2} [MeasurableSpace Z] (ℓ : W → Z → ℝ) (D : MeasureTheory.Measure Z) [MeasureTheory.IsProbabilityMeasure D] {m : ℕ} (hm : 0 < m) (A : (Fin m → Z) → W) (hint : MeasureTheory.Integrable (fun (p : (Fin m → Z) × Z) => ℓ (A p.1) p.2) ((MeasureTheory.Measure.pi fun (x : Fin m) => D).prod D)) (hint' : ∀ (i : Fin m), MeasureTheory.Integrable (fun (S : Fin m → Z) => ℓ (A S) (S i)) (MeasureTheory.Measure.pi fun (x : Fin m) => D)) :
(∫ (S : Fin m → Z), trueRisk ℓ D (A S) - empiricalRisk ℓ S (A S) ∂MeasureTheory.Measure.pi fun (x : Fin m) => D) = replaceOneGap ℓ D A

The expected generalization gap is the expected replace-one gap [ShalevShwartzBenDavid2014, Theorem 13.2]: for m > 0 i.i.d. examples from D, 𝔼_S [L_D(A S) - L_S(A S)] = 𝔼_{(S, z'), i} [ℓ(A(S⁽ⁱ⁾), z_i) - ℓ(A S, z_i)].

The hypotheses ask that the loss of A S on a fresh example be integrable over the joint distribution and its loss on each training example be integrable over the samples; they hold, for example, for bounded losses that are jointly measurable with a measurable rule, and on finite example spaces with measurable singletons.

Stability #

def Cslib.MachineLearning.IsReplaceOneStable {W : Type u_1} {Z : Type u_2} [MeasurableSpace Z] (ℓ : W → Z → ℝ) {m : ℕ} (A : (Fin m → Z) → W) (ε : ℝ) :

A learning rule A on m examples is on-average-replace-one stable at rate ε for the loss ℓ if its expected replace-one gap is at most ε under every distribution D on examples [ShalevShwartzBenDavid2014, Definition 13.3].

The source considers a family of rules, one for each sample size, with a monotonically decreasing rate ε : ℕ → ℝ; that family is stable when IsReplaceOneStable ℓ (A m) (ε m) holds for every m. Monotonicity is not used by any of the results and is not required here.

theorem Cslib.MachineLearning.isReplaceOneStable_iff {W : Type u_1} {Z : Type u_2} [MeasurableSpace Z] (ℓ : W → Z → ℝ) {m : ℕ} (A : (Fin m → Z) → W) (ε : ℝ) :
theorem Cslib.MachineLearning.IsReplaceOneStable.mono {W : Type u_1} {Z : Type u_2} [MeasurableSpace Z] {ℓ : W → Z → ℝ} {m : ℕ} {A : (Fin m → Z) → W} {ε ε' : ℝ} (hA : IsReplaceOneStable ℓ A ε) (h : ε ≤ ε') :

Stability at a rate implies stability at every larger rate.

theorem Cslib.MachineLearning.integral_trueRisk_le_of_replaceOneGap_le {W : Type u_1} {Z : Type u_2} [MeasurableSpace Z] {ℓ : W → Z → ℝ} {m : ℕ} {A : (Fin m → Z) → W} {ε : ℝ} (D : MeasureTheory.Measure Z) [MeasureTheory.IsProbabilityMeasure D] (hm : 0 < m) (hint : MeasureTheory.Integrable (fun (p : (Fin m → Z) × Z) => ℓ (A p.1) p.2) ((MeasureTheory.Measure.pi fun (x : Fin m) => D).prod D)) (hint' : ∀ (i : Fin m), MeasureTheory.Integrable (fun (S : Fin m → Z) => ℓ (A S) (S i)) (MeasureTheory.Measure.pi fun (x : Fin m) => D)) (hgap : replaceOneGap ℓ D A ≤ ε) :
(∫ (S : Fin m → Z), trueRisk ℓ D (A S) ∂MeasureTheory.Measure.pi fun (x : Fin m) => D) ≤ (∫ (S : Fin m → Z), empiricalRisk ℓ S (A S) ∂MeasureTheory.Measure.pi fun (x : Fin m) => D) + ε

If the expected replace-one gap of A under D is at most ε, its expected true risk exceeds its expected empirical risk by at most ε [ShalevShwartzBenDavid2014, Theorem 13.2].

theorem Cslib.MachineLearning.IsReplaceOneStable.integral_trueRisk_le {W : Type u_1} {Z : Type u_2} [MeasurableSpace Z] {ℓ : W → Z → ℝ} {m : ℕ} {A : (Fin m → Z) → W} {ε : ℝ} (hA : IsReplaceOneStable ℓ A ε) (D : MeasureTheory.Measure Z) [MeasureTheory.IsProbabilityMeasure D] (hm : 0 < m) (hint : MeasureTheory.Integrable (fun (p : (Fin m → Z) × Z) => ℓ (A p.1) p.2) ((MeasureTheory.Measure.pi fun (x : Fin m) => D).prod D)) (hint' : ∀ (i : Fin m), MeasureTheory.Integrable (fun (S : Fin m → Z) => ℓ (A S) (S i)) (MeasureTheory.Measure.pi fun (x : Fin m) => D)) :
(∫ (S : Fin m → Z), trueRisk ℓ D (A S) ∂MeasureTheory.Measure.pi fun (x : Fin m) => D) ≤ (∫ (S : Fin m → Z), empiricalRisk ℓ S (A S) ∂MeasureTheory.Measure.pi fun (x : Fin m) => D) + ε

Stable rules do not overfit [ShalevShwartzBenDavid2014, Theorem 13.2 and Definition 13.3]: if A is replace-one stable at rate ε, its expected true risk exceeds its expected empirical risk by at most ε.

theorem Cslib.MachineLearning.isReplaceOneStable_of_forall_le {W : Type u_1} {Z : Type u_2} [MeasurableSpace Z] {ℓ : W → Z → ℝ} {m : ℕ} {A : (Fin m → Z) → W} {ε : ℝ} (hε : 0 ≤ ε) (h : ∀ (S : Fin m → Z) (i : Fin m) (z' z : Z), ℓ (A (Function.update S i z')) z - ℓ (A S) z ≤ ε) :

Uniform stability implies replace-one stability: if replacing any one example of any sample changes the loss of A on every example by at most ε ≥ 0, then A is replace-one stable at rate ε. No measurability is needed.