Algorithm Search⌘K

Proofs: LSH forest

These are the human proofs of LSH forest, at full length.

The LSH forest returns the best of the candidates at the stopping depth, and finds near points with the probability of LSH at any reached depth full

This proof shows: correctness.

We use the names of the pseudocode on the page. Fix the points PP, ∣P∣=n≥1|P| = n \ge 1, the directions, and the query qq. Let λi(v)\lambda_i(v) be the label of vv in tree ii, and lcpi(p)∈{0,…,K}\mathrm{lcp}_i(p) \in \{0, \ldots, K\} the length of the longest common prefix of λi(p)\lambda_i(p) and λi(q)\lambda_i(q). For 0≤x≤K0 \le x \le K let Cx={p∈P:lcpi(p)≥x for some i}C_x = \{p \in P : \mathrm{lcp}_i(p) \ge x \text{ for some } i\}, and CK+1=∅C_{K+1} = \emptyset.

Lemma 1 (nesting). C0=PC_0 = P and Cx+1⊆CxC_{x+1} \subseteq C_x for 0≤x≤K0 \le x \le K.

Proof. Every lcpi(p)≥0\mathrm{lcp}_i(p) \ge 0, and lcpi(p)≥x+1\mathrm{lcp}_i(p) \ge x + 1 implies lcpi(p)≥x\mathrm{lcp}_i(p) \ge x. □\square

Lemma 2 (one round). For a given xx, line L6 sets C=CxC = C_x.

Proof. Tree ii stores the points sorted by label (line L3). The labels that begin with the xx-bit prefix λi(q)[1..x]\lambda_i(q)[1..x] are those ≥\ge the prefix and << the prefix followed by a symbol larger than both bits, in lexicographic order, so they form a contiguous range, and line L6 takes exactly the points with lcpi(p)≥x\mathrm{lcp}_i(p) \ge x. The union over ii is CxC_x. □\square

Lemma 3 (the start). Line L4 sets xx to x0=max⁡i,plcpi(p)x_0 = \max_{i, p} \mathrm{lcp}_i(p), and Cx0≠∅C_{x_0} \ne \emptyset while Cx=∅C_x = \emptyset for x>x0x > x_0.

Proof. In lexicographic order, among the stored labels, one with the longest common prefix with λi(q)\lambda_i(q) is adjacent to the position of λi(q)\lambda_i(q): if a label μ\mu shares tt bits with λi(q)\lambda_i(q), every label between μ\mu and λi(q)\lambda_i(q) in sorted order also begins with those tt bits. So the two neighbors of that position give max⁡plcpi(p)\max_p \mathrm{lcp}_i(p), and line L4 takes the maximum over the trees. The rest is the definition of CxC_x. □\square

Theorem 1 (the candidates). QUERY stops with x=x∗=max⁡{x:∣Cx∣≥min⁡(M,n)}x = x^* = \max\{x : |C_x| \ge \min(M, n)\} and C=Cx∗C = C_{x^*}, and returns the min⁡(k,∣C∣)\min(k, |C|) points of CC of smallest angle to qq. If M≥nM \ge n, they are the kk points of PP of smallest angle.

Proof. The set over which the maximum is taken contains 0, since ∣C0∣=n|C_0| = n, so x∗x^* exists. If x∗>x0x^* > x_0 then Cx∗=∅C_{x^*} = \emptyset by Lemma 3, but ∣Cx∗∣≥min⁡(M,n)≥1|C_{x^*}| \ge \min(M, n) \ge 1 for M≥1M \ge 1; so x∗≤x0x^* \le x_0. The loop tests x=x0,x0−1,…x = x_0, x_0 - 1, \ldots in turn and, by Lemma 2, computes CxC_x; it exits at the first xx with ∣Cx∣≥min⁡(M,n)|C_x| \ge \min(M, n) or at x=0x = 0. Every x>x∗x > x^* fails the test by the definition of x∗x^*, and x∗x^* passes it, so the loop exits at x∗x^* (at x=0x = 0 the test passes too, and x∗=0x^* = 0 then). Line L9 ranks CC. If M≥nM \ge n, the test needs ∣Cx∣=n|C_x| = n, and C=PC = P. □\square

Theorem 2 (comparison with LSH of fixed length). If x∗≤k0x^* \le k_0, then every point that collides with qq in some tree on the first k0k_0 bits, that is every candidate of standard LSH with these ll tables and key length k0k_0, is in CC.

Proof. Such a point is in Ck0⊆Cx∗C_{k_0} \subseteq C_{x^*} by Lemma 1. □\square

Theorem 3 (success probability). Let the lKlK directions be independent standard Gaussian vectors, and let p∈Pp \in P be at angle θ\theta to qq, with s=1−θ/πs = 1 - \theta/\pi. For every 0≤k0≤K0 \le k_0 \le K,

Pr⁡[p∉C]≤(1−sk0)l+Pr⁡[x∗>k0]≤(1−sk0)l+E ∣Ck0+1∣min⁡(M,n).\Pr[p \notin C] \le (1 - s^{k_0})^l + \Pr[x^* > k_0] \le (1 - s^{k_0})^l + \frac{\mathbb{E}\,|C_{k_0 + 1}|}{\min(M, n)}.

Proof. If p∈Ck0p \in C_{k_0} and x∗≤k0x^* \le k_0, then p∈Cp \in C by Theorem 2. So p∉Cp \notin C implies p∉Ck0p \notin C_{k_0} or x∗>k0x^* > k_0, and the union bound gives the first inequality, once we show Pr⁡[p∉Ck0]=(1−sk0)l\Pr[p \notin C_{k_0}] = (1 - s^{k_0})^l. A single bit bi,jb_{i,j} agrees on pp and qq with probability 1−θ/π=s1 - \theta/\pi = s, since a Gaussian direction is uniform in angle and the hyperplane it defines separates pp and qq with probability θ/π\theta/\pi; the bits are independent. So lcpi(p)≥k0\mathrm{lcp}_i(p) \ge k_0 with probability sk0s^{k_0}, independently over the trees, and p∉Ck0p \notin C_{k_0} with probability (1−sk0)l(1 - s^{k_0})^l. For the second inequality, if x∗>k0x^* > k_0 then ∣Ck0+1∣≥∣Cx∗∣≥min⁡(M,n)|C_{k_0 + 1}| \ge |C_{x^*}| \ge \min(M, n) by Lemma 1, and Markov's inequality gives Pr⁡[∣Ck0+1∣≥min⁡(M,n)]≤E∣Ck0+1∣/min⁡(M,n)\Pr[|C_{k_0+1}| \ge \min(M, n)] \le \mathbb{E}|C_{k_0+1}| / \min(M, n). For k0=Kk_0 = K, CK+1=∅C_{K+1} = \emptyset and x∗≤Kx^* \le K always. ■\blacksquare

Back to LSH forest