Content deleted Content added
m clean up |
m →External links: HTTP to HTTPS for SourceForge |
||
(30 intermediate revisions by 21 users not shown) | |||
Line 1:
{{Short description|Algorithmic technique using hashing}}
In [[computer science]], '''locality-sensitive hashing''' ('''LSH''') is
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
==Definitions==
| author1 = Gionis, A.
| author2-link = Piotr Indyk | author2 = Indyk, P. | author3-link = Rajeev Motwani | author3 = Motwani, R.
Line 21 ⟶ 23:
| title-link = Symposium on Theory of Computing
}}</ref>
for
* a [[metric space]] <math>\mathcal M =(M, d)</math>,
* a threshold <math>
* an approximation factor <math>c>1</math>,
* and probabilities <math>
*
*
=== LSH with respect to a similarity measure ===
Alternatively<ref name=Charikar2002>{{cite conference
| last = Charikar|first= Moses S.|author-link=Moses Charikar
Line 40 ⟶ 43:
| pages = 380–388
| doi = 10.1145/509907.509965
|isbn= 1-58113-495-9| citeseerx = 10.1.1.147.4064}}</ref> it is
▲The first family of locality-preserving hash functions was devised as a way to facilitate [[Pipeline (computing)|data pipelining]] in implementations of [[Parallel RAM|parallel random-access machine (PRAM)]] algorithms that use [[universal hashing]] to reduce memory [[Resource contention|contention]] and [[network congestion]].<ref name=Chin1991>{{cite thesis |last=Chin |first=Andrew |date=1991 |title=Complexity Issues in General Purpose Parallel Computing |pages=87–95 |type=DPhil |publisher=University of Oxford |url=https://perma.cc/E47H-WCVP}}</ref><ref name=Chin1994>{{cite journal |last1=Chin |first1=Andrew |date=1994 |title=Locality-Preserving Hash Functions for General Purpose Parallel Computation |url=http://unclaw.com/chin/scholarship/hashfunctions.pdf |journal=Algorithmica |volume=12 |issue=2–3 |pages=170–181 |doi=10.1007/BF01185209|s2cid=18108051 }}</ref>
===Amplification===
Line 102 ⟶ 91:
**[[VisualRank]]
*[[Gene expression]] similarity identification{{citation needed|date=October 2013}}
*[[Audio similarity]] identification
*[[Nearest neighbor search]]
*[[Audio fingerprint]]<ref>
Line 109 ⟶ 98:
| url = https://github.com/worldveil/dejavu| date = 2018-12-19}}
</ref>
*[[Digital video fingerprinting]]<ref>
{{citation
| title = A Simple Introduction to Locality Sensitive Hashing (LSH)
| url =https://www.iunera.com/kraken/fabric/locality-sensitive-hashing-lsh/#7-applications-of-lsh| date = 2025-03-27}}
</ref>
*[[Shared memory]] organization in [[parallel computing]]<ref name=Chin1991 /><ref name=Chin1994 />
*Physical data organization in database management systems<ref>
{{citation
Line 122 ⟶ 116:
{{cite conference
| author1 = Oliver, Jonathan| author2 = Cheng, Chun | author3 = Chen, Yanggui
|
| year = 2013▼
| pages = 7–13 | url = https://www.academia.edu/7833902
| doi = 10.1109/CTC.2013.9
| isbn = 978-1-4799-3076-0
}}
</ref>
*[[Machine Learning]]<ref name="NL">
{{citation
| author1 = Fanaee-T, Hadi
| title = Natural Learning
| arxiv = 2404.05903
}}
</ref>
Line 214 ⟶ 215:
===Random projection===
{{main|Random projection}}
[[File:Cosine-distance.png| thumb | <math>\frac{\theta(u,v)}{\pi}</math> is approximately proportional to <math>1-\cos(\theta(u,v))</math> on the interval [0, <math>\pi</math>
The random projection method of LSH due to [[Moses Charikar]]<ref name=Charikar2002 /> called [[SimHash]] (also sometimes called arccos<ref name=Andoni2008>{{cite journal
Line 233 ⟶ 234:
The basic idea of this technique is to choose a random [[hyperplane]] (defined by a normal unit vector {{mvar|r}}) at the outset and use the hyperplane to hash input vectors.
Given an input vector {{mvar|v}} and a hyperplane defined by {{mvar|r}}, we let <math>h(v) = \sgn(v \cdot r)</math>. That is, <math>h(v) = \pm 1</math> depending on which side of the hyperplane {{mvar|v}} lies. This way, each possible choice of a random hyperplane {{mvar|r}} can be interpreted as a hash function <math>h(v)</math>.
For two vectors
:<math>Pr[h(u) = h(v)] = 1 - \frac{\theta(u,v)}{\pi}.</math>
Since the ratio between <math>\frac{\theta(u,v)}{\pi}</math>
===Stable distributions===
Line 272 ⟶ 273:
| url = http://hal.inria.fr/inria-00567191/en/
| journal = Pattern Recognition Letters
| volume = 31 | issue = 11 | pages = 1348–1358 | doi = 10.1016/j.patrec.2010.04.004 | bibcode = 2010PaReL..31.1348P | s2cid = 2666044 }}</ref>
In particular k-means hash functions are better in practice than projection-based hash functions, but without any theoretical guarantee.
Line 286 ⟶ 287:
In the preprocessing step we hash all {{mvar|n}} {{mvar|d}}-dimensional points from the data set {{mvar|S}} into each of the {{mvar|L}} hash tables. Given that the resulting hash tables have only {{mvar|n}} non-zero entries, one can reduce the amount of memory used per each hash table to <math>O(n)</math> using standard [[hash functions]].
Given a query point {{mvar|q}}, the algorithm iterates over the {{mvar|L}} hash functions {{mvar|g}}. For each {{mvar|g}} considered, it retrieves the data points that are hashed into the same bucket as {{mvar|q}}. The process is stopped as soon as a point within distance
Given the parameters {{mvar|k}} and {{mvar|L}}, the algorithm has the following performance guarantees:
Line 292 ⟶ 293:
* space: <math>O(nL)</math>, plus the space for storing data points;
* query time: <math>O(L(kt+dnP_2^k))</math>;
* the algorithm succeeds in finding a point within distance
For a fixed approximation ratio <math>c=1+\epsilon</math> and probabilities <math>P_1</math> and <math>P_2</math>, one can set <math>k = \
* preprocessing time: <math>O(n^{1+\rho}P_1^{-1}kt)</math>;
* space: <math>O(n^{1+\rho}P_1^{-1})</math>, plus the space for storing data points;
* query time: <math>O(n^{\rho}P_1^{-1}(kt+d))</math>;
===Finding nearest neighbor without fixed dimensionality===
To generalize the above algorithm without radius {{mvar|R}} being fixed, we can take the algorithm and do a sort of binary search over {{mvar|R}}. It has been shown<ref>{{cite journal |last1=Har-Peled |first1=Sariel |last2=Indyk |first2=Piotr |last3=Motwani |first3=Rajeev |title=Approximate Nearest Neighbor: Towards Removing the Curse of Dimensionality |journal=Theory of Computing |date=2012 |volume=8 |issue=Special Issue in Honor of Rajeev Motwani |pages=321-350 |doi=10.4086/toc.2012.v008a014 |url=https://theoryofcomputing.org/articles/v008a014/v008a014.pdf |access-date=23 May 2025}}</ref> that there is a data structure for the approximate nearest neighbor with the following performance guarantees:
* space: <math>O(n^{1+\rho}P_1^{-1}d\log^2 n)</math>;
* query time: <math>O(n^{\rho}P_1^{-1}(kt+d)\log n)</math>;
* the algorithm succeeds in finding the nearest neighbor with probability at least <math>1 - (( 1 - P_1^k ) ^ L\log n)</math>;
===Improvements===
Line 308 ⟶ 316:
It is also sometimes the case that the factor <math>1/P_1</math> 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<ref>Ahle, Thomas Dybdahl. "On the Problem of
==See also==
* {{Annotated link |Bloom filter}}
*
*
*
* {{Annotated link |Geohash}}
*
*
*[[Random indexing]]<ref>Gorman, James, and James R. Curran. [https://aclanthology.org/P06-1046.pdf "Scaling distributional similarity to large corpora."] Proceedings of the 21st International Conference on Computational Linguistics and the 44th annual meeting of the Association for Computational Linguistics. Association for Computational Linguistics, 2006.</ref>
*
*
*
*
* {{Annotated link |Locality of reference}}
==References==
Line 336 ⟶ 346:
==External links==
* [http://web.mit.edu/andoni/www/LSH/index.html Alex Andoni's LSH homepage]
* [
* [https://github.com/simonemainardi/LSHash A Python Locality Sensitive Hashing library that optionally supports persistence via redis]
* [https://web.archive.org/web/20101203074412/http://www.vision.caltech.edu/malaa/software/research/image-search/ Caltech Large Scale Image Search Toolbox]: a Matlab toolbox implementing several LSH hash functions, in addition to Kd-Trees, Hierarchical K-Means, and Inverted File search algorithms.
|