Documentation of 'smile.neighbor.MPLSH' Java class
MPLSH
smile.neighbor

Class 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 setIdenticalExcluded. Note that you may observe weird behavior with String objects. JVM will pool the string literal objects. So the below variables String a = "ABC"; String b = "ABC"; String c = "AB" + "C"; are actually equal in reference test a == 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.

    TODO: not efficient. better not use it right now.

    References

    1. Qin Lv, William Josephson, Zhe Wang, Moses Charikar, and Kai Li. Multi-probe LSH: efficient indexing for high-dimensional similarity search. VLDB, 2007.
    2. 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
      boolean isIdenticalExcluded()
      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.
      void learn(RNNSearch<double[],double[]> range, double[][] samples, double radius)
      Train the posteriori multiple probe algorithm.
      void learn(RNNSearch<double[],double[]> range, double[][] samples, double radius, int Nz)
      Train the posteriori multiple probe algorithm.
      void learn(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.
      void put(double[] key, E value)
      Insert an item into the hash table.
      void range(double[] q, double radius, java.util.List<Neighbor<double[],E>> neighbors)
      Search the neighbors in the given radius of query object, i.e.
      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.
      MPLSH<E> setIdenticalExcluded(boolean excluded)
      Set if exclude query object self from the neighborhood.
      java.lang.String toString() 
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • 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:
        toString in class java.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: NearestNeighborSearch
        Search the nearest neighbor to the given sample.
        Specified by:
        nearest in interface NearestNeighborSearch<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: KNNSearch
        Search the k nearest neighbors to the query.
        Specified by:
        knn in interface KNNSearch<double[],E>
        Parameters:
        q - the query key.
        k - the number of nearest neighbors to search for.
      • 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: RNNSearch
        Search the neighbors in the given radius of query object, i.e. d(q, v) ≤ radius.
        Specified by:
        range in interface RNNSearch<double[],E>
        Parameters:
        q - the query key.
        radius - the radius of search range from target.
        neighbors - the list to store found neighbors in the given range on output.
      • 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

You see the box below because you did not login.