Documentation

CslibFrontier.Foundations.Analysis.SignLabelScore

Squared-error scores for finite sign tests #

Approximate values within 1 / (4 * (m + 1)) of their true signs give a score separated from zero by at least one half. The score is positive exactly when all m target signs agree with the true signs. The empty family is included.

For weighted signs, a separate score tests equality with the integer fingerprint and positivity of a qualifying test. Its tolerance is 1 / (4 * (M + 1)) for total weight at most M, and 1 / 4 for the qualifying test.

Adapted from RootLabelScore and RationalSignMargin in lean-canny at commit 970f28a5ecefc1327402ade16c068aa4b1b2c183. The larger tolerance still gives the same score margin and permits fewer repetitions of the dyadic product. The weighted score adapts FingerprintLabelScore at the same commit.

noncomputable def SignType.labelScore {m : ℕ} (a : Fin m → ℝ) (target : Fin m → SignType) :

Subtract four times the total squared distance from the target signs from one.

theorem SignType.labelScore_margin {m : ℕ} (a : Fin m → ℝ) (s target : Fin m → SignType) (ha : ∀ (i : Fin m), |a i - ↑(s i)| ≤ (4 * (↑m + 1))⁻¹) :
(1 / 2 ≤ labelScore a target ∨ labelScore a target ≤ -1 / 2) ∧ (0 < labelScore a target ↔ ∀ (i : Fin m), s i = target i)

With uniformly accurate approximations, the score is at least one half on agreement and at most minus one half on mismatch. Its sign characterizes agreement.

noncomputable def SignType.fingerprintScore (A b : ℝ) (target : ℤ) :

Subtract four times the squared errors from the integer fingerprint target and the qualifying target 1. The inputs are the approximate weighted sum and qualifying sign.

theorem SignType.fingerprintScore_margin {m : ℕ} (w : Fin m → ℕ) (a : Fin m → ℝ) (s : Fin m → SignType) (b : ℝ) (sigma : SignType) (target : ℤ) {M : ℕ} (hw : ∑ i : Fin m, w i ≤ M) (ha : ∀ (i : Fin m), |a i - ↑(s i)| ≤ (4 * (↑M + 1))⁻¹) (hb : |b - ↑sigma| ≤ 1 / 4) :
have actual := ∑ i : Fin m, ↑(w i) * ↑(s i); have score := fingerprintScore (∑ i : Fin m, ↑(w i) * a i) b target; (1 / 2 ≤ score ∨ score ≤ -1 / 2) ∧ (0 < score ↔ actual = target ∧ sigma = 1)

With approximations accurate to the total-weight tolerance, the fingerprint score has margin at least one half. It is positive exactly when the weighted integer signs match the target and the qualifying sign is positive.