Documentation

CslibFrontier.Computability.PropertyTesting.Distribution.ClosenessCollision

The collision tester for closeness #

Given k samples x of an unknown distribution p and k independent samples y of an unknown distribution q on a finite type, the collision statistic of Diakonikolas–Gouleakis–Peebles–Price, §3 is Z = C₁ + C₂ - ((k - 1) / k) C₃ (closenessStatistic). Here C₁ and C₂ count colliding pairs within x and within y (Cslib.Probability.PMF.collisionCount), and C₃ counts colliding pairs across them (Cslib.Probability.PMF.crossCollisionCount). The statistic estimates the squared ℓ₂ distance without bias: E[Z] = C(k, 2) ‖p - q‖₂² (sum_sum_iid_mul_closenessStatistic).

The variance has a closed form (sum_sum_iid_mul_closenessStatistic_sub_sq). If ‖p‖₂², ‖q‖₂² ≤ b, it is at most (k - 1) (2 k - 1) b + 2 (k - 1)² (k + 1) √b ‖p - q‖₄² (sum_sum_iid_mul_closenessStatistic_sub_sq_le_sqrt_sum_pow_four), hence at most the same with ‖p - q‖₂² in place of ‖p - q‖₄² (sum_sum_iid_mul_closenessStatistic_sub_sq_le). The tester (closenessTester) accepts when Z ≤ C(k, 2) ε² / 2. For 0 < ε, Chebyshev's inequality shows that it distinguishes ‖p - q‖₂ ≤ ε / 2 from ‖p - q‖₂ ≥ ε, with error at most δ on each side, once 36 √b ≤ (k - 1) ε² δ (le_acceptProb₂_closenessTester, acceptProb₂_closenessTester_le; the Lean statements use the squared distances ‖p - q‖₂² ≤ ε² / 4 and ε² ≤ ‖p - q‖₂²). So k = O(√b / ε²) samples suffice, as in Diakonikolas–Gouleakis–Peebles–Price, Theorem 8. The ℓ₂ tester goes back to Batu–Fortnow–Rubinfeld–Smith–White.

Since ‖p‖₂² ≤ 1 and n ‖p - q‖₂² ≥ 4 dist(p, q)² on a domain of size n, this is in particular a closeness tester in statistical distance with k = O(n / ε²) samples (isClosenessTester_closenessTester). This sample complexity is not optimal: it is also the rate of learning both distributions to statistical distance ε / 4 from their empirical distributions and comparing. The ℓ₂ tester is, however, the last step of the optimal tester, which flattens the distributions first.

The source proves Var[Z] ≤ 116 k² b + 16 k³ ‖p - q‖₄² √b (Diakonikolas–Gouleakis–Peebles–Price, Lemma 10) and uses its weakening with ‖p - q‖₂² in the proof of Theorem 8 (§3.2); section, lemma and theorem numbers follow arXiv:1611.03579v1. Here the variance is computed exactly from the cross-collision moments. Since (k - 1) (2 k - 1) ≤ 116 k² and 2 (k - 1)² (k + 1) ≤ 16 k³, the ℓ₄ bound above implies Lemma 10. The constants 2, 36 and 27 are the ones this proof gives.

Main definitions #

Main results #

References #

noncomputable def Cslib.DistributionTesting.closenessStatistic {α : Type u_1} [DecidableEq α] {k : ℕ} (x y : Fin k → α) :

The collision statistic C₁ + C₂ - ((k - 1) / k) C₃ of two samples: the colliding pairs within each sample minus a rescaled count of the colliding pairs across them.

The acceptance threshold C(k, 2) ε² / 2 of the closeness tester with ℓ₂ proximity ε, halfway between 0 and the expected statistic C(k, 2) ε² at ℓ₂ distance ε.

Unfolding lemma for closenessThreshold.

noncomputable def Cslib.DistributionTesting.closenessTester {α : Type u_1} [DecidableEq α] (k : ℕ) (ε : ℝ) :
(Fin k → α) → (Fin k → α) → PMF Bool

