16 #ifndef MLPACK_METHODS_NEIGHBOR_SEARCH_NS_MODEL_HPP 17 #define MLPACK_METHODS_NEIGHBOR_SEARCH_NS_MODEL_HPP 50 virtual const arma::mat&
Dataset()
const = 0;
58 virtual double Epsilon()
const = 0;
64 arma::mat&& referenceSet,
65 const size_t leafSize,
67 const double rho) = 0;
74 arma::Mat<size_t>& neighbors,
76 const size_t leafSize,
77 const double rho) = 0;
83 arma::Mat<size_t>& neighbors,
84 arma::mat& distances) = 0;
90 template<
typename SortPolicy,
91 template<
typename TreeMetricType,
92 typename TreeStatType,
93 typename TreeMatType>
class TreeType,
94 template<typename RuleType> class DualTreeTraversalType =
97 arma::mat>::template DualTreeTraverser,
98 template<
typename RuleType>
class SingleTreeTraversalType =
100 NeighborSearchStat<SortPolicy>,
101 arma::mat>::template SingleTreeTraverser>
108 const double epsilon) :
109 ns(searchMode, epsilon)
122 const arma::mat&
Dataset()
const {
return ns.ReferenceSet(); }
130 double Epsilon()
const {
return ns.Epsilon(); }
137 arma::mat&& referenceSet,
145 arma::mat&& querySet,
147 arma::Mat<size_t>& neighbors,
148 arma::mat& distances,
156 arma::Mat<size_t>& neighbors,
157 arma::mat& distances);
160 template<
typename Archive>
172 DualTreeTraversalType,
184 template<
typename SortPolicy,
185 template<
typename TreeMetricType,
186 typename TreeStatType,
187 typename TreeMatType>
class TreeType,
188 template<typename RuleType> class DualTreeTraversalType =
190 NeighborSearchStat<SortPolicy>,
191 arma::mat>::template DualTreeTraverser,
192 template<
typename RuleType>
class SingleTreeTraversalType =
194 NeighborSearchStat<SortPolicy>,
195 arma::mat>::template SingleTreeTraverser>
199 DualTreeTraversalType,
200 SingleTreeTraversalType>
206 const double epsilon) :
209 DualTreeTraversalType,
210 SingleTreeTraversalType>(searchMode, epsilon)
227 arma::mat&& referenceSet,
228 const size_t leafSize,
235 arma::mat&& querySet,
237 arma::Mat<size_t>& neighbors,
238 arma::mat& distances,
239 const size_t leafSize,
243 template<
typename Archive>
252 DualTreeTraversalType,
253 SingleTreeTraversalType>::ns;
260 template<
typename SortPolicy>
265 tree::SPTree<metric::EuclideanDistance,
266 NeighborSearchStat<SortPolicy>,
267 arma::mat>::template DefeatistDualTreeTraverser,
268 tree::SPTree<metric::EuclideanDistance,
269 NeighborSearchStat<SortPolicy>,
270 arma::mat>::template DefeatistSingleTreeTraverser>
275 const double epsilon) :
281 arma::mat>::template DefeatistDualTreeTraverser,
284 arma::mat>::template DefeatistSingleTreeTraverser>(
298 arma::mat&& referenceSet,
299 const size_t leafSize,
306 arma::mat&& querySet,
308 arma::Mat<size_t>& neighbors,
309 arma::mat& distances,
310 const size_t leafSize,
314 template<
typename Archive>
325 NeighborSearchStat<SortPolicy>,
326 arma::mat>::template DefeatistDualTreeTraverser,
328 NeighborSearchStat<SortPolicy>,
329 arma::mat>::template DefeatistSingleTreeTraverser>::ns;
342 template<
typename SortPolicy>
428 template<
typename Archive>
429 void serialize(Archive& ar,
const uint32_t );
432 const arma::mat&
Dataset()
const;
443 double Tau()
const {
return tau; }
444 double&
Tau() {
return tau; }
447 double Rho()
const {
return rho; }
448 double&
Rho() {
return rho; }
464 const double epsilon);
468 arma::mat&& referenceSet,
470 const double epsilon = 0);
474 arma::mat&& querySet,
476 arma::Mat<size_t>& neighbors,
477 arma::mat& distances);
482 arma::Mat<size_t>& neighbors,
483 arma::mat& distances);
486 std::string TreeName()
const;
493 #include "ns_model_impl.hpp"
virtual ~NSWrapper()
Delete the NSWrapper object.
double Epsilon() const
Get epsilon, the approximation parameter.
Linear algebra utility functions, generally performed on matrices or vectors.
bool RandomBasis() const
Expose randomBasis.
TreeTypes
Enum type to identify each accepted tree type.
NSWrapper is a wrapper class for most NeighborSearch types.
void serialize(Archive &ar, const uint32_t)
Serialize the NeighborSearch model.
NSWrapper(const NeighborSearchMode searchMode, const double epsilon)
Construct the NSWrapper object, initializing the internally-held NeighborSearch object.
NeighborSearchMode & SearchMode()
Modify the search mode.
Extra data for each node in the tree.
NSType ns
The instantiated NeighborSearch object that we are wrapping.
LeafSizeNSWrapper wraps any NeighborSearch types that take a leaf size for tree construction.
virtual ~LeafSizeNSWrapper()
Delete the LeafSizeNSWrapper.
virtual NSWrapperBase * Clone() const =0
Create a new NSWrapperBase that is the same as this one.
virtual LeafSizeNSWrapper * Clone() const
Return a copy of the LeafSizeNSWrapper.
The NeighborSearch class is a template class for performing distance-based neighbor searches...
TreeTypes TreeType() const
Expose treeType.
NeighborSearch< SortPolicy, metric::EuclideanDistance, arma::mat, TreeType, DualTreeTraversalType, SingleTreeTraversalType > NSType
NSWrapperBase is a base wrapper class for holding all NeighborSearch types supported by NSModel...
NSWrapperBase()
Create the NSWrapperBase object.
size_t LeafSize() const
Expose LeafSize.
SpillTree< MetricType, StatisticType, MatType, AxisOrthogonalHyperplane, MidpointSpaceSplit > SPTree
The hybrid spill tree.
virtual void Train(util::Timers &timers, arma::mat &&referenceSet, const size_t leafSize, const double tau, const double rho)=0
Train the NeighborSearch model with the given parameters.
virtual NSWrapper * Clone() const
Create a copy of this NSWrapper object.
double & Epsilon()
Modify epsilon, the approximation parameter.
The NSModel class provides an easy way to serialize a model, abstracts away the different types of tr...
double Tau() const
Expose Tau.
SpillNSWrapper(const NeighborSearchMode searchMode, const double epsilon)
Construct the SpillNSWrapper.
virtual NeighborSearchMode SearchMode() const =0
Get the search mode.
const arma::mat & Dataset() const
Get a reference to the reference set.
virtual const arma::mat & Dataset() const =0
Return a reference to the dataset.
virtual SpillNSWrapper * Clone() const
Return a copy of the SpillNSWrapper.
virtual double Epsilon() const =0
Get the approximation parameter epsilon.
The SpillNSWrapper class wraps the NeighborSearch class when the spill tree is used.
virtual void Search(util::Timers &timers, arma::mat &&querySet, const size_t k, arma::Mat< size_t > &neighbors, arma::mat &distances, const size_t leafSize, const double rho)=0
Perform bichromatic neighbor search (i.e.
LMetric< 2, true > EuclideanDistance
The Euclidean (L2) distance.
double Rho() const
Expose Rho.
virtual ~SpillNSWrapper()
Destruct the SpillNSWrapper.
NeighborSearchMode
NeighborSearchMode represents the different neighbor search modes available.
void serialize(Archive &ar, const uint32_t)
Serialize the NeighborSearch model.
LeafSizeNSWrapper(const NeighborSearchMode searchMode, const double epsilon)
Construct the LeafSizeNSWrapper by delegating to the NSWrapper constructor.
virtual ~NSWrapperBase()
Destruct the NSWrapperBase (nothing to do).
NeighborSearchMode SearchMode() const
Get the search mode.
void serialize(Archive &ar, const uint32_t)
Serialize the NeighborSearch model.