Documentation

CslibFrontier.MachineLearning.Boosting.AdaBoost

AdaBoost #

AdaBoost [FS97] on a finite labelled sample S : Fin m → α × Bool, with a weak learner A : (Fin m → ℝ) → α → Bool that maps weights on the sample to a hypothesis. Round t (a Round: weights and hypothesis) has weights Dₜ, weighted error εₜ and vote weight wₜ = ½ log ((1 - εₜ) / εₜ); the next weights multiply Dₜ i by exp (-wₜ yᵢ hₜ(xᵢ)) (signs ±1, via BitString.signVal) and renormalize (rounds_weights_succ). The output is the sign of the weighted vote ∑ₜ wₜ hₜ.

The weights are the multiplicative-update distribution of the experts setting (CslibFrontier/MachineLearning/OnlineLearning/MultiplicativeUpdate.lean) with the sample points as experts, update factor exp, and the adaptive loss sequence chosen by the weak learner. The proof of the training-error bound is the potential argument of that file: each misclassified point has weight at least 1, and the potential is m times the product of the normalizers, each equal to 2 √(εₜ (1 - εₜ)).

Main definitions #

Main results #

Model and differences from the sources #

[ShalevShwartzBenDavid2014, Theorem 10.2] states the exp (-2 γ² T) bound and proves the product form on pp. 135–137; [MohriRostamizadehTalwalkar2018, Theorem 7.2] states both through exp (-2 ∑ₜ (1/2 - εₜ)²) and proves the product form. Differences:

References #

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

The weighted error of h on the sample S under the weights D: the total weight of the sample points that h labels incorrectly.

The vote weight ½ log ((1 - ε) / ε) of a weak hypothesis with weighted error ε.

noncomputable def Cslib.MachineLearning.Boosting.pointLoss {α : Type u_1} (w : ℝ) (h : α → Bool) (z : α × Bool) :

The exponential loss of h at the labelled point z with vote weight w: -w if h labels z correctly and w otherwise, written with the signs signVal of the prediction and the label. AdaBoost multiplies the weight of z by exp of this loss.

structure Cslib.MachineLearning.Boosting.Round (α : Type u_2) (m : ℕ) :
Type u_2

One round of AdaBoost: the weights on the sample and the weak hypothesis chosen for them.

  • weights : Fin m → ℝ

    The round's weights on the sample points.

  • hyp : α → Bool

    The weak hypothesis returned for these weights.

noncomputable def Cslib.MachineLearning.Boosting.Round.error {α : Type u_1} {m : ℕ} (S : Fin m → α × Bool) (r : Round α m) :

The weighted error of the round's hypothesis under the round's weights.

theorem Cslib.MachineLearning.Boosting.Round.error_def {α : Type u_1} {m : ℕ} (S : Fin m → α × Bool) (r : Round α m) :

Defining equation for Round.error.

noncomputable def Cslib.MachineLearning.Boosting.Round.vote {α : Type u_1} {m : ℕ} (S : Fin m → α × Bool) (r : Round α m) :

The vote weight of the round's hypothesis.

theorem Cslib.MachineLearning.Boosting.Round.vote_def {α : Type u_1} {m : ℕ} (S : Fin m → α × Bool) (r : Round α m) :

Defining equation for Round.vote.

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

The loss vector that AdaBoost hands to the multiplicative update when the weak learner A answers the weights D.

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

The loss sequence that AdaBoost's weak learner A produces against the multiplicative update with factor exp.

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

The rounds of AdaBoost on the sample S with the weak learner A: round t has the weights of the multiplicative update with factor exp against the losses lossSeq, which start uniform, and the hypothesis A returns for them.

theorem Cslib.MachineLearning.Boosting.rounds_weights {α : Type u_1} {m : ℕ} (S : Fin m → α × Bool) (A : (Fin m → ℝ) → α → Bool) (t : ℕ) :

The weights of round t are the multiplicative-update distribution.

theorem Cslib.MachineLearning.Boosting.rounds_hyp {α : Type u_1} {m : ℕ} (S : Fin m → α × Bool) (A : (Fin m → ℝ) → α → Bool) (t : ℕ) :
(rounds S A t).hyp = A (rounds S A t).weights

