Documentation

CslibFrontier.MachineLearning.Boosting.Margin

Margin generalization bounds for boosting and AdaBoost #

This module proves the margin-based generalization theory for voting methods and AdaBoost [SFBL98] [MohriRostamizadehTalwalkar2018, Chapter 7]:

  1. Convex-hull generalization bounds (independent of ensemble size T). Combining the convex-hull invariance of Rademacher complexity (R̂_S(conv H) = R̂_S(H), CslibFrontier.MachineLearning.Rademacher.ConvexHull) with the fixed-ρ and uniform-in-ρ margin bounds (Margin and UniformMargin) yields risk bounds for every scoring function f ∈ convexHull ℝ H directly in terms of the base class H (R_m(H), R̂_{S_X}(H), or the VC dimension of a binary base class B). None of these bounds depends on the number of base hypotheses combined.
  2. Normalized score of AdaBoost. normalizedScore S A T normalizes -score S A T by totalVote S A T = ∑ t < T, (rounds S A t).vote S (matching Rademacher/Margin's sign convention signVal true = -1, signVal false = +1, and falling back to the stopped round's sign function if some round achieves weighted error 0). Whenever every round t < T returns a hypothesis in B with weighted error < 1/2 (T > 0), normalizedScore S A T belongs to convexHull ℝ (signClass B), and every point misclassified by adaBoost S A T has nonpositive signed margin signVal y * normalizedScore S A T x ≤ 0. Thus the uniform margin bound applies simultaneously to all weak learners A valued in B, all round counts T > 0, and all margins ρ ∈ (0, 1].
  3. AdaBoost empirical margin distribution bound [SchapireFreundBartlettLee1998, Theorem 5]. The fraction of training examples on which normalizedScore S A T has margin at most ρ is at most ∏ t < T, 2 εₜ ^ ((1 - ρ) / 2) (1 - εₜ) ^ ((1 + ρ) / 2). Against edge γ ∈ (0, 1/2) (εₜ ≤ 1/2 - γ) and margin 0 ≤ ρ ≤ 2 γ, this is at most ((1 - 2 γ) ^ (1 - ρ) * (1 + 2 γ) ^ (1 + ρ)) ^ (T / 2). For 0 ≤ ρ ≤ γ, the base factor is strictly less than 1 and bounded by exp (-2 γ (γ - ρ)), recovering AdaBoost's exp (-2 γ² T) training-error bound at ρ = 0 and driving the ρ-margin loss exponentially to zero for all ρ < γ.
  4. End-to-end AdaBoost margin generalization bound. Combining the uniform VC margin bound with the exponential training-margin decay bounds the true error of adaBoost S A T simultaneously for all weak learners A valued in B, all T > 0, and all ρ ∈ (0, γ].

Sign convention note #

In Cslib.BitString, signVal true = -1 and signVal false = +1. In AdaBoost.lean, score negates the weighted sum of signVal ((rounds S A t).hyp x) so that 0 < score predicts true. Here normalizedScore reverses that negation (-score / totalVote) so it equals the convex combination ∑ t < T, (wₜ / Z) * signVal (hₜ x) ∈ convexHull ℝ (signClass B) matching Rademacher/Margin's signed margin signVal y * f x.

Main definitions #

Main results #

References #

Convex-hull margin bounds (independent of ensemble size) #

theorem Cslib.MachineLearning.Boosting.convexHull_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 | ∃ f ∈ (convexHull ℝ) H, empiricalMarginLoss ρ f S + 2 / ρ * rademacherComplexity (PMF.map Prod.fst D) H m + √(Real.log (1 / δ) / (2 * ↑m)) < (D.toOuterMeasure {p : α × Bool | BitString.signVal p.2 * f p.1 ≤ 0}).toReal}).toReal ≤ δ

Fixed-margin generalization bound for convex combinations [MohriRostamizadehTalwalkar2018, Section 7.3.3, Corollary 7.5, p. 158]: for a uniformly bounded base class H : Set (α → ℝ) on a finite domain α, fixed margin ρ > 0, m > 0 independent draws from D : PMF (α × Bool), and δ > 0, with probability at least 1 - δ every f ∈ convexHull ℝ H satisfies Pr_D[signVal y * f x ≤ 0] ≤ R̂_{S, ρ}(f) + (2 / ρ) R_m(H) + √(log (1 / δ) / (2 m)).

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

Uniform margin generalization bound for convex combinations [MohriRostamizadehTalwalkar2018, Theorem 5.9 and Lemma 7.4] (uniform-in-ρ counterpart of Corollary 7.5, Section 7.3.3, pp. 157–158): with probability at least 1 - δ, simultaneously for every f ∈ convexHull ℝ H and every ρ ∈ (0, r],

