Locality-sensitive hashing

Algorithmic technique using hashing From Wikipedia, the free encyclopedia

In computer science, locality-sensitive hashing (LSH) is a fuzzy hashing technique that hashes similar input items into the same "buckets" with high probability.[1] (The number of buckets is much smaller than the universe of possible input items.)[1] Since similar items end up in the same buckets, this technique can be used for data clustering and nearest neighbor search. It differs from conventional hashing techniques in that hash collisions are maximized, not minimized. Alternatively, the technique can be seen as a way to reduce the dimensionality of high-dimensional data; high-dimensional input items can be reduced to low-dimensional versions while preserving relative distances between items.

Hashing-based approximate nearest-neighbor search algorithms generally use one of two main categories of hashing methods: either data-independent methods, such as locality-sensitive hashing (LSH); or data-dependent methods, such as locality-preserving hashing (LPH).[2][3]

Locality-preserving hashing was initially devised as a way to facilitate data pipelining in implementations of massively parallel algorithms that use randomized routing and universal hashing to reduce memory contention and network congestion.[4][5]

Definitions

A finite family of functions is defined to be an LSH family[1][6][7] for

  • a metric space ,
  • a threshold ,
  • an approximation factor ,
  • and probabilities

if it satisfies the following condition. For any two points and a hash function chosen uniformly at random from :

  • If , then (i.e., a and b collide) with probability at least ,
  • If , then with probability at most .

Such a family is called -sensitive.

LSH with respect to a similarity measure

Alternatively[8] it is possible to define an LSH family on a universe of items U endowed with a similarity function . In this setting, a LSH scheme is a family of hash functions H coupled with a probability distribution D over H such that a function chosen according to D satisfies for each .

Amplification

Given a -sensitive family , we can construct new families by either the AND-construction or OR-construction of .[1]

To create an AND-construction, we define a new family of hash functions g, where each function g is constructed from k random functions from . We then say that for a hash function , if and only if all for . Since the members of are independently chosen for any , is a -sensitive family.

To create an OR-construction, we define a new family of hash functions g, where each function g is constructed from k random functions from . We then say that for a hash function , if and only if for one or more values of i. Since the members of are independently chosen for any , is a -sensitive family.

Applications

LSH has been applied to several problem domains, including:

Methods

Summarize
Perspective

Bit sampling for Hamming distance

One of the easiest ways to construct an LSH family is by bit sampling.[7] This approach works for the Hamming distance over d-dimensional vectors . Here, the family of hash functions is simply the family of all the projections of points on one of the coordinates, i.e., , where is the th coordinate of . A random function from simply selects a random bit from the input point. This family has the following parameters: , . That is, any two vectors with Hamming distance at most collide under a random with probability at least . Any with Hamming distance at least collide with probability at most .

Min-wise independent permutations

Suppose U is composed of subsets of some ground set of enumerable items S and the similarity function of interest is the Jaccard index J. If π is a permutation on the indices of S, for let . Each possible choice of π defines a single hash function h mapping input sets to elements of S.

Define the function family H to be the set of all such functions and let D be the uniform distribution. Given two sets the event that corresponds exactly to the event that the minimizer of π over lies inside . As h was chosen uniformly at random, and define an LSH scheme for the Jaccard index.

Because the symmetric group on n elements has size n!, choosing a truly random permutation from the full symmetric group is infeasible for even moderately sized n. Because of this fact, there has been significant work on finding a family of permutations that is "min-wise independent" — a permutation family for which each element of the domain has equal probability of being the minimum under a randomly chosen π. It has been established that a min-wise independent family of permutations is at least of size ,[20] and that this bound is tight.[21]

Because min-wise independent families are too big for practical applications, two variant notions of min-wise independence are introduced: restricted min-wise independent permutations families, and approximate min-wise independent families. Restricted min-wise independence is the min-wise independence property restricted to certain sets of cardinality at most k.[22] Approximate min-wise independence differs from the property by at most a fixed ε.[23]

Open source methods

Nilsimsa Hash

