knncolle
Collection of KNN methods in C++
All Classes Namespaces Files Functions Typedefs Pages
knncolle::L2NormalizedBuilder< Index_, Data_, Distance_, Normalized_, Matrix_ > Class Template Referencefinal

Wrapper around a builder with L2 normalization. More...

#include <L2Normalized.hpp>

Inheritance diagram for knncolle::L2NormalizedBuilder< Index_, Data_, Distance_, Normalized_, Matrix_ >:
Collaboration diagram for knncolle::L2NormalizedBuilder< Index_, Data_, Distance_, Normalized_, Matrix_ >:

Public Types

typedef L2NormalizedMatrix< Index_, Data_, Normalized_, Matrix_ > NormalizedMatrix
 
typedef std::conditional< std::is_base_of< Matrix_, NormalizedMatrix >::value, Matrix_, NormalizedMatrix >::type BuilderMatrix
 

Public Member Functions

 L2NormalizedBuilder (std::shared_ptr< const Builder< Index_, Normalized_, Distance_, BuilderMatrix > > builder)
 
Prebuilt< Index_, Data_, Distance_ > * build_raw (const Matrix_ &data) const
 
- Public Member Functions inherited from knncolle::Builder< Index_, Data_, Distance_, Matrix_ >
std::shared_ptr< Prebuilt< Index_, Data_, Distance_ > > build_shared (const Matrix_ &data) const
 
std::unique_ptr< Prebuilt< Index_, Data_, Distance_ > > build_unique (const Matrix_ &data) const
 

Detailed Description

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.

Member Typedef Documentation

◆ BuilderMatrix

template<typename Index_ , typename Data_ , typename Distance_ , typename Normalized_ , class Matrix_ = Matrix<Index_, Data_>>
std::conditional<std::is_base_of<Matrix_,NormalizedMatrix>::value,Matrix_,NormalizedMatrix>::type knncolle::L2NormalizedBuilder< Index_, Data_, Distance_, Normalized_, Matrix_ >::BuilderMatrix

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_.

◆ NormalizedMatrix

template<typename Index_ , typename Data_ , typename Distance_ , typename Normalized_ , class Matrix_ = Matrix<Index_, Data_>>
L2NormalizedMatrix<Index_, Data_, Normalized_, Matrix_> knncolle::L2NormalizedBuilder< Index_, Data_, Distance_, Normalized_, Matrix_ >::NormalizedMatrix

Alias for the type of the normalized matrix.

Constructor & Destructor Documentation

◆ L2NormalizedBuilder()

template<typename Index_ , typename Data_ , typename Distance_ , typename Normalized_ , class Matrix_ = Matrix<Index_, Data_>>
knncolle::L2NormalizedBuilder< Index_, Data_, Distance_, Normalized_, Matrix_ >::L2NormalizedBuilder ( std::shared_ptr< const Builder< Index_, Normalized_, Distance_, BuilderMatrix > > builder)
inline
Parameters
builderPointer to a Builder for an arbitrary neighbor search algorithm.

Member Function Documentation

◆ build_raw()

template<typename Index_ , typename Data_ , typename Distance_ , typename Normalized_ , class Matrix_ = Matrix<Index_, Data_>>
Prebuilt< Index_, Data_, Distance_ > * knncolle::L2NormalizedBuilder< Index_, Data_, Distance_, Normalized_, Matrix_ >::build_raw ( const Matrix_ & data) const
inlinevirtual

The documentation for this class was generated from the following file: