Documentation

CslibFrontier.MachineLearning.Rademacher.Margin

Margin generalization bounds via Rademacher complexity #

For binary classification with real-valued scoring hypotheses h : α → ℝ and labels y : Bool read as signs signVal y ∈ {-1, +1}, a labeled example (x, y) has signed margin signVal y * h x. A nonpositive signed margin (signVal y * h x ≤ 0) counts as a margin error.

For ρ > 0, the ρ-margin loss Φ_ρ(u) = min 1 (max 0 (1 - u / ρ)) [MohriRostamizadehTalwalkar2018, Definition 5.5] interpolates linearly between 1 on (-∞, 0] and 0 on [ρ, ∞):

Combining the [0, 1] Rademacher generalization bounds (CslibFrontier.MachineLearning.Rademacher.Generalization) for the induced margin-loss class {(x, y) ↦ Φ_ρ(signVal y * h x) | h ∈ H} with Talagrand's contraction lemma (CslibFrontier.MachineLearning.Rademacher.Contraction) yields the fixed-margin generalization bounds of [MohriRostamizadehTalwalkar2018, Theorem 5.8, (5.39) and (5.40)]: on a finite domain α, with probability at least 1 - δ over m > 0 independent draws from D : PMF (α × Bool), every hypothesis h in a uniformly bounded class H : Set (α → ℝ) satisfies

where R_m(H) is taken under the input marginal D.map Prod.fst and S_X is the unlabeled sample fun i => (S i).1. Uniform boundedness of H supplies the BddAbove hypothesis required by the real conditional supremum ⨆ in rademacherAverage.

Main definitions #

Main results #

References #

The ρ-margin loss #

noncomputable def Cslib.MachineLearning.marginLoss (ρ u : ℝ) :

The ρ-margin loss Φ_ρ(u) = min 1 (max 0 (1 - u / ρ)) [MohriRostamizadehTalwalkar2018, Definition 5.5].

theorem Cslib.MachineLearning.marginLoss_def (ρ u : ℝ) :
marginLoss ρ u = min 1 (max 0 (1 - u / ρ))

The ρ-margin loss is nonnegative.

The ρ-margin loss is at most 1.

The ρ-margin loss takes values in [0, 1].

theorem Cslib.MachineLearning.marginLoss_of_nonpos {ρ u : ℝ} (hρ : 0 < ρ) (hu : u ≤ 0) :
marginLoss ρ u = 1

On nonpositive margins u ≤ 0 (ρ > 0), the ρ-margin loss equals 1.

theorem Cslib.MachineLearning.marginLoss_of_ge {ρ u : ℝ} (hρ : 0 < ρ) (hu : ρ ≤ u) :
marginLoss ρ u = 0

Beyond margin ρ (ρ ≤ u, ρ > 0), the ρ-margin loss vanishes.

theorem Cslib.MachineLearning.marginLoss_of_mem_Icc {ρ u : ℝ} (hρ : 0 < ρ) (hu : u ∈ Set.Icc 0 ρ) :
marginLoss ρ u = 1 - u / ρ

On [0, ρ] (ρ > 0), the ρ-margin loss is the linear ramp 1 - u / ρ.

theorem Cslib.MachineLearning.boole_le_marginLoss {ρ : ℝ} (hρ : 0 < ρ) (u : ℝ) :
(if u ≤ 0 then 1 else 0) ≤ marginLoss ρ u

Zero-one domination [MohriRostamizadehTalwalkar2018, Section 5.4]: for ρ > 0, the ρ-margin loss dominates the nonpositive-margin indicator 𝟙[u ≤ 0].

theorem Cslib.MachineLearning.marginLoss_le_boole {ρ : ℝ} (hρ : 0 < ρ) (u : ℝ) :
marginLoss ρ u ≤ if u ≤ ρ then 1 else 0

Margin-violation upper bound [MohriRostamizadehTalwalkar2018, (5.37)]: for ρ > 0, the ρ-margin loss is bounded above by the indicator 𝟙[u ≤ ρ].

For ρ ≥ 0, marginLoss ρ is (1 / ρ)-Lipschitz [MohriRostamizadehTalwalkar2018, Section 5.4].

