Documentation

CslibFrontier.Computability.PropertyTesting.Distribution.Basic

Sample-based distribution testers #

A k-sample tester for a property P of distributions on a finite type α is a randomized decision rule T : (Fin k → α) → PMF Bool applied to k independent samples of the unknown distribution p (Cslib.Probability.PMF.iid p k). It must accept every p ∈ P with probability at least 2 / 3 and accept with probability at most 1 / 3 every p at statistical distance at least ε from all of P (IsTester) Canonne. Statistical distance is the total variation distance dist of the metric space on PMF α scoped to Cslib.Probability.PMF. The tester is a semantic Markov kernel: this file counts samples and does not bound running time.

Le Cam's two-point method in mixture form (one_third_le_dist_iid_bind) turns a tester into a lower bound: the k-sample distribution of any p ∈ P is at statistical distance at least 1 / 3 from every mixture of k-sample distributions of distributions ε-far from P. Testers transport along bijections of the domain (IsTester.map_equiv) and, more generally, along any randomized map F of the samples that sends P into a property P' and far distributions to far distributions (IsTester.bind_pi): a tester for P' run on the mapped samples tests P.

A k-sample closeness tester (IsClosenessTester) receives k independent samples of each of two unknown distributions p and q (acceptProb₂). It must accept with probability at least 2 / 3 when p = q and with probability at most 1 / 3 when p and q are at statistical distance at least ε Canonne. A two-sample rule run on both sample tuples passed independently through a randomized map F accepts p, q with the probability that the rule accepts p.bind F, q.bind F (acceptProb₂_bind_pi). With m + k samples of each distribution, the acceptance probability averages, over the first m samples of each, the acceptance probability of the rule on the other k (acceptProb₂_append).

Main definitions #

Main results #

References #

noncomputable def Cslib.DistributionTesting.acceptProb {α : Type u_1} {k : ℕ} (T : (Fin k → α) → PMF Bool) (p : PMF α) :

The probability that the randomized decision rule T accepts k independent samples of p.

theorem Cslib.DistributionTesting.acceptProb_eq {α : Type u_1} {k : ℕ} (T : (Fin k → α) → PMF Bool) (p : PMF α) :

Unfolding lemma for acceptProb.

structure Cslib.DistributionTesting.IsTester {α : Type u_1} [Fintype α] {k : ℕ} (T : (Fin k → α) → PMF Bool) (P : Set (PMF α)) (ε : ℝ) :

T is a k-sample tester for the property P with proximity ε: it accepts every member of P with probability at least 2 / 3, and accepts with probability at most 1 / 3 every distribution at statistical distance at least ε from all of P.

noncomputable def Cslib.DistributionTesting.acceptProb₂ {α : Type u_1} {k : ℕ} (T : (Fin k → α) → (Fin k → α) → PMF Bool) (p q : PMF α) :

The probability that the randomized decision rule T accepts k independent samples of p together with k further independent samples of q.

theorem Cslib.DistributionTesting.acceptProb₂_eq {α : Type u_1} {k : ℕ} (T : (Fin k → α) → (Fin k → α) → PMF Bool) (p q : PMF α) :
acceptProb₂ T p q = (((Probability.PMF.iid p k).bind fun (x : Fin k → α) => (Probability.PMF.iid q k).bind fun (y : Fin k → α) => T x y) true).toReal

Unfolding lemma for acceptProb₂.

theorem Cslib.DistributionTesting.acceptProb₂_nonneg {α : Type u_1} {k : ℕ} (T : (Fin k → α) → (Fin k → α) → PMF Bool) (p q : PMF α) :

Two-sample acceptance probabilities are nonnegative.

theorem Cslib.DistributionTesting.acceptProb₂_le_one {α : Type u_1} {k : ℕ} (T : (Fin k → α) → (Fin k → α) → PMF Bool) (p q : PMF α) :

Two-sample acceptance probabilities are at most one.

structure Cslib.DistributionTesting.IsClosenessTester {α : Type u_1} [Fintype α] {k : ℕ} (T : (Fin k → α) → (Fin k → α) → PMF Bool) (ε : ℝ) :

T is a k-sample closeness tester with proximity ε: given k independent samples of each of two unknown distributions, it accepts with probability at least 2 / 3 when they are equal and with probability at most 1 / 3 when they are at statistical distance at least ε.