Pr_D[signVal y * f x ≤ 0] ≤ R̂_{S, ρ}(f) + (4 / ρ) R_m(H)
  + √(log (log₂ (2 r / ρ)) / m) + √(log (2 / δ) / (2 m)).
theorem Cslib.MachineLearning.Boosting.convexHull_uniform_empirical_margin_bound {α : Type u_1} [Finite α] (D : PMF (α × Bool)) {m : ℕ} (hm : 0 < m) {H : Set (α → ℝ)} {B : ℝ} (hH : ∀ h ∈ H, ∀ (x : α), |h x| ≤ B) {r : ℝ} (hr : 0 < r) {δ : ℝ} (hδ : 0 < δ) :
((Probability.PMF.pi fun (x : Fin m) => D).toOuterMeasure {S : Fin m → α × Bool | ∃ f ∈ (convexHull ℝ) H, ∃ ρ ∈ Set.Ioc 0 r, (empiricalMarginLoss ρ f S + 4 / ρ * empiricalRademacherComplexity H fun (i : Fin m) => (S i).1) + 3 * √(Real.log (Real.logb 2 (2 * r / ρ)) / ↑m) + 3 * √(Real.log (4 / δ) / (2 * ↑m)) < (D.toOuterMeasure {p : α × Bool | BitString.signVal p.2 * f p.1 ≤ 0}).toReal}).toReal ≤ δ

Data-dependent uniform margin generalization bound for convex combinations [MohriRostamizadehTalwalkar2018, Theorem 5.9 and Lemma 7.4] (uniform-in-ρ counterpart of Corollary 7.5, Section 7.3.3, pp. 157–158): same guarantee with the empirical Rademacher complexity R̂_{S_X}(H) of the base class H on the unlabeled sample.

theorem Cslib.MachineLearning.Boosting.convexHull_signClass_vc_uniform_margin_bound {α : Type u_1} [Finite α] (D : PMF (α × Bool)) {m d : ℕ} (hm : 0 < m) {C : PACLearning.ConceptClass α Bool} (hC : ∀ (W : Finset α), PACLearning.SetShatters C ↑W → W.card ≤ d) (hdm : d ≤ m) {δ : ℝ} (hδ : 0 < δ) :
((Probability.PMF.pi fun (x : Fin m) => D).toOuterMeasure {S : Fin m → α × Bool | ∃ f ∈ (convexHull ℝ) (signClass C), ∃ ρ ∈ Set.Ioc 0 1, empiricalMarginLoss ρ f S + 4 / ρ * √(2 * (↑d * Real.log (Real.exp 1 * ↑m / ↑d)) / ↑m) + √(Real.log (Real.logb 2 (2 / ρ)) / ↑m) + √(Real.log (2 / δ) / (2 * ↑m)) < (D.toOuterMeasure {p : α × Bool | BitString.signVal p.2 * f p.1 ≤ 0}).toReal}).toReal ≤ δ

Uniform VC-dimension margin bound for convex combinations of binary classifiers [SchapireFreundBartlettLee1998, Theorem 2] [MohriRostamizadehTalwalkar2018, Section 7.3.3, Corollary 7.6 fixed-ρ VC bound with uniform-in-ρ remark via Theorem 5.9, p. 158]: if every finite set shattered by C : ConceptClass α Bool has size at most d ≤ m, then on a finite domain α, with probability at least 1 - δ over S ~ D^m, every f ∈ convexHull ℝ (signClass C) and every margin ρ ∈ (0, 1] satisfy

Pr_D[signVal y * f x ≤ 0] ≤ R̂_{S, ρ}(f) + (4 / ρ) √(2 d log (e m / d) / m)
  + √(log (log₂ (2 / ρ)) / m) + √(log (2 / δ) / (2 m)).

Normalized AdaBoost score and convex-hull membership #

noncomputable def Cslib.MachineLearning.Boosting.totalVote {α : Type u_1} {m : ℕ} (S : Fin m → α × Bool) (A : (Fin m → ℝ) → α → Bool) (T : ℕ) :

Total vote weight ∑ t < T, (rounds S A t).vote S across the first T rounds of AdaBoost.

theorem Cslib.MachineLearning.Boosting.totalVote_def {α : Type u_1} {m : ℕ} (S : Fin m → α × Bool) (A : (Fin m → ℝ) → α → Bool) (T : ℕ) :
totalVote S A T = ∑ t ∈ Finset.range T, Round.vote S (rounds S A t)

