Lecture 4 theory of locality sensitive hashing

Lecture 4 - Theory of Locality Sensitive Hashing

LSH requires some dimensionality reduction first. You do need to do some preprocessing beforehand to get rid of outliers to make your LSH perform most effectively.

Design a locality sensitive hash function that can be applied to any distance metric Once you know what is the threshold you care about, you tune the curve so that you can get the value you want. (1) Prob that all bands are not equal = P(C1, C2 is a candidate pair) = 1-(1-s^r)^b

How to pick r and b - Pick any two distances d1<d2 - Start with a (d1,d2,(1-d1),(1-d2) family - Apply constructions to amplify into a (d1,d2,p1,p2) sensitive family, where p1 is almost 1 and p2 are almost 0. The curve we plot for the function is 1-(1-s^r)^b (Img 3) - We can accept false positives, but false negatives are lost to us forever. (Img 2)

LSH for other distance measures - Cosine distance - random hyperplanes - Cosine Distance = angle between vectors from the origin to the points in question - polar version: ` d(A,B)= theta = arccos(A • B) / |A|•|B|) ` - general version: ` d(A,B)= theta = A • B / |A|•|B|) ` - LSH for cosine distance- random hyperplanes: a ((d1,d2, (1-di/pi), (1-d2/pi)) sensitive family for d1 and d2 - Every vector v determines a hash function h_v with two buckets (returns +1 or -1) - h_v(x) = +1 if v • x ≥ 0; = -1 if v • x < 0 - This is essentially, in which part of the hyperplane determined by (orthogonal to) v does x lie? - The LSH-family H - set of all functions derived from any set of vectors v1, v2… - For points x and y, - Pr(h(x)=h(y)]=1-d(x,y)/pi. Proof by picture (Img 4) - Process: - Pick some number of random vectors with norm 1 (on the unit sphere), and hash your data for each vector. The result is a signature (sketch) of +!s and -1s for each data point. Amplify using AND and OR constructions. - LSH for Euclidean Distance - project on lines (Img 5) - Is a (a/2, 2a, 1/2, 1/3) sensitive family of hash functions for any a. - Idea: Hash functions correspond to lines - Partition the line into buckets of size a. Project each point onto the line to see which bucket it falls into. An element of the ‘signature’ is a bucket id for that - Nearby points are always close, distance points are rarely in the same bucket. - Is a (a/2, 2a, 1/2, 1/3) sensitive family of hash functions for any a, because - if points are distance d ≤ a/2, prob that they are in the same bucket ≥ 1-d/a = 1/2. - If the points are far apart - d>2a apart, then they can be in the same bucket only if d * cos(theta) ≤ a - Since cos(theta) ≤ 1/2 implies that 60 < theta < 90, ie, theta falls within the rage at at most 1/3 probability. (Img 6) - Process: - Pick random lines, project the points on them, and hash your data to each bucket. Amplify the hashing using AND and OR functions.

How do we overcome the curse of dimensionality with LSH? LSH doesn’t help you address that. If you’re using cosine similarity and you’re aware that your data is highly dimensional and you will return a lot of sketches with -1 (your vectors are orthogonal), you either want to us a metric other than losing similarity, or preprocess your data to remove the curse of dimensionality (dimensionality reduction).

(1) Work with samples if your data is too large.

(Img 1) Screenshot 2019-10-08 at 9.06.38 PM.png

(Img 2) Screenshot 2019-10-08 at 9.25.19 PM.png

(Img 3) Screenshot 2019-10-08 at 9.27.05 PM.png

(Img 4) Screenshot 2019-10-08 at 9.33.18 PM.png

Img 5 Screenshot 2019-10-08 at 9.44.42 PM.png Screenshot 2019-10-08 at 9.53.45 PM.png Screenshot 2019-10-08 at 9.59.22 PM.png

#cs246