15#ifndef MLPACK_METHODS_NEIGHBOR_SEARCH_NS_MODEL_HPP
16#define MLPACK_METHODS_NEIGHBOR_SEARCH_NS_MODEL_HPP
23#include <boost/variant.hpp>
32template<
typename SortPolicy,
33 template<
typename TreeMetricType,
34 typename TreeStatType,
35 typename TreeMatType>
class TreeType>
42 arma::mat>::template DualTreeTraverser>;
54 arma::Mat<size_t>& neighbors;
60 template<
typename NSType>
65 arma::Mat<size_t>& neighbors,
66 arma::mat& distances) :
79template<
typename SortPolicy>
84 const arma::mat& querySet;
88 arma::Mat<size_t>& neighbors;
92 const size_t leafSize;
99 template<
typename NSType>
100 void SearchLeaf(
NSType* ns)
const;
104 template<
template<
typename TreeMetricType,
105 typename TreeStatType,
106 typename TreeMatType>
class TreeType>
110 template<
template<
typename TreeMetricType,
111 typename TreeStatType,
112 typename TreeMatType>
class TreeType>
130 arma::Mat<size_t>& neighbors,
131 arma::mat& distances,
132 const size_t leafSize,
143template<
typename SortPolicy>
148 arma::mat&& referenceSet;
157 template<
typename NSType>
158 void TrainLeaf(
NSType* ns)
const;
162 template<
template<
typename TreeMetricType,
163 typename TreeStatType,
164 typename TreeMatType>
class TreeType>
168 template<
template<
typename TreeMetricType,
169 typename TreeStatType,
170 typename TreeMatType>
class TreeType>
188 const size_t leafSize,
200 template<
typename NSType>
211 template<
typename NSType>
222 template<
typename NSType>
233 template<
typename NSType>
247template<
typename SortPolicy>
293 boost::variant<NSType<SortPolicy, tree::KDTree>*,
352 template<
typename Archive>
371 double Tau()
const {
return tau; }
372 double&
Tau() {
return tau; }
375 double Rho()
const {
return rho; }
376 double&
Rho() {
return rho; }
388 const size_t leafSize,
390 const double epsilon = 0);
395 arma::Mat<size_t>& neighbors,
396 arma::mat& distances);
400 arma::Mat<size_t>& neighbors,
401 arma::mat& distances);
415#include "ns_model_impl.hpp"
BiSearchVisitor executes a bichromatic neighbor search on the given NSType.
void operator()(SpillKNN *ns) const
Bichromatic neighbor search specialized for SPTrees.
void operator()(NSTypeT< tree::KDTree > *ns) const
Bichromatic neighbor search on the given NSType specialized for KDTrees.
void operator()(NSTypeT< tree::Octree > *ns) const
Bichromatic neighbor search specialized for octrees.
void operator()(NSTypeT< tree::BallTree > *ns) const
Bichromatic neighbor search on the given NSType specialized for BallTrees.
BiSearchVisitor(const arma::mat &querySet, const size_t k, arma::Mat< size_t > &neighbors, arma::mat &distances, const size_t leafSize, const double tau, const double rho)
Construct the BiSearchVisitor.
DeleteVisitor deletes the given NSType instance.
void operator()(NSType *ns) const
Delete the NSType object.
EpsilonVisitor exposes the Epsilon method of the given NSType.
double & operator()(NSType *ns) const
Return epsilon, the approximation parameter.
MonoSearchVisitor executes a monochromatic neighbor search on the given NSType.
void operator()(NSType *ns) const
Perform monochromatic nearest neighbor search.
MonoSearchVisitor(const size_t k, arma::Mat< size_t > &neighbors, arma::mat &distances)
Construct the MonoSearchVisitor object with the given parameters.
The NSModel class provides an easy way to serialize a model, abstracts away the different types of tr...
const arma::mat & Dataset() const
Expose the dataset.
NeighborSearchMode SearchMode() const
Expose SearchMode.
~NSModel()
Clean memory, if necessary.
double Rho() const
Expose rho.
double Tau() const
Expose tau.
NSModel & operator=(const NSModel &other)
Copy the given NSModel.
void Search(const size_t k, arma::Mat< size_t > &neighbors, arma::mat &distances)
Perform monochromatic neighbor search.
NSModel(const NSModel &other)
Copy the given NSModel.
TreeTypes
Enum type to identify each accepted tree type.
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.
NSModel & operator=(NSModel &&other)
Take ownership of the given NSModel.
NSModel(NSModel &&other)
Take ownership of the given NSModel.
std::string TreeName() const
Return a string representation of the current tree type.
void BuildModel(arma::mat &&referenceSet, const size_t leafSize, const NeighborSearchMode searchMode, const double epsilon=0)
Build the reference tree.
size_t LeafSize() const
Expose leafSize.
NeighborSearchMode & SearchMode()
TreeTypes TreeType() const
Expose treeType.
bool RandomBasis() const
Expose randomBasis.
void serialize(Archive &ar, const unsigned int)
Serialize the neighbor search model.
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.
double Epsilon() const
Expose Epsilon.
Extra data for each node in the tree.
The NeighborSearch class is a template class for performing distance-based neighbor searches.
ReferenceSetVisitor exposes the referenceSet of the given NSType.
const arma::mat & operator()(NSType *ns) const
Return the reference set.
SearchModeVisitor exposes the SearchMode() method of the given NSType.
NeighborSearchMode & operator()(NSType *ns) const
Return the search mode.
TrainVisitor sets the reference set to a new reference set on the given NSType.
void operator()(SpillKNN *ns) const
Train specialized for SPTrees.
void operator()(NSTypeT< tree::KDTree > *ns) const
Train on the given NSType specialized for KDTrees.
void operator()(NSTypeT< tree::Octree > *ns) const
Train specialized for octrees.
void operator()(NSTypeT< tree::BallTree > *ns) const
Train on the given NSType specialized for BallTrees.
TrainVisitor(arma::mat &&referenceSet, const size_t leafSize, const double tau, const double rho)
Construct the TrainVisitor object with the given reference set, leafSize for BinarySpaceTrees,...
LMetric< 2, true > EuclideanDistance
The Euclidean (L2) distance.
NeighborSearchMode
NeighborSearchMode represents the different neighbor search modes available.
Linear algebra utility functions, generally performed on matrices or vectors.
BOOST_TEMPLATE_CLASS_VERSION(template< typename SortPolicy >, mlpack::neighbor::NSModel< SortPolicy >, 1)
Set the serialization version of the NSModel class.