Empirical and population margin losses #

noncomputable def Cslib.MachineLearning.empiricalMarginLoss {α : Type u_1} (ρ : ℝ) (h : α → ℝ) {m : ℕ} (S : Fin m → α × Bool) :

The empirical ρ-margin loss R̂_{S, ρ}(h) = (1 / m) ∑ i, Φ_ρ (signVal (S i).2 * h (S i).1) of a real-valued hypothesis h : α → ℝ on a labeled sample S : Fin m → α × Bool [MohriRostamizadehTalwalkar2018, Definition 5.6].

theorem Cslib.MachineLearning.empiricalMarginLoss_def {α : Type u_1} (ρ : ℝ) (h : α → ℝ) {m : ℕ} (S : Fin m → α × Bool) :
empiricalMarginLoss ρ h S = Finset.univ.expect fun (i : Fin m) => marginLoss ρ (BitString.signVal (S i).2 * h (S i).1)
theorem Cslib.MachineLearning.empiricalMarginLoss_nonneg {α : Type u_1} (ρ : ℝ) (h : α → ℝ) {m : ℕ} (S : Fin m → α × Bool) :
theorem Cslib.MachineLearning.empiricalMarginLoss_le_one {α : Type u_1} (ρ : ℝ) (h : α → ℝ) {m : ℕ} (S : Fin m → α × Bool) :
theorem Cslib.MachineLearning.empiricalMarginLoss_le_count_div {α : Type u_1} {ρ : ℝ} (hρ : 0 < ρ) (h : α → ℝ) {m : ℕ} (S : Fin m → α × Bool) :
empiricalMarginLoss ρ h S ≤ ↑{i : Fin m | BitString.signVal (S i).2 * h (S i).1 ≤ ρ}.card / ↑m

The empirical ρ-margin loss is at most the fraction of sample points with signed margin at most ρ [MohriRostamizadehTalwalkar2018, (5.37)].

noncomputable def Cslib.MachineLearning.marginRisk {α : Type u_1} [Fintype α] (D : PMF (α × Bool)) (ρ : ℝ) (h : α → ℝ) :

The population ρ-margin loss E_{(x, y) ∼ D}[Φ_ρ(signVal y * h x)] of h : α → ℝ under D : PMF (α × Bool) on a finite domain α.

theorem Cslib.MachineLearning.marginRisk_def {α : Type u_1} [Fintype α] (D : PMF (α × Bool)) (ρ : ℝ) (h : α → ℝ) :
marginRisk D ρ h = ∑ p : α × Bool, (D p).toReal * marginLoss ρ (BitString.signVal p.2 * h p.1)
theorem Cslib.MachineLearning.marginRisk_nonneg {α : Type u_1} [Fintype α] (D : PMF (α × Bool)) (ρ : ℝ) (h : α → ℝ) :
0 ≤ marginRisk D ρ h
theorem Cslib.MachineLearning.marginRisk_le_one {α : Type u_1} [Fintype α] (D : PMF (α × Bool)) (ρ : ℝ) (h : α → ℝ) :
marginRisk D ρ h ≤ 1
theorem Cslib.MachineLearning.marginError_le_marginRisk {α : Type u_1} [Fintype α] (D : PMF (α × Bool)) {ρ : ℝ} (hρ : 0 < ρ) (h : α → ℝ) :

For ρ > 0, the population misclassification probability Pr_D[signVal y * h x ≤ 0] is at most the population ρ-margin loss.

The ρ-margin loss class and contraction #

noncomputable def Cslib.MachineLearning.marginLossClass {α : Type u_1} (ρ : ℝ) (H : Set (α → ℝ)) :
Set (α × Bool → ℝ)

The class of ρ-margin loss functions (x, y) ↦ Φ_ρ (signVal y * h x) induced by a real-valued hypothesis class H : Set (α → ℝ).