Defining equation for totalVote.

noncomputable def Cslib.MachineLearning.Boosting.normalizedScore {α : Type u_1} {m : ℕ} (S : Fin m → α × Bool) (A : (Fin m → ℝ) → α → Bool) (T : ℕ) :
α → ℝ

The normalized scoring function of T rounds of AdaBoost, scaled into [-1, 1] using the signVal convention (signVal true = -1, signVal false = +1): if some round t < T has weighted error 0, it returns signVal ∘ hₜ for the first such round; otherwise it returns -score S A T / totalVote S A T, i.e., ∑ t < T, (wₜ / Z) · signVal (hₜ x).

theorem Cslib.MachineLearning.Boosting.normalizedScore_of_exists_error_zero {α : Type u_1} {m : ℕ} (S : Fin m → α × Bool) (A : (Fin m → ℝ) → α → Bool) {T : ℕ} (hz : ∃ t < T, Round.error S (rounds S A t) = 0) :
normalizedScore S A T = fun (x : α) => BitString.signVal ((rounds S A (Nat.find hz)).hyp x)

When some round t < T achieves weighted error 0, normalizedScore is the sign of that first consistent round's hypothesis.

theorem Cslib.MachineLearning.Boosting.normalizedScore_of_not_exists_error_zero {α : Type u_1} {m : ℕ} (S : Fin m → α × Bool) (A : (Fin m → ℝ) → α → Bool) {T : ℕ} (hz : ¬∃ t < T, Round.error S (rounds S A t) = 0) :
normalizedScore S A T = fun (x : α) => -score S A T x / totalVote S A T

When no round t < T has weighted error 0, normalizedScore equals -score S A T / totalVote S A T.

theorem Cslib.MachineLearning.Boosting.totalVote_pos {α : Type u_1} {m : ℕ} (S : Fin m → α × Bool) (A : (Fin m → ℝ) → α → Bool) {T : ℕ} (hT : 0 < T) (hε₀ : ∀ t < T, 0 < Round.error S (rounds S A t)) (hε : ∀ t < T, Round.error S (rounds S A t) < 1 / 2) :
0 < totalVote S A T

Total vote weight is strictly positive when T > 0 and every round has weighted error in (0, 1/2).

theorem Cslib.MachineLearning.Boosting.normalizedScore_mem_convexHull {α : Type u_1} {m : ℕ} {S : Fin m → α × Bool} {A : (Fin m → ℝ) → α → Bool} {C : PACLearning.ConceptClass α Bool} {T : ℕ} (hT : 0 < T) (hC : ∀ t < T, (rounds S A t).hyp ∈ C) (hε : ∀ t < T, Round.error S (rounds S A t) < 1 / 2) :

When T > 0 and every round t < T chooses a hypothesis in C with weighted error < 1/2, normalizedScore S A T lies in convexHull ℝ (signClass C).

theorem Cslib.MachineLearning.Boosting.signVal_mul_normalizedScore_nonpos_of_adaBoost_ne {α : Type u_1} {m : ℕ} {S : Fin m → α × Bool} {A : (Fin m → ℝ) → α → Bool} {T : ℕ} (hZ : (¬∃ t < T, Round.error S (rounds S A t) = 0) → 0 < totalVote S A T) {x : α} {y : Bool} (hne : adaBoost S A T x ≠ y) :

Every point misclassified by adaBoost S A T has nonpositive signed margin under normalizedScore S A T (provided 0 < totalVote S A T when no round has zero error).

theorem Cslib.MachineLearning.Boosting.adaBoost_uniform_margin_bound_vc {α : Type u_2} [Finite α] (D : PMF (α × Bool)) {m d : ℕ} (hm : 0 < m) {C : PACLearning.ConceptClass α Bool} (hC : ∀ (W : Finset α), PACLearning.SetShatters C ↑W → W.card ≤ d) (hdm : d ≤ m) {δ : ℝ} (hδ : 0 < δ) :
((Probability.PMF.pi fun (x : Fin m) => D).toOuterMeasure {S : Fin m → α × Bool | ∃ (A : (Fin m → ℝ) → α → Bool) (T : ℕ), 0 < T ∧ (∀ t < T, (rounds S A t).hyp ∈ C) ∧ (∀ t < T, Round.error S (rounds S A t) < 1 / 2) ∧ ∃ ρ ∈ Set.Ioc 0 1, empiricalMarginLoss ρ (normalizedScore S A T) S + 4 / ρ * √(2 * (↑d * Real.log (Real.exp 1 * ↑m / ↑d)) / ↑m) + √(Real.log (Real.logb 2 (2 / ρ)) / ↑m) + √(Real.log (2 / δ) / (2 * ↑m)) < (D.toOuterMeasure {p : α × Bool | adaBoost S A T p.1 ≠ p.2}).toReal}).toReal ≤ δ

