template<typename Index_, typename Data_, typename Distance_, typename Normalized_, class Matrix_ = Matrix<Index_, Data_>>
class knncolle::L2NormalizedBuilder< Index_, Data_, Distance_, Normalized_, Matrix_ >
Wrapper around a builder with L2 normalization.
This class applies L2 normalization to each observation vector in its input matrix, and also constructs Searcher instances that L2-normalize each query vector. The premise is that Euclidean distances on L2-normalized vectors are monotonic transformations of the cosine distance. Thus, given an arbitrary algorithm that finds nearest neighbors according to Euclidean distance, users can wrap the former's Builder with this L2NormalizedBuilder to obtain neighbors according to the cosine distance.
- Template Parameters
-
| Index_ | Integer type for the indices. |
| Data_ | Numeric type for the input and query data. |
| Distance_ | Floating point type for the distances. |
| Normalized_ | Floating-point type for the L2-normalized data. |
| Matrix_ | Class of the input data matrix. This should satisfy the Matrix interface. |
template<typename Index_ , typename Data_ , typename Distance_ , typename Normalized_ , class Matrix_ = Matrix<Index_, Data_>>
The expected matrix type in the Builder instance in the constructor.
If Matrix_ is a base class of NormalizedMatrix, the Builder can use the same Matrix_ in its template parametrization. This is because Matrix_ will be compatible with both the L2NormalizedMatrix and the type of the original matrix, allowing us to transparently substitute an instance of the latter with that of the former. In general, this scenario requires the default Matrix_ type and Data_ == Normalized_.
Otherwise, the Builder should explicitly have a NormalizedMatrix in its template parametrization. This is because it will be accepting the normalized matrix in build_raw() instead of Matrix_.