#include <lsh_index.h>
Classes | |
struct | SortScoreIndexPairOnSecond |
Public Types | |
typedef NNIndex< Distance > | BaseClass |
typedef Distance::ResultType | DistanceType |
typedef Distance::ElementType | ElementType |
Public Member Functions | |
void | addPoints (const Matrix< ElementType > &points, float rebuild_threshold=2) |
Incrementally add points to the index. | |
BaseClass * | clone () const |
void | findNeighbors (ResultSet< DistanceType > &result, const ElementType *vec, const SearchParams &) const |
flann_algorithm_t | getType () const |
int | knnSearch (const Matrix< ElementType > &queries, Matrix< size_t > &indices, Matrix< DistanceType > &dists, size_t knn, const SearchParams ¶ms) const |
Perform k-nearest neighbor search. | |
int | knnSearch (const Matrix< ElementType > &queries, std::vector< std::vector< size_t > > &indices, std::vector< std::vector< DistanceType > > &dists, size_t knn, const SearchParams ¶ms) const |
Perform k-nearest neighbor search. | |
void | loadIndex (FILE *stream) |
LshIndex (const IndexParams ¶ms=LshIndexParams(), Distance d=Distance()) | |
LshIndex (const Matrix< ElementType > &input_data, const IndexParams ¶ms=LshIndexParams(), Distance d=Distance()) | |
LshIndex (const LshIndex &other) | |
LshIndex & | operator= (LshIndex other) |
void | saveIndex (FILE *stream) |
template<typename Archive > | |
void | serialize (Archive &ar) |
int | usedMemory () const |
virtual | ~LshIndex () |
Protected Member Functions | |
void | buildIndexImpl () |
void | freeIndex () |
Private Types | |
typedef std::pair< float, unsigned int > | ScoreIndexPair |
Private Member Functions | |
void | fill_xor_mask (lsh::BucketKey key, int lowest_index, unsigned int level, std::vector< lsh::BucketKey > &xor_masks) |
void | getNeighbors (const ElementType *vec, bool do_radius, float radius, bool do_k, unsigned int k_nn, float &checked_average) |
void | getNeighbors (const ElementType *vec, ResultSet< DistanceType > &result) const |
void | swap (LshIndex &other) |
Private Attributes | |
unsigned int | key_size_ |
unsigned int | multi_probe_level_ |
unsigned int | table_number_ |
std::vector< lsh::LshTable < ElementType > > | tables_ |
std::vector< lsh::BucketKey > | xor_masks_ |
Randomized kd-tree index
Contains the k-d trees and other information for indexing a set of points for nearest-neighbor matching.
Definition at line 78 of file lsh_index.h.
typedef NNIndex<Distance> rtflann::LshIndex< Distance >::BaseClass |
Definition at line 84 of file lsh_index.h.
typedef Distance::ResultType rtflann::LshIndex< Distance >::DistanceType |
Reimplemented from rtflann::NNIndex< Distance >.
Definition at line 82 of file lsh_index.h.
typedef Distance::ElementType rtflann::LshIndex< Distance >::ElementType |
Reimplemented from rtflann::NNIndex< Distance >.
Definition at line 81 of file lsh_index.h.
typedef std::pair<float, unsigned int> rtflann::LshIndex< Distance >::ScoreIndexPair [private] |
Defines the comparator on score and index
Definition at line 377 of file lsh_index.h.
rtflann::LshIndex< Distance >::LshIndex | ( | const IndexParams & | params = LshIndexParams() , |
Distance | d = Distance() |
||
) | [inline] |
Constructor
params | parameters passed to the LSH algorithm |
d | the distance used |
Definition at line 90 of file lsh_index.h.
rtflann::LshIndex< Distance >::LshIndex | ( | const Matrix< ElementType > & | input_data, |
const IndexParams & | params = LshIndexParams() , |
||
Distance | d = Distance() |
||
) | [inline] |
Constructor
input_data | dataset with the input features |
params | parameters passed to the LSH algorithm |
d | the distance used |
Definition at line 106 of file lsh_index.h.
rtflann::LshIndex< Distance >::LshIndex | ( | const LshIndex< Distance > & | other | ) | [inline] |
Definition at line 118 of file lsh_index.h.
virtual rtflann::LshIndex< Distance >::~LshIndex | ( | ) | [inline, virtual] |
Definition at line 133 of file lsh_index.h.
void rtflann::LshIndex< Distance >::addPoints | ( | const Matrix< ElementType > & | points, |
float | rebuild_threshold = 2 |
||
) | [inline, virtual] |
Incrementally add points to the index.
points | Matrix with points to be added |
rebuild_threshold |
Reimplemented from rtflann::NNIndex< Distance >.
Definition at line 146 of file lsh_index.h.
void rtflann::LshIndex< Distance >::buildIndexImpl | ( | ) | [inline, protected, virtual] |
Builds the index
Implements rtflann::NNIndex< Distance >.
Definition at line 351 of file lsh_index.h.
BaseClass* rtflann::LshIndex< Distance >::clone | ( | ) | const [inline, virtual] |
Implements rtflann::NNIndex< Distance >.
Definition at line 139 of file lsh_index.h.
void rtflann::LshIndex< Distance >::fill_xor_mask | ( | lsh::BucketKey | key, |
int | lowest_index, | ||
unsigned int | level, | ||
std::vector< lsh::BucketKey > & | xor_masks | ||
) | [inline, private] |
Fills the different xor masks to use when getting the neighbors in multi-probe LSH
key | the key we build neighbors from |
lowest_index | the lowest index of the bit set |
level | the multi-probe level we are at |
xor_masks | all the xor mask |
Definition at line 392 of file lsh_index.h.
void rtflann::LshIndex< Distance >::findNeighbors | ( | ResultSet< DistanceType > & | result, |
const ElementType * | vec, | ||
const SearchParams & | |||
) | const [inline, virtual] |
Find set of nearest neighbors to vec. Their indices are stored inside the result object.
Params: result = the result object in which the indices of the nearest-neighbors are stored vec = the vector for which to search the nearest neighbors maxCheck = the maximum number of restarts (in a best-bin-first manner)
Implements rtflann::NNIndex< Distance >.
Definition at line 341 of file lsh_index.h.
void rtflann::LshIndex< Distance >::freeIndex | ( | ) | [inline, protected, virtual] |
Implements rtflann::NNIndex< Distance >.
Definition at line 368 of file lsh_index.h.
void rtflann::LshIndex< Distance >::getNeighbors | ( | const ElementType * | vec, |
bool | do_radius, | ||
float | radius, | ||
bool | do_k, | ||
unsigned int | k_nn, | ||
float & | checked_average | ||
) | [inline, private] |
Performs the approximate nearest-neighbor search.
vec | the feature to analyze |
do_radius | flag indicating if we check the radius too |
radius | the radius if it is a radius search |
do_k | flag indicating if we limit the number of nn |
k_nn | the number of nearest neighbors |
checked_average | used for debugging |
Definition at line 412 of file lsh_index.h.
void rtflann::LshIndex< Distance >::getNeighbors | ( | const ElementType * | vec, |
ResultSet< DistanceType > & | result | ||
) | const [inline, private] |
Performs the approximate nearest-neighbor search. This is a slower version than the above as it uses the ResultSet
vec | the feature to analyze |
Definition at line 490 of file lsh_index.h.
flann_algorithm_t rtflann::LshIndex< Distance >::getType | ( | ) | const [inline, virtual] |
Implements rtflann::IndexBase.
Definition at line 167 of file lsh_index.h.
int rtflann::LshIndex< Distance >::knnSearch | ( | const Matrix< ElementType > & | queries, |
Matrix< size_t > & | indices, | ||
Matrix< DistanceType > & | dists, | ||
size_t | knn, | ||
const SearchParams & | params | ||
) | const [inline, virtual] |
Perform k-nearest neighbor search.
[in] | queries | The query points for which to find the nearest neighbors |
[out] | indices | The indices of the nearest neighbors found |
[out] | dists | Distances to the nearest neighbors found |
[in] | knn | Number of nearest neighbors to return |
[in] | params | Search parameters |
Reimplemented from rtflann::NNIndex< Distance >.
Definition at line 224 of file lsh_index.h.
int rtflann::LshIndex< Distance >::knnSearch | ( | const Matrix< ElementType > & | queries, |
std::vector< std::vector< size_t > > & | indices, | ||
std::vector< std::vector< DistanceType > > & | dists, | ||
size_t | knn, | ||
const SearchParams & | params | ||
) | const [inline, virtual] |
Perform k-nearest neighbor search.
[in] | queries | The query points for which to find the nearest neighbors |
[out] | indices | The indices of the nearest neighbors found |
[out] | dists | Distances to the nearest neighbors found |
[in] | knn | Number of nearest neighbors to return |
[in] | params | Search parameters |
Reimplemented from rtflann::NNIndex< Distance >.
Definition at line 279 of file lsh_index.h.
void rtflann::LshIndex< Distance >::loadIndex | ( | FILE * | stream | ) | [inline, virtual] |
Implements rtflann::IndexBase.
Definition at line 201 of file lsh_index.h.
LshIndex& rtflann::LshIndex< Distance >::operator= | ( | LshIndex< Distance > | other | ) | [inline] |
Definition at line 127 of file lsh_index.h.
void rtflann::LshIndex< Distance >::saveIndex | ( | FILE * | stream | ) | [inline, virtual] |
Implements rtflann::IndexBase.
Definition at line 195 of file lsh_index.h.
void rtflann::LshIndex< Distance >::serialize | ( | Archive & | ar | ) | [inline] |
Reimplemented from rtflann::NNIndex< Distance >.
Definition at line 174 of file lsh_index.h.
void rtflann::LshIndex< Distance >::swap | ( | LshIndex< Distance > & | other | ) | [inline, private] |
Definition at line 520 of file lsh_index.h.
int rtflann::LshIndex< Distance >::usedMemory | ( | ) | const [inline, virtual] |
Computes the index memory usage Returns: memory used by the index
Implements rtflann::IndexBase.
Definition at line 211 of file lsh_index.h.
unsigned int rtflann::LshIndex< Distance >::key_size_ [private] |
key size
Definition at line 537 of file lsh_index.h.
unsigned int rtflann::LshIndex< Distance >::multi_probe_level_ [private] |
How far should we look for neighbors in multi-probe LSH
Definition at line 539 of file lsh_index.h.
unsigned int rtflann::LshIndex< Distance >::table_number_ [private] |
table number
Definition at line 535 of file lsh_index.h.
std::vector<lsh::LshTable<ElementType> > rtflann::LshIndex< Distance >::tables_ [private] |
The different hash tables
Definition at line 532 of file lsh_index.h.
std::vector<lsh::BucketKey> rtflann::LshIndex< Distance >::xor_masks_ [private] |
The XOR masks to apply to a key to get the neighboring buckets
Definition at line 542 of file lsh_index.h.