mlpack  master
Public Types | Public Member Functions | Private Attributes | 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...

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

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...
 
 ~NSModel ()
 Clean memory, if necessary. More...
 
void BuildModel (arma::mat &&referenceSet, const size_t leafSize, const NeighborSearchMode searchMode, const double epsilon=0)
 Build the reference tree. More...
 
const arma::mat & Dataset () const
 Expose the dataset. More...
 
double Epsilon () const
 Expose Epsilon. More...
 
double & Epsilon ()
 
size_t LeafSize () const
 Expose leafSize. More...
 
size_t & LeafSize ()
 
NSModeloperator= (const NSModel &other)
 Copy the given NSModel. More...
 
NSModeloperator= (NSModel &&other)
 Take ownership of the given NSModel. More...
 
bool RandomBasis () const
 Expose randomBasis. More...
 
bool & RandomBasis ()
 
double Rho () const
 Expose rho. More...
 
double & Rho ()
 
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. More...
 
void Search (const size_t k, arma::Mat< size_t > &neighbors, arma::mat &distances)
 Perform monochromatic neighbor search. More...
 
NeighborSearchMode SearchMode () const
 Expose SearchMode. More...
 
NeighborSearchModeSearchMode ()
 
template<typename Archive >
void Serialize (Archive &ar, const unsigned int)
 Serialize the neighbor search model. More...
 
double Tau () const
 Expose tau. More...
 
double & Tau ()
 
std::string TreeName () const
 Return a string representation of the current tree type. More...
 
TreeTypes TreeType () const
 Expose treeType. More...
 
TreeTypesTreeType ()
 

Private Attributes

size_t leafSize
 For tree types that accept the maxLeafSize parameter. More...
 
boost::variant< NSType< SortPolicy, tree::KDTree > *, NSType< SortPolicy, tree::StandardCoverTree > *, NSType< SortPolicy, tree::RTree > *, NSType< SortPolicy, tree::RStarTree > *, NSType< SortPolicy, tree::BallTree > *, NSType< SortPolicy, tree::XTree > *, NSType< SortPolicy, tree::HilbertRTree > *, NSType< SortPolicy, tree::RPlusTree > *, NSType< SortPolicy, tree::RPlusPlusTree > *, NSType< SortPolicy, tree::VPTree > *, NSType< SortPolicy, tree::RPTree > *, NSType< SortPolicy, tree::MaxRPTree > *, SpillKNN *, NSType< SortPolicy, tree::UBTree > *, NSType< SortPolicy, tree::Octree > * > nSearch
 nSearch holds an instance of the NeigborSearch class for the current treeType. More...
 
arma::mat q
 This is the random projection matrix; only used if randomBasis is true. More...
 
bool randomBasis
 If true, random projections are used. More...
 
double rho
 Balance threshold (for spill trees). More...
 
double tau
 Overlapping size (for spill trees). More...
 
TreeTypes treeType
 Tree type considered for neighbor search. 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.

Definition at line 266 of file ns_model.hpp.

Member Enumeration Documentation

template<typename SortPolicy >
enum mlpack::neighbor::NSModel::TreeTypes

Enum type to identify each accepted tree type.

Enumerator
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 

Definition at line 270 of file ns_model.hpp.

Constructor & Destructor Documentation

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.
template<typename SortPolicy >
mlpack::neighbor::NSModel< SortPolicy >::NSModel ( const NSModel< SortPolicy > &  other)

Copy the given NSModel.

Parameters
otherModel to copy.
template<typename SortPolicy >
mlpack::neighbor::NSModel< SortPolicy >::NSModel ( NSModel< SortPolicy > &&  other)

Take ownership of the given NSModel.

Parameters
otherModel to take ownership of.
template<typename SortPolicy >
mlpack::neighbor::NSModel< SortPolicy >::~NSModel ( )

Clean memory, if necessary.

Member Function Documentation

template<typename SortPolicy >
void mlpack::neighbor::NSModel< SortPolicy >::BuildModel ( arma::mat &&  referenceSet,
const size_t  leafSize,
const NeighborSearchMode  searchMode,
const double  epsilon = 0 
)

Build the reference tree.

template<typename SortPolicy >
const arma::mat& mlpack::neighbor::NSModel< SortPolicy >::Dataset ( ) const

Expose the dataset.

template<typename SortPolicy >
double mlpack::neighbor::NSModel< SortPolicy >::Epsilon ( ) const

Expose Epsilon.

template<typename SortPolicy >
double& mlpack::neighbor::NSModel< SortPolicy >::Epsilon ( )
template<typename SortPolicy >
size_t mlpack::neighbor::NSModel< SortPolicy >::LeafSize ( ) const
inline

Expose leafSize.

Definition at line 385 of file ns_model.hpp.

template<typename SortPolicy >
size_t& mlpack::neighbor::NSModel< SortPolicy >::LeafSize ( )
inline