The collision tester for closeness with ℓ₂ proximity ε: it accepts two samples when their collision statistic is at most closenessThreshold.

Unfolding lemma for closenessTester.

theorem Cslib.DistributionTesting.sum_sum_iid_mul_closenessStatistic {α : Type u_1} [Fintype α] [DecidableEq α] (p q : PMF α) (k : ℕ) :
∑ x : Fin k → α, ∑ y : Fin k → α, ((Probability.PMF.iid p k) x).toReal * ((Probability.PMF.iid q k) y).toReal * closenessStatistic x y = ↑(k.choose 2) * ∑ a : α, ((p a).toReal - (q a).toReal) ^ 2

Mean of the collision statistic: for k independent samples of each of p and q, the expected collision statistic is C(k, 2) ‖p - q‖₂² Diakonikolas–Gouleakis–Peebles–Price, Lemma 9.

theorem Cslib.DistributionTesting.sum_sum_iid_mul_closenessStatistic_sub_sq {α : Type u_1} [Fintype α] [DecidableEq α] (p q : PMF α) (k : ℕ) (hk : k ≠ 0) :
∑ x : Fin k → α, ∑ y : Fin k → α, ((Probability.PMF.iid p k) x).toReal * ((Probability.PMF.iid q k) y).toReal * (closenessStatistic x y - ↑(k.choose 2) * ∑ a : α, ((p a).toReal - (q a).toReal) ^ 2) ^ 2 = (↑k - 1) * (↑k / 2 * (Probability.PMF.collisionProbability p + Probability.PMF.collisionProbability q) + (↑k - 1) * ∑ a : α, (p a).toReal * (q a).toReal + (↑k ^ 2 - 1) * ∑ a : α, ((p a).toReal + (q a).toReal) * ((p a).toReal - (q a).toReal) ^ 2 - (2 * ↑k - 1) * (∑ a : α, (p a).toReal ^ 3 + ∑ a : α, (q a).toReal ^ 3) - ↑k * (↑k - 1) * ((Probability.PMF.collisionProbability p - ∑ a : α, (p a).toReal * (q a).toReal) ^ 2 + (Probability.PMF.collisionProbability q - ∑ a : α, (p a).toReal * (q a).toReal) ^ 2) + ↑k / 2 * (Probability.PMF.collisionProbability p ^ 2 + Probability.PMF.collisionProbability q ^ 2) + (↑k - 1) * (∑ a : α, (p a).toReal * (q a).toReal) ^ 2)

Variance of the collision statistic: with s = ‖p‖₂², s' = ‖q‖₂², t = ∑ a, p(a) q(a) and R = ∑ a, (p(a) + q(a)) (p(a) - q(a))², the statistic of k ≥ 1 samples of each has variance (k - 1) [k (s + s') / 2 + (k - 1) t + (k² - 1) R - (2 k - 1) (‖p‖₃³ + ‖q‖₃³) - k (k - 1) ((s - t)² + (s' - t)²) + k (s² + s'²) / 2 + (k - 1) t²].

theorem Cslib.DistributionTesting.sum_sum_iid_mul_closenessStatistic_sub_sq_le_sqrt_sum_pow_four {α : Type u_1} [Fintype α] [DecidableEq α] (p q : PMF α) {k : ℕ} (hk : k ≠ 0) {b : ℝ} (hp : Probability.PMF.collisionProbability p ≤ b) (hq : Probability.PMF.collisionProbability q ≤ b) :
∑ x : Fin k → α, ∑ y : Fin k → α, ((Probability.PMF.iid p k) x).toReal * ((Probability.PMF.iid q k) y).toReal * (closenessStatistic x y - ↑(k.choose 2) * ∑ a : α, ((p a).toReal - (q a).toReal) ^ 2) ^ 2 ≤ (↑k - 1) * (2 * ↑k - 1) * b + 2 * (↑k - 1) ^ 2 * (↑k + 1) * √b * √(∑ a : α, ((p a).toReal - (q a).toReal) ^ 4)

