12 #ifndef MLPACK_CORE_TREE_COVER_TREE_COVER_TREE_HPP 13 #define MLPACK_CORE_TREE_COVER_TREE_COVER_TREE_HPP 18 #include "../statistic.hpp" 95 template<
typename MetricType = metric::LMetric<2, true>,
96 typename StatisticType = EmptyStatistic,
97 typename MatType = arma::mat,
98 typename RootPo
intPolicy = FirstPo
intIsRoot>
118 const ElemType
base = 2.0,
119 MetricType*
metric = NULL);
132 const ElemType
base = 2.0);
142 const ElemType
base = 2.0);
154 const ElemType
base = 2.0);
189 const size_t pointIndex,
193 arma::Col<size_t>& indices,
194 arma::vec& distances,
198 MetricType&
metric = NULL);
218 const size_t pointIndex,
223 MetricType*
metric = NULL);
244 template<
typename Archive>
256 template<
typename RuleType>
260 template<
typename RuleType>
263 template<
typename RuleType>
317 template<
typename VecType>
319 const VecType&
point,
326 template<
typename VecType>
328 const VecType& point,
351 ElemType
MinDistance(
const arma::vec& other)
const;
355 ElemType
MinDistance(
const arma::vec& other,
const ElemType distance)
const;
365 ElemType
MaxDistance(
const arma::vec& other)
const;
369 ElemType
MaxDistance(
const arma::vec& other,
const ElemType distance)
const;
377 const ElemType distance)
const;
385 const ElemType distance)
const;
414 center = arma::vec(
dataset->col(point));
452 arma::vec& distances,
455 size_t& usedSetSize);
469 const arma::Col<size_t>& indices,
470 arma::vec& distances,
471 const size_t pointSetSize);
487 arma::vec& distances,
488 const ElemType bound,
489 const size_t pointSetSize);
511 arma::vec& distances,
512 const size_t childFarSetSize,
513 const size_t childUsedSetSize,
514 const size_t farSetSize);
517 arma::vec& distances,
521 arma::Col<size_t>& childIndices,
522 const size_t childFarSetSize,
523 const size_t childUsedSetSize);
525 arma::vec& distances,
526 const ElemType bound,
527 const size_t nearSetSize,
528 const size_t pointSetSize);
546 friend class boost::serialization::access;
552 template<
typename Archive>
553 void Serialize(Archive& ar,
const unsigned int );
566 #include "cover_tree_impl.hpp" 569 #include "../cover_tree.hpp" ElemType MaxDistance(const CoverTree &other) const
Return the maximum distance to another node.
void Center(arma::vec ¢er) const
Get the center of the node and store it in the given vector.
size_t point
Index of the point in the matrix which this node represents.
ElemType & FurthestDescendantDistance()
Modify the distance from the center of the node to the furthest descendant.
const MatType * dataset
Reference to the matrix which this tree is built on.
const std::vector< CoverTree * > & Children() const
Get the children.
CoverTree()
A default constructor.
StatisticType & Stat()
Modify the statistic for this node.
std::vector< CoverTree * > & Children()
Modify the children manually (maybe not a great idea).
size_t SortPointSet(arma::Col< size_t > &indices, arma::vec &distances, const size_t childFarSetSize, const size_t childUsedSetSize, const size_t farSetSize)
Assuming that the list of indices and distances is sorted as [ childFarSet | childUsedSet | farSet | ...
size_t Point(const size_t) const
For compatibility with other trees; the argument is ignored.
MetricType * metric
The metric used for this tree.
size_t Descendant(const size_t index) const
Get the index of a particular descendant point.
A dual-tree cover tree traverser; see dual_tree_traverser.hpp.
StatisticType stat
The instantiated statistic.
const MatType & Dataset() const
Get a reference to the dataset.
void RemoveNewImplicitNodes()
Take a look at the last child (the most recently created one) and remove any implicit nodes that have...
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.
MatType::elem_type ElemType
The type held by the matrix type.
math::RangeType< ElemType > RangeDistance(const CoverTree &other) const
Return the minimum and maximum distance to another node.
size_t GetNearestChild(const VecType &point, typename std::enable_if_t< IsVector< VecType >::value > *=0)
Return the index of the nearest child node to the given query point.
ElemType FurthestPointDistance() const
Get the distance to the furthest point. This is always 0 for cover trees.
size_t NumDescendants() const
Get the number of descendant points.
ElemType & ParentDistance()
Modify the distance to the parent.
void ComputeDistances(const size_t pointIndex, const arma::Col< size_t > &indices, arma::vec &distances, const size_t pointSetSize)
Fill the vector of distances with the distances between the point specified by pointIndex and each po...
MetricType & Metric() const
Get the instantiated metric.
ElemType base
The base used to construct the tree.
ElemType MinDistance(const CoverTree &other) const
Return the minimum distance to another node.
MatType Mat
So that other classes can access the matrix type.
ElemType MinimumBoundDistance() const
Get the minimum distance from the center to any bound edge (this is the same as furthestDescendantDis...
void Serialize(Archive &ar, const unsigned int)
Serialize the tree.
ElemType Base() const
Get the base.
CoverTree *& Parent()
Modify the parent node.
size_t NumChildren() const
Get the number of children.
int & Scale()
Modify the scale of this node. Be careful...
const StatisticType & Stat() const
Get the statistic for this node.
CoverTree * parent
The parent node (NULL if this is the root of the tree).
ElemType parentDistance
Distance to the parent.
A single-tree cover tree traverser; see single_tree_traverser.hpp for implementation.
int scale
Scale level of the node.
size_t GetFurthestChild(const VecType &point, typename std::enable_if_t< IsVector< VecType >::value > *=0)
Return the index of the furthest child node to the given query point.
std::vector< CoverTree * > children
The list of children; the first is the self-child.
ElemType ParentDistance() const
Get the distance to the parent.
const CoverTree & Child(const size_t index) const
Get a particular child node.
size_t Point() const
Get the index of the point which this node represents.
ElemType furthestDescendantDistance
Distance to the furthest descendant.
Definition of the Range class, which represents a simple range with a lower and upper bound...
size_t SplitNearFar(arma::Col< size_t > &indices, arma::vec &distances, const ElemType bound, const size_t pointSetSize)
Split the given indices and distances into a near and a far set, returning the number of points in th...
size_t numDescendants
The number of descendant points.
bool localDataset
If true, we own the dataset and need to destroy it in the destructor.
size_t DistanceComps() const
size_t PruneFarSet(arma::Col< size_t > &indices, arma::vec &distances, const ElemType bound, const size_t nearSetSize, const size_t pointSetSize)
ElemType & Base()
Modify the base; don't do this, you'll break everything.
A cover tree is a tree specifically designed to speed up nearest-neighbor computation in high-dimensi...
void CreateChildren(arma::Col< size_t > &indices, arma::vec &distances, size_t nearSetSize, size_t &farSetSize, size_t &usedSetSize)
Create the children for this node.
CoverTree & Child(const size_t index)
Modify a particular child node.
CoverTree *& ChildPtr(const size_t index)
CoverTree * Parent() const
Get the parent node.
If value == true, then VecType is some sort of Armadillo vector or subview.
ElemType FurthestDescendantDistance() const
Get the distance from the center of the node to the furthest descendant.
~CoverTree()
Delete this cover tree node and its children.
typename enable_if< B, T >::type enable_if_t
bool localMetric
Whether or not we need to destroy the metric in the destructor.
int Scale() const
Get the scale of this node.
void MoveToUsedSet(arma::Col< size_t > &indices, arma::vec &distances, size_t &nearSetSize, size_t &farSetSize, size_t &usedSetSize, arma::Col< size_t > &childIndices, const size_t childFarSetSize, const size_t childUsedSetSize)