Documentation

CslibFrontier.MachineLearning.Replicable.Amplification

Amplification of accuracy and replicability #

This module formalizes confidence and replicability amplification theorems for shared-seed replicable algorithms [ILPS22]:

Main definitions #

Main results #

References #

Confidence amplification: majority vote and median-of-runs #

noncomputable def Cslib.MachineLearning.Replicable.majorityVote {X : Type u} {Ω : Type v} {m : ℕ} (A : Algorithm X Ω Bool m) (r : ℕ) :
Algorithm X (Fin (2 * (r + 1)) → Ω) Bool (2 * (r + 1) * m)

Run a Boolean algorithm 2 * (r + 1) times on disjoint blocks with independent shared seeds and return the majority bit (breaking ties toward true).

theorem Cslib.MachineLearning.Replicable.majorityVote_replicable {X : Type u} {Ω : Type v} {m : ℕ} {A : Algorithm X Ω Bool m} {𝒟 : Set (PMF X)} {ρ : ℝ} (h : IsReplicableFor A 𝒟 ρ) (r : ℕ) :
IsReplicableFor (majorityVote A r) 𝒟 (↑(2 * (r + 1)) * ρ)
theorem Cslib.MachineLearning.Replicable.majorityVote_accurate {X : Type u} {Ω : Type v} {m : ℕ} {A : Algorithm X Ω Bool m} {𝒟 : Set (PMF X)} {target : PMF X → Bool} {β₀ : ℝ} (hacc : IsAccurateFor A 𝒟 (fun (D : PMF X) => {target D}) β₀) (hβ₀ : β₀ ≤ 1 / 2) (r : ℕ) :
IsAccurateFor (majorityVote A r) 𝒟 (fun (D : PMF X) => {target D}) ((4 * β₀ * (1 - β₀)) ^ (r + 1))
theorem Cslib.MachineLearning.Replicable.exists_majorityVote {X : Type u} {Ω : Type v} {m : ℕ} {A : Algorithm X Ω Bool m} {𝒟 : Set (PMF X)} {target : PMF X → Bool} {β₀ β : ℝ} (hacc : IsAccurateFor A 𝒟 (fun (D : PMF X) => {target D}) β₀) (hβ₀_nonneg : 0 ≤ β₀) (hβ₀ : β₀ < 1 / 2) (hβ : 0 < β) :
∃ (r : ℕ), IsAccurateFor (majorityVote A r) 𝒟 (fun (D : PMF X) => {target D}) β

For any Boolean algorithm with error β₀ < 1 / 2 and any target β > 0, taking the majority of 2 * (r + 1) independent repetitions achieves failure probability at most β.

noncomputable def Cslib.MachineLearning.Replicable.medianOfRuns {X : Type u} {Ω : Type v} {m : ℕ} (A : Algorithm X Ω ℝ m) (r : ℕ) :
Algorithm X (Fin (2 * (r + 1)) → Ω) ℝ (2 * (r + 1) * m)

Run a real-valued algorithm 2 * (r + 1) times on disjoint blocks with independent shared seeds and output Cslib.median.

theorem Cslib.MachineLearning.Replicable.medianOfRuns_replicable {X : Type u} {Ω : Type v} {m : ℕ} {A : Algorithm X Ω ℝ m} {𝒟 : Set (PMF X)} {ρ : ℝ} (h : IsReplicableFor A 𝒟 ρ) (r : ℕ) :
IsReplicableFor (medianOfRuns A r) 𝒟 (↑(2 * (r + 1)) * ρ)
theorem Cslib.MachineLearning.Replicable.medianOfRuns_accurate {X : Type u} {Ω : Type v} {m : ℕ} {A : Algorithm X Ω ℝ m} {𝒟 : Set (PMF X)} {target : PMF X → ℝ} {ε β₀ : ℝ} (hacc : EstimatesFor A 𝒟 target ε β₀) (hβ₀ : β₀ ≤ 1 / 2) (r : ℕ) :
EstimatesFor (medianOfRuns A r) 𝒟 target ε ((4 * β₀ * (1 - β₀)) ^ (r + 1))
theorem Cslib.MachineLearning.Replicable.exists_medianOfRuns {X : Type u} {Ω : Type v} {m : ℕ} {A : Algorithm X Ω ℝ m} {𝒟 : Set (PMF X)} {target : PMF X → ℝ} {ε β₀ β : ℝ} (hacc : EstimatesFor A 𝒟 target ε β₀) (hβ₀_nonneg : 0 ≤ β₀) (hβ₀ : β₀ < 1 / 2) (hβ : 0 < β) :
∃ (r : ℕ), EstimatesFor (medianOfRuns A r) 𝒟 target ε β

