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>;
44 template<
typename SortPolicy>
47 static const std::string
Name() {
return "neighbor_search_model"; }
53 static const std::string
Name() {
return "nearest_neighbor_search_model"; }
59 static const std::string
Name() {
return "furthest_neighbor_search_model"; }
72 arma::Mat<size_t>& neighbors;
78 template<
typename NSType>
83 arma::Mat<size_t>& neighbors,
84 arma::mat& distances) :
97 template<
typename SortPolicy>
102 const arma::mat& querySet;
106 arma::Mat<size_t>& neighbors;
108 arma::mat& distances;
110 const size_t leafSize;
117 template<
typename NSType>
118 void SearchLeaf(
NSType* ns)
const;
122 template<
template<
typename TreeMetricType,
123 typename TreeStatType,
124 typename TreeMatType>
class TreeType>
128 template<
template<
typename TreeMetricType,
129 typename TreeStatType,
130 typename TreeMatType>
class TreeType>
131 void operator()(
NSTypeT<TreeType>* ns)
const;
148 arma::Mat<size_t>& neighbors,
149 arma::mat& distances,
150 const size_t leafSize,
161 template<
typename SortPolicy>
166 arma::mat&& referenceSet;
175 template<
typename NSType>
176 void TrainLeaf(
NSType* ns)
const;
180 template<
template<
typename TreeMetricType,
181 typename TreeStatType,
182 typename TreeMatType>
class TreeType>
186 template<
template<
typename TreeMetricType,
187 typename TreeStatType,
188 typename TreeMatType>
class TreeType>
189 void operator()(
NSTypeT<TreeType>* ns)
const;
206 const size_t leafSize,
218 template<
typename NSType>
231 searchMode(searchMode)
235 template<
typename NSType>
246 template<
typename NSType>
257 template<
typename NSType>
268 template<
typename NSType>
282 template<
typename SortPolicy>
328 boost::variant<NSType<SortPolicy, tree::KDTree>*,
355 template<
typename Archive>
356 void Serialize(Archive& ar,
const unsigned int );
359 const arma::mat&
Dataset()
const;
375 double Tau()
const {
return tau; }
376 double&
Tau() {
return tau; }
379 double Rho()
const {
return rho; }
380 double&
Rho() {
return rho; }
392 const size_t leafSize,
394 const double epsilon = 0);
397 void Search(arma::mat&& querySet,
399 arma::Mat<size_t>& neighbors,
400 arma::mat& distances);
403 void Search(
const size_t k,
404 arma::Mat<size_t>& neighbors,
405 arma::mat& distances);
419 #include "ns_model_impl.hpp"
TreeTypes TreeType() const
Expose treeType.
double Epsilon() const
Expose Epsilon.
#define BOOST_TEMPLATE_CLASS_VERSION(SIGNATURE, T, N)
Use this like BOOST_CLASS_VERSION(), but for templated classes.
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.
std::string TreeName() const
Return a string representation of the current tree type.
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.
void operator()(NSType *ns) const
Delete the NSType object.
TreeTypes
Enum type to identify each accepted tree type.
SetSearchModeVisitor modifies the SearchMode method of the given NSType.
ReferenceSetVisitor exposes the referenceSet of the given NSType.
SearchModeVisitor exposes the SearchMode() method of the given NSType.
The NeighborSearch class is a template class for performing distance-based neighbor searches...
void operator()(NSTypeT< TreeType > *ns) const
Default Train on the given NSType instance.
double Rho() const
Expose rho.
NeighborSearchMode SearchMode() const
Access the search mode.
NeighborSearch< SortPolicy, metric::EuclideanDistance, arma::mat, TreeType, TreeType< metric::EuclideanDistance, NeighborSearchStat< SortPolicy >, arma::mat >::template DualTreeTraverser > NSType
Alias template for euclidean neighbor search.
void operator()(NSType *ns) const
Perform monochromatic nearest neighbor search.
This class implements the necessary methods for the SortPolicy template parameter of the NeighborSear...
~NSModel()
Clean memory, if necessary.
This class implements the necessary methods for the SortPolicy template parameter of the NeighborSear...
static const std::string Name()
BiSearchVisitor executes a bichromatic neighbor search on the given NSType.
static const std::string Name()
const arma::mat & operator()(NSType *ns) const
Return the reference set.
double & operator()(NSType *ns) const
Return epsilon, the approximation parameter.
void Serialize(Archive &ar, const unsigned int)
Serialize the neighbor search model.
The NSModel class provides an easy way to serialize a model, abstracts away the different types of tr...
static const std::string Name()
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...
SetSearchModeVisitor(const NeighborSearchMode searchMode)
Construct the SetSearchModeVisitor object with the given mode.
double Tau() const
Expose tau.
TrainVisitor sets the reference set to a new reference set on the given NSType.
void operator()(NSTypeT< TreeType > *ns) const
Default Bichromatic neighbor search on the given NSType instance.
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.
NeighborSearchMode operator()(NSType *ns) const
Return the search mode.
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.
size_t LeafSize() const
Expose leafSize.
DeleteVisitor deletes the given NSType instance.
LMetric< 2, true > EuclideanDistance
The Euclidean (L2) distance.
void SetSearchMode(const NeighborSearchMode mode)
Modify the search mode.
NeighborSearchMode
NeighborSearchMode represents the different neighbor search modes available.
const arma::mat & Dataset() const
Expose the dataset.
bool RandomBasis() const
Expose randomBasis.
void operator()(NSType *ns) const
Set the search mode.