Go to the documentation of this file.
13 #ifndef MLPACK_CORE_TREE_RECTANGLE_TREE_RECTANGLE_TREE_HPP
14 #define MLPACK_CORE_TREE_RECTANGLE_TREE_RECTANGLE_TREE_HPP
18 #include "../hrectbound.hpp"
19 #include "../statistic.hpp"
48 typename StatisticType = EmptyStatistic,
49 typename MatType = arma::mat,
50 typename SplitType = RTreeSplit,
51 typename DescentType = RTreeDescentHeuristic,
52 template<
typename>
class AuxiliaryInformationType =
53 NoAuxiliaryInformation>
57 static_assert(boost::is_same<MetricType, metric::EuclideanDistance>::value,
58 "RectangleTree: MetricType must be metric::EuclideanDistance.");
69 size_t maxNumChildren;
71 size_t minNumChildren;
75 std::vector<RectangleTree*> children;
87 size_t numDescendants;
99 const MatType* dataset;
104 std::vector<size_t> points;
106 AuxiliaryInformationType<RectangleTree> auxiliaryInfo;
111 template<
typename RuleType>
114 template<
typename RuleType>
132 const size_t maxLeafSize = 20,
133 const size_t minLeafSize = 8,
134 const size_t maxNumChildren = 5,
135 const size_t minNumChildren = 2,
136 const size_t firstDataIndex = 0);
153 const size_t maxLeafSize = 20,
154 const size_t minLeafSize = 8,
155 const size_t maxNumChildren = 5,
156 const size_t minNumChildren = 2,
157 const size_t firstDataIndex = 0);
168 const size_t numMaxChildren = 0);
179 const bool deepCopy =
true,
206 template<
typename Archive>
246 void InsertPoint(
const size_t point, std::vector<bool>& relevels);
261 std::vector<bool>& relevels);
280 bool DeletePoint(
const size_t point, std::vector<bool>& relevels);
320 const StatisticType&
Stat()
const {
return stat; }
322 StatisticType&
Stat() {
return stat; }
326 {
return auxiliaryInfo; }
329 {
return auxiliaryInfo; }
360 const MatType&
Dataset()
const {
return *dataset; }
362 MatType&
Dataset() {
return const_cast<MatType&
>(*dataset); }
365 MetricType
Metric()
const {
return MetricType(); }
379 template<
typename VecType>
381 const VecType& point,
388 template<
typename VecType>
390 const VecType& point,
439 return *children[child];
449 return *children[child];
480 size_t Point(
const size_t index)
const {
return points[index]; }
484 size_t&
Point(
const size_t index) {
return points[index]; }
505 template<
typename VecType>
514 template<
typename VecType>
523 template<
typename VecType>
525 const VecType& point,
543 size_t Begin()
const {
return begin; }
548 size_t Count()
const {
return count; }
558 void SplitNode(std::vector<bool>& relevels);
577 friend class boost::serialization::access;
603 std::vector<bool>& relevels,
604 const bool usePoint);
632 template<
typename Archive>
640 #include "rectangle_tree_impl.hpp"
AuxiliaryInformationType< RectangleTree > & AuxiliaryInfo()
Modify the split object of this node.
size_t & Begin()
Modify the index of the beginning point of this subset.
ElemType MinDistance(const VecType &point, typename std::enable_if_t< IsVector< VecType >::value > *=0) const
Calculates minimum bound-to-point distance.
size_t TreeSize() const
Obtains the number of nodes in the tree, starting with this.
bool RemoveNode(const RectangleTree *node, std::vector< bool > &relevels)
Removes a node from the tree.
void serialize(Archive &ar, const unsigned int)
Serialize the tree.
bool IsLeaf() const
Return whether or not this node is a leaf (true if it has no children).
MatType::elem_type ElemType
The element type held by the matrix type.
The core includes that mlpack expects; standard C++ includes and Armadillo.
size_t Descendant(const size_t index) const
Return the index (with reference to the dataset) of a particular descendant of this node.
MatType Mat
So other classes can use TreeType::Mat.
void NullifyData()
Nullify the auxiliary information.
size_t MinNumChildren() const
Return the minimum number of children (in a non-leaf node).
friend DescentType
Give friend access for DescentType.
ElemType MaxDistance(const RectangleTree &other) const
Return the maximum distance to another node.
RectangleTree(const RectangleTree &other, const bool deepCopy=true, RectangleTree *newParent=NULL)
Create a rectangle tree by copying the other tree.
void Center(arma::vec ¢er)
Get the centroid of the node and store it in the given vector.
ElemType MinimumBoundDistance() const
Return the minimum distance from the center to any edge of the bound.
const bound::HRectBound< MetricType > & Bound() const
Return the bound object for this node.
math::RangeType< ElemType > RangeDistance(const VecType &point, typename std::enable_if_t< IsVector< VecType >::value > *=0) const
Return the minimum and maximum distance to another point.
size_t MaxNumChildren() const
Return the maximum number of children (in a non-leaf node).
size_t & NumChildren()
Modify the number of child nodes. Be careful.
ElemType ParentDistance() const
Return the distance from the center of this node to the center of the parent node.
MatType & Dataset()
Modify the dataset which the tree is built on. Be careful!
RectangleTree *& Parent()
Modify the parent of this node.
ElemType FurthestPointDistance() const
Return the furthest distance to a point held in this node.
void InsertPoint(const size_t point)
Inserts a point into the tree.
RectangleTree(const MatType &data, const size_t maxLeafSize=20, const size_t minLeafSize=8, const size_t maxNumChildren=5, const size_t minNumChildren=2, const size_t firstDataIndex=0)
Construct this as the root node of a rectangle type tree using the given dataset.
friend AuxiliaryInformation
Give friend access for AuxiliaryInformationType.
size_t & Count()
Modify the number of points in this subset.
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.
size_t & MaxLeafSize()
Modify the maximum leaf size.
size_t & MaxNumChildren()
Modify the maximum number of children (in a non-leaf node).
size_t & Point(const size_t index)
Modify the index of a particular point in this node.
Linear algebra utility functions, generally performed on matrices or vectors.
A single traverser for rectangle type trees.
typename enable_if< B, T >::type enable_if_t
MetricType Metric() const
Get the metric which the tree uses.
bool ShrinkBoundForPoint(const arma::vec &point)
Shrink the bound object of this node for the removal of a point.
RectangleTree & Child(const size_t child)
Modify the specified child.
math::RangeType< ElemType > RangeDistance(const RectangleTree &other) const
Return the minimum and maximum distance to another node.
size_t GetFurthestChild(const RectangleTree &queryNode)
Return the index of the furthest child node to the given query node.
math::RangeType< ElemType > RangeDistance(const HRectBound &other) const
Calculates minimum and maximum bound-to-bound distance.
size_t Begin() const
Return the index of the beginning point of this subset.
const StatisticType & Stat() const
Return the statistic object for this node.
const MatType & Dataset() const
Get the dataset which the tree is built on.
ElemType FurthestDescendantDistance() const
Return the furthest possible descendant distance.
const RectangleTree * FindByBeginCount(size_t begin, size_t count) const
Find a node in this tree by its begin and count (const).
void Center(arma::Col< ElemType > ¢er) const
Calculates the center of the range, placing it into the given vector.
RectangleTree * FindByBeginCount(size_t begin, size_t count)
Find a node in this tree by its begin and count.
ElemType MaxDistance(const VecType &point, typename std::enable_if_t< IsVector< VecType >::value > *=0) const
Calculates maximum bound-to-point squared distance.
bool DeletePoint(const size_t point, std::vector< bool > &relevels)
Deletes a point from the tree, updates the bounding rectangle, tracking levels.
ElemType MaxDistance(const VecType &point, typename std::enable_if_t< IsVector< VecType >::value > *=0) const
Return the maximum distance to another point.
ElemType & ParentDistance()
Modify the distance from the center of this node to the center of the parent node.
A rectangle type tree tree, such as an R-tree or X-tree.
void SoftDelete()
Delete this node of the tree, but leave the stuff contained in it intact.
size_t GetNearestChild(const RectangleTree &queryNode)
Return the index of the nearest child node to the given query node.
RectangleTree(RectangleTree *parentNode, const size_t numMaxChildren=0)
Construct this as an empty node with the specified parent.
size_t & MinLeafSize()
Modify the minimum leaf size.
friend SplitType
Give friend access for SplitType.
RectangleTree(Archive &ar, const typename std::enable_if_t< Archive::is_loading::value > *=0)
Construct the tree from a boost::serialization archive.
size_t Point(const size_t index) const
Return the index (with reference to the dataset) of a particular point in this node.
size_t NumChildren() const
Return the number of child nodes. (One level beneath this one only.)
size_t NumDescendants() const
Return the number of descendants of this node.
A dual tree traverser for rectangle type trees.
ElemType MinDistance(const RectangleTree &other) const
Return the minimum distance to another node.
LMetric< 2, true > EuclideanDistance
The Euclidean (L2) distance.
size_t MaxLeafSize() const
Return the maximum leaf size.
void InsertPoint(const size_t point, std::vector< bool > &relevels)
Inserts a point into the tree, tracking which levels have been inserted into.
AuxiliaryInformationType< RectangleTree > AuxiliaryInformation
The auxiliary information type held by the tree.
RectangleTree()
A default constructor.
RectangleTree * Parent() const
Gets the parent of this node.
size_t Count() const
Return the number of points in this subset.
const AuxiliaryInformationType< RectangleTree > & AuxiliaryInfo() const
Return the auxiliary information object of this node.
void CondenseTree(const arma::vec &point, std::vector< bool > &relevels, const bool usePoint)
Condense the bounding rectangles for this node based on the removal of the point specified by the arm...
void InsertNode(RectangleTree *node, const size_t level, std::vector< bool > &relevels)
Inserts a node into the tree, tracking which levels have been inserted into.
bool ShrinkBoundForBound(const bound::HRectBound< MetricType > &changedBound)
Shrink the bound object of this node for the removal of a child node.
~RectangleTree()
Deletes this node, deallocating the memory for the children and calling their destructors in turn.
size_t & MinNumChildren()
Modify the minimum number of children (in a non-leaf node).
size_t NumPoints() const
Return the number of points in this node (returns 0 if this node is not a leaf).
StatisticType & Stat()
Modify the statistic object for this node.
ElemType MinWidth() const
Get the minimum width of the bound.
size_t MinLeafSize() const
Return the minimum leaf size.
RectangleTree(RectangleTree &&other)
Create a rectangle tree by moving the other tree.
RectangleTree(MatType &&data, const size_t maxLeafSize=20, const size_t minLeafSize=8, const size_t maxNumChildren=5, const size_t minNumChildren=2, const size_t firstDataIndex=0)
Construct this as the root node of a rectangle tree type using the given dataset, and taking ownershi...
ElemType MinDistance(const VecType &point, typename std::enable_if_t< IsVector< VecType >::value > *=0) const
Return the minimum distance to another point.
RectangleTree * ExactClone()
Make an exact copy of this node, pointers and everything.
RectangleTree & operator=(const RectangleTree &other)
Copy the given rectangle tree.
size_t TreeDepth() const
Obtains the number of levels below this node in the tree, starting with this.
bound::HRectBound< MetricType > & Bound()
Modify the bound object for this node.
RectangleTree & Child(const size_t child) const
Get the specified child.
bool DeletePoint(const size_t point)
Deletes a point from the treeand, updates the bounding rectangle.
RectangleTree & operator=(RectangleTree &&other)
Take ownership of the given rectangle tree.
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.
If value == true, then VecType is some sort of Armadillo vector or subview.