mlpack 3.4.2
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
19namespace mlpack {
20namespace cf {
21
41template<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.
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.
neighbor::NeighborSearch< neighbor::NearestNeighborSort, metric::LMetric< TPower, true > > NeighborSearchType
LMetricSearch(const arma::mat &referenceSet)
The L_p metric for arbitrary integer p, with an option to take the root.
Definition: lmetric.hpp:64
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...
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
The core includes that mlpack expects; standard C++ includes and Armadillo.