Definition at line 386 of file ns_model.hpp.

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

Copy the given NSModel.

Parameters
otherModel to copy.
template<typename SortPolicy >
NSModel& mlpack::neighbor::NSModel< SortPolicy >::operator= ( NSModel< SortPolicy > &&  other)

Take ownership of the given NSModel.

Parameters
otherModel to take ownership of.
template<typename SortPolicy >
bool mlpack::neighbor::NSModel< SortPolicy >::RandomBasis ( ) const
inline

Expose randomBasis.

Definition at line 401 of file ns_model.hpp.

template<typename SortPolicy >
bool& mlpack::neighbor::NSModel< SortPolicy >::RandomBasis ( )
inline

Definition at line 402 of file ns_model.hpp.

References BOOST_TEMPLATE_CLASS_VERSION(), and string().

template<typename SortPolicy >
double mlpack::neighbor::NSModel< SortPolicy >::Rho ( ) const
inline

Expose rho.

Definition at line 393 of file ns_model.hpp.

template<typename SortPolicy >
double& mlpack::neighbor::NSModel< SortPolicy >::Rho ( )
inline

Definition at line 394 of file ns_model.hpp.

template<typename SortPolicy >
void mlpack::neighbor::NSModel< SortPolicy >::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.

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.

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

Expose SearchMode.

template<typename SortPolicy >
NeighborSearchMode& mlpack::neighbor::NSModel< SortPolicy >::SearchMode ( )
template<typename SortPolicy >
template<typename Archive >
void mlpack::neighbor::NSModel< SortPolicy >::Serialize ( Archive &  ar,
const unsigned  int 
)

Serialize the neighbor search model.

template<typename SortPolicy >
double mlpack::neighbor::NSModel< SortPolicy >::Tau ( ) const
inline

Expose tau.

Definition at line 389 of file ns_model.hpp.

template<typename SortPolicy >
double& mlpack::neighbor::NSModel< SortPolicy >::Tau ( )
inline

Definition at line 390 of file ns_model.hpp.

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

Return a string representation of the current tree type.

template<typename SortPolicy >
TreeTypes mlpack::neighbor::NSModel< SortPolicy >::TreeType ( ) const
inline

Expose treeType.

Definition at line 397 of file ns_model.hpp.

template<typename SortPolicy >
TreeTypes& mlpack::neighbor::NSModel< SortPolicy >::TreeType ( )
inline

Definition at line 398 of file ns_model.hpp.

Member Data Documentation

template<typename SortPolicy >
size_t mlpack::neighbor::NSModel< SortPolicy >::leafSize
private

For tree types that accept the maxLeafSize parameter.

Definition at line 294 of file ns_model.hpp.

template<typename SortPolicy >
boost::variant<NSType<SortPolicy, tree::KDTree>*, NSType<SortPolicy, tree::StandardCoverTree>*, NSType<SortPolicy, tree::RTree>*, NSType<SortPolicy, tree::RStarTree>*, NSType<SortPolicy, tree::BallTree>*, NSType<SortPolicy, tree::XTree>*, NSType<SortPolicy, tree::HilbertRTree>*, NSType<SortPolicy, tree::RPlusTree>*, NSType<SortPolicy, tree::RPlusPlusTree>*, NSType<SortPolicy, tree::VPTree>*, NSType<SortPolicy, tree::RPTree>*, NSType<SortPolicy, tree::MaxRPTree>*, SpillKNN*, NSType<SortPolicy, tree::UBTree>*, NSType<SortPolicy, tree::Octree>*> mlpack::neighbor::NSModel< SortPolicy >::nSearch
private

nSearch holds an instance of the NeigborSearch class for the current treeType.

It is initialized every time BuildModel is executed. We access to the contained value through the visitor classes defined above.

Definition at line 325 of file ns_model.hpp.

template<typename SortPolicy >
arma::mat mlpack::neighbor::NSModel< SortPolicy >::q
private

This is the random projection matrix; only used if randomBasis is true.

Definition at line 304 of file ns_model.hpp.

template<typename SortPolicy >
bool mlpack::neighbor::NSModel< SortPolicy >::randomBasis
private

If true, random projections are used.

Definition at line 302 of file ns_model.hpp.

template<typename SortPolicy >
double mlpack::neighbor::NSModel< SortPolicy >::rho
private

Balance threshold (for spill trees).

Definition at line 299 of file ns_model.hpp.

template<typename SortPolicy >
double mlpack::neighbor::NSModel< SortPolicy >::tau
private

Overlapping size (for spill trees).

Definition at line 297 of file ns_model.hpp.

template<typename SortPolicy >
TreeTypes mlpack::neighbor::NSModel< SortPolicy >::treeType
private

Tree type considered for neighbor search.

Definition at line 291 of file ns_model.hpp.


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