DisparateImpact.lean

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

/-
DisparateImpact.lean. Equations 0.37 and 14.5, the disparate impact ratio and the per-group verdict.

The disparate impact ratio is the favourable-decision rate in one group over the rate in
another. It is one exactly when the two rates agree, it inverts when the groups are
swapped, and a threshold rule on it, the four-fifths rule, is a statement about the rate
gap. The per-group false-clear verdict of equation 14.5 is the worst group's rate over the
groups large enough to score, so it clears a bar exactly when every scored group does.
-/
import Mathlib

namespace DMO.DisparateImpact

open Finset

/-- **Equation 0.37.** The disparate impact ratio of the favourable rate `ra` in group `a` to
the rate `rb` in group `b`. -/
noncomputable def ratio (ra rb : ℝ) : ℝ := ra / rb

/-- **Parity.** The ratio is one exactly when the two rates agree. -/
theorem ratio_eq_one_iff (ra rb : ℝ) (hb : 0 < rb) : ratio ra rb = 1 ↔ ra = rb := by
  unfold ratio
  rw [div_eq_one_iff_eq hb.ne']

/-- Swapping the groups inverts the ratio. -/
theorem ratio_swap (ra rb : ℝ) : ratio rb ra = (ratio ra rb)⁻¹ := by
  unfold ratio
  rw [inv_div]

/-- **The four-fifths rule** as a rate gap. The ratio is at least four fifths exactly when the
disadvantaged group's rate is within one fifth of the other's, relative to that other. -/
theorem four_fifths_iff (ra rb : ℝ) (hb : 0 < rb) : 4 / 5 ≤ ratio ra rb ↔ rb - ra ≤ rb / 5 := by
  unfold ratio
  rw [le_div_iff₀ hb]
  constructor <;> intro h <;> linarith

variable {γ : Type*}

/-- **Equation 14.5.** The per-group verdict, the worst false-clear rate over the groups
large enough to score. -/
noncomputable def verdict (G : Finset γ) (hG : G.Nonempty) (fc : γ → ℝ) : ℝ := G.sup' hG fc

/-- The verdict clears a bar exactly when every scored group does. -/
theorem verdict_le_iff (G : Finset γ) (hG : G.Nonempty) (fc : γ → ℝ) (bar : ℝ) :
    verdict G hG fc ≤ bar ↔ ∀ g ∈ G, fc g ≤ bar :=
  Finset.sup'_le_iff hG fc

/-- The verdict is at least the pooled rate, so pooling can only hide the worst group. -/
theorem weighted_le_verdict (G : Finset γ) (hG : G.Nonempty) (fc w : γ → ℝ)
    (hw : ∀ g ∈ G, 0 ≤ w g) (hsum : ∑ g ∈ G, w g = 1) :
    ∑ g ∈ G, w g * fc g ≤ verdict G hG fc := by
  unfold verdict
  calc ∑ g ∈ G, w g * fc g ≤ ∑ g ∈ G, w g * G.sup' hG fc := by
        apply Finset.sum_le_sum
        intro g hg
        exact mul_le_mul_of_nonneg_left (Finset.le_sup' fc hg) (hw g hg)
    _ = G.sup' hG fc := by rw [← Finset.sum_mul, hsum, one_mul]

end DMO.DisparateImpact