Locality-sensitive hashing and AND/OR amplification #
A keyed hash family hash : ι → X → Y with seed law seed : PMF ι makes x and x' collide
with probability collisionProb seed hash x x'. The family is locality sensitive for a pair
of relations near and far when near pairs collide with probability at least p₁ and far pairs
with probability at most p₂ (Cslib.Probability.IsLocalitySensitive). With
near x x' := d x x' ≤ r₁ and far x x' := r₂ ≤ d x x' for a distance d, this is the
(r₁, r₂, p₁, p₂)-sensitive family of Indyk and Motwani [IM98]
((r, cr, p₁, p₂) in [HPIM12];
(d₁, d₂, p₁, p₂) in [LRU20], Section 3.6.1). Universal hashing is the
case near := (· = ·), far := (· ≠ ·), p₁ = 1
(Cslib.Probability.IsUniversalHash.isLocalitySensitive).
Collision probabilities of independent repetitions are exact:
- the AND construction (
andHash), concatenatingkindependently keyed hashes, collides with probabilityp ^ k(collisionProb_andHash); - the OR construction, declaring a collision when one of
Lindependent hashes collides, does so with probability1 - (1 - p) ^ L(orCollisionProb_eq); - their composition,
Lbands ofkrows, collides with probabilitysCurve k L p = 1 - (1 - p ^ k) ^ L(orCollisionProb_andHash). This is the S-curve of the banding technique ([LRU20], Sections 3.4.2 and 3.6.3).
Both constructions preserve sensitivity with the transformed probabilities. If
0 ≤ p₂ < p₁ ≤ 1, then for all δ > 0 and δ' > 0 some k and L = ⌈log (1/δ) / p₁ ^ k⌉₊
make near pairs collide with probability at least 1 - δ and far pairs with probability at most
δ' (IsLocalitySensitive.exists_banded). The explicit bounds behind it are le_sCurve
(near pairs: 1 - δ ≤ sCurve k L p once log (1/δ) ≤ L p₁ ^ k) and sCurve_le (far pairs:
sCurve k L p ≤ L p₂ ^ k, a union bound over the bands).
Charikar's observation ([Cha02], Lemma 1) that 1 - collisionProb satisfies the triangle
inequality is collisionProb_triangle.
Probabilities are real numbers, the toReal of PMF.toOuterMeasure, so that the S-curve can be
manipulated by ordinary real analysis. No finiteness of the seed space is assumed; independent
draws use Cslib.Probability.PMF.iid. These are information-theoretic statements. The
(c, r)-approximate near-neighbour structure built from them, with its failure bound and
parameters, is in CslibFrontier.DataStructure.NearNeighbor.LSH; its n ^ ρ query time and the
cost of evaluating the hashes are not formalized.
Main definitions #
Cslib.Probability.collisionProb: the collision probability of two inputs.Cslib.Probability.IsLocalitySensitive:(near, far, p₁, p₂)-sensitive families.Cslib.Probability.andHash: the AND construction (concatenation ofkhashes).Cslib.Probability.orCollisionProb: collision probability of the OR construction.Cslib.Probability.sCurve: the banding curve1 - (1 - p ^ k) ^ L.
Main results #
Cslib.Probability.collisionProb_andHash,Cslib.Probability.orCollisionProb_eq,Cslib.Probability.orCollisionProb_andHash: exact AND, OR and banded collision laws.Cslib.Probability.IsLocalitySensitive.and,Cslib.Probability.IsLocalitySensitive.or,Cslib.Probability.IsLocalitySensitive.banded: amplified sensitivity.Cslib.Probability.le_sCurve,Cslib.Probability.sCurve_le,Cslib.Probability.exists_sCurve_gap: the S-curve gap with explicit parameters.Cslib.Probability.IsLocalitySensitive.exists_banded: banded amplification to errorδon near pairs andδ'on far pairs.Cslib.Probability.collisionProb_triangle: Charikar's triangle inequality.Cslib.Probability.IsUniversalHash.isLocalitySensitive: universal families are locality sensitive.
References #
- P. Indyk, R. Motwani, Approximate nearest neighbors: towards removing the curse of dimensionality
- S. Har-Peled, P. Indyk, R. Motwani, Approximate nearest neighbor: towards removing the curse of dimensionality
- J. Leskovec, A. Rajaraman, J. D. Ullman, Mining of Massive Datasets, Chapter 3.
- M. S. Charikar, Similarity estimation techniques from rounding algorithms
Collision probability #
The probability that x and x' collide under the keyed family hash with seed law
seed. Not to be confused with Cslib.Probability.PMF.collisionProbability, the probability
that two independent samples of one law agree.
Charikar's triangle inequality ([Cha02], Lemma 1): the non-collision probability
1 - collisionProb of any keyed family satisfies the triangle inequality. If x and z are
separated, then x and y, or y and z, are separated.
Locality-sensitive families #
A collision-probability function prob is (near, far, p₁, p₂)-sensitive when near pairs
collide with probability at least p₁ and far pairs with probability at most p₂
([IM98]; [LRU20], Section 3.6.1). For a keyed family, take
prob := collisionProb seed hash; for a distance d, take near x x' := d x x' ≤ r₁ and
far x x' := r₂ ≤ d x x'. The function is left abstract so that the OR construction, which is a
collision rule rather than a hash, is covered too.
An ε-universal family is locality sensitive for equality and inequality with p₁ = 1 and
p₂ = ε.
A near pair is not far when p₂ < p₁.
The AND construction #
The AND construction turns a (p₁, p₂)-sensitive family into a (p₁ ^ k, p₂ ^ k)-sensitive
one.
The OR construction #
The OR construction turns a (p₁, p₂)-sensitive family into a
(1 - (1 - p₁) ^ L, 1 - (1 - p₂) ^ L)-sensitive one.
Banding and the S-curve #
The S-curve of banding: L bands of k rows each collide in some band with probability
1 - (1 - p ^ k) ^ L when one row collides with probability p.
L bands of k independently keyed rows collide in some band with probability
sCurve k L p.
Banding turns a (p₁, p₂)-sensitive family into a (sCurve k L p₁, sCurve k L p₂)-sensitive
one.
The S-curve gap. If 0 ≤ p₂ < p₁ ≤ 1, then for all δ > 0 and δ' > 0 there is a
number of rows k such that L = ⌈log (1/δ) / p₁ ^ k⌉₊ bands give 1 - δ ≤ sCurve k L p for
every p ∈ [p₁, 1] and sCurve k L p ≤ δ' for every p ∈ [0, p₂]. The proof takes k with
(p₂ / p₁) ^ k ≤ δ' / (2 (c + 1)) and p₂ ^ k ≤ δ' / 2, where c = max 0 (log (1/δ)).
Banded amplification. A (near, far, p₁, p₂)-sensitive family with 0 ≤ p₂ < p₁ ≤ 1
can be amplified by banding with k rows and L = ⌈log (1/δ) / p₁ ^ k⌉₊ bands so that near
pairs collide with probability at least 1 - δ and far pairs with probability at most δ'.