theorem Cslib.DistributionTesting.acceptProb₂_eq_sum {α : Type u_1} [Fintype α] {k : ℕ} (T : (Fin k → α) → (Fin k → α) → PMF Bool) (p q : PMF α) :
acceptProb₂ T p q = ∑ x : Fin k → α, ∑ y : Fin k → α, ((Probability.PMF.iid p k) x).toReal * ((Probability.PMF.iid q k) y).toReal * ((T x y) true).toReal

The two-sample acceptance probability as an expectation over both sample tuples.

theorem Cslib.DistributionTesting.acceptProb₂_append {α : Type u_1} [Fintype α] {m k : ℕ} (T : (Fin (m + k) → α) → (Fin (m + k) → α) → PMF Bool) (p q : PMF α) :
acceptProb₂ T p q = ∑ x₁ : Fin m → α, ∑ y₁ : Fin m → α, ((Probability.PMF.iid p m) x₁).toReal * ((Probability.PMF.iid q m) y₁).toReal * acceptProb₂ (fun (x₂ y₂ : Fin k → α) => T (Fin.append x₁ x₂) (Fin.append y₁ y₂)) p q

Conditioning on the first samples. With m + k samples of each distribution, the acceptance probability averages, over the first m samples x₁, y₁ of each, the acceptance probability of the rule with x₁, y₁ fixed on the other k samples.

theorem Cslib.DistributionTesting.acceptProb₂_pure {α : Type u_1} [Fintype α] {k : ℕ} (A : (Fin k → α) → (Fin k → α) → Bool) (p q : PMF α) :
acceptProb₂ (fun (x y : Fin k → α) => PMF.pure (A x y)) p q = ∑ x : Fin k → α, ∑ y : Fin k → α, ((Probability.PMF.iid p k) x).toReal * ((Probability.PMF.iid q k) y).toReal * if A x y = true then 1 else 0

A deterministic two-sample decision rule accepts with the probability of its acceptance region.

theorem Cslib.DistributionTesting.acceptProb₂_pure_eq_one_sub {α : Type u_1} [Fintype α] {k : ℕ} (A : (Fin k → α) → (Fin k → α) → Bool) (p q : PMF α) :
acceptProb₂ (fun (x y : Fin k → α) => PMF.pure (A x y)) p q = 1 - ∑ x : Fin k → α, ∑ y : Fin k → α, ((Probability.PMF.iid p k) x).toReal * ((Probability.PMF.iid q k) y).toReal * if (!A x y) = true then 1 else 0

A deterministic two-sample rule accepts with probability one minus the mass of its rejection region.

theorem Cslib.DistributionTesting.acceptProb_pure {α : Type u_1} [Fintype α] {k : ℕ} (A : (Fin k → α) → Bool) (p : PMF α) :
acceptProb (fun (x : Fin k → α) => PMF.pure (A x)) p = ∑ x : Fin k → α, ((Probability.PMF.iid p k) x).toReal * if A x = true then 1 else 0

A deterministic decision rule accepts with the probability of its acceptance region.

theorem Cslib.DistributionTesting.acceptProb_pure_eq_one_sub {α : Type u_1} [Fintype α] {k : ℕ} (A : (Fin k → α) → Bool) (p : PMF α) :
acceptProb (fun (x : Fin k → α) => PMF.pure (A x)) p = 1 - ∑ x : Fin k → α, ((Probability.PMF.iid p k) x).toReal * if (!A x) = true then 1 else 0

A deterministic rule accepts with probability one minus the mass of its rejection region.

theorem Cslib.DistributionTesting.abs_acceptProb_sub_le {α : Type u_1} [Fintype α] {k : ℕ} (T : (Fin k → α) → PMF Bool) (p q : PMF α) :

Acceptance probabilities differ by at most the statistical distance of the k-sample distributions.

theorem Cslib.DistributionTesting.one_third_le_dist_iid_bind {α : Type u_1} [Fintype α] {ι : Type u_3} [Finite ι] {k : ℕ} {T : (Fin k → α) → PMF Bool} {P : Set (PMF α)} {ε : ℝ} (hT : IsTester T P ε) {p : PMF α} (hp : p ∈ P) (μ : PMF ι) (f : ι → PMF α) (hf : ∀ (i : ι), ∀ q ∈ P, ε ≤ dist (f i) q) :
1 / 3 ≤ dist (Probability.PMF.iid p k) (μ.bind fun (i : ι) => Probability.PMF.iid (f i) k)