Nilsimsa is a locality-sensitive hashing algorithm used in anti-spam efforts.[24] The goal of Nilsimsa is to generate a hash digest of an email message such that the digests of two similar messages are similar to each other. The paper suggests that the Nilsimsa satisfies three requirements:

  1. The digest identifying each message should not vary significantly for changes that can be produced automatically.
  2. The encoding must be robust against intentional attacks.
  3. The encoding should support an extremely low risk of false positives.

Testing performed in the paper on a range of file types identified the Nilsimsa hash as having a significantly higher false positive rate when compared to other similarity digest schemes such as TLSH, Ssdeep and Sdhash.[25]

TLSH

TLSH is locality-sensitive hashing algorithm designed for a range of security and digital forensic applications.[18] The goal of TLSH is to generate hash digests for messages such that low distances between digests indicate that their corresponding messages are likely to be similar.

An implementation of TLSH is available as open-source software.[26]

Random projection

Thumb
is approximately proportional to on the interval [0,

The random projection method of LSH due to Moses Charikar[8] called SimHash (also sometimes called arccos[27]) uses an approximation of the cosine distance between vectors. The technique was used to approximate the NP-complete max-cut problem.[8]

The basic idea of this technique is to choose a random hyperplane (defined by a normal unit vector r) at the outset and use the hyperplane to hash input vectors.

Given an input vector v and a hyperplane defined by r, we let . That is, depending on which side of the hyperplane v lies. This way, each possible choice of a random hyperplane r can be interpreted as a hash function .

For two vectors u,v with angle between them, it can be shown that

Since the ratio between and is at least 0.439 when ,[8][28] the probability of two vectors being on different sides of the random hyperplane is approximately proportional to the cosine distance between them.

Stable distributions

The hash function [29] maps a d-dimensional vector onto the set of integers. Each hash function in the family is indexed by a choice of random and where is a d-dimensional vector with entries chosen independently from a stable distribution and is a real number chosen uniformly from the range [0,r]. For a fixed the hash function is given by .

Other construction methods for hash functions have been proposed to better fit the data. [30] In particular k-means hash functions are better in practice than projection-based hash functions, but without any theoretical guarantee.

Semantic hashing

Semantic hashing is a technique that attempts to map input items to addresses such that closer inputs have higher semantic similarity.[31] The hashcodes are found via training of an artificial neural network or graphical model.[citation needed]

Summarize
Perspective

One of the main applications of LSH is to provide a method for efficient approximate nearest neighbor search algorithms. Consider an LSH family . The algorithm has two main parameters: the width parameter k and the number of hash tables L.

In the first step, we define a new family of hash functions g, where each function g is obtained by concatenating k functions from , i.e., . In other words, a random hash function g is obtained by concatenating k randomly chosen hash functions from . The algorithm then constructs L hash tables, each corresponding to a different randomly chosen hash function g.

In the preprocessing step we hash all n d-dimensional points from the data set S into each of the L hash tables. Given that the resulting hash tables have only n non-zero entries, one can reduce the amount of memory used per each hash table to using standard hash functions.

Given a query point q, the algorithm iterates over the L hash functions g. For each g considered, it retrieves the data points that are hashed into the same bucket as q. The process is stopped as soon as a point within distance cR from q is found.

Given the parameters k and L, the algorithm has the following performance guarantees:

  • preprocessing time: , where t is the time to evaluate a function on an input point p;
  • space: , plus the space for storing data points;
  • query time: ;
  • the algorithm succeeds in finding a point within distance cR from q (if there exists a point within distance R) with probability at least ;

For a fixed approximation ratio and probabilities and , one can set and , where . Then one obtains the following performance guarantees:

  • preprocessing time: ;
  • space: , plus the space for storing data points;
  • query time: ;

Improvements

When t is large, it is possible to reduce the hashing time from . This was shown by[32] and[33] which gave

  • query time: ;
  • space: ;

It is also sometimes the case that the factor can be very large. This happens for example with Jaccard similarity data, where even the most similar neighbor often has a quite low Jaccard similarity with the query. In[34] it was shown how to reduce the query time to (not including hashing costs) and similarly the space usage.

See also

References

Further reading

Loading related searches...

Wikiwand - on

Seamless Wikipedia browsing. On steroids.