Documentation

CslibFrontier.MachineLearning.Replicable.MoserTardos

Replicable constraint solving by Moser–Tardos #

A learner sees a dataset S and must output an assignment avoiding every bad event A i, where the variables are to be sampled from distributions P̂ S v estimated from the data. Running the Moser–Tardos algorithm with samples drawn by correlated sampling from a shared seed makes the output replicable: two runs on independent datasets, sharing the seed, give the same output except with probability 4 ∑ v, E_{S, S'} d_TV(P̂ S v, P̂ S' v), plus the probability that a dataset is not one on which the estimates satisfy the local-lemma hypothesis.

The replicability interface Cslib.MachineLearning.Replicable.Algorithm takes the shared seed from a PMF, so the seed is finite here:

The algorithm is budgetedMoserTardos. Its disagreement bound (disagreeProb_budgetedMoserTardos_le) needs the local-lemma hypothesis e p (d + 1) ≤ 1 for the estimates of the datasets in a set good, and pays Pr[S ∉ good] for the others; it does not depend on the budget, the number of events or the dependency degree. Two runs whose histories agree through the budget give equal Option outputs, including a shared timeout none (budgetedOutput_eq_of_not_diverge). A run whose history diverges from the other's can time out on only one side, and that case is counted in the divergence probability. The budget enters through the timeout probability: a single run times out with probability at most |ι| / ((d + 1) (B + 1)) (seedTable_timeout_le). A rule that stops only when no event occurs never outputs a bad assignment (budgetedOutput_eq_some), so the learner is accurate up to that timeout probability (isAccurateOn_budgetedMoserTardos, isAccurate_budgetedMoserTardos).

