14 #ifndef __MLPACK_CORE_TREE_COVER_TREE_COVER_TREE_HPP 15 #define __MLPACK_CORE_TREE_COVER_TREE_COVER_TREE_HPP 19 #include "../statistic.hpp" 94 template<
typename MetricType = metric::LMetric<2, true>,
95 typename StatisticType = EmptyStatistic,
96 typename MatType = arma::mat,
97 typename RootPo
intPolicy = FirstPo
intIsRoot>
114 const double base = 2.0,
115 MetricType*
metric = NULL);
128 const double base = 2.0);
138 const double base = 2.0);
150 const double base = 2.0);
185 const size_t pointIndex,
189 arma::Col<size_t>& indices,
190 arma::vec& distances,
194 MetricType&
metric = NULL);
214 const size_t pointIndex,
219 MetricType*
metric = NULL);
232 template<
typename Archive>
235 const typename boost::enable_if<typename Archive::is_loading>::type* = 0);
244 template<
typename RuleType>
248 template<
typename RuleType>
251 template<
typename RuleType>
313 double MinDistance(
const arma::vec& other,
const double distance)
const;
327 double MaxDistance(
const arma::vec& other,
const double distance)
const;
413 arma::vec& distances,
416 size_t& usedSetSize);
430 const arma::Col<size_t>& indices,
431 arma::vec& distances,
432 const size_t pointSetSize);
448 arma::vec& distances,
450 const size_t pointSetSize);
472 arma::vec& distances,
473 const size_t childFarSetSize,
474 const size_t childUsedSetSize,
475 const size_t farSetSize);
478 arma::vec& distances,
482 arma::Col<size_t>& childIndices,
483 const size_t childFarSetSize,
484 const size_t childUsedSetSize);
486 arma::vec& distances,
488 const size_t nearSetSize,
489 const size_t pointSetSize);
507 friend class boost::serialization::access;
513 template<
typename Archive>
514 void Serialize(Archive& ar,
const unsigned int );
527 #include "cover_tree_impl.hpp" 530 #include "../cover_tree.hpp"
size_t point
Index of the point in the matrix which this node represents.
const MatType * dataset
Reference to the matrix which this tree is built on.
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 DistanceComps() const
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 | ...
const StatisticType & Stat() const
Get the statistic for this node.
MetricType * metric
The metric used for this tree.
int Scale() const
Get the scale of this node.
MetricType & Metric() const
Get the instantiated metric.
A dual-tree cover tree traverser; see dual_tree_traverser.hpp.
StatisticType stat
The instantiated statistic.
void RemoveNewImplicitNodes()
Take a look at the last child (the most recently created one) and remove any implicit nodes that have...
double base
The base used to construct the tree.
Linear algebra utility functions, generally performed on matrices or vectors.
void Center(arma::vec ¢er) const
Get the center of the node and store it in the given vector.
double parentDistance
Distance to the parent.
size_t NumDescendants() const
Get the number of descendant points.
double furthestDescendantDistance
Distance to the furthest descendant.
const std::vector< CoverTree * > & Children() const
Get the children.
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...
const MatType & Dataset() const
Get a reference to the dataset.
double FurthestDescendantDistance() const
Get the distance from the center of the node to the furthest descendant.
void Serialize(Archive &ar, const unsigned int)
Serialize the tree.
double & ParentDistance()
Modify the distance to the parent.
double FurthestPointDistance() const
Get the distance to the furthest point. This is always 0 for cover trees.
double Base() const
Get the base.
CoverTree *& Parent()
Modify the parent node.
Simple real-valued range.
int & Scale()
Modify the scale of this node. Be careful...
size_t PruneFarSet(arma::Col< size_t > &indices, arma::vec &distances, const double bound, const size_t nearSetSize, const size_t pointSetSize)
double MinDistance(const CoverTree *other) const
Return the minimum distance to another node.
CoverTree * parent
The parent node (NULL if this is the root of the tree).
double MaxDistance(const CoverTree *other) const
Return the maximum distance to another node.
double MinimumBoundDistance() const
Get the minimum distance from the center to any bound edge (this is the same as furthestDescendantDis...
size_t Point(const size_t) const
For compatibility with other trees; the argument is ignored.
math::Range RangeDistance(const CoverTree *other) const
Return the minimum and maximum distance to another node.
Include all of the base components required to write MLPACK methods, and the main MLPACK Doxygen docu...
A single-tree cover tree traverser; see single_tree_traverser.hpp for implementation.
int scale
Scale level of the node.
size_t Point() const
Get the index of the point which this node represents.
const CoverTree & Child(const size_t index) const
Get a particular child node.
std::vector< CoverTree * > children
The list of children; the first is the self-child.
double ParentDistance() const
Get the distance to the parent.
double & Base()
Modify the base; don't do this, you'll break everything.
static bool HasSelfChildren()
Returns true: this tree does have self-children.
double & FurthestDescendantDistance()
Modify the distance from the center of the node to the furthest descendant.
size_t SplitNearFar(arma::Col< size_t > &indices, arma::vec &distances, const double 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 NumChildren() const
Get the number of children.
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)
size_t Descendant(const size_t index) const
Get the index of a particular descendant point.
~CoverTree()
Delete this cover tree node and its children.
bool localMetric
Whether or not we need to destroy the metric in the destructor.
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)
CoverTree * Parent() const
Get the parent node.