theorem Cslib.MachineLearning.mem_marginLossClass {α : Type u_1} {ρ : ℝ} {H : Set (α → ℝ)} {f : α × Bool → ℝ} :
f ∈ marginLossClass ρ H ↔ ∃ h ∈ H, (fun (p : α × Bool) => marginLoss ρ (BitString.signVal p.2 * h p.1)) = f
theorem Cslib.MachineLearning.mem_Icc_of_mem_marginLossClass {α : Type u_1} {ρ : ℝ} {H : Set (α → ℝ)} {f : α × Bool → ℝ} (hf : f ∈ marginLossClass ρ H) (p : α × Bool) :
f p ∈ Set.Icc 0 1

Functions in marginLossClass ρ H take values in [0, 1].

theorem Cslib.MachineLearning.empiricalRademacherComplexity_marginLossClass_le {α : Type u_1} {ρ : ℝ} (hρ : 0 ≤ ρ) {H : Set (α → ℝ)} {B : ℝ} (hH : ∀ h ∈ H, ∀ (x : α), |h x| ≤ B) {m : ℕ} (S : Fin m → α × Bool) :

Contraction of marginLossClass (empirical) [MohriRostamizadehTalwalkar2018, proof of Theorem 5.8]: for ρ ≥ 0 and a uniformly bounded class H : Set (α → ℝ), the empirical Rademacher complexity of marginLossClass ρ H on S is at most (1 / ρ) times that of H on the unlabeled points fun i => (S i).1.

theorem Cslib.MachineLearning.rademacherComplexity_marginLossClass_le {α : Type u_1} [Fintype α] (D : PMF (α × Bool)) {ρ : ℝ} (hρ : 0 ≤ ρ) {H : Set (α → ℝ)} {B : ℝ} (hH : ∀ h ∈ H, ∀ (x : α), |h x| ≤ B) (m : ℕ) :

Contraction of marginLossClass (population) [MohriRostamizadehTalwalkar2018, proof of Theorem 5.8]: for ρ ≥ 0 and a uniformly bounded class H : Set (α → ℝ) on a finite domain α, the Rademacher complexity of marginLossClass ρ H under D is at most (1 / ρ) times that of H under D.map Prod.fst.

Margin generalization bounds #

theorem Cslib.MachineLearning.rademacherComplexity_marginRisk_bound {α : Type u_1} [Fintype α] (D : PMF (α × Bool)) {m : ℕ} (hm : 0 < m) {H : Set (α → ℝ)} {B : ℝ} (hH : ∀ h ∈ H, ∀ (x : α), |h x| ≤ B) {ρ : ℝ} (hρ : 0 < ρ) {δ : ℝ} (hδ : 0 < δ) :
((Probability.PMF.pi fun (x : Fin m) => D).toOuterMeasure {S : Fin m → α × Bool | ∃ h ∈ H, empiricalMarginLoss ρ h S + 2 / ρ * rademacherComplexity (PMF.map Prod.fst D) H m + √(Real.log (1 / δ) / (2 * ↑m)) < marginRisk D ρ h}).toReal ≤ δ

Population ρ-margin risk generalization bound via R_m(H).

theorem Cslib.MachineLearning.empiricalRademacherComplexity_marginRisk_bound {α : Type u_1} [Fintype α] (D : PMF (α × Bool)) {m : ℕ} (hm : 0 < m) {H : Set (α → ℝ)} {B : ℝ} (hH : ∀ h ∈ H, ∀ (x : α), |h x| ≤ B) {ρ : ℝ} (hρ : 0 < ρ) {δ : ℝ} (hδ : 0 < δ) :
((Probability.PMF.pi fun (x : Fin m) => D).toOuterMeasure {S : Fin m → α × Bool | ∃ h ∈ H, (empiricalMarginLoss ρ h S + 2 / ρ * empiricalRademacherComplexity H fun (i : Fin m) => (S i).1) + 3 * √(Real.log (2 / δ) / (2 * ↑m)) < marginRisk D ρ h}).toReal ≤ δ

Data-dependent population ρ-margin risk generalization bound via R̂_{S_X}(H).

