Wrapper around a builder with L2 normalization. More...
#include <L2Normalized.hpp>
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 |
![]() | |
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 |
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.
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. |
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_
.
L2NormalizedMatrix<Index_, Data_, Normalized_, Matrix_> knncolle::L2NormalizedBuilder< Index_, Data_, Distance_, Normalized_, Matrix_ >::NormalizedMatrix |
Alias for the type of the normalized matrix.
|
inline |
builder | Pointer to a Builder for an arbitrary neighbor search algorithm. |
|
inlinevirtual |
Creates a L2NormalizedPrebuilt
instance.
Implements knncolle::Builder< Index_, Data_, Distance_, Matrix_ >.