lmetric_search.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_METHODS_CF_LMETRIC_SEARCH_HPP
13 #define MLPACK_METHODS_CF_LMETRIC_SEARCH_HPP
14 
15 #include <mlpack/prereqs.hpp>
18 
19 namespace mlpack {
20 namespace cf {
21 
41 template<int TPower>
43 {
44  public:
48 
52  LMetricSearch(const arma::mat& referenceSet) : neighborSearch(referenceSet)
53  { }
54 
64  void Search(const arma::mat& query, const size_t k,
65  arma::Mat<size_t>& neighbors, arma::mat& similarities)
66  {
67  neighborSearch.Search(query, k, neighbors, similarities);
68 
69  // Calculate similarities from L_p distance. We restrict that similarities
70  // are not larger than one.
71  similarities = 1.0 / (1.0 + similarities);
72  }
73 
74  private:
76  NeighborSearchType neighborSearch;
77 };
78 
80 
81 } // namespace cf
82 } // namespace mlpack
83 
84 #endif
Nearest neighbor search with L_p distance.
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.
void Search(const arma::mat &query, const size_t k, arma::Mat< size_t > &neighbors, arma::mat &similarities)
Given a set of query points, find the nearest k neighbors, and return similarites.
LMetricSearch(const arma::mat &referenceSet)
void Search(const MatType &querySet, const size_t k, arma::Mat< size_t > &neighbors, arma::mat &distances)
For each point in the query set, compute the nearest neighbors and store the output in the given matr...