Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/JorenSix/TarsosLSH
A Java library implementing practical nearest neighbour search algorithm for multidimensional vectors that operates in sublinear time. It implements Locality-sensitive Hashing (LSH) and multi index hashing for hamming space.
https://github.com/JorenSix/TarsosLSH
java lsh multi-dimensional-hashing nearest-neighbor-search
Last synced: 6 days ago
JSON representation
A Java library implementing practical nearest neighbour search algorithm for multidimensional vectors that operates in sublinear time. It implements Locality-sensitive Hashing (LSH) and multi index hashing for hamming space.
- Host: GitHub
- URL: https://github.com/JorenSix/TarsosLSH
- Owner: JorenSix
- License: lgpl-3.0
- Created: 2013-03-25T13:57:36.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2020-07-26T11:35:16.000Z (over 4 years ago)
- Last Synced: 2024-08-02T07:14:26.577Z (3 months ago)
- Topics: java, lsh, multi-dimensional-hashing, nearest-neighbor-search
- Language: Java
- Homepage:
- Size: 22.5 MB
- Stars: 200
- Watchers: 28
- Forks: 84
- Open Issues: 5
-
Metadata Files:
- Readme: README.textile
- License: LICENSE.txt
Awesome Lists containing this project
- awesome-vector-search - TarsosLSH - A Java library implementing practical nearest neighbour search algorithm for multidimensional vectors
README
h1. TarsosLSH - Locality Sensitive Hashing (LSH) in Java
TarsosLSH is a Java library implementing sub-linear nearest neigbour search algorithms. It contains both an approximate and an exact search algorithm. The first, Locality-sensitive Hashing (LSH) is a randomized approximate search algorithm for a number of search spaces. The second, Multi-index hashing is an exact nearest neigbour search algorithm which is limited to Hamming space.
Locality-sensitive Hashing (LSH), a practical nearest neighbour search algorithm for multidimensional vectors that operates in sublinear time. It supports several Locality Sensitive Hashing (LSH) families: the Euclidean hash family (L2), city block hash family (L1) and cosine hash family. The library tries to hit the sweet spot between being capable enough to get real tasks done, and compact enough to serve as a demonstration on how LSH works.
Multi-index hashing is an exact, sub-linear nearest neighbour search algorithm in hamming space. It is a simple algorithm that seeks a balance between storage space requirements and query performance.
h2. Quickly Getting Started with TarsosLSH
Head over to the "TarsosLSH release repository":http://0110.be/releases/TarsosLSH/ and download the latest "TarsosLSH library":http://0110.be/releases/TarsosLSH/TarsosLSH-latest/TarsosLSH-latest.jar. Consult the "TarsosLSH API documentation":http://0110.be/releases/TarsosLSH/TarsosLSH-latest/TarsosLSH-latest-Documentation/. If you, for some reason, want to build from source, you need "Apache Ant":http://ant.apache.org/ and "git":http://git-scm.com/ installed on your system. The following commands fetch the source and build the library and example jars:
git clone https://[email protected]/JorenSix/TarsosLSH.git
cd TarsosLSH/build
ant #Builds the core TarsosLSH library
ant javadoc #build the API documentation
When everything runs correctly you should be able to run the command line application, and have the latest version of the TarsosLSH library for inclusion in your projects. Also, the Javadoc documentation for the API should be available in TarsosLSH/doc. Drop me a line (joren _ at _ 0110 _ dot _ be) if you use TarsosLSH in your project. Always nice to hear how this software is used.The fastest way to get something on your screen is executing this on your command line: @java - jar TarsosLSH.jar@ this lets LSH run on a random data set. The full reference of the command line application is included below:
Name
TarsosLSH: finds the nearest neighbours in a data set quickly, using LSH.
Synopsis
java - jar TarsosLSH.jar [options]
Description
Tries to find nearest neighbours for each vector in the
query file, using Euclidean (L2) distance by default.
Both dataset.txt and queries.txt have a similar format:
an optional identifier for the vector and a list of N
coordinates (which should be doubles).
[Identifier] coord1 coord2 ... coordN
[Identifier] coord1 coord2 ... coordN
For an example data set with two elements and 4 dimensions:
Hans 12 24 18.5 -45.6
Jane 13 19 -12.0 49.8
Options are:
-d dataset.txt
The dataset with vectors to store in the hash table
-q queries.txt
A list of vectors to query against the stored dataset
-f cos|l1|l2
Defines the hash family to use:
l1 City block hash family (L1)
l2 Euclidean hash family(L2)
cos Cosine distance hash family
-r radius
Defines the radius in which near neighbours should
be found. Should be a double. By default a reasonable
radius is determined automatically.
-h n_hashes
An integer that determines the number of hashes to
use. By default 4, 32 for the cosine hash family.
-t n_tables
An integer that determines the number of hash tables,
each with n_hashes, to use. By default 4.
-n n_neighbours
Number of neighbours in the neighbourhood, defaults to 3.
-b
Benchmark the settings.
--help
Prints this helpful message.
Examples
Search for nearest neighbours using the l2 hash family with a radius of 500
and utilizing 5 hash tables, each with 3 hashes.
java -jar TarsosLSH.jar -f l2 -r 500 -h 3 -t 5 -d dataset.txt -q queries.txt
h2. Source Code OrganizationThe source tree is divided in three directories:
* @src@ contains the source files, the core functionality.
** @src/be/tarsos/lsh@ Contains the LSH implementation
** @src/be/tarsos/mih@ Contains an implementation of a multi index hash algorithm
* @test@ contains unit tests for some of the functionality.
* @build@ contains ANT build files. Either to build Java documentation and runnable JAR-files.h2. License
The TarsosLSH license is distributed under the LGPL license.
h2. Further Reading
This section includes a links to resources used to implement this library.
* The "LSH-page":http://www.mit.edu/~andoni/LSH/ maintained by Alexandr Andoni contains pointers to good resources:
** "Locality-Sensitive Hashing Scheme Based on p-Stable Distributions":http://theory.lcs.mit.edu/~indyk/nips-nn.ps a chapter by Alexandr Andoni, Mayur Datar, Nicole Immorlica, Piotr Indyk, and Vahab Mirrokni which appeared in the book Nearest Neighbor Methods in Learning and Vision: Theory and Practice, by T. Darrell and P. Indyk and G. Shakhnarovich (eds.), MIT Press, 2006.
** "Similarity Search in High Dimensions via Hashing":http://theory.csail.mit.edu/~indyk/vldb99.ps The original LSH Paper for hamming distance by Gionis, Aristides and Indyk, Piotr and Motwani, Rajeev.
* "Locality-Sensitive Hashing for Finding Nearest Neighbors":http://www.slaney.org/malcolm/yahoo/Slaney2008-LSHTutorial.pdf a good introduction of LSH by Malcom Slaney & Michael Casey
* "Finding Similar Items":http://i.stanford.edu/~ullman/mmds/ch3.pdf, Chapter Three of "Mining of Massive Datasets" by Anand Rajaraman and Jeff Ullman is a textbook introducing the LSH concept.
* "Szudzik pairing functions":http://szudzik.com/ElegantPairing.pdf by Matthew Szudzik. Explains how integer hashes can be combined deterministically to form a reversible, unique new hash.For more information on Multi-Index Hashing:
* "Fast Search in Hamming Space with Multi-Index Hashing":http://www.cs.toronto.edu/~norouzi/research/papers/multi_index_hashing.pdf, Mohammad Norouzi, Ali Punjani, David Fleet - IEEE Computer Vision and Pattern Recognition (CVPR), 2012.
* An extended version of "Fast Exact Search in Hamming Space with Multi-Index Hashing":http://arxiv.org/abs/1307.2982
* "Compact Discrete Representations for Scalable Similarity Search":https://tspace.library.utoronto.ca/bitstream/1807/73095/3/Norouzi_Mohammad_201606_PhD_thesis.pdf
* A github repository with a "Multi-Index Hashing C++ implementation":https://github.com/norouzi/mihh2. Dependencies
TarsosLSH relies on "MapDB":http://www.mapdb.org/ for storage which in turn depends on "eclipse collections":https://www.eclipse.org/collections/.
h2. Change log