Documentation

CslibFrontier.MachineLearning.Replicable.Basic

Replicable sample algorithms with a shared seed #

A randomized sample algorithm of sample size m over domain X with shared seed space Ω and output type α consists of a distribution seed : PMF Ω for the shared randomness and a sample-to-output kernel run : (Fin m → X) → Ω → PMF α (Algorithm) [ILPS22]. When the algorithm is deterministic given the sample and seed, Algorithm.deterministic lifts a map (Fin m → X) → Ω → α into Algorithm.

Program packages a ProbComp-backed seed generator seed : ProbComp Ω and sample runner run : (Fin m → X) → Ω → ProbComp α, together with single-run Program.exec and two-sample shared-seed Program.coupledExec, interpreted semantically into Algorithm via ProbComp.eval (Program.toAlgorithm). Note that Program fixes probabilistic control over ProbComp without providing finite-precision real representations or native resource bounds.

Running A twice on independent i.i.d. samples S₁, S₂ ~ D^m with the same shared seed r ~ seed induces the joint output distribution Algorithm.pairedOutput A D on α × α. The disagreement probability Algorithm.disagreeProb A D is Pr[y₁ ≠ y₂] under this coupling, and Algorithm.agreeProb A D = 1 - Algorithm.disagreeProb A D is Pr[y₁ = y₂].

Main definitions #

Main results #

References #

structure Cslib.MachineLearning.Replicable.Algorithm (X : Type u) (Ω : Type v) (α : Type w) (m : ℕ) :
Type (max (max u v) w)

A semantic randomized sample algorithm of sample size m over domain X with shared seed distribution seed : PMF Ω and output type α. Given sample S and shared seed r, run S r : PMF α is the conditional output distribution (which is pure when all randomness lies in the shared seed).

  • seed : PMF Ω

    Distribution of the shared random seed.

  • run : (Fin m → X) → Ω → PMF α

    Conditional output distribution given the sample and shared seed.

noncomputable def Cslib.MachineLearning.Replicable.Algorithm.deterministic {X : Type u} {Ω : Type v} {α : Type w} {m : ℕ} (seed : PMF Ω) (f : (Fin m → X) → Ω → α) :
Algorithm X Ω α m

Construct an Algorithm whose randomness lies entirely in the shared seed.

noncomputable def Cslib.MachineLearning.Replicable.Algorithm.output {X : Type u} {Ω : Type v} {α : Type w} {m : ℕ} (A : Algorithm X Ω α m) (S : Fin m → X) :
PMF α

Single-execution marginal output distribution on a fixed sample S.

noncomputable def Cslib.MachineLearning.Replicable.Algorithm.marginal {X : Type u} {Ω : Type v} {α : Type w} {m : ℕ} (A : Algorithm X Ω α m) (D : PMF X) :
PMF α

Single-execution marginal output distribution on m i.i.d. samples from D.

noncomputable def Cslib.MachineLearning.Replicable.Algorithm.pairedOutput {X : Type u} {Ω : Type v} {α : Type w} {m : ℕ} (A : Algorithm X Ω α m) (D : PMF X) :
PMF (α × α)

Two-sample shared-seed joint output distribution on α × α when S₁, S₂ ~ iid D m are drawn independently and executed with the same shared seed r ~ A.seed.

theorem Cslib.MachineLearning.Replicable.Algorithm.marginal_eq_seed_bind {X : Type u} {Ω : Type v} {α : Type w} {m : ℕ} (A : Algorithm X Ω α m) (D : PMF X) :
A.marginal D = A.seed.bind fun (r : Ω) => (Probability.PMF.iid D m).bind fun (S : Fin m → X) => A.run S r

The single-execution marginal equals drawing the shared seed first, then the sample.

noncomputable def Cslib.MachineLearning.Replicable.Algorithm.disagreeProb {X : Type u} {Ω : Type v} {α : Type w} {m : ℕ} (A : Algorithm X Ω α m) (D : PMF X) :

Probability that two independent i.i.d. samples sharing a seed yield different outputs.

noncomputable def Cslib.MachineLearning.Replicable.Algorithm.agreeProb {X : Type u} {Ω : Type v} {α : Type w} {m : ℕ} (A : Algorithm X Ω α m) (D : PMF X) :

Probability that two independent i.i.d. samples sharing a seed yield the same output.