Uniform T-independent margin bound for AdaBoost [SchapireFreundBartlettLee1998, Theorem 2] [MohriRostamizadehTalwalkar2018, Section 7.3.3, Corollary 7.6 fixed-ρ VC bound with uniform-in-ρ remark via Theorem 5.9, p. 158]: on a finite domain α, for a base class C : ConceptClass α Bool with every shattered finite set of size at most d ≤ m, with probability at least 1 - δ over S ~ D^m, every weak learner A whose first T > 0 rounds lie in C with weighted errors < 1/2 and every margin ρ ∈ (0, 1] satisfy

Pr_D[adaBoost S A T x ≠ y] ≤ R̂_{S, ρ}(normalizedScore S A T)
  + (4 / ρ) √(2 d log (e m / d) / m) + √(log (log₂ (2 / ρ)) / m) + √(log (2 / δ) / (2 m)).

Note the bound does not depend on the number of boosting rounds T.

Empirical margin distribution of AdaBoost (Schapire–Freund–Bartlett–Lee 1998, Thm. 5) #

theorem Cslib.MachineLearning.Boosting.marginFactor_lt_one {γ ρ : ℝ} (hγ₀ : 0 < γ) (hγ₁ : γ < 1 / 2) (hρ₀ : 0 ≤ ρ) (hργ : ρ ≤ γ) :
(1 - 2 * γ) ^ (1 - ρ) * (1 + 2 * γ) ^ (1 + ρ) < 1

For 0 < γ < 1/2 and 0 ≤ ρ ≤ γ, the per-round AdaBoost margin factor (1 - 2 γ) ^ (1 - ρ) * (1 + 2 γ) ^ (1 + ρ) is strictly less than 1.

theorem Cslib.MachineLearning.Boosting.sqrt_marginFactor_le_exp {γ ρ : ℝ} (hγ₀ : 0 < γ) (hγ₁ : γ < 1 / 2) (hρ₀ : 0 ≤ ρ) (hργ : ρ ≤ γ) :
√((1 - 2 * γ) ^ (1 - ρ) * (1 + 2 * γ) ^ (1 + ρ)) ≤ Real.exp (-(2 * γ * (γ - ρ)))

Exponential upper bound for the per-round margin factor: for 0 < γ < 1/2 and 0 ≤ ρ ≤ γ, √((1 - 2 γ) ^ (1 - ρ) * (1 + 2 γ) ^ (1 + ρ)) ≤ exp (-2 γ (γ - ρ)). At ρ = 0, this recovers exp (-2 γ²).

theorem Cslib.MachineLearning.Boosting.marginCount_normalizedScore_le_prod {α : Type u_1} {m : ℕ} (S : Fin m → α × Bool) (A : (Fin m → ℝ) → α → Bool) {T : ℕ} (hT : 0 < T) {ρ : ℝ} (hρ : ρ < 1) (hε : ∀ t < T, Round.error S (rounds S A t) < 1 / 2) :
↑{i : Fin m | BitString.signVal (S i).2 * normalizedScore S A T (S i).1 ≤ ρ}.card / ↑m ≤ ∏ t ∈ Finset.range T, 2 * Round.error S (rounds S A t) ^ ((1 - ρ) / 2) * (1 - Round.error S (rounds S A t)) ^ ((1 + ρ) / 2)

AdaBoost empirical margin distribution bound, product form [SchapireFreundBartlettLee1998, Theorem 5]: for any ρ < 1, if every round t < T has weighted error εₜ < 1/2 (so positive vote weight wₜ > 0, and if some round hits εₜ = 0 every point has margin +1), the fraction of sample points with signed margin at most ρ under normalizedScore S A T is at most ∏ t < T, 2 εₜ ^ ((1 - ρ) / 2) (1 - εₜ) ^ ((1 + ρ) / 2).

theorem Cslib.MachineLearning.Boosting.marginCount_normalizedScore_le_pow {α : Type u_1} {m : ℕ} (S : Fin m → α × Bool) (A : (Fin m → ℝ) → α → Bool) {T : ℕ} (hT : 0 < T) {γ ρ : ℝ} (hγ₀ : 0 < γ) (hγ₁ : γ < 1 / 2) (hρ₀ : 0 ≤ ρ) (hρ : ρ ≤ 2 * γ) (hε : ∀ t < T, Round.error S (rounds S A t) ≤ 1 / 2 - γ) :
↑{i : Fin m | BitString.signVal (S i).2 * normalizedScore S A T (S i).1 ≤ ρ}.card / ↑m ≤ √((1 - 2 * γ) ^ (1 - ρ) * (1 + 2 * γ) ^ (1 + ρ)) ^ T