For any real estimator within ε except with probability β₀ < 1 / 2 and any β > 0, medianOfRuns achieves (ε, β) estimation accuracy.

Finite-domain heavy-hitter amplification #

noncomputable def Cslib.MachineLearning.Replicable.empFreq {α : Type w} [DecidableEq α] (k : ℕ) (v : Fin k → α) (y : α) :

Empirical frequency of y : α in a tuple v : Fin k → α.

noncomputable def Cslib.MachineLearning.Replicable.pickThresholded {α : Type w} [Fintype α] [Nonempty α] [LinearOrder α] (a b : ℝ) (N k : ℕ) (i : Fin N) (v : Fin k → α) :
α

Least element of α whose empirical frequency crosses thresholdValue a b N i, falling back to Finset.univ.min' if none qualifies.

noncomputable def Cslib.MachineLearning.Replicable.amplifyFinite {X : Type u} {Ω : Type v} {α : Type w} {m : ℕ} [Fintype α] [Nonempty α] [LinearOrder α] (A : Algorithm X Ω α m) (a b : ℝ) (k N : ℕ) [NeZero N] :
Algorithm X (Fin N) α (k * m)

Finite-domain heavy-hitter amplification: runs A independently with fresh internal seeds on k disjoint m-sample blocks, shares a single threshold i : Fin N across [a, b), and outputs the least element whose empirical frequency crosses thresholdValue a b N i.

theorem Cslib.MachineLearning.Replicable.isReplicable_amplifyFinite {X : Type u} {Ω : Type v} {α : Type w} {m : ℕ} [Fintype α] [Nonempty α] [LinearOrder α] (A : Algorithm X Ω α m) {a b δ : ℝ} (hab : a < b) (hδ : 0 ≤ δ) (k N : ℕ) [NeZero k] [NeZero N] :
IsReplicable (amplifyFinite A a b k N) (2 * (↑(Fintype.card α) * (2 * Real.exp (-2 * ↑k * δ ^ 2))) + ↑(Fintype.card α) * (2 * δ / (b - a) + 1 / ↑N))

Strong replicability of amplifyFinite: for any a < b, k, N ≥ 1, and δ ≥ 0, amplifyFinite A a b k N is strongly ρ-replicable over all distributions D : PMF X with ρ = 2 * |α| * (2 * exp(-2 * k * δ^2)) + |α| * (2 * δ / (b - a) + 1 / N).

theorem Cslib.MachineLearning.Replicable.isAccurateFor_amplifyFinite {X : Type u} {Ω : Type v} {α : Type w} {m : ℕ} [Fintype α] [Nonempty α] [LinearOrder α] (A : Algorithm X Ω α m) {𝒟 : Set (PMF X)} {good : PMF X → Set α} {β₀ a b δ : ℝ} (hacc : IsAccurateFor A 𝒟 good β₀) (hab : a ≤ b) (hδ : 0 ≤ δ) (ha : β₀ + δ < a) (hb : b ≤ (1 - β₀) / ↑(Fintype.card α) - δ) (k N : ℕ) [NeZero k] [NeZero N] :
IsAccurateFor (amplifyFinite A a b k N) 𝒟 good (↑(Fintype.card α) * (2 * Real.exp (-2 * ↑k * δ ^ 2)))

Accuracy of amplifyFinite: if A errs with probability at most β₀ < 1 / (|α| + 1) on 𝒟 and the threshold window [a, b) satisfies β₀ + δ < a ≤ b ≤ (1 - β₀) / |α| - δ, then amplifyFinite A a b k N errs on 𝒟 with probability at most |α| * (2 * exp (-2 * k * δ^2)).

theorem Cslib.MachineLearning.Replicable.exists_amplifyFinite {X : Type u} {Ω : Type v} {α : Type w} {m : ℕ} [Fintype α] [Nonempty α] [LinearOrder α] (A : Algorithm X Ω α m) {𝒟 : Set (PMF X)} {good : PMF X → Set α} {β₀ ρ β : ℝ} (hacc : IsAccurateFor A 𝒟 good β₀) (_hβ₀_nonneg : 0 ≤ β₀) (hβ₀ : β₀ < 1 / (↑(Fintype.card α) + 1)) (hρ : 0 < ρ) (hβ : 0 < β) :
∃ (a : ℝ) (b : ℝ) (k : ℕ) (N : ℕ) (_ : NeZero k) (x : NeZero N), IsReplicable (amplifyFinite A a b k N) ρ ∧ IsAccurateFor (amplifyFinite A a b k N) 𝒟 good β

