OutputMetric.lean
Lean 4 source, lean/DataMiningAsObservation/OutputMetric.lean at commit bccca4f. Appendix C, Machine-checked statements, says what each file proves. All Lean files.
/-
OutputMetric.lean. Chapter 1 section 1.2 and chapter 6 section 6.1, the output metric.
The output metric is the rule by which a consumer's mistakes are scored, the second element
of an observer. The consumer `x` and the consumer `−x` have the same read operator and
reverse every comparison, so the read operator alone does not fix the observer. And two
cost matrices score the same pair of classifiers in opposite orders, so naming the output
metric is naming what a downstream mistake is.
-/
import Mathlib
import DataMiningAsObservation.ReadOperator
namespace DMO.OutputMetric
open DMO.ReadOperator
variable {Ω : Type*} [Fintype Ω] {n : ℕ}
/-- **Negating a consumer reverses every comparison.** -/
theorem neg_reverses (C : (Fin n → ℝ) → ℝ) (x y : Fin n → ℝ) :
(fun z => -C z) x < (fun z => -C z) y ↔ C y < C x := by
simp
/-- **Negating a consumer leaves its read operator unchanged.** -/
theorem readOp_of_neg (w : Ω → ℝ) (g : Ω → Fin n → ℝ) :
readOp w (fun ω => -g ω) = readOp w g :=
readOp_neg w g
/-- A cost metric: `cFP` per false positive and `cFN` per false negative. -/
def cost (cFP cFN : ℝ) (fp fn : ℕ) : ℝ := cFP * fp + cFN * fn
/-- **Two classifiers with the same error count get opposite verdicts from two cost
metrics.** Classifier A makes one false positive and three false negatives, classifier B
three and one. Charging false negatives double prefers B, charging false positives double
prefers A. -/
theorem cost_flips :
(1 + 3 : ℕ) = 3 + 1 ∧ cost 1 2 3 1 < cost 1 2 1 3 ∧ cost 2 1 1 3 < cost 2 1 3 1 := by
norm_num [cost]
end DMO.OutputMetric