smile.neighbor
Class MPLSH<E>
- java.lang.Object
-
- smile.neighbor.MPLSH<E>
-
- Type Parameters:
E- the type of data objects in the hash table.
- All Implemented Interfaces:
- KNNSearch<double[],E>, NearestNeighborSearch<double[],E>, RNNSearch<double[],E>
public class MPLSH<E> extends java.lang.Object implements NearestNeighborSearch<double[],E>, KNNSearch<double[],E>, RNNSearch<double[],E>
Multi-Probe Locality-Sensitive Hashing. LSH is an efficient algorithm for approximate nearest neighbor search in high dimensional spaces by performing probabilistic dimension reduction of data. The basic idea is to hash the input items so that similar items are mapped to the same buckets with high probability (the number of buckets being much smaller than the universe of possible input items). A drawback of LSH is the requirement for a large number of hash tables in order to achieve good search quality. Multi-probe LSH is designed to overcome this drawback. Multi-probe LSH intelligently probes multiple buckets that are likely to contain query results in a hash table.By default, the query object (reference equality) is excluded from the neighborhood. You may change this behavior with
TODO: not efficient. better not use it right now.setIdenticalExcluded. Note that you may observe weird behavior with String objects. JVM will pool the string literal objects. So the below variablesString a = "ABC"; String b = "ABC"; String c = "AB" + "C";are actually equal in reference testa == b == c. With toy data that you type explicitly in the code, this will cause problems. Fortunately, the data would be read from secondary storage in production.References
- Qin Lv, William Josephson, Zhe Wang, Moses Charikar, and Kai Li. Multi-probe LSH: efficient indexing for high-dimensional similarity search. VLDB, 2007.
- Alexis Joly and Olivier Buisson. A posteriori multi-probe locality sensitive hashing. ACM international conference on Multimedia, 2008.
- See Also:
LSH
-
-
Constructor Summary
Constructors Constructor and Description MPLSH(int d, int L, int k, double r)Constructor.MPLSH(int d, int L, int k, double r, int H)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description booleanisIdenticalExcluded()Get whether if query object self be excluded from the neighborhood.Neighbor<double[],E>[]knn(double[] q, int k)Search the k nearest neighbors to the query.Neighbor<double[],E>[]knn(double[] q, int k, double recall, int T)Returns the approximate k-nearest neighbors.voidlearn(RNNSearch<double[],double[]> range, double[][] samples, double radius)Train the posteriori multiple probe algorithm.voidlearn(RNNSearch<double[],double[]> range, double[][] samples, double radius, int Nz)Train the posteriori multiple probe algorithm.voidlearn(RNNSearch<double[],double[]> range, double[][] samples, double radius, int Nz, double sigma)Train the posteriori multiple probe algorithm.Neighbor<double[],E>nearest(double[] q)Search the nearest neighbor to the given sample.Neighbor<double[],E>nearest(double[] q, double recall, int T)Returns the approximate nearest neighbor.voidput(double[] key, E value)Insert an item into the hash table.voidrange(double[] q, double radius, java.util.List<Neighbor<double[],E>> neighbors)Search the neighbors in the given radius of query object, i.e.voidrange(double[] q, double radius, java.util.List<Neighbor<double[],E>> neighbors, double recall, int T)Search the neighbors in the given radius of query object, i.e.MPLSH<E>setIdenticalExcluded(boolean excluded)Set if exclude query object self from the neighborhood.java.lang.StringtoString()
-
-
-
Constructor Detail
-
MPLSH
public MPLSH(int d, int L, int k, double r)Constructor.- Parameters:
d- the dimensionality of data.L- the number of hash tables.k- the number of random projection hash functions, which is usually set to log(N) where N is the dataset size.r- the width of random projections. It should be sufficiently away from 0. But we should not choose an r value that is too large, which will increase the query time.
-
MPLSH
public MPLSH(int d, int L, int k, double r, int H)Constructor.- Parameters:
d- the dimensionality of data.L- the number of hash tables.k- the number of random projection hash functions, which is usually set to log(N) where N is the dataset size.r- the width of random projections. It should be sufficiently away from 0. But we should not choose an r value that is too large, which will increase the query time.H- the number of buckets of hash tables.
-
-
Method Detail
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
isIdenticalExcluded
public boolean isIdenticalExcluded()
Get whether if query object self be excluded from the neighborhood.
-
setIdenticalExcluded
public MPLSH<E> setIdenticalExcluded(boolean excluded)
Set if exclude query object self from the neighborhood.
-
put
public void put(double[] key, E value)Insert an item into the hash table.
-
learn
public void learn(RNNSearch<double[],double[]> range, double[][] samples, double radius)
Train the posteriori multiple probe algorithm.- Parameters:
range- the neighborhood search data structure.radius- the radius for range search.samples- the training samples.
-
learn
public void learn(RNNSearch<double[],double[]> range, double[][] samples, double radius, int Nz)
Train the posteriori multiple probe algorithm.- Parameters:
range- the neighborhood search data structure.radius- the radius for range search.Nz- the number of quantized values.
-
learn
public void learn(RNNSearch<double[],double[]> range, double[][] samples, double radius, int Nz, double sigma)
Train the posteriori multiple probe algorithm.- Parameters:
range- the neighborhood search data structure.radius- the radius for range search.Nz- the number of quantized values.sigma- the Parzen window width.
-
nearest
public Neighbor<double[],E> nearest(double[] q)
Description copied from interface:NearestNeighborSearchSearch the nearest neighbor to the given sample.- Specified by:
nearestin interfaceNearestNeighborSearch<double[],E>- Parameters:
q- the query key.- Returns:
- the nearest neighbor
-
nearest
public Neighbor<double[],E> nearest(double[] q, double recall, int T)
Returns the approximate nearest neighbor. A posteriori multiple probe model has to be trained already.- Parameters:
q- the query object.recall- the expected recall rate.T- the maximum number of probes.
-
knn
public Neighbor<double[],E>[] knn(double[] q, int k)
Description copied from interface:KNNSearchSearch the k nearest neighbors to the query.
-
knn
public Neighbor<double[],E>[] knn(double[] q, int k, double recall, int T)
Returns the approximate k-nearest neighbors. A posteriori multiple probe model has to be trained already.- Parameters:
q- the query object.k- the number of nearest neighbors to search for.recall- the expected recall rate.T- the maximum number of probes.
-
range
public void range(double[] q, double radius, java.util.List<Neighbor<double[],E>> neighbors)Description copied from interface:RNNSearchSearch the neighbors in the given radius of query object, i.e. d(q, v) ≤ radius.
-
range
public void range(double[] q, double radius, java.util.List<Neighbor<double[],E>> neighbors, double recall, int T)Search the neighbors in the given radius of query object, i.e. d(x, v) ≤ radius.- Parameters:
q- the query object.radius- the radius of search range.neighbors- the list to store found neighbors in the given range on output.recall- the expected recall rate.T- the maximum number of probes.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG