mlpack
Public Types | Public Member Functions | List of all members
mlpack::neighbor::NSModel< SortPolicy > Class Template Reference

The NSModel class provides an easy way to serialize a model, abstracts away the different types of trees, and also reflects the NeighborSearch API. More...

#include <ns_model.hpp>

Public Types

enum  TreeTypes {
  KD_TREE, COVER_TREE, R_TREE, R_STAR_TREE,
  BALL_TREE, X_TREE, HILBERT_R_TREE, R_PLUS_TREE,
  R_PLUS_PLUS_TREE, VP_TREE, RP_TREE, MAX_RP_TREE,
  SPILL_TREE, UB_TREE, OCTREE
}
 Enum type to identify each accepted tree type.
 

Public Member Functions

 NSModel (TreeTypes treeType=TreeTypes::KD_TREE, bool randomBasis=false)
 Initialize the NSModel with the given type and whether or not a random basis should be used. More...
 
 NSModel (const NSModel &other)
 Copy the given NSModel. More...
 
 NSModel (NSModel &&other)
 Take ownership of the given NSModel. More...
 
NSModeloperator= (const NSModel &other)
 Copy the given NSModel. More...
 
NSModeloperator= (NSModel &&other)
 Take ownership of the given NSModel. More...
 
 ~NSModel ()
 Clean memory, if necessary.
 
template<typename Archive >
void serialize (Archive &ar, const uint32_t)
 Serialize the neighbor search model. More...
 
const arma::mat & Dataset () const
 Expose the dataset.
 
NeighborSearchMode SearchMode () const
 Expose SearchMode. More...
 
NeighborSearchModeSearchMode ()
 Modify the search mode.
 
size_t LeafSize () const
 Expose LeafSize.
 
size_t & LeafSize ()
 
double Tau () const
 Expose Tau.
 
double & Tau ()
 
double Rho () const
 Expose Rho.
 
double & Rho ()
 
double Epsilon () const
 Expose Epsilon.
 
double & Epsilon ()
 
TreeTypes TreeType () const
 Expose treeType.
 
TreeTypesTreeType ()
 
bool RandomBasis () const
 Expose randomBasis.
 
bool & RandomBasis ()
 
void InitializeModel (const NeighborSearchMode searchMode, const double epsilon)
 Initialize the model type. (This does not perform any training.) More...
 
void BuildModel (arma::mat &&referenceSet, const NeighborSearchMode searchMode, const double epsilon=0)
 Build the reference tree.
 
void Search (arma::mat &&querySet, const size_t k, arma::Mat< size_t > &neighbors, arma::mat &distances)
 Perform neighbor search. The query set will be reordered.
 
void Search (const size_t k, arma::Mat< size_t > &neighbors, arma::mat &distances)
 Perform monochromatic neighbor search. More...
 
std::string TreeName () const
 Return a string representation of the current tree type. More...
 

Detailed Description

template<typename SortPolicy>
class mlpack::neighbor::NSModel< SortPolicy >

The NSModel class provides an easy way to serialize a model, abstracts away the different types of trees, and also reflects the NeighborSearch API.

This class is meant to be used by the command-line mlpack_knn and mlpack_kfn programs, and thus does not have the same complete functionality and flexibility as the NeighborSearch class. So if you are using it outside of mlpack_knn and mlpack_kfn, be aware that it is limited!

Template Parameters
SortPolicyThe sort policy for distances; see NearestNeighborSort.

Constructor & Destructor Documentation

◆ NSModel() [1/3]

template<typename SortPolicy >
mlpack::neighbor::NSModel< SortPolicy >::NSModel ( TreeTypes  treeType = TreeTypes::KD_TREE,
bool  randomBasis = false 
)

Initialize the NSModel with the given type and whether or not a random basis should be used.

Parameters
treeTypeType of tree to use.
randomBasisWhether or not to project the points onto a random basis before searching.

◆ NSModel() [2/3]

template<typename SortPolicy >
mlpack::neighbor::NSModel< SortPolicy >::NSModel ( const NSModel< SortPolicy > &  other)

Copy the given NSModel.

Parameters
otherModel to copy.

◆ NSModel() [3/3]

template<typename SortPolicy >
mlpack::neighbor::NSModel< SortPolicy >::NSModel ( NSModel< SortPolicy > &&  other)

Take ownership of the given NSModel.

Parameters
otherModel to take ownership of.

Member Function Documentation

◆ InitializeModel()

template<typename SortPolicy >
void mlpack::neighbor::NSModel< SortPolicy >::InitializeModel ( const NeighborSearchMode  searchMode,
const double  epsilon 
)

Initialize the model type. (This does not perform any training.)

Initialize a model given the tree type. (No training happens here.)

◆ operator=() [1/2]

template<typename SortPolicy >
NSModel< SortPolicy > & mlpack::neighbor::NSModel< SortPolicy >::operator= ( const NSModel< SortPolicy > &  other)

Copy the given NSModel.

Parameters
otherModel to copy.

◆ operator=() [2/2]

template<typename SortPolicy >
NSModel< SortPolicy > & mlpack::neighbor::NSModel< SortPolicy >::operator= ( NSModel< SortPolicy > &&  other)

Take ownership of the given NSModel.

Parameters
otherModel to take ownership of.

◆ Search()

template<typename SortPolicy >
void mlpack::neighbor::NSModel< SortPolicy >::Search ( const size_t  k,
arma::Mat< size_t > &  neighbors,
arma::mat &  distances 
)

Perform monochromatic neighbor search.

Perform neighbor search.

◆ SearchMode()

template<typename SortPolicy >
NeighborSearchMode mlpack::neighbor::NSModel< SortPolicy >::SearchMode ( ) const

Expose SearchMode.

Access the search mode.

◆ serialize()

template<typename SortPolicy >
template<typename Archive >
void mlpack::neighbor::NSModel< SortPolicy >::serialize ( Archive &  ar,
const uint32_t   
)

Serialize the neighbor search model.

Serialize the kNN model.

◆ TreeName()

template<typename SortPolicy >
std::string mlpack::neighbor::NSModel< SortPolicy >::TreeName ( ) const

Return a string representation of the current tree type.

Get the name of the tree type.


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