Hierarchical kmeans index. More...
#include <opencv2/flann/kmeans_index.h>
Classes | |
class | KMeansDistanceComputer |
Public Types | |
typedef void(KMeansIndex::* | centersAlgFunction) (int, int *, int, int *, int &) |
typedef Distance::ResultType | DistanceType |
typedef Distance::ElementType | ElementType |
Public Member Functions | |
KMeansIndex (const Matrix< ElementType > &inputData, const IndexParams ¶ms=KMeansIndexParams(), Distance d=Distance()) | |
Index constructor. More... | |
KMeansIndex (const KMeansIndex &) | |
virtual | ~KMeansIndex () |
Index destructor. More... | |
void | buildIndex () CV_OVERRIDE |
Builds the index. More... | |
void | chooseCentersGonzales (int k, int *indices, int indices_length, int *centers, int ¢ers_length) |
Chooses the initial centers in the k-means using Gonzales' algorithm so that the centers are spaced apart from each other. More... | |
void | chooseCentersKMeanspp (int k, int *indices, int indices_length, int *centers, int ¢ers_length) |
Chooses the initial centers in the k-means using the algorithm proposed in the KMeans++ paper: Arthur, David; Vassilvitskii, Sergei - k-means++: The Advantages of Careful Seeding. More... | |
void | chooseCentersRandom (int k, int *indices, int indices_length, int *centers, int ¢ers_length) |
Chooses the initial centers in the k-means clustering in a random manner. More... | |
void | findNeighbors (ResultSet< DistanceType > &result, const ElementType *vec, const SearchParams &searchParams) CV_OVERRIDE |
Find set of nearest neighbors to vec. More... | |
int | getClusterCenters (Matrix< DistanceType > ¢ers) |
Clustering function that takes a cut in the hierarchical k-means tree and return the clusters centers of that clustering. More... | |
IndexParams | getParameters () const CV_OVERRIDE |
flann_algorithm_t | getType () const CV_OVERRIDE |
virtual void | knnSearch (const Matrix< ElementType > &queries, Matrix< int > &indices, Matrix< DistanceType > &dists, int knn, const SearchParams ¶ms) |
Perform k-nearest neighbor search. More... | |
void | loadIndex (FILE *stream) CV_OVERRIDE |
Loads the index from a stream. More... | |
KMeansIndex & | operator= (const KMeansIndex &) |
virtual int | radiusSearch (const Matrix< ElementType > &query, Matrix< int > &indices, Matrix< DistanceType > &dists, float radius, const SearchParams ¶ms) |
Perform radius search. More... | |
void | saveIndex (FILE *stream) CV_OVERRIDE |
Saves the index to a stream. More... | |
void | set_cb_index (float index) |
size_t | size () const CV_OVERRIDE |
Returns size of index. More... | |
int | usedMemory () const CV_OVERRIDE |
Computes the inde memory usage Returns: memory used by the index. More... | |
size_t | veclen () const CV_OVERRIDE |
Returns the length of an index feature. More... | |
Public Attributes | |
centersAlgFunction | chooseCenters |
The function used for choosing the cluster centers. More... | |
Hierarchical kmeans index.
Contains a tree constructed through a hierarchical kmeans clustering and other information for indexing a set of points for nearest-neighbour matching.
typedef void(KMeansIndex::* cvflann::KMeansIndex< Distance >::centersAlgFunction) (int, int *, int, int *, int &) |
typedef Distance::ResultType cvflann::KMeansIndex< Distance >::DistanceType |
typedef Distance::ElementType cvflann::KMeansIndex< Distance >::ElementType |
|
inline |
Index constructor.
Params: inputData = dataset with the input features params = parameters passed to the hierarchical k-means algorithm
References cvflann::KMeansIndex< Distance >::chooseCentersGonzales(), cvflann::KMeansIndex< Distance >::chooseCentersKMeanspp(), cvflann::KMeansIndex< Distance >::chooseCentersRandom(), cvflann::FLANN_CENTERS_GONZALES, cvflann::FLANN_CENTERS_KMEANSPP, cvflann::FLANN_CENTERS_RANDOM, cvflann::get_param(), and cv::max().
cvflann::KMeansIndex< Distance >::KMeansIndex | ( | const KMeansIndex< Distance > & | ) |
|
inlinevirtual |
Index destructor.
Release the memory used by the index.
|
inlinevirtual |
Builds the index.
Implements cvflann::NNIndex< Distance >.
Referenced by cvflann::AutotunedIndex< Distance >::getType(), and cvflann::hierarchicalClustering().
|
inline |
Chooses the initial centers in the k-means using Gonzales' algorithm so that the centers are spaced apart from each other.
Params: k = number of centers vecs = the dataset of points indices = indices in the dataset Returns:
References cvflann::rand_int().
Referenced by cvflann::KMeansIndex< Distance >::KMeansIndex().
|
inline |
Chooses the initial centers in the k-means using the algorithm proposed in the KMeans++ paper: Arthur, David; Vassilvitskii, Sergei - k-means++: The Advantages of Careful Seeding.
Implementation of this function was converted from the one provided in Arthur's code.
Params: k = number of centers vecs = the dataset of points indices = indices in the dataset Returns:
References cv::min(), cvflann::rand_double(), and cvflann::rand_int().
Referenced by cvflann::KMeansIndex< Distance >::KMeansIndex().
|
inline |
Chooses the initial centers in the k-means clustering in a random manner.
Params: k = number of centers vecs = the dataset of points indices = indices in the dataset indices_length = length of indices vector
References cvflann::UniqueRandom::next().
Referenced by cvflann::KMeansIndex< Distance >::KMeansIndex().
|
inlinevirtual |
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 searchParams = parameters that influence the search algorithm (checks, cb_index)
Implements cvflann::NNIndex< Distance >.
References cvflann::FLANN_CHECKS_UNLIMITED, cvflann::get_param(), cvflann::BranchStruct< T, DistanceType >::node, and cvflann::Heap< T >::popMin().
|
inline |
Clustering function that takes a cut in the hierarchical k-means tree and return the clusters centers of that clustering.
Params: numClusters = number of clusters to have in the clustering computed Returns: number of cluster centers
References cvflann::Logger::info(), and cvflann::Matrix< T >::rows.
Referenced by cvflann::hierarchicalClustering().
|
inlinevirtual |
Implements cvflann::NNIndex< Distance >.
References cvflann::ResultSet< DistanceType >::addPoint(), cv::AutoBuffer< _Tp, fixed_size >::data(), cvflann::ResultSet< DistanceType >::full(), cvflann::Heap< T >::insert(), cvflann::load_value(), cv::max(), cv::mean(), cv::parallel_for_(), cvflann::save_value(), cv::sort(), cv::sqrt(), cv::sum(), cv::swap(), and cvflann::ResultSet< DistanceType >::worstDist().
|
inlinevirtual |
Implements cvflann::NNIndex< Distance >.
References cvflann::FLANN_INDEX_KMEANS.
|
inlinevirtualinherited |
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 in cvflann::Index< Distance >, cvflann::Index< cv::L2< ElementType > >, cvflann::Index< cv::L1< ElementType > >, cvflann::KDTreeSingleIndex< Distance >, and cvflann::LshIndex< Distance >.
|
inlinevirtual |
Loads the index from a stream.
stream | The stream from which the index is loaded |
Implements cvflann::NNIndex< Distance >.
References cvflann::load_value().
KMeansIndex& cvflann::KMeansIndex< Distance >::operator= | ( | const KMeansIndex< Distance > & | ) |
|
inlinevirtualinherited |
Perform radius search.
[in] | query | The query point |
[out] | indices | The indinces of the neighbors found within the given radius |
[out] | dists | The distances to the nearest neighbors found |
[in] | radius | The radius used for search |
[in] | params | Search parameters |
Reimplemented in cvflann::Index< Distance >, cvflann::Index< cv::L2< ElementType > >, and cvflann::Index< cv::L1< ElementType > >.
|
inlinevirtual |
Saves the index to a stream.
stream | The stream to save the index to |
Implements cvflann::NNIndex< Distance >.
References cvflann::save_value().
|
inline |
Referenced by cvflann::AutotunedIndex< Distance >::getType().
|
inlinevirtual |
Returns size of index.
Implements cvflann::NNIndex< Distance >.
|
inlinevirtual |
Computes the inde memory usage Returns: memory used by the index.
Implements cvflann::NNIndex< Distance >.
Referenced by cvflann::AutotunedIndex< Distance >::getType().
|
inlinevirtual |
Returns the length of an index feature.
Implements cvflann::NNIndex< Distance >.
centersAlgFunction cvflann::KMeansIndex< Distance >::chooseCenters |
The function used for choosing the cluster centers.