theorem Cslib.MachineLearning.Replicable.Algorithm.disagreeProb_nonneg {X : Type u} {Ω : Type v} {α : Type w} {m : ℕ} (A : Algorithm X Ω α m) (D : PMF X) :
theorem Cslib.MachineLearning.Replicable.Algorithm.agreeProb_nonneg {X : Type u} {Ω : Type v} {α : Type w} {m : ℕ} (A : Algorithm X Ω α m) (D : PMF X) :
theorem Cslib.MachineLearning.Replicable.Algorithm.disagreeProb_le_one {X : Type u} {Ω : Type v} {α : Type w} {m : ℕ} (A : Algorithm X Ω α m) (D : PMF X) :
theorem Cslib.MachineLearning.Replicable.Algorithm.agreeProb_le_one {X : Type u} {Ω : Type v} {α : Type w} {m : ℕ} (A : Algorithm X Ω α m) (D : PMF X) :
theorem Cslib.MachineLearning.Replicable.Algorithm.agreeProb_add_disagreeProb {X : Type u} {Ω : Type v} {α : Type w} {m : ℕ} (A : Algorithm X Ω α m) (D : PMF X) :

Agreement and disagreement probabilities sum to 1.

theorem Cslib.MachineLearning.Replicable.Algorithm.pairedOutput_deterministic {X : Type u} {Ω : Type v} {α : Type w} {m : ℕ} (seed : PMF Ω) (f : (Fin m → X) → Ω → α) (D : PMF X) :
(deterministic seed f).pairedOutput D = seed.bind fun (r : Ω) => (Probability.PMF.iid D m).bind fun (S₁ : Fin m → X) => PMF.map (fun (S₂ : Fin m → X) => (f S₁ r, f S₂ r)) (Probability.PMF.iid D m)

Paired output distribution for an algorithm that is deterministic given sample and seed.

theorem Cslib.MachineLearning.Replicable.Algorithm.disagreeProb_deterministic {X : Type u} {Ω : Type v} {α : Type w} {m : ℕ} (seed : PMF Ω) (f : (Fin m → X) → Ω → α) (D : PMF X) :
(deterministic seed f).disagreeProb D = ((seed.bind fun (r : Ω) => (Probability.PMF.iid D m).bind fun (S₁ : Fin m → X) => PMF.map (fun (S₂ : Fin m → X) => (f S₁ r, f S₂ r)) (Probability.PMF.iid D m)).toOuterMeasure {p : α × α | p.1 ≠ p.2}).toReal

Disagreement probability for an algorithm that is deterministic given sample and seed, expressed by integrating the per-pair seed disagreement probability over independent samples.

theorem Cslib.MachineLearning.Replicable.Algorithm.disagreeProb_deterministic_eq_tsum_seed {X : Type u} {Ω : Type v} {α : Type w} {m : ℕ} (seed : PMF Ω) (f : (Fin m → X) → Ω → α) (D : PMF X) :
(deterministic seed f).disagreeProb D = ∑' (r : Ω), (seed r).toReal * (((Probability.PMF.iid D m).bind fun (S₁ : Fin m → X) => PMF.map (fun (S₂ : Fin m → X) => (f S₁ r, f S₂ r)) (Probability.PMF.iid D m)).toOuterMeasure {p : α × α | p.1 ≠ p.2}).toReal

Disagreement probability of a deterministic-given-seed algorithm expressed as a tsum over the shared seed of the conditional pair-disagreement probability.

theorem Cslib.MachineLearning.Replicable.Algorithm.pairedOutput_deterministic_eq_samples {X : Type u} {Ω : Type v} {α : Type w} {m : ℕ} (seed : PMF Ω) (f : (Fin m → X) → Ω → α) (D : PMF X) :
(deterministic seed f).pairedOutput D = (Probability.PMF.iid D m).bind fun (S₁ : Fin m → X) => (Probability.PMF.iid D m).bind fun (S₂ : Fin m → X) => PMF.map (fun (r : Ω) => (f S₁ r, f S₂ r)) seed

Paired output distribution of a deterministic-given-seed algorithm, drawing the two independent samples first, then the shared seed.

theorem Cslib.MachineLearning.Replicable.Algorithm.disagreeProb_deterministic_eq_tsum_samples {X : Type u} {Ω : Type v} {α : Type w} {m : ℕ} (seed : PMF Ω) (f : (Fin m → X) → Ω → α) (D : PMF X) :
(deterministic seed f).disagreeProb D = ∑' (S₁ : Fin m → X), ((Probability.PMF.iid D m) S₁).toReal * ∑' (S₂ : Fin m → X), ((Probability.PMF.iid D m) S₂).toReal * (seed.toOuterMeasure {r : Ω | f S₁ r ≠ f S₂ r}).toReal

Disagreement probability of a deterministic-given-seed algorithm expressed by drawing the two independent samples first, then the shared seed.

