knncolle_kmknn
KMKNN in knncolle
Loading...
Searching...
No Matches
knncolle_kmknn Namespace Reference

Namespace for the knncolle_kmeans library. More...

Classes

class  KmknnBuilder
 Perform a nearest neighbor search based on k-means clustering. More...
 
struct  KmknnOptions
 Options for KmknnBuilder construction. More...
 
struct  KmknnPrebuiltTypes
 Template types of a saved KMKNN index. More...
 

Functions

template<class KmeansFloat_ >
std::function< void(const std::filesystem::path &)> & custom_save_for_kmknn_kmeansfloat ()
 
KmknnPrebuiltTypes load_kmknn_prebuilt_types (const std::filesystem::path &dir)
 
template<typename Index_ , typename Data_ , typename Distance_ , class DistanceMetricData_ = knncolle::DistanceMetric<Data_, Distance_>, typename KmeansFloat_ = Distance_, class DistanceMetricCenter_ = knncolle::DistanceMetric<KmeansFloat_, Distance_>>
auto load_kmknn_prebuilt (const std::filesystem::path &dir)
 

Detailed Description

Namespace for the knncolle_kmeans library.

Function Documentation

◆ custom_save_for_kmknn_kmeansfloat()

template<class KmeansFloat_ >
std::function< void(const std::filesystem::path &)> & knncolle_kmknn::custom_save_for_kmknn_kmeansfloat ( )

Define a global function to preserve KmeansFloat_ type information when saving a prebuilt KMKNN index in knncolle::Prebuilt::save(). Users should define their own function here to handle an KmeansFloat_ type that is unknown to knncolle::get_numeric_type(). The action of setting/unsetting the global function is not thread-safe and should be done in a serial section.

The sole argument of the global function is the same dir provided to knncolle::Prebuilt::save(). If set, the global function is generally expected to write information about KmeansFloat_ to files inside dir. It is recommended that the names of such files should not start with an upper-case letter to avoid conflicts with files generated by save().

Template Parameters
KmeansFloat_Floating-point type of the cluster centroids.
Returns
Reference to a global function for saving information about KmeansFloat_. By default, the global function is not set. If set, the global function will be called by the knncolle::Prebuilt::save() method for the KMKNN knncolle::Prebuilt subclass.

◆ load_kmknn_prebuilt()

template<typename Index_ , typename Data_ , typename Distance_ , class DistanceMetricData_ = knncolle::DistanceMetric<Data_, Distance_>, typename KmeansFloat_ = Distance_, class DistanceMetricCenter_ = knncolle::DistanceMetric<KmeansFloat_, Distance_>>
auto knncolle_kmknn::load_kmknn_prebuilt ( const std::filesystem::path & dir)

Helper function to define a knncolle::LoadPrebuiltFunction for KMKNN in knncolle::load_prebuilt_raw().

To load an KMKNN index from disk, users are expected to define and register an KMKNN-specific knncolle::LoadPrebuiltFunction. In this function, users should call load_kmknn_prebuilt_types() to figure out the saved index's KmknnFloat_. Then, they should call load_kmknn_prebuilt() with the appropriate types to return a pointer to a knncolle::Prebuilt object. This user-defined function should be registered in load_prebuilt_registry() with the key in knncolle_kmknn::kmknn_prebuilt_save_name.

For unknown types, users can set custom_save_for_kmknn_kmeansfloat(). Each custom function saves additional information about its type to disk during a knncolle::Prebuilt::save() call. That information can then be parsed in the user-defined knncolle::LoadPrebuiltFunction to recover an KMKNN index with the appropriate template types.

Template Parameters
Index_Integer type for the observation indices.
Data_Numeric type for the input and query data.
Distance_Floating-point type for the distances.
DistanceMetricData_Class implementing the calculation of distances between observations. This should satisfy the knncolle::DistanceMetric interface.
KmeansFloat_Floating-point type of the cluster centroids.
DistanceMetricCenter_Class implementing the calculation of distances between an observation and a cluster centroid. This should satisfy the knncolle::DistanceMetric interface.
Parameters
dirPath to a directory in which a prebuilt KMKNN index was saved. An KMKNN index would typically be saved by calling the knncolle::Prebuilt::save() method of the KMKNN subclass instance.
Returns
Pointer to a knncolle::Prebuilt KMKNN index.

◆ load_kmknn_prebuilt_types()

KmknnPrebuiltTypes knncolle_kmknn::load_kmknn_prebuilt_types ( const std::filesystem::path & dir)
inline
Parameters
dirPath to a directory in which a prebuilt KMKNN index was saved. An Kmknn index would typically be saved by calling the knncolle::Prebuilt::save() method of the Kmknn subclass instance.
Returns
Template types of the saved instance of a knncolle::Prebuilt KMKNN subclass. This is typically used to choose template parameters for load_kmknn_prebuilt().