Documentation

CslibFrontier.Probability.KWiseIndependent.CountSketch

One row of a Count-Sketch #

A row of the Count-Sketch of Charikar, Chen and Farach-Colton [CCFC04] has w buckets. Its seed (θ, φ) consists of a seed θ of a bucket hash h θ : X → Fin w and an independent seed φ of a sign hash ε (g φ x) = ±1. For weights f : X → ℝ on a finite set S, the bucket j holds ∑ x ∈ S with h θ x = j, f x ε (g φ x), and the estimate of f a is the bucket of a times the sign of a. Collisions of a with the other points add the noise ∑ x ∈ S with h θ x = h θ a, f x ε (g φ x), summed over x ≠ a.

For a two-universal bucket family and a pairwise independent family of signs of mean zero:

These are equations (5.1)–(5.6) of [Chakrabarti2025, Section 5.3.1], for arbitrary real weights, so they apply to turnstile streams as well as to insertion streams. Only an upper bound on collision probabilities is assumed of the bucket family.

Main results #

References #

theorem Cslib.Probability.CountSketch.expect_sum_ite_mul_sign_mul_sign {ι : Type u_1} {κ : Type u_2} {X : Type u_3} {Y : Type u_4} [Fintype ι] [Nonempty ι] [Fintype κ] [Fintype Y] [DecidableEq Y] {w : ℕ} {h : ι → X → Fin w} {g : κ → X → Y} {ε : Y → ℝ} (hg : IsKWiseIndependentHash 2 g) (hε : ∀ (y : Y), ε y ^ 2 = 1) (hε₀ : (Finset.univ.expect fun (y : Y) => ε y) = 0) {S : Finset X} {a : X} (ha : a ∈ S) (f : X → ℝ) :
(Finset.univ.expect fun (p : ι × κ) => (∑ x ∈ S, if h p.1 x = h p.1 a then f x * ε (g p.2 x) else 0) * ε (g p.2 a)) = f a

The Count-Sketch estimate is unbiased [Chakrabarti2025, equations (5.1)–(5.2)]: for any bucket hash h, an independent pairwise independent sign family ε ∘ g of mean zero, and a ∈ S, the bucket of a times the sign of a has mean f a. Only the pairwise independence of the signs is used.

theorem Cslib.Probability.CountSketch.expect_sq_sum_ite_mul_sign_le {ι : Type u_1} {κ : Type u_2} {X : Type u_3} {Y : Type u_4} [Fintype ι] [Nonempty ι] [Fintype κ] [Fintype Y] [DecidableEq Y] {w : ℕ} {h : ι → X → Fin w} {g : κ → X → Y} {ε : Y → ℝ} (hh : IsTwoUniversal (PMF.uniformOfFintype ι) h) (hg : IsKWiseIndependentHash 2 g) (hε : ∀ (y : Y), ε y ^ 2 = 1) (hε₀ : (Finset.univ.expect fun (y : Y) => ε y) = 0) {S : Finset X} {a : X} (ha : a ∉ S) (f : X → ℝ) :
(Finset.univ.expect fun (p : ι × κ) => (∑ x ∈ S, if h p.1 x = h p.1 a then f x * ε (g p.2 x) else 0) ^ 2) ≤ (∑ x ∈ S, f x ^ 2) / ↑w

The second moment of the Count-Sketch noise [Chakrabarti2025, equations (5.3)–(5.5)]: with a two-universal bucket family h and an independent pairwise independent sign family ε ∘ g of mean zero, the noise added to the bucket of a ∉ S by the points of S has second moment at most ∑ x ∈ S, f x ² / w.

theorem Cslib.Probability.CountSketch.dens_abs_sum_ite_mul_sign_gt_le {ι : Type u_1} {κ : Type u_2} {X : Type u_3} {Y : Type u_4} [Fintype ι] [Nonempty ι] [Fintype κ] [Fintype Y] [DecidableEq Y] {w : ℕ} {h : ι → X → Fin w} {g : κ → X → Y} {ε : Y → ℝ} (hh : IsTwoUniversal (PMF.uniformOfFintype ι) h) (hg : IsKWiseIndependentHash 2 g) (hε : ∀ (y : Y), ε y ^ 2 = 1) (hε₀ : (Finset.univ.expect fun (y : Y) => ε y) = 0) {S : Finset X} {a : X} (ha : a ∉ S) (f : X → ℝ) {t : ℝ} (ht : 0 ≤ t) (hw : 3 * ∑ x ∈ S, f x ^ 2 ≤ ↑w * t ^ 2) :
↑{p : ι × κ | t < |∑ x ∈ S, if h p.1 x = h p.1 a then f x * ε (g p.2 x) else 0|}.dens ≤ 1 / 3

One row of a Count-Sketch [Chakrabarti2025, equation (5.6)]: with a two-universal bucket family h and an independent pairwise independent sign family ε ∘ g of mean zero, the noise added to the bucket of a ∉ S by the points of S exceeds t ≥ 0 in absolute value for at most a third of the seeds once 3 ∑ x ∈ S, f x ² ≤ w t².