Boosting.lean

Lean 4 source, lean/DataMiningAsObservation/Boosting.lean at commit bccca4f. Appendix C, Machine-checked statements, says what each file proves. All Lean files.

/-
Boosting.lean. Chapter 7 section 7.1, boosting.

Boosting fits a sequence of weak scorers, each on the rows the previous ones got wrong,
and sums them with a step size set by the weighted error. The step size is positive
exactly when the weak scorer beats chance, and after the rows are reweighted the weighted
error of the scorer just fitted is one half, so the next scorer must find something new.
-/
import Mathlib

namespace DMO.Boosting

/-- The step size for weighted error `ε`. -/
noncomputable def alpha (ε : ℝ) : ℝ := (1 / 2) * Real.log ((1 - ε) / ε)

/-- **The step size is positive exactly when the scorer beats chance.** -/
theorem alpha_pos_iff (ε : ℝ) (h0 : 0 < ε) (h1 : ε < 1) : 0 < alpha ε ↔ ε < 1 / 2 := by
  unfold alpha
  have h1' : 0 < 1 - ε := by linarith
  rw [mul_pos_iff_of_pos_left (by norm_num), Real.log_pos_iff (by positivity), lt_div_iff₀ h0]
  constructor <;> intro h <;> linarith

/-- **The step size is zero at chance.** -/
theorem alpha_half : alpha (1 / 2) = 0 := by
  norm_num [alpha]

/-- **After reweighting, the scorer's weighted error is one half.** The wrong rows carry
weight `ε` scaled up by `r` and the right rows weight `1 − ε` scaled down by `r`, with
`r² = (1 − ε)/ε`. -/
theorem reweighted_error_half (ε r : ℝ) (h0 : 0 < ε) (h1 : ε < 1) (hr : 0 < r)
    (hr2 : r ^ 2 = (1 - ε) / ε) : ε * r / (ε * r + (1 - ε) / r) = 1 / 2 := by
  have h1' : 0 < 1 - ε := by linarith
  have key : 1 - ε = ε * r ^ 2 := by
    rw [hr2, mul_div_cancel₀ _ h0.ne']
  have hden : ε * r + (1 - ε) / r ≠ 0 := by positivity
  rw [div_eq_iff hden, key]
  field_simp
  ring

end DMO.Boosting