Finite-domain amplification theorem [ILPS22]: for any finite nonempty linearly ordered output type α, if A achieves error β₀ < 1 / (|α| + 1) on 𝒟 (with no replicability assumption at all on A), then for any target ρ > 0 and β > 0, there exist thresholds a, b : ℝ and k, N ≥ 1 such that amplifyFinite A a b k N is strongly ρ-replicable and (good, β)-accurate on 𝒟.

General-domain replicability amplification (DecidableEq α, ρ₀ < 1 / 2) #

def Cslib.MachineLearning.Replicable.strictMajorityCandidate {α : Type w} {k : ℕ} [DecidableEq α] (v : Fin k → α) (fallback : α) :
α

Pick a candidate from v : Fin k → α appearing strictly more than k / 2 times, or fallback if no strict majority exists.

theorem Cslib.MachineLearning.Replicable.strictMajorityCandidate_eq_of_lt_two_mul {α : Type w} {k : ℕ} [DecidableEq α] (v : Fin k → α) (fallback y : α) (hy : k < 2 * {j : Fin k | v j = y}.card) :
noncomputable def Cslib.MachineLearning.Replicable.seedOutput {X : Type u} {Ω : Type v} {α : Type w} {m : ℕ} (A : Algorithm X Ω α m) (D : PMF X) (r : Ω) :
PMF α

Output distribution of A on D conditioned on a fixed seed r.

@[reducible, inline]
noncomputable abbrev Cslib.MachineLearning.Replicable.seedColl {X : Type u} {Ω : Type v} {α : Type w} {m : ℕ} (A : Algorithm X Ω α m) (D : PMF X) (r : Ω) :

Collision probability of A on D at shared seed r: Probability.PMF.collisionProbability (seedOutput A D r).

noncomputable def Cslib.MachineLearning.Replicable.trialRun {X : Type u} {Ω : Type v} {α : Type w} {m : ℕ} [DecidableEq α] (A : Algorithm X Ω α m) (k₁ k₂ : ℕ) [NeZero k₂] (S : Fin (k₁ * (m + m) + k₂ * m) → X) (r : Ω) :
PMF (ℝ × α)

Single candidate-seed trial inside amplifyReplicability: using k₁ independent sample pairs to estimate the seed's collision probability and k₂ independent samples to find its strict-majority output.

noncomputable def Cslib.MachineLearning.Replicable.pickFirstThresholded {α : Type w} {T : ℕ} [NeZero T] (a b : ℝ) (N : ℕ) (i : Fin N) (trials : Fin T → ℝ × α) :
α

Pick the first trial t whose empirical collision estimate passes thresholdRound a b N i, falling back to trial 0 when none qualifies.

noncomputable def Cslib.MachineLearning.Replicable.amplifyReplicability {X : Type u} {Ω : Type v} {α : Type w} {m : ℕ} [DecidableEq α] (A : Algorithm X Ω α m) (a b : ℝ) (T k₁ k₂ N : ℕ) [NeZero T] [NeZero k₂] [NeZero N] :
Algorithm X ((Fin T → Ω) × Fin N) α (T * (k₁ * (m + m) + k₂ * m))

General-domain replicability amplification [ILPS22]: draws T independent shared seeds r_t ~ A.seed and one threshold i ~ uniform (Fin N), runs trialRun on each candidate seed over disjoint sample blocks, and outputs the strict-majority candidate of the first seed passing thresholdValue a b N i.

theorem Cslib.MachineLearning.Replicable.disagreeProb_amplifyReplicability_le {X : Type u} {Ω : Type v} {α : Type w} {m : ℕ} [DecidableEq α] (A : Algorithm X Ω α m) (D : PMF X) {a b θ_acc δ : ℝ} (hab : a < b) (hδ : 0 ≤ δ) (ha_half : 1 / 2 + δ < a) (hb_acc : b ≤ θ_acc - δ) (hθ_lt : θ_acc < 1) (T k₁ k₂ N : ℕ) [NeZero T] [NeZero k₁] [NeZero k₂] [NeZero N] :
(amplifyReplicability A a b T k₁ k₂ N).disagreeProb D ≤ (A.disagreeProb D / (1 - θ_acc)) ^ T + 2 * (↑T * (2 * Real.exp (-2 * ↑k₁ * δ ^ 2) + 2 * Real.exp (-2 * ↑k₂ * ((a - δ - 1 / 2) / 2) ^ 2))) + ↑T * (2 * δ / (b - a) + 1 / ↑N)

Disagreement probability upper bound for amplifyReplicability: if 1 / 2 + δ < a < b ≤ θ_acc - δ and θ_acc < 1, then (amplifyReplicability A a b T k₁ k₂ N).disagreeProb D is bounded by the bad-seed probability (A.disagreeProb D / (1 - θ_acc)) ^ T, twice the concentration error over T trials, and the threshold discretization error T * (2 * δ / (b - a) + 1 / N).