noncomputable def Cslib.MachineLearning.Replicable.Algorithm.map {X : Type u} {Ω : Type v} {α : Type w} {γ : Type z} {m : ℕ} (A : Algorithm X Ω α m) (f : α → γ) :
Algorithm X Ω γ m

Deterministic post-processing of an algorithm's output.

noncomputable def Cslib.MachineLearning.Replicable.Algorithm.mapWithSeed {X : Type u} {Ω : Type v} {α : Type w} {γ : Type z} {m : ℕ} (A : Algorithm X Ω α m) (f : Ω → α → γ) :
Algorithm X Ω γ m

Post-processing with access to the shared seed r.

theorem Cslib.MachineLearning.Replicable.Algorithm.marginal_map {X : Type u} {Ω : Type v} {α : Type w} {γ : Type z} {m : ℕ} (A : Algorithm X Ω α m) (f : α → γ) (D : PMF X) :
(A.map f).marginal D = PMF.map f (A.marginal D)
theorem Cslib.MachineLearning.Replicable.Algorithm.disagreeProb_mapWithSeed_le {X : Type u} {Ω : Type v} {α : Type w} {γ : Type z} {m : ℕ} (A : Algorithm X Ω α m) (f : Ω → α → γ) (D : PMF X) :
theorem Cslib.MachineLearning.Replicable.Algorithm.disagreeProb_map_le {X : Type u} {Ω : Type v} {α : Type w} {γ : Type z} {m : ℕ} (A : Algorithm X Ω α m) (f : α → γ) (D : PMF X) :

ProbComp-backed shared-seed programs #

A ProbComp-backed randomized sample algorithm: seed samples the shared randomness using finite uniform choices, and run S r represents the sample-and-seed step as a ProbComp computation interpreted via Program.toAlgorithm (allowing noncomputable real-arithmetic maps).

  • seed : ProbComp Ω

    Program sampling the shared random seed.

  • run : (Fin m → X) → Ω → ProbComp α

    Program executed on the sample and shared seed.

def Cslib.MachineLearning.Replicable.Program.deterministic {X Ω α : Type} {m : ℕ} (seed : ProbComp Ω) (f : (Fin m → X) → Ω → α) :
Program X Ω α m

Construct a Program whose execution is deterministic once the shared seed is sampled.

def Cslib.MachineLearning.Replicable.Program.exec {X Ω α : Type} {m : ℕ} (P : Program X Ω α m) (S : Fin m → X) :

Single execution of P on sample S as a ProbComp program.

def Cslib.MachineLearning.Replicable.Program.coupledExec {X Ω α : Type} {m : ℕ} (P : Program X Ω α m) (S₁ S₂ : Fin m → X) :
ProbComp (α × α)

Paired execution of P on two samples S₁, S₂ sharing one draw of P.seed.

noncomputable def Cslib.MachineLearning.Replicable.Program.toAlgorithm {X Ω α : Type} {m : ℕ} (P : Program X Ω α m) :
Algorithm X Ω α m

Semantic Algorithm obtained by interpreting P.seed and P.run via ProbComp.eval.

theorem Cslib.MachineLearning.Replicable.Program.eval_exec {X Ω α : Type} {m : ℕ} (P : Program X Ω α m) (S : Fin m → X) :
theorem Cslib.MachineLearning.Replicable.Program.eval_coupledExec {X Ω α : Type} {m : ℕ} (P : Program X Ω α m) (S₁ S₂ : Fin m → X) :
(P.coupledExec S₁ S₂).eval = P.seed.eval.bind fun (r : Ω) => (P.run S₁ r).eval.bind fun (y₁ : α) => PMF.map (fun (y₂ : α) => (y₁, y₂)) (P.run S₂ r).eval
theorem Cslib.MachineLearning.Replicable.Program.pairedOutput_toAlgorithm {X Ω α : Type} {m : ℕ} (P : Program X Ω α m) (D : PMF X) :
P.toAlgorithm.pairedOutput D = (Probability.PMF.iid D m).bind fun (S₁ : Fin m → X) => (Probability.PMF.iid D m).bind fun (S₂ : Fin m → X) => (P.coupledExec S₁ S₂).eval

Evaluating the paired ProbComp execution over independent samples agrees with Algorithm.pairedOutput.

@[simp]
theorem Cslib.MachineLearning.Replicable.Program.toAlgorithm_deterministic {X Ω α : Type} {m : ℕ} (seed : ProbComp Ω) (f : (Fin m → X) → Ω → α) :
def Cslib.MachineLearning.Replicable.Program.map {X Ω α γ : Type} {m : ℕ} (P : Program X Ω α m) (f : α → γ) :
Program X Ω γ m