The hypothesis of round t is the weak learner's answer to the round's weights.

theorem Cslib.MachineLearning.Boosting.lossSeq_apply {α : Type u_1} {m : ℕ} (S : Fin m → α × Bool) (A : (Fin m → ℝ) → α → Bool) (t : ℕ) (i : Fin m) :
lossSeq S A t i = pointLoss (Round.vote S (rounds S A t)) (rounds S A t).hyp (S i)

The loss of round t is the exponential loss of the round's hypothesis with its vote weight.

theorem Cslib.MachineLearning.Boosting.rounds_weights_pos {α : Type u_1} {m : ℕ} (S : Fin m → α × Bool) (A : (Fin m → ℝ) → α → Bool) (t : ℕ) (i : Fin m) :
0 < (rounds S A t).weights i

AdaBoost's weights are positive.

theorem Cslib.MachineLearning.Boosting.rounds_zero_weights {α : Type u_1} {m : ℕ} (S : Fin m → α × Bool) (A : (Fin m → ℝ) → α → Bool) (i : Fin m) :
(rounds S A 0).weights i = 1 / ↑m

AdaBoost starts from the uniform weights.

theorem Cslib.MachineLearning.Boosting.sum_rounds_weights {α : Type u_1} {m : ℕ} (S : Fin m → α × Bool) (A : (Fin m → ℝ) → α → Bool) (t : ℕ) [NeZero m] :
∑ i : Fin m, (rounds S A t).weights i = 1

AdaBoost's weights form a distribution on a nonempty sample.

theorem Cslib.MachineLearning.Boosting.rounds_weights_succ {α : Type u_1} {m : ℕ} (S : Fin m → α × Bool) (A : (Fin m → ℝ) → α → Bool) (t : ℕ) (i : Fin m) :
(rounds S A (t + 1)).weights i = (rounds S A t).weights i * Real.exp (pointLoss (Round.vote S (rounds S A t)) (rounds S A t).hyp (S i)) / ∑ j : Fin m, (rounds S A t).weights j * Real.exp (pointLoss (Round.vote S (rounds S A t)) (rounds S A t).hyp (S j))

The AdaBoost update [ShalevShwartzBenDavid2014, Section 10.2]: the weight of a sample point is multiplied by exp (-wₜ yᵢ hₜ(xᵢ)), its exponential loss, and the weights are renormalized.

theorem Cslib.MachineLearning.Boosting.sum_mul_exp_pointLoss {α : Type u_1} {m : ℕ} {S : Fin m → α × Bool} {D : Fin m → ℝ} {h : α → Bool} (hD : ∑ i : Fin m, D i = 1) (hε₀ : 0 < weightedError S D h) (hε₁ : weightedError S D h < 1) :
∑ i : Fin m, D i * Real.exp (pointLoss (voteWeight (weightedError S D h)) h (S i)) = 2 * √(weightedError S D h * (1 - weightedError S D h))

The AdaBoost normalizer [ShalevShwartzBenDavid2014, proof of Theorem 10.2]: under a distribution D on the sample, if the hypothesis h has weighted error ε with 0 < ε < 1, then reweighting by the exponential loss with vote weight voteWeight ε multiplies the total weight by 2 √(ε (1 - ε)).

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

The weighted vote of the first T rounds at x: the total vote weight of the hypotheses predicting true minus that of the hypotheses predicting false (signVal true = -1).

theorem Cslib.MachineLearning.Boosting.score_def {α : Type u_1} {m : ℕ} (S : Fin m → α × Bool) (A : (Fin m → ℝ) → α → Bool) (T : ℕ) (x : α) :
score S A T x = -∑ t ∈ Finset.range T, Round.vote S (rounds S A t) * BitString.signVal ((rounds S A t).hyp x)

Defining equation for score.

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

AdaBoost [FS97] run for T rounds on the sample S with the weak learner A. If some round before T has weighted error 0, the output is the hypothesis of the first such round (AdaBoost stops there). Otherwise it is the sign of the weighted vote score, with ties going to false.

