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 P, ∣P∣=n≥1, the directions, and the query q. Let λi(v) be the label of v in tree i, and lcpi(p)∈{0,…,K} the length of the longest common prefix of λi(p) and λi(q). For 0≤x≤K let Cx={p∈P:lcpi(p)≥x for some i}, and CK+1=∅.
Lemma 1 (nesting). C0=P and Cx+1⊆Cx for 0≤x≤K.
Proof. Every lcpi(p)≥0, and lcpi(p)≥x+1 implies lcpi(p)≥x. □
Lemma 2 (one round). For a given x, line L6 sets C=Cx.
Proof. Tree i stores the points sorted by label (line L3). The labels that begin with the x-bit prefix λi(q)[1..x] are those ≥ 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. The union over i is Cx. □
Lemma 3 (the start). Line L4 sets x to x0=maxi,plcpi(p), and Cx0=∅ while Cx=∅ for x>x0.
Proof. In lexicographic order, among the stored labels, one with the longest common prefix with λi(q) is adjacent to the position of λi(q): if a label μ shares t bits with λi(q), every label between μ and λi(q) in sorted order also begins with those t bits. So the two neighbors of that position give maxplcpi(p), and line L4 takes the maximum over the trees. The rest is the definition of Cx. □
Theorem 1 (the candidates). QUERY stops with x=x∗=max{x:∣Cx∣≥min(M,n)} and C=Cx∗, and returns the min(k,∣C∣) points of C of smallest angle to q. If M≥n, they are the k points of P of smallest angle.
Proof. The set over which the maximum is taken contains 0, since ∣C0∣=n, so x∗ exists. If x∗>x0 then Cx∗=∅ by Lemma 3, but ∣Cx∗∣≥min(M,n)≥1 for M≥1; so x∗≤x0. The loop tests x=x0,x0−1,… in turn and, by Lemma 2, computes Cx; it exits at the first x with ∣Cx∣≥min(M,n) or at x=0. Every x>x∗ fails the test by the definition of x∗, and x∗ passes it, so the loop exits at x∗ (at x=0 the test passes too, and x∗=0 then). Line L9 ranks C. If M≥n, the test needs ∣Cx∣=n, and C=P. □
Theorem 2 (comparison with LSH of fixed length). If x∗≤k0, then every point that collides with q in some tree on the first k0 bits, that is every candidate of standard LSH with these l tables and key length k0, is in C.
Proof. Such a point is in Ck0⊆Cx∗ by Lemma 1. □
Theorem 3 (success probability). Let the lK directions be independent standard Gaussian vectors, and let p∈P be at angle θ to q, with s=1−θ/π. For every 0≤k0≤K,
Pr[p∈/C]≤(1−sk0)l+Pr[x∗>k0]≤(1−sk0)l+min(M,n)E∣Ck0+1∣. Proof. If p∈Ck0 and x∗≤k0, then p∈C by Theorem 2. So p∈/C implies p∈/Ck0 or x∗>k0, and the union bound gives the first inequality, once we show Pr[p∈/Ck0]=(1−sk0)l. A single bit bi,j agrees on p and q with probability 1−θ/π=s, since a Gaussian direction is uniform in angle and the hyperplane it defines separates p and q with probability θ/π; the bits are independent. So lcpi(p)≥k0 with probability sk0, independently over the trees, and p∈/Ck0 with probability (1−sk0)l. For the second inequality, if x∗>k0 then ∣Ck0+1∣≥∣Cx∗∣≥min(M,n) by Lemma 1, and Markov's inequality gives Pr[∣Ck0+1∣≥min(M,n)]≤E∣Ck0+1∣/min(M,n). For k0=K, CK+1=∅ and x∗≤K always. ■