K-Approximate-Nearest-Neighbor Search with LSH
>>> from mlpack import lsh
This program will calculate the k approximate-nearest-neighbors of a set of points using locality-sensitive hashing. You may specify a separate set of reference points and query points, or just a reference set which will be used as both the reference and query set.
For example, the following will return 5 neighbors from the data for each point in 'input' and store the distances in 'distances' and the neighbors in 'neighbors':
>>> output = lsh(k=5, reference=input)
>>> distances = output['distances']
>>> neighbors = output['neighbors']
The output is organized such that row i and column j in the neighbors output corresponds to the index of the point in the reference set which is the j'th nearest neighbor from the point in the query set with index i. Row j and column i in the distances output file corresponds to the distance between those two points.
Because this is approximate-nearest-neighbors search, results may be different from run to run. Thus, the 'seed' parameter can be specified to set the random seed.
This program also has many other parameters to control its functionality; see the parameter-specific documentation for more information.
- bucket_size (int): The size of a bucket in the second level hash. Default value 500.
- copy_all_inputs (bool): If specified, all input parameters will be deep copied before the method is run. This is useful for debugging problems where the input parameters are being modified by the algorithm, but can slow down the code.
- hash_width (float): The hash width for the first-level hashing in the LSH preprocessing. By default, the LSH class automatically estimates a hash width for its use. Default value 0.
- input_model (mlpack.LSHSearchType): Input LSH model.
- k (int): Number of nearest neighbors to find. Default value 0.
- num_probes (int): Number of additional probes for multiprobe LSH; if 0, traditional LSH is used. Default value 0.
- projections (int): The number of hash functions for each table Default value 10.
- query (numpy matrix or arraylike, float dtype): Matrix containing query points (optional).
- reference (numpy matrix or arraylike, float dtype): Matrix containing the reference dataset.
- second_hash_size (int): The size of the second level hash table. Default value 99901.
- seed (int): Random seed. If 0, 'std::time(NULL)' is used. Default value 0.
- tables (int): The number of hash tables to be used. Default value 30.
- true_neighbors (numpy matrix or arraylike, int/long dtype): Matrix of true neighbors to compute recall with (the recall is printed when -v is specified).
- verbose (bool): Display informational messages and the full list of parameters and timers at the end of execution.
The return value from the binding is a dict containing the following elements:
- distances (numpy matrix, float dtype): Matrix to output distances into.
- neighbors (numpy matrix, int dtype): Matrix to output neighbors into.
- output_model (mlpack.LSHSearchType): Output for trained LSH model.