Documentation

CslibFrontier.Probability.LocalitySensitiveHash.Measure

Measure-theoretic locality-sensitive hashing #

The base module CslibFrontier.Probability.LocalitySensitiveHash defines collision probabilities and AND/OR amplification for discrete seed laws seed : PMF ι. Continuous LSH families such as SimHash (stdGaussian E) and p-stable LSH (Gaussian/Cauchy projections paired with a uniform shift) draw seeds from a probability measure seed : Measure ι on a measurable space.

This module extends keyed collision probability (Cslib.Probability.measureCollisionProb), Charikar's triangle inequality (measureCollisionProb_triangle), and AND/OR/banding amplification to arbitrary probability measures using Mathlib's finite product measure Measure.pi, reusing IsLocalitySensitive, andHash, sCurve, and exists_sCurve_gap from CslibFrontier.Probability.LocalitySensitiveHash.

Main definitions #

Main results #

References #

Collision probability under a probability measure #

noncomputable def Cslib.Probability.measureCollisionProb {ι : Type u_1} {X : Type u_2} {Y : Type u_3} [MeasurableSpace ι] (seed : MeasureTheory.Measure ι) (hash : ι → X → Y) (x x' : X) :

The probability that x and x' collide under hash when the seed is drawn from seed.

theorem Cslib.Probability.measureCollisionProb_nonneg {ι : Type u_1} {X : Type u_2} {Y : Type u_3} [MeasurableSpace ι] (seed : MeasureTheory.Measure ι) (hash : ι → X → Y) (x x' : X) :
0 ≤ measureCollisionProb seed hash x x'
theorem Cslib.Probability.measureCollisionProb_le_one {ι : Type u_1} {X : Type u_2} {Y : Type u_3} [MeasurableSpace ι] (seed : MeasureTheory.Measure ι) [MeasureTheory.IsProbabilityMeasure seed] (hash : ι → X → Y) (x x' : X) :
measureCollisionProb seed hash x x' ≤ 1
@[simp]
theorem Cslib.Probability.measureCollisionProb_self {ι : Type u_1} {X : Type u_2} {Y : Type u_3} [MeasurableSpace ι] (seed : MeasureTheory.Measure ι) [MeasureTheory.IsProbabilityMeasure seed] (hash : ι → X → Y) (x : X) :
measureCollisionProb seed hash x x = 1
theorem Cslib.Probability.measureCollisionProb_comm {ι : Type u_1} {X : Type u_2} {Y : Type u_3} [MeasurableSpace ι] (seed : MeasureTheory.Measure ι) (hash : ι → X → Y) (x x' : X) :
measureCollisionProb seed hash x x' = measureCollisionProb seed hash x' x
theorem Cslib.Probability.measureCollisionProb_toMeasure {ι : Type u_1} {X : Type u_2} {Y : Type u_3} [MeasurableSpace ι] (seed : PMF ι) (hash : ι → X → Y) {x x' : X} (hmeas : MeasurableSet {i : ι | hash i x = hash i x'}) :
measureCollisionProb seed.toMeasure hash x x' = collisionProb seed hash x x'

A discrete seed law PMF converted via PMF.toMeasure has the same collision probability when the collision event is measurable.

theorem Cslib.Probability.measureCollisionProb_triangle {ι : Type u_1} {X : Type u_2} {Y : Type u_3} [MeasurableSpace ι] (seed : MeasureTheory.Measure ι) [MeasureTheory.IsProbabilityMeasure seed] (hash : ι → X → Y) {x y z : X} (hxy : MeasurableSet {i : ι | hash i x = hash i y}) (hyz : MeasurableSet {i : ι | hash i y = hash i z}) (hxz : MeasurableSet {i : ι | hash i x = hash i z}) :
1 - measureCollisionProb seed hash x z ≤ 1 - measureCollisionProb seed hash x y + (1 - measureCollisionProb seed hash y z)

Charikar's triangle inequality ([Cha02], Lemma 1) for a measure-valued seed law: 1 - measureCollisionProb satisfies the triangle inequality whenever the collision events are measurable.

AND and OR amplification under Measure.pi #

theorem Cslib.Probability.setOf_andHash_eq {ι : Type u_1} {X : Type u_2} {Y : Type u_3} (hash : ι → X → Y) (k : ℕ) (x x' : X) :
{s : Fin k → ι | andHash hash k s x = andHash hash k s x'} = Set.univ.pi fun (x_1 : Fin k) => {i : ι | hash i x = hash i x'}

Box representation of the collision set for the AND construction.

theorem Cslib.Probability.measurableSet_andHash_eq {ι : Type u_1} {X : Type u_2} {Y : Type u_3} [MeasurableSpace ι] (hash : ι → X → Y) (k : ℕ) {x x' : X} (hmeas : MeasurableSet {i : ι | hash i x = hash i x'}) :
MeasurableSet {s : Fin k → ι | andHash hash k s x = andHash hash k s x'}

Single-draw measurability of the collision event passes to the k-fold AND construction.

theorem Cslib.Probability.measureCollisionProb_andHash {ι : Type u_1} {X : Type u_2} {Y : Type u_3} [MeasurableSpace ι] (seed : MeasureTheory.Measure ι) [MeasureTheory.IsProbabilityMeasure seed] (hash : ι → X → Y) (k : ℕ) (x x' : X) :
measureCollisionProb (MeasureTheory.Measure.pi fun (x : Fin k) => seed) (andHash hash k) x x' = measureCollisionProb seed hash x x' ^ k

k independent draws from a probability measure seed all yield a collision with probability measureCollisionProb seed hash x x' ^ k.

theorem Cslib.Probability.IsLocalitySensitive.measureAnd {ι : Type u_1} {X : Type u_2} {Y : Type u_3} [MeasurableSpace ι] {seed : MeasureTheory.Measure ι} [MeasureTheory.IsProbabilityMeasure seed] {hash : ι → X → Y} {near far : X → X → Prop} {p₁ p₂ : ℝ} (h : IsLocalitySensitive (measureCollisionProb seed hash) near far p₁ p₂) (hp₁ : 0 ≤ p₁) (k : ℕ) :
IsLocalitySensitive (measureCollisionProb (MeasureTheory.Measure.pi fun (x : Fin k) => seed) (andHash hash k)) near far (p₁ ^ k) (p₂ ^ k)

The AND construction on a (p₁, p₂)-sensitive family under a probability measure seed is (p₁ ^ k, p₂ ^ k)-sensitive under Measure.pi.

noncomputable def Cslib.Probability.measureOrCollisionProb {ι : Type u_1} {X : Type u_2} {Y : Type u_3} [MeasurableSpace ι] (seed : MeasureTheory.Measure ι) (hash : ι → X → Y) (L : ℕ) (x x' : X) :

The probability that at least one of L independent seeds drawn from Measure.pi yields a collision between x and x'.

theorem Cslib.Probability.measureOrCollisionProb_eq {ι : Type u_1} {X : Type u_2} {Y : Type u_3} [MeasurableSpace ι] (seed : MeasureTheory.Measure ι) [MeasureTheory.IsProbabilityMeasure seed] (hash : ι → X → Y) (L : ℕ) {x x' : X} (hmeas : MeasurableSet {i : ι | hash i x = hash i x'}) :
measureOrCollisionProb seed hash L x x' = 1 - (1 - measureCollisionProb seed hash x x') ^ L

One of L independent draws from a probability measure collides with probability 1 - (1 - p) ^ L, provided the single-draw collision event is measurable.

theorem Cslib.Probability.IsLocalitySensitive.measureOr {ι : Type u_1} {X : Type u_2} {Y : Type u_3} [MeasurableSpace ι] {seed : MeasureTheory.Measure ι} [MeasureTheory.IsProbabilityMeasure seed] {hash : ι → X → Y} {near far : X → X → Prop} {p₁ p₂ : ℝ} (h : IsLocalitySensitive (measureCollisionProb seed hash) near far p₁ p₂) (hmeas : ∀ (x x' : X), MeasurableSet {i : ι | hash i x = hash i x'}) (hp₂ : p₂ ≤ 1) (L : ℕ) :
IsLocalitySensitive (measureOrCollisionProb seed hash L) near far (1 - (1 - p₁) ^ L) (1 - (1 - p₂) ^ L)

The OR construction under Measure.pi turns a (p₁, p₂)-sensitive family into a (1 - (1 - p₁) ^ L, 1 - (1 - p₂) ^ L)-sensitive one.

theorem Cslib.Probability.measureOrCollisionProb_andHash {ι : Type u_1} {X : Type u_2} {Y : Type u_3} [MeasurableSpace ι] (seed : MeasureTheory.Measure ι) [MeasureTheory.IsProbabilityMeasure seed] (hash : ι → X → Y) (k L : ℕ) {x x' : X} (hmeas : MeasurableSet {i : ι | hash i x = hash i x'}) :
measureOrCollisionProb (MeasureTheory.Measure.pi fun (x : Fin k) => seed) (andHash hash k) L x x' = sCurve k L (measureCollisionProb seed hash x x')

L bands of k independent draws from a probability measure collide in some band with probability sCurve k L (measureCollisionProb seed hash x x').

theorem Cslib.Probability.IsLocalitySensitive.measureBanded {ι : Type u_1} {X : Type u_2} {Y : Type u_3} [MeasurableSpace ι] {seed : MeasureTheory.Measure ι} [MeasureTheory.IsProbabilityMeasure seed] {hash : ι → X → Y} {near far : X → X → Prop} {p₁ p₂ : ℝ} (h : IsLocalitySensitive (measureCollisionProb seed hash) near far p₁ p₂) (hmeas : ∀ (x x' : X), MeasurableSet {i : ι | hash i x = hash i x'}) (hp₁ : 0 ≤ p₁) (hp₂ : p₂ ≤ 1) (k L : ℕ) :
IsLocalitySensitive (measureOrCollisionProb (MeasureTheory.Measure.pi fun (x : Fin k) => seed) (andHash hash k) L) near far (sCurve k L p₁) (sCurve k L p₂)

Banding turns a (p₁, p₂)-sensitive family under a probability measure into an (sCurve k L p₁, sCurve k L p₂)-sensitive family.

theorem Cslib.Probability.IsLocalitySensitive.exists_measureBanded {ι : Type u_1} {X : Type u_2} {Y : Type u_3} [MeasurableSpace ι] {seed : MeasureTheory.Measure ι} [MeasureTheory.IsProbabilityMeasure seed] {hash : ι → X → Y} {near far : X → X → Prop} {p₁ p₂ δ δ' : ℝ} (h : IsLocalitySensitive (measureCollisionProb seed hash) near far p₁ p₂) (hmeas : ∀ (x x' : X), MeasurableSet {i : ι | hash i x = hash i x'}) (hp₂ : 0 ≤ p₂) (hp₁₂ : p₂ < p₁) (hp₁ : p₁ ≤ 1) (hδ : 0 < δ) (hδ' : 0 < δ') :
∃ (k : ℕ) (L : ℕ), L = ⌈Real.log δ⁻¹ / p₁ ^ k⌉₊ ∧ IsLocalitySensitive (measureOrCollisionProb (MeasureTheory.Measure.pi fun (x : Fin k) => seed) (andHash hash k) L) near far (1 - δ) δ'

Banded amplification for probability-measure seed laws: a (near, far, p₁, p₂)-sensitive family with 0 ≤ p₂ < p₁ ≤ 1 amplifies via k AND-rows and L = ⌈log (1/δ) / p₁ ^ k⌉₊ OR-bands to error δ on near pairs and δ' on far pairs.