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,
192 const ElemType parentDistance,
193 arma::Col<size_t>& indices,
194 arma::vec& distances,
198 MetricType& metric = NULL);
218 const size_t pointIndex,
221 const ElemType parentDistance,
222 const ElemType furthestDescendantDistance,
223 MetricType* metric = NULL);
244 template<
typename Archive>
256 template<
typename RuleType>
260 template<
typename RuleType>
263 template<
typename RuleType>
267 const MatType&
Dataset()
const {
return *dataset; }
270 size_t Point()
const {
return point; }
272 size_t Point(
const size_t)
const {
return point; }
274 bool IsLeaf()
const {
return (children.size() == 0); }
288 const std::vector<CoverTree*>&
Children()
const {
return children; }
290 std::vector<CoverTree*>&
Children() {
return children; }
304 ElemType
Base()
const {
return base; }
306 ElemType&
Base() {
return base; }
309 const StatisticType&
Stat()
const {
return stat; }
311 StatisticType&
Stat() {
return stat; }
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;
402 {
return furthestDescendantDistance; }
414 center = arma::vec(dataset->col(point));
418 MetricType&
Metric()
const {
return *metric; }
422 const MatType* dataset;
426 std::vector<CoverTree*> children;
434 size_t numDescendants;
438 ElemType parentDistance;
440 ElemType furthestDescendantDistance;
451 void CreateChildren(arma::Col<size_t>& indices,
452 arma::vec& distances,
455 size_t& usedSetSize);
468 void ComputeDistances(
const size_t pointIndex,
469 const arma::Col<size_t>& indices,
470 arma::vec& distances,
471 const size_t pointSetSize);
486 size_t SplitNearFar(arma::Col<size_t>& indices,
487 arma::vec& distances,
488 const ElemType bound,
489 const size_t pointSetSize);
510 size_t SortPointSet(arma::Col<size_t>& indices,
511 arma::vec& distances,
512 const size_t childFarSetSize,
513 const size_t childUsedSetSize,
514 const size_t farSetSize);
516 void MoveToUsedSet(arma::Col<size_t>& indices,
517 arma::vec& distances,
521 arma::Col<size_t>& childIndices,
522 const size_t childFarSetSize,
523 const size_t childUsedSetSize);
524 size_t PruneFarSet(arma::Col<size_t>& indices,
525 arma::vec& distances,
526 const ElemType bound,
527 const size_t nearSetSize,
528 const size_t pointSetSize);
534 void RemoveNewImplicitNodes();
546 friend class boost::serialization::access;
552 template<
typename Archive>
553 void serialize(Archive& ar,
const unsigned int );
559 size_t distanceComps;
566 #include "cover_tree_impl.hpp" 569 #include "../cover_tree.hpp" 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.
size_t DistanceComps() const
MatType Mat
So that other classes can access the matrix type.
void Center(arma::vec ¢er) const
Get the center of the node and store it in the given vector.
A dual-tree cover tree traverser; see dual_tree_traverser.hpp.
typename enable_if< B, T >::type enable_if_t
ElemType Base() const
Get the base.
size_t Point() const
Get the index of the point which this node represents.
MatType::elem_type ElemType
The type held by the matrix type.
ElemType MaxDistance(const CoverTree &other) const
Return the maximum distance to another node.
The core includes that mlpack expects; standard C++ includes and Armadillo.
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.
ElemType & FurthestDescendantDistance()
Modify the distance from the center of the node to the furthest descendant.
const std::vector< CoverTree * > & Children() const
Get the children.
int & Scale()
Modify the scale of this node. Be careful...
StatisticType & Stat()
Modify the statistic for this node.
CoverTree()
A default constructor.
CoverTree *& Parent()
Modify the parent node.
CoverTree * Parent() const
Get the parent node.
std::vector< CoverTree * > & Children()
Modify the children manually (maybe not a great idea).
int Scale() const
Get the scale of this node.
~CoverTree()
Delete this cover tree node and its children.
const StatisticType & Stat() const
Get the statistic for this node.
void serialize(Archive &ar, const unsigned int)
Serialize the tree.
CoverTree *& ChildPtr(const size_t index)
A single-tree cover tree traverser; see single_tree_traverser.hpp for implementation.
ElemType ParentDistance() const
Get the distance to the parent.
ElemType MinDistance(const CoverTree &other) const
Return the minimum distance to another node.
size_t Point(const size_t) const
For compatibility with other trees; the argument is ignored.
const MatType & Dataset() const
Get a reference to the dataset.
size_t NumChildren() const
Get the number of children.
ElemType FurthestPointDistance() const
Get the distance to the furthest point. This is always 0 for cover trees.
ElemType & Base()
Modify the base; don't do this, you'll break everything.
Definition of the Range class, which represents a simple range with a lower and upper bound...
CoverTree & Child(const size_t index)
Modify a particular child node.
ElemType MinimumBoundDistance() const
Get the minimum distance from the center to any bound edge (this is the same as furthestDescendantDis...
MetricType & Metric() const
Get the instantiated metric.
size_t Descendant(const size_t index) const
Get the index of a particular descendant point.
ElemType FurthestDescendantDistance() const
Get the distance from the center of the node to the furthest descendant.
math::RangeType< ElemType > RangeDistance(const CoverTree &other) const
Return the minimum and maximum distance to another node.
A cover tree is a tree specifically designed to speed up nearest-neighbor computation in high-dimensi...
ElemType & ParentDistance()
Modify the distance to the parent.
const CoverTree & Child(const size_t index) const
Get a particular child node.
If value == true, then VecType is some sort of Armadillo vector or subview.
size_t NumDescendants() const
Get the number of descendant points.