Variance bound for the collision statistic: if ‖p‖₂², ‖q‖₂² ≤ b, the statistic of k ≥ 1 samples of each has variance at most (k - 1) (2 k - 1) b + 2 (k - 1)² (k + 1) √b ‖p - q‖₄². Since (k - 1) (2 k - 1) ≤ 116 k² and 2 (k - 1)² (k + 1) ≤ 16 k³, this implies Diakonikolas–Gouleakis–Peebles–Price, Lemma 10.

theorem Cslib.DistributionTesting.sum_sum_iid_mul_closenessStatistic_sub_sq_le {α : Type u_1} [Fintype α] [DecidableEq α] (p q : PMF α) {k : ℕ} (hk : k ≠ 0) {b : ℝ} (hp : Probability.PMF.collisionProbability p ≤ b) (hq : Probability.PMF.collisionProbability q ≤ b) :
∑ x : Fin k → α, ∑ y : Fin k → α, ((Probability.PMF.iid p k) x).toReal * ((Probability.PMF.iid q k) y).toReal * (closenessStatistic x y - ↑(k.choose 2) * ∑ a : α, ((p a).toReal - (q a).toReal) ^ 2) ^ 2 ≤ (↑k - 1) * (2 * ↑k - 1) * b + 2 * (↑k - 1) ^ 2 * (↑k + 1) * √b * ∑ a : α, ((p a).toReal - (q a).toReal) ^ 2

Variance bound for the collision statistic in ℓ₂: if ‖p‖₂², ‖q‖₂² ≤ b, the statistic of k ≥ 1 samples of each has variance at most (k - 1) (2 k - 1) b + 2 (k - 1)² (k + 1) √b ‖p - q‖₂². This is the form used by the tester.

theorem Cslib.DistributionTesting.le_acceptProb₂_closenessTester {α : Type u_1} [Fintype α] [DecidableEq α] {p q : PMF α} {k : ℕ} {ε δ b : ℝ} (hδ : 0 < δ) (hp : Probability.PMF.collisionProbability p ≤ b) (hq : Probability.PMF.collisionProbability q ≤ b) (hk : 36 * √b ≤ (↑k - 1) * ε ^ 2 * δ) (hpq : ∑ a : α, ((p a).toReal - (q a).toReal) ^ 2 ≤ ε ^ 2 / 4) :

Completeness of the ℓ₂ closeness tester: if ‖p‖₂², ‖q‖₂² ≤ b, ‖p - q‖₂² ≤ ε² / 4 (that is, ‖p - q‖₂ ≤ ε / 2 for 0 < ε) and 36 √b ≤ (k - 1) ε² δ, the tester accepts with probability at least 1 - δ.

theorem Cslib.DistributionTesting.acceptProb₂_closenessTester_le {α : Type u_1} [Fintype α] [DecidableEq α] {p q : PMF α} {k : ℕ} {ε δ b : ℝ} (hδ : 0 < δ) (hp : Probability.PMF.collisionProbability p ≤ b) (hq : Probability.PMF.collisionProbability q ≤ b) (hk : 36 * √b ≤ (↑k - 1) * ε ^ 2 * δ) (hpq : ε ^ 2 ≤ ∑ a : α, ((p a).toReal - (q a).toReal) ^ 2) :

Soundness of the ℓ₂ closeness tester: if ‖p‖₂², ‖q‖₂² ≤ b, ε² ≤ ‖p - q‖₂² (that is, ‖p - q‖₂ ≥ ε for 0 < ε) and 36 √b ≤ (k - 1) ε² δ, the tester accepts with probability at most δ.

theorem Cslib.DistributionTesting.isClosenessTester_closenessTester {α : Type u_1} [Fintype α] [DecidableEq α] {k : ℕ} {ε : ℝ} (hε : 0 < ε) (hk : 27 * ↑(Fintype.card α) ≤ (↑k - 1) * ε ^ 2) :

A closeness tester in statistical distance: on a domain of size n, the collision tester with ℓ₂ proximity 2 ε / √n is a closeness tester with proximity ε whenever 27 n ≤ (k - 1) ε².