A binary space partitioning tree, such as a kd-tree or a ball tree.
class DualTreeTraverser
A dual-tree traverser for binary space trees; see dual_tree_traverser.hpp. class SingleTreeTraverser
A single-tree traverser for binary space trees; see single_tree_traverser.hpp for implementation.
typedef MatType Mat
So other classes can use TreeType::Mat.
BinarySpaceTree (MatType &data, const size_t maxLeafSize=20)
Construct this as the root node of a binary space tree using the given dataset. BinarySpaceTree (MatType &data, std::vector< size_t > &oldFromNew, const size_t maxLeafSize=20)
Construct this as the root node of a binary space tree using the given dataset. BinarySpaceTree (MatType &data, std::vector< size_t > &oldFromNew, std::vector< size_t > &newFromOld, const size_t maxLeafSize=20)
Construct this as the root node of a binary space tree using the given dataset. BinarySpaceTree (MatType &data, const size_t begin, const size_t count, BinarySpaceTree *parent=NULL, const size_t maxLeafSize=20)
Construct this node on a subset of the given matrix, starting at column begin and using count points. BinarySpaceTree (MatType &data, const size_t begin, const size_t count, std::vector< size_t > &oldFromNew, BinarySpaceTree *parent=NULL, const size_t maxLeafSize=20)
Construct this node on a subset of the given matrix, starting at column begin_in and using count_in points. BinarySpaceTree (MatType &data, const size_t begin, const size_t count, std::vector< size_t > &oldFromNew, std::vector< size_t > &newFromOld, BinarySpaceTree *parent=NULL, const size_t maxLeafSize=20)
Construct this node on a subset of the given matrix, starting at column begin_in and using count_in points. BinarySpaceTree (const BinarySpaceTree &other)
Create a binary space tree by copying the other tree. ~BinarySpaceTree ()
Deletes this node, deallocating the memory for the children and calling their destructors in turn. size_t Begin () const
Return the index of the beginning point of this subset. size_t & Begin ()
Modify the index of the beginning point of this subset. const BoundType & Bound () const
Return the bound object for this node. BoundType & Bound ()
Return the bound object for this node. void Centroid (arma::vec ¢roid)
Get the centroid of the node and store it in the given vector. BinarySpaceTree & Child (const size_t child) const
Return the specified child (0 will be left, 1 will be right). size_t Count () const
Return the number of points in this subset. size_t & Count ()
Modify the number of points in this subset. const MatType & Dataset () const
Get the dataset which the tree is built on. MatType & Dataset ()
Modify the dataset which the tree is built on. Be careful! size_t Descendant (const size_t index) const
Return the index (with reference to the dataset) of a particular descendant of this node. size_t End () const
Gets the index one beyond the last index in the subset. size_t ExtendTree (const size_t level)
Fills the tree to the specified level. const BinarySpaceTree * FindByBeginCount (size_t begin, size_t count) const
Find a node in this tree by its begin and count (const). BinarySpaceTree * FindByBeginCount (size_t begin, size_t count)
Find a node in this tree by its begin and count. double FurthestDescendantDistance () const
Return the furthest possible descendant distance. double FurthestPointDistance () const
Return the furthest distance to a point held in this node. size_t GetSplitDimension () const
Returns the dimension this parent's children are split on. bool IsLeaf () const
Return whether or not this node is a leaf (true if it has no children). BinarySpaceTree * Left () const
Gets the left child of this node. BinarySpaceTree *& Left ()
Modify the left child of this node. double MaxDistance (const BinarySpaceTree *other) const
Return the maximum distance to another node. template<typename VecType > double MaxDistance (const VecType &point, typename boost::enable_if< IsVector< VecType > >::type *=0) const
Return the maximum distance to another point. size_t MaxLeafSize () const
Return the max leaf size. size_t & MaxLeafSize ()
Modify the max leaf size. BoundType::MetricType Metric () const
Get the metric which the tree uses. double MinDistance (const BinarySpaceTree *other) const
Return the minimum distance to another node. template<typename VecType > double MinDistance (const VecType &point, typename boost::enable_if< IsVector< VecType > >::type *=0) const
Return the minimum distance to another point. double MinimumBoundDistance () const
Return the minimum distance from the center of the node to any bound edge. size_t NumChildren () const
Return the number of children in this node. size_t NumDescendants () const
Return the number of descendants of this node. size_t NumPoints () const
Return the number of points in this node (0 if not a leaf). BinarySpaceTree * Parent () const
Gets the parent of this node. BinarySpaceTree *& Parent ()
Modify the parent of this node. double ParentDistance () const
Return the distance from the center of this node to the center of the parent node. double & ParentDistance ()
Modify the distance from the center of this node to the center of the parent node. size_t Point (const size_t index) const
Return the index (with reference to the dataset) of a particular point in this node. math::Range RangeDistance (const BinarySpaceTree *other) const
Return the minimum and maximum distance to another node. template<typename VecType > math::Range RangeDistance (const VecType &point, typename boost::enable_if< IsVector< VecType > >::type *=0) const
Return the minimum and maximum distance to another point. BinarySpaceTree * Right () const
Gets the right child of this node. BinarySpaceTree *& Right ()
Modify the right child of this node. size_t SplitDimension () const
Get the split dimension for this node. size_t & SplitDimension ()
Modify the split dimension for this node. const StatisticType & Stat () const
Return the statistic object for this node. StatisticType & Stat ()
Return the statistic object for this node. std::string ToString () const
Returns a string representation of this object. size_t TreeDepth () const
Obtains the number of levels below this node in the tree, starting with this. size_t TreeSize () const
Obtains the number of nodes in the tree, starting with this.
static bool HasSelfChildren ()
Returns false: this tree type does not have self children.
BinarySpaceTree (const size_t begin, const size_t count, BoundType bound, StatisticType stat, const int maxLeafSize=20)
Private copy constructor, available only to fill (pad) the tree to a specified level. BinarySpaceTree * CopyMe ()
void SplitNode (MatType &data)
Splits the current node, assigning its left and right children recursively. void SplitNode (MatType &data, std::vector< size_t > &oldFromNew)
Splits the current node, assigning its left and right children recursively.
size_t begin
The index of the first point in the dataset contained in this node (and its children). BoundType bound
The bound object for this node. size_t count
The number of points of the dataset contained in this node (and its children). MatType & dataset
The dataset. double furthestDescendantDistance
The worst possible distance to the furthest descendant, cached to speed things up. BinarySpaceTree * left
The left child node. size_t maxLeafSize
The max leaf size. double minimumBoundDistance
The minimum distance from the center to any edge of the bound. BinarySpaceTree * parent
The parent node (NULL if this is the root of the tree). double parentDistance
The distance from the centroid of this node to the centroid of the parent. BinarySpaceTree * right
The right child node. size_t splitDimension
The dimension this node split on if it is a parent. StatisticType stat
Any extra data contained in the node.
A binary space partitioning tree, such as a KD-tree or a ball tree.
Once the bound and type of dataset is defined, the tree will construct itself. Call the constructor with the dataset to build the tree on, and the entire tree will be built.
This particular tree does not allow growth, so you cannot add or delete nodes from it. If you need to add or delete a node, the better procedure is to rebuild the tree entirely.
This tree does take one runtime parameter in the constructor, which is the max leaf size to be used.
Template Parameters:
BoundType The bound used for each node. The valid types of bounds and the necessary skeleton interface for this class can be found in bounds/.
StatisticType Extra data contained in the node. See statistic.hpp for the necessary skeleton interface.
MatType The dataset class.
SplitType The class that partitions the dataset/points at a particular node into two parts. Its definition decides the way this split is done.
Definition at line 59 of file binary_space_tree.hpp.
So other classes can use TreeType::Mat.
Definition at line 94 of file binary_space_tree.hpp.
Construct this as the root node of a binary space tree using the given dataset. This will modify the ordering of the points in the dataset!
Parameters:
data Dataset to create tree from. This will be modified!
maxLeafSize Size of each leaf in the tree.
Referenced by mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::CopyMe().
Construct this as the root node of a binary space tree using the given dataset. This will modify the ordering of points in the dataset! A mapping of the old point indices to the new point indices is filled.
Parameters:
data Dataset to create tree from. This will be modified!
oldFromNew Vector which will be filled with the old positions for each new point.
maxLeafSize Size of each leaf in the tree.
Construct this as the root node of a binary space tree using the given dataset. This will modify the ordering of points in the dataset! A mapping of the old point indices to the new point indices is filled, as well as a mapping of the new point indices to the old point indices.
Parameters:
data Dataset to create tree from. This will be modified!
oldFromNew Vector which will be filled with the old positions for each new point.
newFromOld Vector which will be filled with the new positions for each old point.
maxLeafSize Size of each leaf in the tree.
Construct this node on a subset of the given matrix, starting at column begin and using count points. The ordering of that subset of points will be modified! This is used for recursive tree-building by the other constructors which don't specify point indices.
Parameters:
data Dataset to create tree from. This will be modified!
begin Index of point to start tree construction with.
count Number of points to use to construct tree.
maxLeafSize Size of each leaf in the tree.
Construct this node on a subset of the given matrix, starting at column begin_in and using count_in points. The ordering of that subset of points will be modified! This is used for recursive tree-building by the other constructors which don't specify point indices.
A mapping of the old point indices to the new point indices is filled, but it is expected that the vector is already allocated with size greater than or equal to (begin_in + count_in), and if that is not true, invalid memory reads (and writes) will occur.
Parameters:
data Dataset to create tree from. This will be modified!
begin Index of point to start tree construction with.
count Number of points to use to construct tree.
oldFromNew Vector which will be filled with the old positions for each new point.
maxLeafSize Size of each leaf in the tree.
Construct this node on a subset of the given matrix, starting at column begin_in and using count_in points. The ordering of that subset of points will be modified! This is used for recursive tree-building by the other constructors which don't specify point indices.
A mapping of the old point indices to the new point indices is filled, as well as a mapping of the new point indices to the old point indices. It is expected that the vector is already allocated with size greater than or equal to (begin_in + count_in), and if that is not true, invalid memory reads (and writes) will occur.
Parameters:
data Dataset to create tree from. This will be modified!
begin Index of point to start tree construction with.
count Number of points to use to construct tree.
oldFromNew Vector which will be filled with the old positions for each new point.
newFromOld Vector which will be filled with the new positions for each old point.
maxLeafSize Size of each leaf in the tree.
Create a binary space tree by copying the other tree. Be careful! This can take a long time and use a lot of memory.
Parameters:
other Tree to be replicated.
Deletes this node, deallocating the memory for the children and calling their destructors in turn. This will invalidate any pointers or references to any nodes which are children of this one.
Private copy constructor, available only to fill (pad) the tree to a specified level.
Definition at line 460 of file binary_space_tree.hpp.
Return the index of the beginning point of this subset.
Definition at line 438 of file binary_space_tree.hpp.
References mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::begin.
Modify the index of the beginning point of this subset.
Definition at line 440 of file binary_space_tree.hpp.
References mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::begin.
Return the bound object for this node.
Definition at line 260 of file binary_space_tree.hpp.
References mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::bound.
Referenced by mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::MaxDistance(), mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::MinDistance(), and mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::RangeDistance().
Return the bound object for this node.
Definition at line 262 of file binary_space_tree.hpp.
References mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::bound.
Get the centroid of the node and store it in the given vector.
Definition at line 309 of file binary_space_tree.hpp.
References mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::bound.
Return the specified child (0 will be left, 1 will be right). If the index is greater than 1, this will return the right child.
Parameters:
child Index of child to return.
Definition at line 473 of file binary_space_tree.hpp.
References mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::begin, mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::BinarySpaceTree(), mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::bound, mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::count, mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::maxLeafSize, and mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::stat.
Return the number of points in this subset.
Definition at line 448 of file binary_space_tree.hpp.
References mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::count.
Modify the number of points in this subset.
Definition at line 450 of file binary_space_tree.hpp.
References mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::count.
Get the dataset which the tree is built on.
Definition at line 301 of file binary_space_tree.hpp.
References mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::dataset.
Modify the dataset which the tree is built on. Be careful!
Definition at line 303 of file binary_space_tree.hpp.
References mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::dataset.
Return the index (with reference to the dataset) of a particular descendant of this node. The index should be greater than zero but less than the number of descendants.
Parameters:
index Index of the descendant.
Gets the index one beyond the last index in the subset.
Fills the tree to the specified level.
Find a node in this tree by its begin and count (const). Every node is uniquely identified by these two numbers. This is useful for communicating position over the network, when pointers would be invalid.
Parameters:
begin The begin() of the node to find.
count The count() of the node to find.
Returns:
The found node, or NULL if not found.
Find a node in this tree by its begin and count. Every node is uniquely identified by these two numbers. This is useful for communicating position over the network, when pointers would be invalid.
Parameters:
begin The begin() of the node to find.
count The count() of the node to find.
Returns:
The found node, or NULL if not found.
Return the furthest possible descendant distance. This returns the maximum distance from the centroid to the edge of the bound and not the empirical quantity which is the actual furthest descendant distance. So the actual furthest descendant distance may be less than what this method returns (but it will never be greater than this).
Return the furthest distance to a point held in this node. If this is not a leaf node, then the distance is 0 because the node holds no points.
Returns the dimension this parent's children are split on.
Returns false: this tree type does not have self children.
Definition at line 453 of file binary_space_tree.hpp.
Return whether or not this node is a leaf (true if it has no children).
Gets the left child of this node.
Definition at line 281 of file binary_space_tree.hpp.
References mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::left.
Modify the left child of this node.
Definition at line 283 of file binary_space_tree.hpp.
References mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::left.
Return the maximum distance to another node.
Definition at line 383 of file binary_space_tree.hpp.
References mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::bound, and mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::Bound().
Return the maximum distance to another point.
Definition at line 405 of file binary_space_tree.hpp.
References mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::bound.
Return the max leaf size.
Definition at line 273 of file binary_space_tree.hpp.
References mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::maxLeafSize.
Modify the max leaf size.
Definition at line 275 of file binary_space_tree.hpp.
References mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::maxLeafSize.
Get the metric which the tree uses.
Definition at line 306 of file binary_space_tree.hpp.
References mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::bound.
Return the minimum distance to another node.
Definition at line 377 of file binary_space_tree.hpp.
References mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::bound, and mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::Bound().
Return the minimum distance to another point.
Definition at line 396 of file binary_space_tree.hpp.
References mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::bound.
Return the minimum distance from the center of the node to any bound edge.
Return the number of children in this node.
Return the number of descendants of this node. For a non-leaf in a binary space tree, this is the number of points at the descendant leaves. For a leaf, this is the number of points in the leaf.
Return the number of points in this node (0 if not a leaf).
Gets the parent of this node.
Definition at line 291 of file binary_space_tree.hpp.
References mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::parent.
Modify the parent of this node.
Definition at line 293 of file binary_space_tree.hpp.
References mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::parent.
Return the distance from the center of this node to the center of the parent node.
Definition at line 334 of file binary_space_tree.hpp.
References mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::parentDistance.
Modify the distance from the center of this node to the center of the parent node.
Definition at line 337 of file binary_space_tree.hpp.
References mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::parentDistance.
Return the index (with reference to the dataset) of a particular point in this node. This will happily return invalid indices if the given index is greater than the number of points in this node (obtained with NumPoints()) -- be careful.
Parameters:
index Index of point for which a dataset index is wanted.
Return the minimum and maximum distance to another node.
Definition at line 389 of file binary_space_tree.hpp.
References mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::bound, and mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::Bound().
Return the minimum and maximum distance to another point.
Definition at line 415 of file binary_space_tree.hpp.
References mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::bound.
Gets the right child of this node.
Definition at line 286 of file binary_space_tree.hpp.
References mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::right.
Modify the right child of this node.
Definition at line 288 of file binary_space_tree.hpp.
References mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::right.
Get the split dimension for this node.
Definition at line 296 of file binary_space_tree.hpp.
References mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::splitDimension.
Modify the split dimension for this node.
Definition at line 298 of file binary_space_tree.hpp.
References mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::splitDimension.
Splits the current node, assigning its left and right children recursively.
Parameters:
data Dataset which we are using.
Splits the current node, assigning its left and right children recursively. Also returns a list of the changed indices.
Parameters:
data Dataset which we are using.
oldFromNew Vector holding permuted indices.
Return the statistic object for this node.
Definition at line 265 of file binary_space_tree.hpp.
References mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::stat.
Return the statistic object for this node.
Definition at line 267 of file binary_space_tree.hpp.
References mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::stat.
Returns a string representation of this object.
Obtains the number of levels below this node in the tree, starting with this.
Obtains the number of nodes in the tree, starting with this.
The index of the first point in the dataset contained in this node (and its children).
Definition at line 70 of file binary_space_tree.hpp.
Referenced by mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::Begin(), and mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::CopyMe().
The bound object for this node.
Definition at line 77 of file binary_space_tree.hpp.
Referenced by mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::Bound(), mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::Centroid(), mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::CopyMe(), mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::MaxDistance(), mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::Metric(), mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::MinDistance(), and mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::RangeDistance().
The number of points of the dataset contained in this node (and its children).
Definition at line 73 of file binary_space_tree.hpp.
Referenced by mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::CopyMe(), and mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::Count().
The dataset.
Definition at line 90 of file binary_space_tree.hpp.
Referenced by mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::Dataset().
The worst possible distance to the furthest descendant, cached to speed things up.
Definition at line 86 of file binary_space_tree.hpp.
The left child node.
Definition at line 63 of file binary_space_tree.hpp.
Referenced by mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::Left().
The max leaf size.
Definition at line 75 of file binary_space_tree.hpp.
Referenced by mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::CopyMe(), and mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::MaxLeafSize().
The minimum distance from the center to any edge of the bound.
Definition at line 88 of file binary_space_tree.hpp.
The parent node (NULL if this is the root of the tree).
Definition at line 67 of file binary_space_tree.hpp.
Referenced by mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::Parent().
The distance from the centroid of this node to the centroid of the parent.
Definition at line 83 of file binary_space_tree.hpp.
Referenced by mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::ParentDistance().
The right child node.
Definition at line 65 of file binary_space_tree.hpp.
Referenced by mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::Right().
The dimension this node split on if it is a parent.
Definition at line 81 of file binary_space_tree.hpp.
Referenced by mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::SplitDimension().
Any extra data contained in the node.
Definition at line 79 of file binary_space_tree.hpp.
Referenced by mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::CopyMe(), and mlpack::tree::BinarySpaceTree< BoundType, StatisticType, MatType, SplitType >::Stat().
Generated automatically by Doxygen for MLPACK from the source code.