theorem Cslib.MachineLearning.Boosting.adaBoost_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) :
adaBoost S A T = (rounds S A (Nat.find hz)).hyp

When some round before T has weighted error 0, adaBoost returns the hypothesis of the first such round.

theorem Cslib.MachineLearning.Boosting.adaBoost_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) :
adaBoost S A T = fun (x : α) => decide (0 < score S A T x)

When no round before T has weighted error 0, adaBoost returns the sign of score.

theorem Cslib.MachineLearning.Boosting.sum_lossSeq {α : Type u_1} {m : ℕ} (S : Fin m → α × Bool) (A : (Fin m → ℝ) → α → Bool) (T : ℕ) (i : Fin m) :
∑ t ∈ Finset.range T, lossSeq S A t i = score S A T (S i).1 * BitString.signVal (S i).2

The cumulative loss at a sample point is the weighted vote times the sign of the label: it is nonnegative exactly where the vote disagrees with the label.

theorem Cslib.MachineLearning.Boosting.sum_lossSeq_nonneg {α : Type u_1} {m : ℕ} (S : Fin m → α × Bool) (A : (Fin m → ℝ) → α → Bool) {T : ℕ} {i : Fin m} (hi : decide (0 < score S A T (S i).1) ≠ (S i).2) :
0 ≤ ∑ t ∈ Finset.range T, lossSeq S A t i

Where the weighted vote errs, the cumulative loss is nonnegative.

theorem Cslib.MachineLearning.Boosting.hyp_eq_of_error_eq_zero {α : Type u_1} {m : ℕ} (S : Fin m → α × Bool) (A : (Fin m → ℝ) → α → Bool) {t : ℕ} (h : Round.error S (rounds S A t) = 0) (i : Fin m) :
(rounds S A t).hyp (S i).1 = (S i).2

A round with weighted error 0 has a hypothesis consistent with the sample, since every sample point has positive weight.

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

The number of sample points where the weighted vote errs is at most the potential of the multiplicative update, since each such point has weight at least 1.

theorem Cslib.MachineLearning.Boosting.rounds_error_nonneg {α : Type u_1} {m : ℕ} (S : Fin m → α × Bool) (A : (Fin m → ℝ) → α → Bool) (t : ℕ) :
0 ≤ Round.error S (rounds S A t)

The weighted error of every round is nonnegative.

theorem Cslib.MachineLearning.Boosting.potential_lossSeq_eq {α : Type u_1} {m : ℕ} (S : Fin m → α × Bool) (A : (Fin m → ℝ) → α → Bool) [NeZero m] {T : ℕ} (hz : ¬∃ t < T, Round.error S (rounds S A t) = 0) (hlt : ∀ t < T, Round.error S (rounds S A t) < 1) :

Exact potential of the exponential multiplicative update in AdaBoost after T rounds, when every round before T has weighted error in (0, 1).

theorem Cslib.MachineLearning.Boosting.empiricalMiscount_adaBoost_le_prod {α : Type u_1} {m : ℕ} (S : Fin m → α × Bool) (A : (Fin m → ℝ) → α → Bool) {T : ℕ} (hlt : ∀ t < T, Round.error S (rounds S A t) < 1) :
↑(PACLearning.empiricalMiscount (adaBoost S A T) S) / ↑m ≤ ∏ t ∈ Finset.range T, 2 * √(Round.error S (rounds S A t) * (1 - Round.error S (rounds S A t)))

The AdaBoost training-error bound, product form ([SSBD14], proof of Theorem 10.2; [MRT18], proof of Theorem 7.2): if every round before T has weighted error εₜ < 1, the fraction of sample points that the output of T rounds of AdaBoost misclassifies is at most ∏ₜ 2 √(εₜ (1 - εₜ)). A round with εₜ = 0 stops AdaBoost with a consistent hypothesis.

theorem Cslib.MachineLearning.Boosting.two_mul_sqrt_le_exp (ε : ℝ) :
2 * √(ε * (1 - ε)) ≤ Real.exp (-(2 * (1 / 2 - ε) ^ 2))

