jsat.linear.vectorcollection.lsh
Class E2LSH<V extends Vec>
- java.lang.Object
-
- jsat.linear.vectorcollection.lsh.E2LSH<V>
-
public class E2LSH<V extends Vec> extends java.lang.ObjectThis is an implementation of Locality Sensitive Hashing for theL1andL2distance metrics. This is essentially a vector collection that can only perform a radius search for a pre-defined radius. In addition, the results are only approximate - not all of the correct points may be returned, and it is possible no points will be returned when the truth is that some data points do exist.
Searching is done using thesearchR(jsat.linear.Vec, boolean)methods. While the set of points returned is approximate, the distance values are exact. This is because no approximate distance is available, so the distances must be computed to remove violators.
LSH may be useful if any of the following apply to your problem
- Only need to do a radius searches of a small number of fixed size increments
- You need only the first few nearest neighbors, and can compute a threshold for the NN
- Approximate neighbor results do not heavily impact the results of your algorithm
- You want to find near-duplicates in a data set
This implementation is based heavily on the following, but is not an exact re-implementation.
See:
- Datar, M., Immorlica, N., Indyk, P.,&Mirrokni, V. S. (2004). Locality-sensitive hashing scheme based on p-stable distributions. Proceedings of the twentieth annual symposium on Computational geometry - SCG ’04 (pp. 253–262). New York, New York, USA: ACM Press. doi:10.1145/997817.997857
- Andoni, Alex (2005). E2LSH Manual 0.1
-
-
Constructor Summary
Constructors Constructor and Description E2LSH(java.util.List<V> vecs, double radius, double eps, int w, int k, double delta, DistanceMetric dm)Creates a new LSH scheme for a given distance metricE2LSH(java.util.List<V> vecs, double radius, double eps, int w, int k, double delta, DistanceMetric dm, java.util.List<java.lang.Double> distCache)Creates a new LSH scheme for a given distance metric
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description doublegetC()Returns the multiplier used on the radius that controls the degree of approximation.intgetL()Returns how many separate hash tables have been created for this distance metric.doublegetRadius()Returns the desired approximate radius for which to return resultsjava.util.List<? extends VecPaired<Vec,java.lang.Double>>searchR(Vec q)Performs a search for points within the setradiusof the query point.java.util.List<? extends VecPaired<Vec,java.lang.Double>>searchR(Vec q, boolean approx)Performs a search for points within the setradiusof the query point.
-
-
-
Constructor Detail
-
E2LSH
public E2LSH(java.util.List<V> vecs, double radius, double eps, int w, int k, double delta, DistanceMetric dm, java.util.List<java.lang.Double> distCache)
Creates a new LSH scheme for a given distance metric- Parameters:
vecs- the set of vector to place into the LSHradius- the searchR radius for vectorseps- the approximation error, where vectors as fast as R(1+eps) are likely to be returned. Must be positive.w- the projection radius. If given a value <= 0, a default value of 4 will be used.k- the number of hash functions to conjoin into the final hash per vector. If a value <= 0 is given, a default value will be computed.delta- (1-delta) will be the desired minimum probability of correctly selecting the correct nearest neighbor if there is only 1-NN within a distance ofradius. It will be used to determine some numbergetL()hash tables to reach the desired probability. 0.10 is a good value.dm- the distance metric to use, must beEuclideanDistanceorManhattanDistance.distCache- the distance acceleration cache to use, ifnull, and it is supported, one will not be built. This is provided to a void redundant calculation when initializing multiple LSH tables using the same data set.
-
E2LSH
public E2LSH(java.util.List<V> vecs, double radius, double eps, int w, int k, double delta, DistanceMetric dm)
Creates a new LSH scheme for a given distance metric- Parameters:
vecs- the set of vector to place into the LSHradius- the searchR radius for vectorseps- the approximation error, where vectors as fast as R(1+eps) are likely to be returned. Must be positive.w- the projection radius. If given a value <= 0, a default value of 4 will be used.k- the number of hash functions to conjoin into the final hash per vector. If a value <= 0 is given, a default value will be computed.delta- (1-delta) will be the desired minimum probability of correctly selecting the correct nearest neighbor if there is only 1-NN within a distance ofradius. It will be used to determine some numbergetL()hash tables to reach the desired probability. 0.10 is a good value.dm- the distance metric to use, must beEuclideanDistanceorManhattanDistance.
-
-
Method Detail
-
searchR
public java.util.List<? extends VecPaired<Vec,java.lang.Double>> searchR(Vec q)
Performs a search for points within the setradiusof the query point.- Parameters:
q- the query point to search near- Returns:
- a list of vectors paired with their true distance from the query point that are within the desired radius of the query point
-
searchR
public java.util.List<? extends VecPaired<Vec,java.lang.Double>> searchR(Vec q, boolean approx)
Performs a search for points within the setradiusof the query point.- Parameters:
q- the query point to search nearapprox- whether or not to return results in the approximate query range- Returns:
- a list of vectors paired with their true distance from the query point that are within the desired radius of the query point
-
getC
public double getC()
Returns the multiplier used on the radius that controls the degree of approximation.- Returns:
- the radius approximation multiplier > 1
-
getRadius
public double getRadius()
Returns the desired approximate radius for which to return results- Returns:
- the radius in use
-
getL
public int getL()
Returns how many separate hash tables have been created for this distance metric.- Returns:
- the number of hash tables in use
-
-
DataMelt 3.0 © DataMelt by jWork.ORG