Locality-sensitive hashing from p-stable distributions #
Datar, Immorlica, Indyk, and Mirrokni ([DIIM04]) construct
locality-sensitive hash families for \ell_p distances (p ∈ (0, 2]) by projecting onto a
vector a with i.i.d. p-stable coordinates, shifting by b ~ Uniform[0, r), and quantizing
into buckets of width r: h_{a,b}(v) = ⌊(⟨a, v⟩ + b) / r⌋.
Conditioned on a, two real projections x, y collide under b ~ Uniform[0, r) with
probability max 0 (1 - |x - y| / r) (measureReal_uniformInterval_floor_eq). Integrating over
the random projection gives stableCollisionProb μ r c = ∫ z, max 0 (1 - c * |z| / r) ∂μ
when ⟨a, u - v⟩ has the law of c * Z for Z ~ μ
(measureCollisionProb_intervalFloorHash_of_map).
Specializing to the two standard stable laws:
p = 2(Gaussian / Euclidean norm): undera ~ stdGaussian E(p2StableHash),Pr[p2StableHash r (a, b) u = p2StableHash r (a, b) v] = p2StableProb r ‖u - v‖(measureCollisionProb_p2StableHash), matching the integral of [DIIM04] (p2StableProb_eq_integral) and evaluating explicitly in terms of(gaussianReal 0 1).real (Icc (-r / c) (r / c))andexp(p2StableProb_eq_sub).p = 1(Cauchy /\ell_1norm): under i.i.d. Cauchy coordinatesa_i ~ cauchyMeasure 0 1(p1StableHash), 1-stability (ProbabilityTheory.pi_cauchyMeasure_map_dotProduct) yieldsPr[p1StableHash r (a, b) u = p1StableHash r (a, b) v] = p1StableProb r (∑ i, |u i - v i|)(measureCollisionProb_p1StableHash), with closed form(2 / π) arctan (r / c) - (c / (π r)) log (1 + (r / c) ^ 2)(p1StableProb_eq).
For both families, the collision probability is strictly positive and strictly decreasing in the
distance c ≥ 0, giving (d₁, d₂) sensitivity (isLocalitySensitive_p2StableHash,
isLocalitySensitive_p1StableHash).
Main definitions #
Cslib.Probability.uniformInterval: Lebesgue measure conditioned onSet.Ico 0 r.Cslib.Probability.intervalFloorHash: quantized bucket hash⌊(proj a x + b) / r⌋.Cslib.Probability.stableCollisionProb:∫ z, max 0 (1 - c * |z| / r) ∂μ.Cslib.Probability.p2StableHash,Cslib.Probability.p2StableProb: Gaussianp = 2family.Cslib.Probability.p1StableHash,Cslib.Probability.p1StableProb: Cauchyp = 1family.
Main results #
Cslib.Probability.measureReal_uniformInterval_floor_eq: exact interval collision probabilitymax 0 (1 - |x - y| / r).Cslib.Probability.measureCollisionProb_intervalFloorHash: general Fubini bucket collision law.Cslib.Probability.measureCollisionProb_p2StableHash,Cslib.Probability.p2StableProb_eq_integral,Cslib.Probability.p2StableProb_eq_sub,Cslib.Probability.p2StableProb_strictAnti,Cslib.Probability.isLocalitySensitive_p2StableHash: Gaussianp = 2collision law, formulas, strict monotonicity, and LSH sensitivity.Cslib.Probability.measureCollisionProb_p1StableHash,Cslib.Probability.p1StableProb_eq,Cslib.Probability.p1StableProb_strictAnti,Cslib.Probability.isLocalitySensitive_p1StableHash: Cauchyp = 1collision law, closed form, strict monotonicity, and LSH sensitivity.
References #
Uniform shift on [0, r) and quantized bucket collisions #
The uniform probability measure on [0, r), defined by conditioning Lebesgue measure on
Set.Ico 0 r.
For r > 0, uniformInterval r is a probability measure.
Application of uniformInterval r to a set s.
The collision set of intervalFloorHash is measurable whenever proj · x is measurable.
General Fubini collision formula for intervalFloorHash: under any probability measure
μ on the projection space paired with uniformInterval r, u and v collide with probability
∫ a, max 0 (1 - |proj a u - proj a v| / r) ∂μ.
Abstract collision integral and symmetric-density properties #
The expected collision probability ∫ z, max 0 (1 - c * |z| / r) ∂μ for a scalar 1-D
distribution μ at distance c and bucket width r.
Reduction of measureCollisionProb_intervalFloorHash when proj a u - proj a v is the
law of c * Z under ν.
p = 2: Gaussian 2-stable LSH #
The p = 2 (Gaussian) LSH function of width r on an inner product space E:
⌊(⟪a, x⟫ + b) / r⌋.
Exact collision probability for Gaussian p = 2 LSH at distance c and bucket width r.
The p = 2 collision event is measurable.
Exact integral representation for p = 2 ([DIIM04]): for r > 0
and c > 0, p2StableProb r c = ∫ t in 0..r, (2 / c) * gaussianPDFReal 0 1 (t / c) * (1 - t / r).
Closed-form evaluation for p = 2: for r > 0 and c > 0, p2StableProb r c equals
(gaussianReal 0 1).real (Icc (-r / c) (r / c)) -
√(2 / π) * (c / r) * (1 - exp (-(r / c) ^ 2 / 2)).
Gaussian p = 2 LSH collision probability ([DIIM04]):
under (stdGaussian E).prod (uniformInterval r), p2StableHash r collides on u and v
with probability p2StableProb r ‖u - v‖.
Gaussian p = 2 LSH is (d₁, d₂, p2StableProb r d₁, p2StableProb r d₂)-sensitive for the
Euclidean distance when 0 < r and 0 ≤ d₂.
p = 1: Cauchy 1-stable LSH #
Exact collision probability for Cauchy p = 1 LSH at \ell_1 distance c and width r.
The p = 1 collision event is measurable.
Closed-form evaluation for p = 1: for r > 0 and c > 0,
p1StableProb r c = (2 / π) arctan (r / c) - (c / (π r)) log (1 + (r / c) ^ 2).
Cauchy p = 1 LSH collision probability ([DIIM04]): under
Measure.pi (fun _ : ι => cauchyMeasure 0 1) paired with uniformInterval r, p1StableHash r
collides on u and v with probability p1StableProb r (∑ i, |u i - v i|).
Cauchy p = 1 LSH is (d₁, d₂, p1StableProb r d₁, p1StableProb r d₂)-sensitive for the
\ell_1 distance ∑ i, |u i - v i| when 0 < r and 0 ≤ d₂.