Deterministic post-processing of a Program.

@[simp]
theorem Cslib.MachineLearning.Replicable.Program.toAlgorithm_map {X Ω α γ : Type} {m : ℕ} (P : Program X Ω α m) (f : α → γ) :

Replicability and accuracy predicates #

def Cslib.MachineLearning.Replicable.IsReplicableFor {X : Type u} {Ω : Type v} {α : Type w} {m : ℕ} (A : Algorithm X Ω α m) (𝒟 : Set (PMF X)) (ρ : ℝ) :

Weak (distribution-family) ρ-replicability: A is ρ-replicable over the distribution family 𝒟 if for every D ∈ 𝒟, two runs on independent m-samples from D sharing A.seed disagree with probability at most ρ [ILPS22].

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

Single-distribution ρ-replicability.

@[reducible, inline]
abbrev Cslib.MachineLearning.Replicable.IsReplicable {X : Type u} {Ω : Type v} {α : Type w} {m : ℕ} (A : Algorithm X Ω α m) (ρ : ℝ) :

Strong (distribution-free) ρ-replicability: A is ρ-replicable under all distributions D : PMF X [ILPS22].

theorem Cslib.MachineLearning.Replicable.isReplicableFor_iff_agreeProb {X : Type u} {Ω : Type v} {α : Type w} {m : ℕ} {A : Algorithm X Ω α m} {𝒟 : Set (PMF X)} {ρ : ℝ} :
IsReplicableFor A 𝒟 ρ ↔ ∀ D ∈ 𝒟, 1 - ρ ≤ A.agreeProb D
theorem Cslib.MachineLearning.Replicable.isReplicable_iff {X : Type u} {Ω : Type v} {α : Type w} {m : ℕ} {A : Algorithm X Ω α m} {ρ : ℝ} :
IsReplicable A ρ ↔ ∀ (D : PMF X), A.disagreeProb D ≤ ρ
theorem Cslib.MachineLearning.Replicable.IsReplicableFor.mono {X : Type u} {Ω : Type v} {α : Type w} {m : ℕ} {A : Algorithm X Ω α m} {𝒟 : Set (PMF X)} {ρ ρ' : ℝ} (h : IsReplicableFor A 𝒟 ρ) (hρ : ρ ≤ ρ') :
IsReplicableFor A 𝒟 ρ'
theorem Cslib.MachineLearning.Replicable.IsReplicableFor.antitone {X : Type u} {Ω : Type v} {α : Type w} {m : ℕ} {A : Algorithm X Ω α m} {𝒟 𝒟' : Set (PMF X)} {ρ : ℝ} (h : IsReplicableFor A 𝒟 ρ) (h𝒟 : 𝒟' ⊆ 𝒟) :
IsReplicableFor A 𝒟' ρ
theorem Cslib.MachineLearning.Replicable.IsReplicable.toIsReplicableFor {X : Type u} {Ω : Type v} {α : Type w} {m : ℕ} {A : Algorithm X Ω α m} {ρ : ℝ} (h : IsReplicable A ρ) (𝒟 : Set (PMF X)) :
IsReplicableFor A 𝒟 ρ
theorem Cslib.MachineLearning.Replicable.IsReplicableFor.toIsReplicableOn {X : Type u} {Ω : Type v} {α : Type w} {m : ℕ} {A : Algorithm X Ω α m} {𝒟 : Set (PMF X)} {ρ : ℝ} (h : IsReplicableFor A 𝒟 ρ) {D : PMF X} (hD : D ∈ 𝒟) :
theorem Cslib.MachineLearning.Replicable.IsReplicableFor.mapWithSeed {X : Type u} {Ω : Type v} {α : Type w} {γ : Type z} {m : ℕ} {A : Algorithm X Ω α m} {𝒟 : Set (PMF X)} {ρ : ℝ} (h : IsReplicableFor A 𝒟 ρ) (f : Ω → α → γ) :
theorem Cslib.MachineLearning.Replicable.IsReplicableFor.map {X : Type u} {Ω : Type v} {α : Type w} {γ : Type z} {m : ℕ} {A : Algorithm X Ω α m} {𝒟 : Set (PMF X)} {ρ : ℝ} (h : IsReplicableFor A 𝒟 ρ) (f : α → γ) :
IsReplicableFor (A.map f) 𝒟 ρ
def Cslib.MachineLearning.Replicable.IsAccurateFor {X : Type u} {Ω : Type v} {α : Type w} {m : ℕ} (A : Algorithm X Ω α m) (𝒟 : Set (PMF X)) (good : PMF X → Set α) (β : ℝ) :

