Algorithm Search⌘K

Proofs: Random hyperplane LSH

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

Random hyperplanes collide with probability 1 − θ/π, and the L-table query succeeds with probability at least 1 − 1/e − 1/3 full

This proof shows: correctness.

We use the names of the pseudocode on the page. All vectors are nonzero, and θ(x,y)∈[0,π]\theta(x, y) \in [0, \pi] is the angle between xx and yy.

Lemma 1 (one hyperplane). Let r∈Rdr \in \mathbb{R}^d have independent N(0,1)N(0, 1) coordinates, and let br(x)=1b_r(x) = 1 if r⋅x≥0r \cdot x \ge 0 and 00 otherwise. Then Pr⁡[br(x)=br(y)]=1−θ(x,y)/π\Pr[b_r(x) = b_r(y)] = 1 - \theta(x, y)/\pi.

Proof. If xx and yy are parallel, then either y=λxy = \lambda x with λ>0\lambda > 0, the angle is 0 and the bits are always equal, or λ<0\lambda < 0, the angle is π\pi, and the bits differ unless r⋅x=0r \cdot x = 0, an event of probability 0. Otherwise xx and yy span a plane WW. Write r=s+tr = s + t with s∈Ws \in W and t⊥Wt \perp W; then r⋅x=s⋅xr \cdot x = s \cdot x and r⋅y=s⋅yr \cdot y = s \cdot y. The standard Gaussian is invariant under orthogonal maps, so in an orthonormal basis of WW the two coordinates of ss are independent N(0,1)N(0,1), and the direction of ss is uniform on the unit circle of WW, and s≠0s \ne 0 with probability 1. Let ϕ\phi be that direction. Then s⋅x≥0s \cdot x \ge 0 exactly when ϕ\phi lies in the closed half circle centered at the direction of xx, and the same for yy. The two half circles are centered at directions an angle θ\theta apart, so their symmetric difference is two arcs of length θ\theta each, of total measure 2θ2\theta out of 2π2\pi. The bits differ exactly when ϕ\phi lies in this symmetric difference (up to the endpoints, of measure 0). So Pr⁡[br(x)≠br(y)]=2θ/(2π)=θ/π\Pr[b_r(x) \ne b_r(y)] = 2\theta/(2\pi) = \theta/\pi. □\square

Lemma 2 (one table). For one table ℓ\ell, with kk hyperplanes drawn independently in line L3, Pr⁡[HASH(x,Rℓ)=HASH(y,Rℓ)]=(1−θ(x,y)/π)k\Pr[\mathrm{HASH}(x, R_\ell) = \mathrm{HASH}(y, R_\ell)] = (1 - \theta(x,y)/\pi)^k.

Proof. By line L1 the keys are equal exactly when all kk bits agree. The bits use independent vectors r1,…,rkr_1, \ldots, r_k, so the events are independent, and each has probability 1−θ/π1 - \theta/\pi by Lemma 1. □\square

Lemma 3 (soundness). Whatever the random choices, QUERY returns either "none" or a vector x∈Px \in P with θ(q,x)≤θ2\theta(q, x) \le \theta_2.

Proof. Every bucket holds only vectors of PP, inserted in line L4. The only line that returns a vector is L8, and it tests θ(q,x)≤θ2\theta(q, x) \le \theta_2 first. □\square

Theorem. Let 0<θ1<θ2<π0 < \theta_1 < \theta_2 < \pi, p1=1−θ1/πp_1 = 1 - \theta_1/\pi, p2=1−θ2/πp_2 = 1 - \theta_2/\pi, ρ=ln⁡(1/p1)/ln⁡(1/p2)\rho = \ln(1/p_1)/\ln(1/p_2), k=⌈log⁡1/p2n⌉k = \lceil \log_{1/p_2} n \rceil and L=⌈nρ/p1⌉L = \lceil n^{\rho}/p_1 \rceil, with n=∣P∣≥2n = |P| \ge 2. If some p∗∈Pp^* \in P has θ(q,p∗)≤θ1\theta(q, p^*) \le \theta_1, then QUERY returns a vector within angle θ2\theta_2 of qq with probability at least 1−1/e−1/31 - 1/e - 1/3.

Proof. Define two events over the random hyperplanes.

E1E_1: for every ℓ\ell, p∗p^* is not in the bucket Tℓ[HASH(q,Rℓ)]T_\ell[\mathrm{HASH}(q, R_\ell)]. Since 1−θ/π1 - \theta/\pi decreases in θ\theta and θ(q,p∗)≤θ1\theta(q, p^*) \le \theta_1, Lemma 2 gives a collision probability of at least p1kp_1^k in each table, and the tables are independent, so Pr⁡[E1]≤(1−p1k)L≤e−Lp1k\Pr[E_1] \le (1 - p_1^k)^L \le e^{-L p_1^k}. Now k≤log⁡1/p2n+1k \le \log_{1/p_2} n + 1, so p1k≥p1⋅p1log⁡1/p2n=p1⋅n−ln⁡(1/p1)/ln⁡(1/p2)=p1n−ρp_1^k \ge p_1 \cdot p_1^{\log_{1/p_2} n} = p_1 \cdot n^{-\ln(1/p_1)/\ln(1/p_2)} = p_1 n^{-\rho}. With L≥nρ/p1L \ge n^{\rho}/p_1 this gives Lp1k≥1L p_1^k \ge 1 and Pr⁡[E1]≤1/e\Pr[E_1] \le 1/e.

E2E_2: the number FF of pairs (ℓ,x)(\ell, x) with xx in the bucket of qq in table ℓ\ell and θ(q,x)>θ2\theta(q, x) > \theta_2 is at least 3L3L. For each such xx and ℓ\ell, Lemma 2 gives a probability at most p2k≤p2log⁡1/p2n=1/np_2^k \le p_2^{\log_{1/p_2} n} = 1/n. There are at most nn such xx and LL tables, so by linearity of expectation E[F]≤L\mathbb{E}[F] \le L. By Markov's inequality, Pr⁡[E2]=Pr⁡[F≥3L]≤L/(3L)=1/3\Pr[E_2] = \Pr[F \ge 3L] \le L/(3L) = 1/3.

Assume neither event happens. Each execution of line L9 follows a failed test in line L8, so it counts a pair (ℓ,x)(\ell, x) with xx in the bucket of qq in table ℓ\ell and θ(q,x)>θ2\theta(q, x) > \theta_2, and different executions count different pairs. Since F<3LF < 3L, the counter cc stays below 3L3L, and line L10 never returns. So the loops run until line L8 returns a vector, or until every bucket of qq has been scanned. Since E1E_1 fails, p∗p^* is in one of these buckets, and line L8 returns when it reaches p∗p^*, if not earlier. So QUERY returns a vector, and by Lemma 3 it is within θ2\theta_2. By the union bound the probability of E1∪E2E_1 \cup E_2 is at most 1/e+1/31/e + 1/3, so QUERY succeeds with probability at least 1−1/e−1/3≈0.29881 - 1/e - 1/3 \approx 0.2988. ■\blacksquare

Back to Random hyperplane LSH