Nearest neighbor search with cosine distance. More...
Public Member Functions | |
CosineSearch (const arma::mat &referenceSet) | |
Constructor with reference set. More... | |
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. More... | |
Nearest neighbor search with cosine distance.
Note that, with normalized vectors, neighbor search with cosine distance is equivalent to neighbor search with Euclidean distance. Therefore, instead of performing neighbor search directly with cosine distance, we first normalize all vectors to unit length, and then use neighbor::KNN (i.e. NeighborSearch with Euclidean distance, KDTree). Cosine similarities are calculated from Euclidean distance.
An example of how to use CosineSearch in CF is shown below:
Definition at line 44 of file cosine_search.hpp.
|
inline |
Constructor with reference set.
All vectors in reference set are normalized to unit length.
referenceSet | Set of reference points. |
Definition at line 53 of file cosine_search.hpp.
|
inline |
Given a set of query points, find the nearest k neighbors, and return similarities.
Similarities are non-negative and no larger than one.
query | A set of query points. |
k | Number of neighbors to search. |
neighbors | Nearest neighbors. |
similarities | Similarities between query point and its neighbors. |
Definition at line 70 of file cosine_search.hpp.