Accuracy over a distribution family: under D ∈ 𝒟, the single-run marginal output fails the acceptable set good D with probability at most β.

@[reducible, inline]
abbrev Cslib.MachineLearning.Replicable.IsAccurateOn {X : Type u} {Ω : Type v} {α : Type w} {m : ℕ} (A : Algorithm X Ω α m) (D : PMF X) (S : Set α) (β : ℝ) :

Single-distribution accuracy against an acceptable output set S.

@[reducible, inline]
abbrev Cslib.MachineLearning.Replicable.IsAccurate {X : Type u} {Ω : Type v} {α : Type w} {m : ℕ} (A : Algorithm X Ω α m) (good : PMF X → Set α) (β : ℝ) :

Strong (distribution-free) accuracy over all distributions.

@[reducible, inline]
abbrev Cslib.MachineLearning.Replicable.EstimatesFor {X : Type u} {Ω : Type v} {m : ℕ} (A : Algorithm X Ω ℝ m) (𝒟 : Set (PMF X)) (target : PMF X → ℝ) (ε β : ℝ) :

(ε, β)-estimation accuracy for real-valued outputs: under every D ∈ 𝒟, the output is within ε of target D except with probability at most β.

@[reducible, inline]
abbrev Cslib.MachineLearning.Replicable.Estimates {X : Type u} {Ω : Type v} {m : ℕ} (A : Algorithm X Ω ℝ m) (target : PMF X → ℝ) (ε β : ℝ) :

Strong (ε, β)-estimation accuracy over all distributions.

theorem Cslib.MachineLearning.Replicable.isAccurateFor_iff_prob_good {X : Type u} {Ω : Type v} {α : Type w} {m : ℕ} {A : Algorithm X Ω α m} {𝒟 : Set (PMF X)} {good : PMF X → Set α} {β : ℝ} :
IsAccurateFor A 𝒟 good β ↔ ∀ D ∈ 𝒟, 1 - β ≤ ((A.marginal D).toOuterMeasure (good D)).toReal
theorem Cslib.MachineLearning.Replicable.IsAccurateFor.mono {X : Type u} {Ω : Type v} {α : Type w} {m : ℕ} {A : Algorithm X Ω α m} {𝒟 : Set (PMF X)} {good : PMF X → Set α} {β β' : ℝ} (h : IsAccurateFor A 𝒟 good β) (hβ : β ≤ β') :
IsAccurateFor A 𝒟 good β'
theorem Cslib.MachineLearning.Replicable.IsAccurateFor.antitone {X : Type u} {Ω : Type v} {α : Type w} {m : ℕ} {A : Algorithm X Ω α m} {𝒟 𝒟' : Set (PMF X)} {good : PMF X → Set α} {β : ℝ} (h : IsAccurateFor A 𝒟 good β) (h𝒟 : 𝒟' ⊆ 𝒟) :
IsAccurateFor A 𝒟' good β
theorem Cslib.MachineLearning.Replicable.IsAccurateFor.map {X : Type u} {Ω : Type v} {α : Type w} {γ : Type z} {m : ℕ} {A : Algorithm X Ω α m} {𝒟 : Set (PMF X)} {good : PMF X → Set α} {good' : PMF X → Set γ} {β : ℝ} (f : α → γ) (h : IsAccurateFor A 𝒟 good β) (hgood : ∀ D ∈ 𝒟, ∀ y ∈ good D, f y ∈ good' D) :
IsAccurateFor (A.map f) 𝒟 good' β
theorem Cslib.MachineLearning.Replicable.EstimatesFor.mono {X : Type u} {Ω : Type v} {m : ℕ} {A : Algorithm X Ω ℝ m} {𝒟 : Set (PMF X)} {target : PMF X → ℝ} {ε ε' β β' : ℝ} (h : EstimatesFor A 𝒟 target ε β) (hε : ε ≤ ε') (hβ : β ≤ β') :
EstimatesFor A 𝒟 target ε' β'
theorem Cslib.MachineLearning.Replicable.EstimatesFor.antitone {X : Type u} {Ω : Type v} {m : ℕ} {A : Algorithm X Ω ℝ m} {𝒟 𝒟' : Set (PMF X)} {target : PMF X → ℝ} {ε β : ℝ} (h : EstimatesFor A 𝒟 target ε β) (h𝒟 : 𝒟' ⊆ 𝒟) :
EstimatesFor A 𝒟' target ε β