12 #ifndef MLPACK_METHODS_CF_COSINE_SEARCH_HPP 13 #define MLPACK_METHODS_CF_COSINE_SEARCH_HPP 56 arma::mat normalizedSet = arma::normalise(referenceSet, 2, 0);
58 neighborSearch.
Train(std::move(normalizedSet));
70 void Search(
const arma::mat& query,
const size_t k,
71 arma::Mat<size_t>& neighbors, arma::mat& similarities)
74 arma::mat normalizedQuery = arma::normalise(query, 2, 0);
76 neighborSearch.
Search(normalizedQuery, k, neighbors, similarities);
84 similarities = 1 - arma::pow(similarities, 2) / 4.0;
Nearest neighbor search with cosine distance.
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.
The NeighborSearch class is a template class for performing distance-based neighbor searches...
CosineSearch(const arma::mat &referenceSet)
Constructor with reference set.
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 similarities.
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...
void Train(MatType referenceSet)
Set the reference set to a new reference set, and build a tree if necessary.