theorem Cslib.MachineLearning.Replicable.isAccurateFor_amplifyReplicability {X : Type u} {Ω : Type v} {α : Type w} {m : ℕ} [DecidableEq α] (A : Algorithm X Ω α m) {𝒟 : Set (PMF X)} {good : PMF X → Set α} {ρ₀ β₀ a b θ_acc δ : ℝ} (hrep : IsReplicableFor A 𝒟 ρ₀) (hacc : IsAccurateFor A 𝒟 good β₀) (hab : a < b) (hδ : 0 ≤ δ) (ha_half : 1 / 2 + δ < a) (hb_acc : b ≤ θ_acc - δ) (hθ_lt : θ_acc < 1) (T k₁ k₂ N : ℕ) [NeZero T] [NeZero k₁] [NeZero k₂] [NeZero N] :
IsAccurateFor (amplifyReplicability A a b T k₁ k₂ N) 𝒟 good ((ρ₀ / (1 - θ_acc)) ^ T + ↑T * (β₀ / (a - δ)) + ↑T * (2 * Real.exp (-2 * ↑k₁ * δ ^ 2) + 2 * Real.exp (-2 * ↑k₂ * ((a - δ - 1 / 2) / 2) ^ 2)))

Accuracy preservation for amplifyReplicability: under IsReplicableFor A 𝒟 ρ₀ and IsAccurateFor A 𝒟 good β₀ with 1 / 2 + δ < a < b ≤ θ_acc - δ and θ_acc < 1, the failure probability of amplifyReplicability is bounded by the bad-seed probability (ρ₀ / (1 - θ_acc)) ^ T, the Markov union bound (T : ℝ) * (β₀ / (a - δ)) over the T candidate seeds, and the per-trial concentration errors.

theorem Cslib.MachineLearning.Replicable.exists_amplifyReplicability_accurate {ρ₀ ρ β : ℝ} (hρ₀_nonneg : 0 ≤ ρ₀) (hρ₀ : ρ₀ < 1 / 2) (hρ : 0 < ρ) (hβ : 0 < β) :
∃ (a : ℝ) (b : ℝ) (T : ℕ) (k₁ : ℕ) (k₂ : ℕ) (N : ℕ) (x : NeZero T) (_ : NeZero k₁) (x_2 : NeZero k₂) (x_3 : NeZero N) (β₀_req : ℝ), 0 < β₀_req ∧ ∀ {X : Type u} {Ω : Type v} {α : Type w} {m : ℕ} [inst : DecidableEq α] (A : Algorithm X Ω α m) {𝒟 : Set (PMF X)} {good : PMF X → Set α} {β₀ : ℝ}, IsReplicableFor A 𝒟 ρ₀ → IsAccurateFor A 𝒟 good β₀ → β₀ ≤ β₀_req → IsReplicableFor (amplifyReplicability A a b T k₁ k₂ N) 𝒟 ρ ∧ IsAccurateFor (amplifyReplicability A a b T k₁ k₂ N) 𝒟 good β

General-domain replicability and accuracy-preserving amplification: over any [DecidableEq α], for any initial ρ₀ < 1 / 2 and target ρ, β > 0, there exist shared-seed and trial parameters (a, b, T, k₁, k₂, N) together with an initial-error threshold β₀_req > 0 (of order O(β / T)) such that any ρ₀-replicable algorithm A whose error satisfies β₀ ≤ β₀_req is amplified to ρ-replicability while preserving (good, β) accuracy.

theorem Cslib.MachineLearning.Replicable.exists_amplifyReplicability {X : Type u} {Ω : Type v} {α : Type w} {m : ℕ} [DecidableEq α] (A : Algorithm X Ω α m) {𝒟 : Set (PMF X)} {ρ₀ ρ : ℝ} (hrep : IsReplicableFor A 𝒟 ρ₀) (hρ₀_nonneg : 0 ≤ ρ₀) (hρ₀ : ρ₀ < 1 / 2) (hρ : 0 < ρ) :
∃ (a : ℝ) (b : ℝ) (T : ℕ) (k₁ : ℕ) (k₂ : ℕ) (N : ℕ) (x : NeZero T) (_ : NeZero k₁) (x_2 : NeZero k₂) (x_3 : NeZero N), IsReplicableFor (amplifyReplicability A a b T k₁ k₂ N) 𝒟 ρ

General-domain replicability amplification [ILPS22]: over any [DecidableEq α] output type, any algorithm A that is weakly (or strongly) ρ₀-replicable on 𝒟 with ρ₀ < 1 / 2 can be amplified to ρ-replicability for any target ρ > 0. See exists_amplifyReplicability_accurate for preserved (good, β) accuracy under O(β / T) initial error.