15 #ifndef MLPACK_METHODS_NEIGHBOR_SEARCH_NS_MODEL_HPP 16 #define MLPACK_METHODS_NEIGHBOR_SEARCH_NS_MODEL_HPP 23 #include <boost/variant.hpp> 32 template<
typename SortPolicy,
33 template<
typename TreeMetricType,
34 typename TreeStatType,
35 typename TreeMatType>
class TreeType>
36 using
NSType = NeighborSearch<SortPolicy,
41 NeighborSearchStat<SortPolicy>,
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) :
79 template<
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>
113 void operator()(
NSTypeT<TreeType>* ns)
const;
130 arma::Mat<size_t>& neighbors,
131 arma::mat& distances,
132 const size_t leafSize,
143 template<
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>
171 void operator()(
NSTypeT<TreeType>* ns)
const;
188 const size_t leafSize,
200 template<
typename NSType>
211 template<
typename NSType>
222 template<
typename NSType>
233 template<
typename NSType>
247 template<
typename SortPolicy>
293 boost::variant<NSType<SortPolicy, tree::KDTree>*,
352 template<
typename Archive>
353 void serialize(Archive& ar,
const unsigned int );
356 const arma::mat&
Dataset()
const;
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);
393 void Search(arma::mat&& querySet,
395 arma::Mat<size_t>& neighbors,
396 arma::mat& distances);
399 void Search(
const size_t k,
400 arma::Mat<size_t>& neighbors,
401 arma::mat& distances);
415 #include "ns_model_impl.hpp"
double Epsilon() const
Expose Epsilon.
void operator()(NSTypeT< TreeType > *ns) const
Default Bichromatic neighbor search on the given NSType instance.
MonoSearchVisitor(const size_t k, arma::Mat< size_t > &neighbors, arma::mat &distances)
Construct the MonoSearchVisitor object with the given parameters.
EpsilonVisitor exposes the Epsilon method of the given NSType.
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, and tau and rho for spill trees.
Linear algebra utility functions, generally performed on matrices or vectors.
bool RandomBasis() const
Expose randomBasis.
TreeTypes
Enum type to identify each accepted tree type.
const arma::mat & operator()(NSType *ns) const
Return the reference set.
BOOST_TEMPLATE_CLASS_VERSION(template< typename SortPolicy >, mlpack::neighbor::NSModel< SortPolicy >, 1)
Set the serialization version of the NSModel class.
ReferenceSetVisitor exposes the referenceSet of the given NSType.
SearchModeVisitor exposes the SearchMode() method of the given NSType.
void operator()(NSTypeT< TreeType > *ns) const
Default Train on the given NSType instance.
The NeighborSearch class is a template class for performing distance-based neighbor searches...
TreeTypes TreeType() const
Expose treeType.
const arma::mat & Dataset() const
Expose the dataset.
NeighborSearch< SortPolicy, metric::EuclideanDistance, arma::mat, TreeType, TreeType< metric::EuclideanDistance, NeighborSearchStat< SortPolicy >, arma::mat >::template DualTreeTraverser > NSType
Alias template for euclidean neighbor search.
void serialize(Archive &ar, const unsigned int)
Serialize the neighbor search model.
~NSModel()
Clean memory, if necessary.
size_t LeafSize() const
Expose leafSize.
BiSearchVisitor executes a bichromatic neighbor search on the given NSType.
NSModel & operator=(const NSModel &other)
Copy the given NSModel.
std::string TreeName() const
Return a string representation of the current tree type.
The NSModel class provides an easy way to serialize a model, abstracts away the different types of tr...
double Tau() const
Expose tau.
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...
NeighborSearchMode & operator()(NSType *ns) const
Return the search mode.
TrainVisitor sets the reference set to a new reference set on the given NSType.
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.
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.
void operator()(NSType *ns) const
Perform monochromatic nearest neighbor search.
MonoSearchVisitor executes a monochromatic neighbor search on the given NSType.
void BuildModel(arma::mat &&referenceSet, const size_t leafSize, const NeighborSearchMode searchMode, const double epsilon=0)
Build the reference tree.
NeighborSearchMode SearchMode() const
Expose SearchMode.
DeleteVisitor deletes the given NSType instance.
LMetric< 2, true > EuclideanDistance
The Euclidean (L2) distance.
double Rho() const
Expose rho.
double & operator()(NSType *ns) const
Return epsilon, the approximation parameter.
NeighborSearchMode
NeighborSearchMode represents the different neighbor search modes available.
void operator()(NSType *ns) const
Delete the NSType object.