AdaBoost empirical margin distribution bound, edge form [SchapireFreundBartlettLee1998, Theorem 5]: if every round t < T has weighted error at most 1/2 - γ with 0 < γ < 1/2, then for every margin ρ ∈ [0, 2 γ],

Pr_{i ∼ S}[yᵢ · normalizedScore(xᵢ) ≤ ρ] ≤ ((1 - 2 γ)^(1 - ρ) (1 + 2 γ)^(1 + ρ))^(T / 2).
theorem Cslib.MachineLearning.Boosting.marginCount_normalizedScore_le_exp {α : Type u_1} {m : ℕ} (S : Fin m → α × Bool) (A : (Fin m → ℝ) → α → Bool) {T : ℕ} (hT : 0 < T) {γ ρ : ℝ} (hγ₀ : 0 < γ) (hγ₁ : γ < 1 / 2) (hρ₀ : 0 ≤ ρ) (hργ : ρ ≤ γ) (hε : ∀ t < T, Round.error S (rounds S A t) ≤ 1 / 2 - γ) :
↑{i : Fin m | BitString.signVal (S i).2 * normalizedScore S A T (S i).1 ≤ ρ}.card / ↑m ≤ Real.exp (-(2 * γ * (γ - ρ) * ↑T))

Exponential decay of AdaBoost's empirical margin loss: if every round t < T has weighted error at most 1/2 - γ (0 < γ < 1/2), then for every margin ρ ∈ [0, γ], the fraction of training examples with margin at most ρ is at most exp (-2 γ (γ - ρ) T). Setting ρ = 0 recovers exp (-2 γ² T).

theorem Cslib.MachineLearning.Boosting.adaBoost_generalization_bound_of_edge {α : Type u_2} [Finite α] (D : PMF (α × Bool)) {m d : ℕ} (hm : 0 < m) {C : PACLearning.ConceptClass α Bool} (hC : ∀ (W : Finset α), PACLearning.SetShatters C ↑W → W.card ≤ d) (hdm : d ≤ m) {δ : ℝ} (hδ : 0 < δ) :
((Probability.PMF.pi fun (x : Fin m) => D).toOuterMeasure {S : Fin m → α × Bool | ∃ (A : (Fin m → ℝ) → α → Bool) (T : ℕ) (γ : ℝ) (ρ : ℝ), 0 < T ∧ 0 < γ ∧ γ < 1 / 2 ∧ 0 < ρ ∧ ρ ≤ γ ∧ (∀ t < T, (rounds S A t).hyp ∈ C) ∧ (∀ t < T, Round.error S (rounds S A t) ≤ 1 / 2 - γ) ∧ Real.exp (-(2 * γ * (γ - ρ) * ↑T)) + 4 / ρ * √(2 * (↑d * Real.log (Real.exp 1 * ↑m / ↑d)) / ↑m) + √(Real.log (Real.logb 2 (2 / ρ)) / ↑m) + √(Real.log (2 / δ) / (2 * ↑m)) < (D.toOuterMeasure {p : α × Bool | adaBoost S A T p.1 ≠ p.2}).toReal}).toReal ≤ δ

End-to-end margin generalization bound for AdaBoost under an edge assumption [SchapireFreundBartlettLee1998, Theorems 2 and 5] [MohriRostamizadehTalwalkar2018, Section 7.3.3, Corollary 7.6 fixed-ρ VC bound with uniform-in-ρ remark via Theorem 5.9 and Theorem 7.7, pp. 158–160]: combines adaBoost_uniform_margin_bound_vc with marginCount_normalizedScore_le_exp (R̂_{S, ρ} ≤ #{i | margin ≤ ρ} / m ≤ exp (-2 γ (γ - ρ) T)). On a finite domain α, for a base class C of VC dimension at most d ≤ m, with probability at least 1 - δ over S ~ D^m, for every weak learner A returning hypotheses in C with round errors ≤ 1/2 - γ (0 < γ < 1/2), every T > 0, and every margin ρ ∈ (0, γ],

Pr_D[adaBoost S A T x ≠ y] ≤ exp (-2 γ (γ - ρ) T)
  + (4 / ρ) √(2 d log (e m / d) / m) + √(log (log₂ (2 / ρ)) / m) + √(log (2 / δ) / (2 m)).