12 #ifndef MLPACK_CORE_TREE_OCTREE_OCTREE_HPP 13 #define MLPACK_CORE_TREE_OCTREE_OCTREE_HPP 16 #include "../hrectbound.hpp" 17 #include "../statistic.hpp" 23 typename StatisticType = EmptyStatistic,
24 typename MatType = arma::mat>
34 template<
typename RuleType>
38 template<
typename RuleType>
76 Octree(
const MatType& data,
const size_t maxLeafSize = 20);
90 Octree(
const MatType& data,
91 std::vector<size_t>& oldFromNew,
92 const size_t maxLeafSize = 20);
109 Octree(
const MatType& data,
110 std::vector<size_t>& oldFromNew,
111 std::vector<size_t>& newFromOld,
112 const size_t maxLeafSize = 20);
122 Octree(MatType&& data,
const size_t maxLeafSize = 20);
137 std::vector<size_t>& oldFromNew,
138 const size_t maxLeafSize = 20);
156 std::vector<size_t>& oldFromNew,
157 std::vector<size_t>& newFromOld,
158 const size_t maxLeafSize = 20);
176 const arma::vec& center,
178 const size_t maxLeafSize = 20);
203 std::vector<size_t>& oldFromNew,
204 const arma::vec& center,
206 const size_t maxLeafSize = 20);
228 template<
typename Archive>
260 MetricType
Metric()
const {
return MetricType(); }
266 template<
typename VecType>
268 const VecType& point,
275 template<
typename VecType>
277 const VecType& point,
326 const Octree&
Child(
const size_t child)
const {
return *children[child]; }
357 size_t Point(
const size_t index)
const;
367 template<
typename VecType>
369 const VecType& point,
372 template<
typename VecType>
374 const VecType& point,
377 template<
typename VecType>
379 const VecType& point,
386 template<
typename Archive>
387 void Serialize(Archive& ar,
const unsigned int );
399 friend class boost::serialization::access;
412 const size_t maxLeafSize);
425 std::vector<size_t>& oldFromNew,
426 const size_t maxLeafSize);
441 template<
typename VecType>
453 #include "octree_impl.hpp" StatisticType & Stat()
Modify the statistic object for this node.
std::vector< Octree * > children
The children held by this node.
A dual-tree traverser; see dual_tree_traverser.hpp.
bound::HRectBound< MetricType > & Bound()
Modify the bound object for this node.
SplitInfo(const size_t d, const arma::vec &c)
Create the SplitInfo object.
ElemType MinimumBoundDistance() const
Return the minimum distance from the center of the node to any bound edge.
Linear algebra utility functions, generally performed on matrices or vectors.
const Octree & Child(const size_t child) const
Return the specified child.
LMetric< 2, true > EuclideanDistance
The Euclidean (L2) distance.
void SplitNode(const arma::vec ¢er, const double width, const size_t maxLeafSize)
Split the node, using the given center and the given maximum width of this node.
~Octree()
Destroy the tree.
ElemType MaxDistance(const Octree &other) const
Return the maximum distance to another node.
Octree()
A default constructor.
The core includes that mlpack expects; standard C++ includes and Armadillo.
math::RangeType< ElemType > RangeDistance(const Octree &other) const
Return the minimum and maximum distance to another node.
const arma::vec & center
The center of the node.
bool IsLeaf() const
Return whether or not the node is a leaf.
MatType Mat
So other classes can use TreeType::Mat.
static bool AssignToLeftNode(const VecType &point, const SplitInfo &s)
size_t Point(const size_t index) const
Return the index (with reference to the dataset) of a particular point in this node.
MetricType Metric() const
Return the metric that this tree uses.
void Center(arma::Col< ElemType > ¢er) const
Calculates the center of the range, placing it into the given vector.
ElemType & ParentDistance()
Modify the distance from the center of this node to the center of the parent node.
MetricType metric
An instantiated metric.
void Serialize(Archive &ar, const unsigned int)
Serialize the tree.
size_t GetNearestChild(const VecType &point, typename std::enable_if_t< IsVector< VecType >::value > *=0) const
Return the index of the nearest child node to the given query point.
Octree *& Parent()
Modify the pointer to the parent (be careful!).
MatType::elem_type ElemType
The type of element held in MatType.
ElemType MinDistance(const Octree &other) const
Return the minimum distance to another node.
bound::HRectBound< MetricType > bound
The minimum bounding rectangle of the points held in the node (and its children). ...
Octree & Child(const size_t child)
Return the specified child.
size_t NumChildren() const
Return the number of children in this node.
This is used for sorting points while splitting.
size_t NumPoints() const
Return the number of points in this node (0 if not a leaf).
void Center(arma::vec ¢er) const
Store the center of the bounding region in the given vector.
size_t d
The dimension we are splitting on.
A single-tree traverser; see single_tree_traverser.hpp.
Octree * Parent() const
Get the pointer to the parent.
Octree * parent
The parent (NULL if this node is the root).
const StatisticType & Stat() const
Return the statistic object for this node.
StatisticType stat
The statistic.
size_t GetFurthestChild(const VecType &point, typename std::enable_if_t< IsVector< VecType >::value > *=0) const
Return the index of the furthest child node to the given query point.
size_t begin
The index of the first point in the dataset contained in this node (and its children).
size_t Descendant(const size_t index) const
Return the index (with reference to the dataset) of a particular descendant.
size_t NumDescendants() const
Return the number of descendants of this node.
Octree *& ChildPtr(const size_t child)
Return the pointer to the given child.
ElemType ParentDistance() const
Return the distance from the center of this node to the center of the parent node.
ElemType parentDistance
The distance from the center of this node to the center of the parent.
ElemType FurthestPointDistance() const
Return the furthest distance to a point held in this node.
ElemType FurthestDescendantDistance() const
Return the furthest possible descendant distance.
MatType * dataset
The dataset.
const bound::HRectBound< MetricType > & Bound() const
Return the bound object for this node.
If value == true, then VecType is some sort of Armadillo vector or subview.
ElemType furthestDescendantDistance
The distance to the furthest descendant, cached to speed things up.
typename enable_if< B, T >::type enable_if_t
size_t count
The number of points of the dataset contained in this node (and its children).
const MatType & Dataset() const
Return the dataset used by this node.