theorem Cslib.MachineLearning.rademacherComplexity_margin_bound {α : Type u_1} [Fintype α] (D : PMF (α × Bool)) {m : ℕ} (hm : 0 < m) {H : Set (α → ℝ)} {B : ℝ} (hH : ∀ h ∈ H, ∀ (x : α), |h x| ≤ B) {ρ : ℝ} (hρ : 0 < ρ) {δ : ℝ} (hδ : 0 < δ) :
((Probability.PMF.pi fun (x : Fin m) => D).toOuterMeasure {S : Fin m → α × Bool | ∃ h ∈ H, empiricalMarginLoss ρ h S + 2 / ρ * rademacherComplexity (PMF.map Prod.fst D) H m + √(Real.log (1 / δ) / (2 * ↑m)) < (D.toOuterMeasure {p : α × Bool | BitString.signVal p.2 * h p.1 ≤ 0}).toReal}).toReal ≤ δ

Margin generalization bound [MohriRostamizadehTalwalkar2018, Theorem 5.8, (5.39)]: for a uniformly bounded class H : Set (α → ℝ) on a finite domain α, margin ρ > 0, and m > 0 independent draws from D : PMF (α × Bool), with probability at least 1 - δ every h ∈ H satisfies Pr_D[signVal y * h x ≤ 0] ≤ R̂_{S, ρ}(h) + (2 / ρ) R_m(H) + √(log (1 / δ) / (2 m)), where R_m(H) is taken under the marginal D.map Prod.fst.

theorem Cslib.MachineLearning.empiricalRademacherComplexity_margin_bound {α : Type u_1} [Finite α] (D : PMF (α × Bool)) {m : ℕ} (hm : 0 < m) {H : Set (α → ℝ)} {B : ℝ} (hH : ∀ h ∈ H, ∀ (x : α), |h x| ≤ B) {ρ : ℝ} (hρ : 0 < ρ) {δ : ℝ} (hδ : 0 < δ) :
((Probability.PMF.pi fun (x : Fin m) => D).toOuterMeasure {S : Fin m → α × Bool | ∃ h ∈ H, (empiricalMarginLoss ρ h S + 2 / ρ * empiricalRademacherComplexity H fun (i : Fin m) => (S i).1) + 3 * √(Real.log (2 / δ) / (2 * ↑m)) < (D.toOuterMeasure {p : α × Bool | BitString.signVal p.2 * h p.1 ≤ 0}).toReal}).toReal ≤ δ

Data-dependent margin generalization bound [MohriRostamizadehTalwalkar2018, Theorem 5.8, (5.40)]: for a uniformly bounded class H : Set (α → ℝ) on a finite domain α, margin ρ > 0, and m > 0 independent draws from D : PMF (α × Bool), with probability at least 1 - δ every h ∈ H satisfies Pr_D[signVal y * h x ≤ 0] ≤ R̂_{S, ρ}(h) + (2 / ρ) R̂_{S_X}(H) + 3 √(log (2 / δ) / (2 m)), where S_X is the sequence of unlabeled inputs fun i => (S i).1.

theorem Cslib.MachineLearning.margin_bound_of_finset {α : Type u_1} [Finite α] (D : PMF (α × Bool)) {m : ℕ} (hm : 0 < m) {H : Finset (α → ℝ)} {B : ℝ} (hB : 0 ≤ B) (hH : ∀ h ∈ H, ∀ (x : α), |h x| ≤ B) {ρ : ℝ} (hρ : 0 < ρ) {δ : ℝ} (hδ : 0 < δ) :
((Probability.PMF.pi fun (x : Fin m) => D).toOuterMeasure {S : Fin m → α × Bool | ∃ h ∈ H, empiricalMarginLoss ρ h S + 2 * B / ρ * √(2 * Real.log ↑H.card / ↑m) + √(Real.log (1 / δ) / (2 * ↑m)) < (D.toOuterMeasure {p : α × Bool | BitString.signVal p.2 * h p.1 ≤ 0}).toReal}).toReal ≤ δ

Finite-class margin bound through Massart's lemma [MohriRostamizadehTalwalkar2018, Theorems 3.7 and 5.8]: for a finite class H : Finset (α → ℝ) with values in [-B, B] (B ≥ 0), margin ρ > 0, and m > 0 independent draws from D, with probability at least 1 - δ every h ∈ H satisfies Pr_D[signVal y * h x ≤ 0] ≤ R̂_{S, ρ}(h) + (2 B / ρ) √(2 log |H| / m) + √(log (1 / δ) / (2 m)).