Le Cam's method for testers: if T is a k-sample tester for P, then the k-sample distribution of any p ∈ P is at statistical distance at least 1 / 3 from every mixture of k-sample distributions of distributions that are ε-far from P.

theorem Cslib.DistributionTesting.acceptProb_comp_equiv {α : Type u_1} {β : Type u_2} {k : ℕ} (e : α ≃ β) (T : (Fin k → α) → PMF Bool) (p : PMF β) :
acceptProb (fun (x : Fin k → β) => T fun (i : Fin k) => e.symm (x i)) p = acceptProb T (PMF.map (⇑e.symm) p)

Relabelling the samples of a decision rule along a bijection.

theorem Cslib.DistributionTesting.IsTester.map_equiv {α : Type u_1} {β : Type u_2} [Fintype α] [Fintype β] {k : ℕ} {T : (Fin k → α) → PMF Bool} {P : Set (PMF α)} {ε : ℝ} (hT : IsTester T P ε) (e : α ≃ β) :
IsTester (fun (x : Fin k → β) => T fun (i : Fin k) => e.symm (x i)) (PMF.map ⇑e '' P) ε

A tester transports along any bijection of the domain.

theorem Cslib.DistributionTesting.acceptProb_bind_pi {α : Type u_1} {β : Type u_2} [Finite α] [Finite β] {k : ℕ} (F : α → PMF β) (T : (Fin k → β) → PMF Bool) (p : PMF α) :
acceptProb (fun (x : Fin k → α) => (Probability.PMF.pi fun (i : Fin k) => F (x i)).bind T) p = acceptProb T (p.bind F)

Running a decision rule on samples passed independently through a randomized map F accepts p with the probability that the rule accepts p.bind F.

theorem Cslib.DistributionTesting.acceptProb₂_bind_pi {α : Type u_1} {β : Type u_2} [Finite α] [Finite β] {k : ℕ} (F : α → PMF β) (T : (Fin k → β) → (Fin k → β) → PMF Bool) (p q : PMF α) :
acceptProb₂ (fun (x y : Fin k → α) => (Probability.PMF.pi fun (i : Fin k) => F (x i)).bind fun (x' : Fin k → β) => (Probability.PMF.pi fun (i : Fin k) => F (y i)).bind fun (y' : Fin k → β) => T x' y') p q = acceptProb₂ T (p.bind F) (q.bind F)

Running a two-sample decision rule on both sample tuples passed independently through a randomized map F accepts p, q with the probability that the rule accepts p.bind F, q.bind F.

theorem Cslib.DistributionTesting.IsTester.bind_pi {α : Type u_1} {β : Type u_2} [Fintype α] [Fintype β] {k : ℕ} {T : (Fin k → β) → PMF Bool} {P' : Set (PMF β)} {ε' : ℝ} (hT : IsTester T P' ε') (F : α → PMF β) {P : Set (PMF α)} {ε : ℝ} (hmem : ∀ q ∈ P, q.bind F ∈ P') (hfar : ∀ (p : PMF α), (∀ q ∈ P, ε ≤ dist p q) → ∀ q' ∈ P', ε' ≤ dist (p.bind F) q') :
IsTester (fun (x : Fin k → α) => (Probability.PMF.pi fun (i : Fin k) => F (x i)).bind T) P ε

Reduction along a randomized map. If F sends every member of P into P' and every distribution ε-far from P to one ε'-far from P', then a k-sample tester for P' with proximity ε', run on the samples passed independently through F, is a k-sample tester for P with proximity ε.

theorem Cslib.DistributionTesting.IsTester.comp_equiv_uniform {α : Type u_1} {β : Type u_2} [Fintype α] [Fintype β] [Nonempty α] [Nonempty β] {k : ℕ} {T : (Fin k → α) → PMF Bool} {ε : ℝ} (hT : IsTester T {Probability.PMF.uniformOfFintype α} ε) (e : α ≃ β) :
IsTester (fun (x : Fin k → β) => T fun (i : Fin k) => e.symm (x i)) {Probability.PMF.uniformOfFintype β} ε

A uniformity tester transports along any bijection of the domain.