The statement and its proof route are original (cslib-frontier issue #6718).

Main definitions #

Main results #

Implementation notes #

seedTable_disagree_le transfers the first-disagreement bound (Cslib.Probability.MoserTardos.coupledTable_diverge_le_two_mul) from the infinite coupled table to the finite seed, and seedTable_timeout_le transfers the Moser–Tardos resampling bound (Cslib.Probability.MoserTardos.exists_measurable_ge_resamplings, with the symmetric weights of Cslib.Probability.MoserTardos.lll_of_symm) followed by Markov's inequality. The budgeted outputs depend only on the samples with index at most B, and the laws of those samples under the seed and under the independent table are the same product (a private lemma).

No statement mentions a measurable structure: the hypotheses are stated with the product distribution Cslib.Probability.PMF.pi, and the proofs equip each α v with the discrete structure locally.

References #

def Cslib.MachineLearning.Replicable.budgetedOutput {V : Type u_1} {ι : Type u_2} [DecidableEq V] {α : V → Type u_3} (vbl : ι → Finset V) (r : List ι → ((v : V) → α v) → Option ι) (B : ℕ) (T : (p : V × ℕ) → α p.1) :
Option ((v : V) → α v)

The output of the run of historyRule r on the table T budgeted to B steps: the current assignment if the rule has stopped after B steps, and none (a timeout) otherwise.

theorem Cslib.MachineLearning.Replicable.budgetedOutput_eq_some {V : Type u_1} {ι : Type u_2} [DecidableEq V] {α : V → Type u_3} {vbl : ι → Finset V} {r : List ι → ((v : V) → α v) → Option ι} {B : ℕ} {A : ι → Set ((v : V) → α v)} (hstop : ∀ (w : List ι) (a : (v : V) → α v), r w a = none → ∀ (i : ι), a ∉ A i) {T : (p : V × ℕ) → α p.1} {a : (v : V) → α v} (h : budgetedOutput vbl r B T = some a) (i : ι) :
a ∉ A i

A rule that stops only when no event occurs outputs only assignments avoiding every event.

theorem Cslib.MachineLearning.Replicable.dependsOn_budgetedOutput {V : Type u_1} {ι : Type u_2} [DecidableEq V] {α : V → Type u_3} {vbl : ι → Finset V} {r : List ι → ((v : V) → α v) → Option ι} {B : ℕ} [Fintype V] :

The budgeted output depends only on the entries (v, k) with k ≤ B.

theorem Cslib.MachineLearning.Replicable.budgetedOutput_eq_of_not_diverge {V : Type u_1} {ι : Type u_2} [DecidableEq V] {α : V → Type u_3} {vbl : ι → Finset V} {r : List ι → ((v : V) → α v) → Option ι} {B : ℕ} {T : (p : V × ℕ) → α p.1 × α p.1} (hT : ¬Probability.MoserTardos.Diverge vbl r T) :

Two coupled runs that do not diverge have the same budgeted output.

@[reducible, inline]
abbrev Cslib.MachineLearning.Replicable.BudgetSeed {V : Type u_1} (α : V → Type u_3) [(v : V) → Fintype (α v)] (L B : ℕ) :
Type (max u_1 u_3)

The shared seed of the budgeted run: an enumeration of the cells of α v × Fin L for each variable v and each of its first B + 1 samples.

def Cslib.MachineLearning.Replicable.seedTable {V : Type u_1} {α : V → Type u_2} [(v : V) → Fintype (α v)] [(v : V) → DecidableEq (α v)] {L : ℕ} [NeZero L] (B : ℕ) (P : (v : V) → Probability.CorrelatedSampling.GridDist (α v) L) (σ : BudgetSeed α L B) (p : V × ℕ) :
α p.1

The table given by the seed σ for the grid distributions P: entry (v, k) is sampled from P v by correlated sampling from the enumeration at (v, min k B). A run budgeted to B steps reads only the entries with k ≤ B.

theorem Cslib.MachineLearning.Replicable.seedTable_disagree_le {V : Type u_1} [Fintype V] [DecidableEq V] {α : V → Type u_2} [(v : V) → Fintype (α v)] [(v : V) → DecidableEq (α v)] {L : ℕ} [NeZero L] (B : ℕ) {ι : Type u_3} [Finite ι] (vbl : ι → Finset V) (r : List ι → ((v : V) → α v) → Option ι) (P Q : (v : V) → Probability.CorrelatedSampling.GridDist (α v) L) (A : ι → Set ((v : V) → α v)) (hA : ∀ (i : ι), DependsOn (fun (x : (i : V) → α i) => x ∈ A i) ↑(vbl i)) (Γ : ι → Finset ι) (hΓ : ∀ (i j : ι), j ≠ i → ¬Disjoint (vbl i) (vbl j) → j ∈ Γ i) {d : ℕ} (hΓd : ∀ (i : ι), (Γ i).card ≤ d) {p : ℝ} (hP : ∀ (i : ι), ((Probability.PMF.pi fun (v : V) => (P v).toPMF).toOuterMeasure (A i)).toReal ≤ p) (hp : Real.exp 1 * p * (↑d + 1) ≤ 1) (hr : ∀ (w : List ι) (a : (v : V) → α v) (i : ι), r w a = some i → a ∈ A i) :
((Probability.PMF.uniformOfFintype (BudgetSeed α L B)).toOuterMeasure {σ : BudgetSeed α L B | budgetedOutput vbl r B (seedTable B P σ) ≠ budgetedOutput vbl r B (seedTable B Q σ)}).toReal ≤ 4 * ∑ v : V, dist (P v).toPMF (Q v).toPMF

Replicable runs for fixed estimates (original). Let r be a non-anticipating rule that only selects occurring events. Suppose every event has at most d neighbours in Γ and probability at most p under the product of the P v, with e p (d + 1) ≤ 1. Then two runs budgeted to B steps, one with P and one with Q, reading the tables of one uniformly random seed, give different outputs with probability at most 4 ∑ v, d_TV(P v, Q v).

theorem Cslib.MachineLearning.Replicable.seedTable_timeout_le {V : Type u_1} [Fintype V] [DecidableEq V] {α : V → Type u_2} [(v : V) → Fintype (α v)] [(v : V) → DecidableEq (α v)] {L : ℕ} [NeZero L] (B : ℕ) {ι : Type u_3} [Fintype ι] (vbl : ι → Finset V) (r : List ι → ((v : V) → α v) → Option ι) (P : (v : V) → Probability.CorrelatedSampling.GridDist (α v) L) (A : ι → Set ((v : V) → α v)) (hA : ∀ (i : ι), DependsOn (fun (x : (i : V) → α i) => x ∈ A i) ↑(vbl i)) (Γ : ι → Finset ι) (hΓ : ∀ (i j : ι), j ≠ i → ¬Disjoint (vbl i) (vbl j) → j ∈ Γ i) {d : ℕ} (hΓd : ∀ (i : ι), (Γ i).card ≤ d) {p : ℝ} (hP : ∀ (i : ι), ((Probability.PMF.pi fun (v : V) => (P v).toPMF).toOuterMeasure (A i)).toReal ≤ p) (hp : Real.exp 1 * p * (↑d + 1) ≤ 1) (hr : ∀ (w : List ι) (a : (v : V) → α v) (i : ι), r w a = some i → a ∈ A i) :
((Probability.PMF.uniformOfFintype (BudgetSeed α L B)).toOuterMeasure {σ : BudgetSeed α L B | budgetedOutput vbl r B (seedTable B P σ) = none}).toReal ≤ ↑(Fintype.card ι) / ((↑d + 1) * (↑B + 1))

Timeouts are rare (original). Let r be a non-anticipating rule that only selects occurring events. Suppose every event has at most d neighbours in Γ and probability at most p under the product of the P v, with e p (d + 1) ≤ 1. Then a run budgeted to B steps on the table of a uniformly random seed times out with probability at most |ι| / ((d + 1) (B + 1)).

A timeout means B + 1 resamplings. By Moser–Tardos the expected number of resamplings of each event is at most 1 / (d + 1) on the independent table, which the seed reproduces on the entries the budgeted run reads; Markov's inequality gives the bound.

noncomputable def Cslib.MachineLearning.Replicable.budgetedMoserTardos {V : Type u_1} [Fintype V] [DecidableEq V] {α : V → Type u_2} [(v : V) → Fintype (α v)] [(v : V) → DecidableEq (α v)] {L : ℕ} [NeZero L] (B : ℕ) {ι : Type u_3} {X : Type u_4} {m : ℕ} (vbl : ι → Finset V) (r : List ι → ((v : V) → α v) → Option ι) (est : (Fin m → X) → (v : V) → Probability.CorrelatedSampling.GridDist (α v) L) :
Algorithm X (BudgetSeed α L B) (Option ((v : V) → α v)) m

The budgeted Moser–Tardos learner. On the dataset S, it runs the rule historyRule r for B steps on the table of the shared seed for the estimated grid distributions P̂ S, and outputs the budgeted output: an assignment, or none on a timeout.

def Cslib.MachineLearning.Replicable.goodOutput {V : Type u_1} {α : V → Type u_2} {ι : Type u_3} (A : ι → Set ((v : V) → α v)) :
Set (Option ((v : V) → α v))

The outputs of budgetedMoserTardos that are assignments avoiding every event.

theorem Cslib.MachineLearning.Replicable.isAccurateOn_budgetedMoserTardos {V : Type u_1} [Fintype V] [DecidableEq V] {α : V → Type u_2} [(v : V) → Fintype (α v)] [(v : V) → DecidableEq (α v)] {L : ℕ} [NeZero L] (B : ℕ) {ι : Type u_3} {X : Type u_4} [Fintype ι] {m : ℕ} (vbl : ι → Finset V) (r : List ι → ((v : V) → α v) → Option ι) (est : (Fin m → X) → (v : V) → Probability.CorrelatedSampling.GridDist (α v) L) (A : ι → Set ((v : V) → α v)) (hA : ∀ (i : ι), DependsOn (fun (x : (i : V) → α i) => x ∈ A i) ↑(vbl i)) (Γ : ι → Finset ι) (hΓ : ∀ (i j : ι), j ≠ i → ¬Disjoint (vbl i) (vbl j) → j ∈ Γ i) {d : ℕ} (hΓd : ∀ (i : ι), (Γ i).card ≤ d) {p : ℝ} (good : Set (Fin m → X)) (hP : ∀ S ∈ good, ∀ (i : ι), ((Probability.PMF.pi fun (v : V) => (est S v).toPMF).toOuterMeasure (A i)).toReal ≤ p) (hp : Real.exp 1 * p * (↑d + 1) ≤ 1) (hr : ∀ (w : List ι) (a : (v : V) → α v) (i : ι), r w a = some i → a ∈ A i) (hstop : ∀ (w : List ι) (a : (v : V) → α v), r w a = none → ∀ (i : ι), a ∉ A i) (D : PMF X) :
IsAccurateOn (budgetedMoserTardos B vbl r est) D (goodOutput A) (↑(Fintype.card ι) / ((↑d + 1) * (↑B + 1)) + ((Probability.PMF.iid D m).toOuterMeasure goodᶜ).toReal)

Accuracy of the budgeted learner (original). Let r be a non-anticipating rule that only selects occurring events and stops only when no event occurs. Suppose that for every dataset in good every event has at most d neighbours in Γ and probability at most p under the product of the estimates P̂ S v, with e p (d + 1) ≤ 1. Then on an m-sample from D the learner fails to output an assignment avoiding every event with probability at most |ι| / ((d + 1) (B + 1)) plus the probability that the sample is not in good.

theorem Cslib.MachineLearning.Replicable.isAccurate_budgetedMoserTardos {V : Type u_1} [Fintype V] [DecidableEq V] {α : V → Type u_2} [(v : V) → Fintype (α v)] [(v : V) → DecidableEq (α v)] {L : ℕ} [NeZero L] (B : ℕ) {ι : Type u_3} {X : Type u_4} [Fintype ι] {m : ℕ} (vbl : ι → Finset V) (r : List ι → ((v : V) → α v) → Option ι) (est : (Fin m → X) → (v : V) → Probability.CorrelatedSampling.GridDist (α v) L) (A : ι → Set ((v : V) → α v)) (hA : ∀ (i : ι), DependsOn (fun (x : (i : V) → α i) => x ∈ A i) ↑(vbl i)) (Γ : ι → Finset ι) (hΓ : ∀ (i j : ι), j ≠ i → ¬Disjoint (vbl i) (vbl j) → j ∈ Γ i) {d : ℕ} (hΓd : ∀ (i : ι), (Γ i).card ≤ d) {p : ℝ} (hP : ∀ (S : Fin m → X) (i : ι), ((Probability.PMF.pi fun (v : V) => (est S v).toPMF).toOuterMeasure (A i)).toReal ≤ p) (hp : Real.exp 1 * p * (↑d + 1) ≤ 1) (hr : ∀ (w : List ι) (a : (v : V) → α v) (i : ι), r w a = some i → a ∈ A i) (hstop : ∀ (w : List ι) (a : (v : V) → α v), r w a = none → ∀ (i : ι), a ∉ A i) :
IsAccurate (budgetedMoserTardos B vbl r est) (fun (x : PMF X) => goodOutput A) (↑(Fintype.card ι) / ((↑d + 1) * (↑B + 1)))

Strong accuracy of the budgeted learner (original). If the local-lemma hypothesis holds for the estimates of every dataset, the learner outputs an assignment avoiding every event except with probability at most |ι| / ((d + 1) (B + 1)), for every distribution of the data.

theorem Cslib.MachineLearning.Replicable.disagreeProb_budgetedMoserTardos_le {V : Type u_1} [Fintype V] [DecidableEq V] {α : V → Type u_2} [(v : V) → Fintype (α v)] [(v : V) → DecidableEq (α v)] {L : ℕ} [NeZero L] (B : ℕ) {ι : Type u_3} {X : Type u_4} [Finite ι] {m : ℕ} (vbl : ι → Finset V) (r : List ι → ((v : V) → α v) → Option ι) (est : (Fin m → X) → (v : V) → Probability.CorrelatedSampling.GridDist (α v) L) (A : ι → Set ((v : V) → α v)) (hA : ∀ (i : ι), DependsOn (fun (x : (i : V) → α i) => x ∈ A i) ↑(vbl i)) (Γ : ι → Finset ι) (hΓ : ∀ (i j : ι), j ≠ i → ¬Disjoint (vbl i) (vbl j) → j ∈ Γ i) {d : ℕ} (hΓd : ∀ (i : ι), (Γ i).card ≤ d) {p : ℝ} (good : Set (Fin m → X)) (hP : ∀ S ∈ good, ∀ (i : ι), ((Probability.PMF.pi fun (v : V) => (est S v).toPMF).toOuterMeasure (A i)).toReal ≤ p) (hp : Real.exp 1 * p * (↑d + 1) ≤ 1) (hr : ∀ (w : List ι) (a : (v : V) → α v) (i : ι), r w a = some i → a ∈ A i) (D : PMF X) :
(budgetedMoserTardos B vbl r est).disagreeProb D ≤ 4 * ∑ v : V, ∑' (S₁ : Fin m → X) (S₂ : Fin m → X), ((Probability.PMF.iid D m) S₁).toReal * ((Probability.PMF.iid D m) S₂).toReal * dist (est S₁ v).toPMF (est S₂ v).toPMF + ((Probability.PMF.iid D m).toOuterMeasure goodᶜ).toReal

Replicable constraint solving (original). Let r be a non-anticipating rule that only selects occurring events, and let the dataset S determine grid estimates P̂ S v of the variables' distributions. Suppose that for every dataset in good every event has at most d neighbours in Γ and probability at most p under the product of the P̂ S v, with e p (d + 1) ≤ 1. Then two runs of budgetedMoserTardos on independent m-samples from D, sharing the seed, disagree with probability ρ ≤ 4 ∑ v, E_{S, S'} d_TV(P̂ S v, P̂ S' v) + Pr[S ∉ good], for every budget B. With good = Set.univ the last term vanishes.