The AdaBoost factor of an error ε is at most exp (-2 (1/2 - ε)²), since 4 ε (1 - ε) = 1 - 4 (1/2 - ε)².

theorem Cslib.MachineLearning.Boosting.empiricalMiscount_adaBoost_le_exp_sum {α : Type u_1} {m : ℕ} (S : Fin m → α × Bool) (A : (Fin m → ℝ) → α → Bool) {T : ℕ} (hlt : ∀ t < T, Round.error S (rounds S A t) < 1) :
↑(PACLearning.empiricalMiscount (adaBoost S A T) S) / ↑m ≤ Real.exp (-(2 * ∑ t ∈ Finset.range T, (1 / 2 - Round.error S (rounds S A t)) ^ 2))

The AdaBoost training-error bound in terms of the edges [MohriRostamizadehTalwalkar2018, Theorem 7.2, (7.3)]: if every round before T has weighted error εₜ < 1, the fraction of sample points that the output of T rounds misclassifies is at most exp (-2 ∑ₜ (1/2 - εₜ)²).

theorem Cslib.MachineLearning.Boosting.empiricalMiscount_adaBoost_le_exp {α : Type u_1} {m : ℕ} (S : Fin m → α × Bool) (A : (Fin m → ℝ) → α → Bool) {T : ℕ} {γ : ℝ} (hγ : 0 ≤ γ) (hε : ∀ t < T, Round.error S (rounds S A t) ≤ 1 / 2 - γ) :
↑(PACLearning.empiricalMiscount (adaBoost S A T) S) / ↑m ≤ Real.exp (-(2 * γ ^ 2 * ↑T))

The AdaBoost training-error bound, exponential form [ShalevShwartzBenDavid2014, Theorem 10.2; MohriRostamizadehTalwalkar2018, Theorem 7.2, (7.4)]: if every round before T has weighted error at most 1/2 - γ with γ ≥ 0, the fraction of sample points that the output of T rounds misclassifies is at most exp (-2 γ² T).

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

The weak learner A has edge γ on the sample S: for every distribution on the sample with positive weights, the hypothesis it returns has weighted error at most 1/2 - γ.

theorem Cslib.MachineLearning.Boosting.IsWeakLearner.rounds_error_le {α : Type u_1} {m : ℕ} {S : Fin m → α × Bool} {A : (Fin m → ℝ) → α → Bool} {γ : ℝ} [NeZero m] (hA : IsWeakLearner S A γ) (t : ℕ) :
Round.error S (rounds S A t) ≤ 1 / 2 - γ

Against a weak learner with edge γ, every round of AdaBoost has weighted error at most 1/2 - γ.

theorem Cslib.MachineLearning.Boosting.IsWeakLearner.empiricalMiscount_adaBoost_eq_zero {α : Type u_1} {m : ℕ} {S : Fin m → α × Bool} {A : (Fin m → ℝ) → α → Bool} {γ : ℝ} (hA : IsWeakLearner S A γ) (hγ : 0 ≤ γ) {T : ℕ} (hT : Real.log ↑m < 2 * γ ^ 2 * ↑T) :

Weak learning gives consistency, a consequence of [ShalevShwartzBenDavid2014, Theorem 10.2]: against a weak learner with edge γ ≥ 0, AdaBoost run for T rounds with log m < 2 γ² T returns a hypothesis that is consistent with the sample.

theorem Cslib.MachineLearning.Boosting.IsWeakLearner.adaBoost_eq {α : Type u_1} {m : ℕ} {S : Fin m → α × Bool} {A : (Fin m → ℝ) → α → Bool} {γ : ℝ} (hA : IsWeakLearner S A γ) (hγ : 0 ≤ γ) {T : ℕ} (hT : Real.log ↑m < 2 * γ ^ 2 * ↑T) (i : Fin m) :
adaBoost S A T (S i).1 = (S i).2

Under the hypotheses of empiricalMiscount_adaBoost_eq_zero, the output labels every sample point correctly.