Algorithm Search⌘K

Proofs: Locality-sensitive hashing

These are the human proofs of Locality-sensitive hashing, at full length.

LSH answers the (c, r)-near neighbor query with constant probability full

This proof shows: correctness.

Let H\mathcal{H} be (r,cr,p1,p2)(r, c r, p_1, p_2)-sensitive with 0<p2<p1≤10 < p_2 < p_1 \le 1 and ρ=ln⁡(1/p1)/ln⁡(1/p2)\rho = \ln(1/p_1)/\ln(1/p_2). Let ∣P∣=n≥1|P| = n \ge 1, k=⌈log⁡1/p2n⌉k = \lceil \log_{1/p_2} n \rceil and L=⌈nρ/p1⌉L = \lceil n^\rho / p_1 \rceil. The functions hj,ih_{j,i} of line L2 are independent. Fix a query qq.

Claim 1 (no far answer). If LSH-QUERY returns a point xx, then δ(q,x)≤cr\delta(q, x) \le c r.

Proof. The only line that returns a point is L9, and it does so only when δ(q,x)≤cr\delta(q, x) \le c r. □\square

So if no point is within crc r, the query returns none, which is the correct answer. From now on assume that p∗∈Pp^* \in P has δ(q,p∗)≤r\delta(q, p^*) \le r.

Claim 2. Let E1E_1 be the event that gj(p∗)=gj(q)g_j(p^*) = g_j(q) for some jj. Then Pr⁡[E1]≥1−1/e\Pr[E_1] \ge 1 - 1/e.

Proof. For one table, Pr⁡[gj(p∗)=gj(q)]=∏i=1kPr⁡[hj,i(p∗)=hj,i(q)]≥p1k\Pr[g_j(p^*) = g_j(q)] = \prod_{i=1}^{k} \Pr[h_{j,i}(p^*) = h_{j,i}(q)] \ge p_1^k, by independence and the sensitivity for δ≤r\delta \le r. Since k<log⁡1/p2n+1k < \log_{1/p_2} n + 1 and p1≤1p_1 \le 1,

p1k≥p1log⁡1/p2n+1=p1⋅nlog⁡1/p2p1=p1⋅n−ρ.p_1^k \ge p_1^{\log_{1/p_2} n + 1} = p_1 \cdot n^{\log_{1/p_2} p_1} = p_1 \cdot n^{-\rho}.

Here log⁡1/p2p1=ln⁡p1/ln⁡(1/p2)=−ρ\log_{1/p_2} p_1 = \ln p_1 / \ln(1/p_2) = -\rho. So Lp1k≥(nρ/p1)⋅p1n−ρ=1L p_1^k \ge (n^\rho / p_1) \cdot p_1 n^{-\rho} = 1. The tables are independent, so Pr⁡[not E1]≤(1−p1k)L≤e−Lp1k≤e−1\Pr[\text{not } E_1] \le (1 - p_1^k)^L \le e^{-L p_1^k} \le e^{-1}, using 1−x≤e−x1 - x \le e^{-x}. □\square

Claim 3. Let F={x∈P:δ(q,x)>cr}F = \{x \in P : \delta(q, x) > c r\}, and let ZZ be the number of pairs (j,x)(j, x) with x∈Fx \in F and gj(x)=gj(q)g_j(x) = g_j(q). Let E2E_2 be the event Z<3LZ < 3L. Then Pr⁡[E2]≥2/3\Pr[E_2] \ge 2/3.

Proof. For x∈Fx \in F, δ(q,x)≥cr\delta(q, x) \ge c r, so each function collides with probability at most p2p_2, and Pr⁡[gj(x)=gj(q)]≤p2k≤p2log⁡1/p2n=1/n\Pr[g_j(x) = g_j(q)] \le p_2^k \le p_2^{\log_{1/p_2} n} = 1/n. By linearity of expectation, E[Z]≤L⋅∣F∣⋅(1/n)≤L\mathbb{E}[Z] \le L \cdot |F| \cdot (1/n) \le L. By Markov's inequality, Pr⁡[Z≥3L]≤E[Z]/(3L)≤1/3\Pr[Z \ge 3L] \le \mathbb{E}[Z]/(3L) \le 1/3. □\square

Claim 4. If E1E_1 and E2E_2 hold, the query returns a point within crc r.

Proof. Each increment of line L8 counts one pair (j,x)(j, x) with xx in the bucket of qq in table jj. Assume the query does not return a point. Then line L9 never succeeded, so each counted pair has x∈Fx \in F, and the count is at most Z<3LZ < 3L. So line L10 never stopped the query, and the loops of lines L6 and L7 ran to the end and counted every pair of every bucket of qq. By E1E_1 the pair (j,p∗)(j, p^*) for some jj is among them, and p∗∉Fp^* \notin F. This contradicts the fact that each counted pair has x∈Fx \in F. So the query returns a point, which is within crc r by Claim 1. □\square

Theorem. If some point of PP is within rr of qq, LSH-QUERY returns a point within crc r of qq with probability at least 2/3−1/e>0.292/3 - 1/e > 0.29. If no point is within crc r, it returns none with probability 1.

Proof. The second part is Claim 1. For the first, by Claim 4 and the union bound, the failure probability is at most Pr⁡[not E1]+Pr⁡[not E2]≤1/e+1/3\Pr[\text{not } E_1] + \Pr[\text{not } E_2] \le 1/e + 1/3, and 1−1/e−1/3=2/3−1/e≈0.29881 - 1/e - 1/3 = 2/3 - 1/e \approx 0.2988. ■\blacksquare

Termination and cost. The loop of line L6 runs LL times, and the inner loop stops after at most 3L3L increments in total by line L10, or at the end of a finite bucket. So the query computes at most 3L3L distances and LkLk hash values.

Back to Locality-sensitive hashing