DecisionBoundary.lean

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

/-
DecisionBoundary.lean. Chapter 6 section 6.1, the decision boundary.

The decision boundary is the set of inputs whose score equals the threshold. For a linear
classifier it is an affine hyperplane. Moving along the weight direction crosses it in
exactly one place, moving orthogonally to the weights never crosses it, and every point of
the boundary is the same distance from the origin along the weights. The boundary is where
the classifier's read direction and its threshold meet, and nothing else about the input
enters it.
-/
import Mathlib
import DataMiningAsObservation.Classifier

namespace DMO.DecisionBoundary

open DMO.Classifier

variable {n : ℕ}

/-- The decision boundary at threshold `τ`. -/
def boundary (w : Fin n → ℝ) (b τ : ℝ) : Set (Fin n → ℝ) := {x | score w b x = τ}

/-- **Moving orthogonally to the weights never crosses the boundary.** -/
theorem orth_stays (w : Fin n → ℝ) (b τ : ℝ) (x v : Fin n → ℝ) (hv : w ⬝ᵥ v = 0) :
    x ∈ boundary w b τ ↔ x + v ∈ boundary w b τ := by
  unfold boundary
  simp only [Set.mem_setOf_eq]
  rw [score_orth w b x v hv]

/-- **Moving along the weights crosses the boundary exactly once.** From any `x`, the step
`t • w` lands on the boundary for exactly one `t`. -/
theorem cross_once (w : Fin n → ℝ) (hw : w ⬝ᵥ w ≠ 0) (b τ : ℝ) (x : Fin n → ℝ) :
    ∃! t : ℝ, x + t • w ∈ boundary w b τ := by
  refine ⟨(τ - score w b x) / (w ⬝ᵥ w), ?_, ?_⟩
  · unfold boundary score
    simp only [Set.mem_setOf_eq]
    rw [dotProduct_add, dotProduct_smul, smul_eq_mul]
    field_simp
    try ring
  · intro t ht
    unfold boundary score at ht
    simp only [Set.mem_setOf_eq] at ht
    rw [dotProduct_add, dotProduct_smul, smul_eq_mul] at ht
    unfold score
    field_simp
    linarith

/-- **The boundary is a level set of the read direction.** Two boundary points have the same
projection on the weights. -/
theorem same_projection (w : Fin n → ℝ) (b τ : ℝ) (x y : Fin n → ℝ) (hx : x ∈ boundary w b τ)
    (hy : y ∈ boundary w b τ) : w ⬝ᵥ x = w ⬝ᵥ y := by
  unfold boundary score at hx hy
  simp only [Set.mem_setOf_eq] at hx hy
  linarith

end DMO.DecisionBoundary