knncolle
Collection of KNN methods in C++
Loading...
Searching...
No Matches
Public Member Functions | List of all members
knncolle::KmknnSearcher< Distance_, Dim_, Index_, Store_, Float_ > Class Template Reference

KMKNN searcher. More...

#include <Kmknn.hpp>

Inheritance diagram for knncolle::KmknnSearcher< Distance_, Dim_, Index_, Store_, Float_ >:
Inheritance graph
[legend]
Collaboration diagram for knncolle::KmknnSearcher< Distance_, Dim_, Index_, Store_, Float_ >:
Collaboration graph
[legend]

Public Member Functions

void search (Index_ i, Index_ k, std::vector< Index_ > *output_indices, std::vector< Float_ > *output_distances)
 
void search (const Float_ *query, Index_ k, std::vector< Index_ > *output_indices, std::vector< Float_ > *output_distances)
 
bool can_search_all () const
 
Index_ search_all (Index_ i, Float_ d, std::vector< Index_ > *output_indices, std::vector< Float_ > *output_distances)
 
Index_ search_all (const Float_ *query, Float_ d, std::vector< Index_ > *output_indices, std::vector< Float_ > *output_distances)
 

Detailed Description

template<class Distance_, typename Dim_, typename Index_, typename Store_, typename Float_>
class knncolle::KmknnSearcher< Distance_, Dim_, Index_, Store_, Float_ >

KMKNN searcher.

Instances of this class are usually constructed using KmknnPrebuilt::initialize().

Template Parameters
Distance_A distance calculation class satisfying the MockDistance contract.
Dim_Integer type for the number of dimensions.
Index_Integer type for the indices.
Store_Floating point type for the stored data.
Float_Floating point type for the query data and output distances.

Member Function Documentation

◆ can_search_all()

bool knncolle::KmknnSearcher< Distance_, Dim_, Index_, Store_, Float_ >::can_search_all ( ) const
inlinevirtual

It is expected that the return value of this method should be constant throughout the lifetime of any Searcher instance.

Returns
Whether this instance has an implementation of the search_all() method.

Reimplemented from knncolle::Searcher< Index_, Float_ >.

◆ search() [1/2]

void knncolle::KmknnSearcher< Distance_, Dim_, Index_, Store_, Float_ >::search ( const Float_ query,
Index_  k,
std::vector< Index_ > *  output_indices,
std::vector< Float_ > *  output_distances 
)
inlinevirtual

Find the nearest neighbors of a new observation.

Parameters
queryPointer to an array of length equal to Prebuilt::num_dimensions(), containing the coordinates of the query point.
kThe number of neighbors to identify. This should be a non-negative integer that is no greater than the number of observations in Prebuilt::num_observations().
[out]output_indicesPointer to a vector, to be filled with the identities of the nearest neighbors in order of increasing distance. On output, the length of the vector should be equal to k. All entries should be unique and less than Prebuilt::num_observations(). Optionally NULL, in which case no indices are returned.
[out]output_distancesPointer to a vector, to be filled with the distances of the nearest neighbors. This corresponds to the indices reported in output_indices. Optionally NULL, in which case no distances are returned.

Implements knncolle::Searcher< Index_, Float_ >.

◆ search() [2/2]

void knncolle::KmknnSearcher< Distance_, Dim_, Index_, Store_, Float_ >::search ( Index_  i,
Index_  k,
std::vector< Index_ > *  output_indices,
std::vector< Float_ > *  output_distances 
)
inlinevirtual

Find the nearest neighbors of the i-th observation in the dataset.

Parameters
iThe index of the observation of interest. This should be non-negative and less than the total number of observations in Prebuilt::num_observations().
kThe number of neighbors to identify. This should be a non-negative integer that is less than the total number of observations in Prebuilt::num_observations(). (Except if Prebuilt::num_observations() == 0, in which case the only valid choice for k is also zero.) Users can call cap_k() to easily cap k based on Prebuilt::num_observations().
[out]output_indicesPointer to a vector, to be filled with the identities of the nearest neighbors in order of increasing distance. On output, the length of the vector should be equal to k. All entries should be unique and less than Prebuilt::num_observations(). This vector is guaranteed to not contain i itself. Optionally NULL, in which case no indices are returned.
[out]output_distancesPointer to a vector, to be filled with the distances of the nearest neighbors. This corresponds to the indices reported in output_indices. Optionally NULL, in which case no distances are returned.

Implements knncolle::Searcher< Index_, Float_ >.

◆ search_all() [1/2]

template<class Distance_ , typename Dim_ , typename Index_ , typename Store_ , typename Float_ >
Index_ knncolle::KmknnSearcher< Distance_, Dim_, Index_, Store_, Float_ >::search_all ( const Float_ *  query,
Float_  distance,
std::vector< Index_ > *  output_indices,
std::vector< Float_ > *  output_distances 
)
inlinevirtual

Find all neighbors of a new observation within a certain distance. This method is optional and may not be implemented by subclasses, so applications should check can_search_all() before attempting a call. A run-time exception is thrown if this method is called on a subclass that does not implement it.

Parameters
queryPointer to an array of length equal to Prebuilt::num_dimensions(), containing the coordinates of the query point.
distanceThe distance in which to consider neighbors.
[out]output_indicesPointer to a vector, to be filled with the identities of the nearest neighbors in order of increasing distance. Optionally NULL, in which case no indices are returned.
[out]output_distancesPointer to a vector, to be filled with the distances of the nearest neighbors. This corresponds to the indices reported in output_indices. Optionally NULL, in which case no distances are returned.
Returns
Number of neighbors within distance of query.

Reimplemented from knncolle::Searcher< Index_, Float_ >.

◆ search_all() [2/2]

template<class Distance_ , typename Dim_ , typename Index_ , typename Store_ , typename Float_ >
Index_ knncolle::KmknnSearcher< Distance_, Dim_, Index_, Store_, Float_ >::search_all ( Index_  i,
Float_  distance,
std::vector< Index_ > *  output_indices,
std::vector< Float_ > *  output_distances 
)
inlinevirtual

Find all neighbors of the i-th observation within a certain distance. This method is optional and may not be implemented by subclasses, so applications should check can_search_all() before attempting a call. A run-time exception is thrown if this method is called on a subclass that does not implement it.

Parameters
iThe index of the observation of interest. This should be non-negative and less than the total number of observations in Prebuilt::num_observations().
distanceThe distance in which to consider neighbors.
[out]output_indicesPointer to a vector, to be filled with the identities of the nearest neighbors in order of increasing distance. This vector is guaranteed to not contain i itself. Optionally NULL, in which case no indices are returned.
[out]output_distancesPointer to a vector, to be filled with the distances of the nearest neighbors. This corresponds to the indices reported in output_indices. Optionally NULL, in which case no distances are returned.
Returns
Number of neighbors within distance of i.

Reimplemented from knncolle::Searcher< Index_, Float_ >.


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