Skip to content

A Java library implementing Locality-sensitive Hashing (LSH), a practical nearest neighbour search algorithm for multidimensional vectors that operates in sublinear time.

Notifications You must be signed in to change notification settings

bluesjjw/TarsosLSH

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TarsosLSH – Locality Sensitive Hashing (LSH) in Java

TarsosLSH is a Java library implementing 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.

Quickly Getting Started with TarsosLSH

Head over to the TarsosLSH release repository and download the latest TarsosLSH library. Consult the TarsosLSH API documentation. If you, for some reason, want to build from source, you need Apache Ant and git 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 (L<sub>2</sub>) 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 (L<sub>1</sub>)
			l2	Euclidean hash family(L<sub>2</sub>)
			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


Source Code Organization

The source tree is divided in three directories:

  • src contains the source files, the core functionality.
  • test contains unit tests for some of the functionality.
  • build contains ANT build files. Either to build Java documentation and runnable JAR-files.

License

The TarsosLSH license is distributed under the LGPL license.

Further Reading

This section includes a links to resources used to implement this library.

Change log

Version 0.5
2013-04-17

First release which includes several LSH families.

Version 0.6
2013-06-13

Added serialization options to store LSH hashes, which makes the library more practical in real-world scenario’s. Later database support should be added.

Version 0.7
2015-03-16

Maintenance release with changed package names and small fixes to the documentation and build file.

About

A Java library implementing Locality-sensitive Hashing (LSH), a practical nearest neighbour search algorithm for multidimensional vectors that operates in sublinear time.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 98.0%
  • Shell 1.3%
  • Ruby 0.7%