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>
43 std::vector<Octree*> children;
76 Octree(
const MatType& data,
const size_t maxLeafSize = 20);
91 std::vector<size_t>& oldFromNew,
92 const size_t maxLeafSize = 20);
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);
242 template<
typename Archive>
253 const MatType&
Dataset()
const {
return *dataset; }
266 const StatisticType&
Stat()
const {
return stat; }
268 StatisticType&
Stat() {
return stat; }
274 MetricType
Metric()
const {
return MetricType(); }
280 template<
typename VecType>
282 const VecType& point,
289 template<
typename VecType>
291 const VecType& point,
340 const Octree&
Child(
const size_t child)
const {
return *children[child]; }
371 size_t Point(
const size_t index)
const;
381 template<
typename VecType>
383 const VecType& point,
386 template<
typename VecType>
388 const VecType& point,
391 template<
typename VecType>
393 const VecType& point,
400 template<
typename Archive>
413 friend class boost::serialization::access;
424 void SplitNode(
const arma::vec& center,
426 const size_t maxLeafSize);
437 void SplitNode(
const arma::vec& center,
439 std::vector<size_t>& oldFromNew,
440 const size_t maxLeafSize);
458 template<
typename VecType>
459 static bool AssignToLeftNode(
const VecType& point,
const SplitInfo& s)
470#include "octree_impl.hpp"
Hyper-rectangle bound for an L-metric.
void Center(arma::Col< ElemType > ¢er) const
Calculates the center of the range, placing it into the given vector.
Simple real-valued range.
A dual-tree traverser; see dual_tree_traverser.hpp.
A single-tree traverser; see single_tree_traverser.hpp.
Octree(MatType &&data, std::vector< size_t > &oldFromNew, std::vector< size_t > &newFromOld, const size_t maxLeafSize=20)
Construct this as the root node of an octree on the given dataset.
Octree(Octree *parent, const size_t begin, const size_t count, const arma::vec ¢er, const double width, const size_t maxLeafSize=20)
Construct this node as a child of the given parent, starting at column begin and using count points.
ElemType MaxDistance(const Octree &other) const
Return the maximum distance to another node.
Octree & operator=(Octree &&other)
Take ownership of the given Octree.
size_t NumChildren() const
Return the number of children in this node.
ElemType MinimumBoundDistance() const
Return the minimum distance from the center of the node to any bound edge.
MatType::elem_type ElemType
The type of element held in MatType.
ElemType & ParentDistance()
Modify the distance from the center of this node to the center of the parent 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).
Octree & Child(const size_t child)
Return the specified child.
StatisticType & Stat()
Modify the statistic object for this node.
Octree * Parent() const
Get the pointer to the parent.
Octree & operator=(const Octree &other)
Copy the given Octree.
math::RangeType< ElemType > RangeDistance(const Octree &other) const
Return the minimum and maximum distance to another node.
Octree *& ChildPtr(const size_t child)
Return the pointer to the given child.
ElemType MinDistance(const Octree &other) const
Return the minimum distance to another node.
size_t Point(const size_t index) const
Return the index (with reference to the dataset) of a particular point in this node.
MatType Mat
So other classes can use TreeType::Mat.
Octree(const MatType &data, std::vector< size_t > &oldFromNew, std::vector< size_t > &newFromOld, const size_t maxLeafSize=20)
Construct this as the root node of an octree on the given dataset.
Octree()
A default constructor.
ElemType MinDistance(const VecType &point, typename std::enable_if_t< IsVector< VecType >::value > *=0) const
Return the minimum distance to the given point.
Octree *& Parent()
Modify the pointer to the parent (be careful!).
Octree(Octree *parent, const size_t begin, const size_t count, std::vector< size_t > &oldFromNew, const arma::vec ¢er, const double width, const size_t maxLeafSize=20)
Construct this node as a child of the given parent, starting at column begin and using count points.
Octree(const MatType &data, const size_t maxLeafSize=20)
Construct this as the root node of an octree on the given dataset.
bool IsLeaf() const
Return whether or not the node is a leaf.
size_t Descendant(const size_t index) const
Return the index (with reference to the dataset) of a particular descendant.
size_t GetNearestChild(const Octree &queryNode) const
Return the index of the nearest child node to the given query node.
void Center(arma::vec ¢er) const
Store the center of the bounding region in the given vector.
const StatisticType & Stat() const
Return the statistic object for this node.
const bound::HRectBound< MetricType > & Bound() const
Return the bound object for this node.
Octree(MatType &&data, const size_t maxLeafSize=20)
Construct this as the root node of an octree on the given dataset.
size_t GetFurthestChild(const Octree &queryNode) const
Return the index of the furthest child node to the given query node.
MetricType Metric() const
Return the metric that this tree uses.
const Octree & Child(const size_t child) const
Return the specified child.
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(const MatType &data, std::vector< size_t > &oldFromNew, const size_t maxLeafSize=20)
Construct this as the root node of an octree on the given dataset.
ElemType FurthestPointDistance() const
Return the furthest distance to a point held in 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 node.
Octree(Archive &ar, const typename std::enable_if_t< Archive::is_loading::value > *=0)
Initialize the tree from a boost::serialization archive.
~Octree()
Destroy the tree.
Octree(MatType &&data, std::vector< size_t > &oldFromNew, const size_t maxLeafSize=20)
Construct this as the root node of an octree on the given dataset.
const MatType & Dataset() const
Return the dataset used by this node.
ElemType FurthestDescendantDistance() const
Return the furthest possible descendant distance.
Octree(const Octree &other)
Copy the given tree.
ElemType MaxDistance(const VecType &point, typename std::enable_if_t< IsVector< VecType >::value > *=0) const
Return the maximum distance to the given point.
void serialize(Archive &ar, const unsigned int)
Serialize the tree.
Octree(Octree &&other)
Move the given tree.
bound::HRectBound< MetricType > & Bound()
Modify the bound object for this node.
ElemType ParentDistance() const
Return the distance from the center of this node to the center of the parent node.
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.
LMetric< 2, true > EuclideanDistance
The Euclidean (L2) distance.
Linear algebra utility functions, generally performed on matrices or vectors.
typename enable_if< B, T >::type enable_if_t
The core includes that mlpack expects; standard C++ includes and Armadillo.
If value == true, then VecType is some sort of Armadillo vector or subview.
size_t d
The dimension we are splitting on.
SplitInfo(const size_t d, const arma::vec &c)
Create the SplitInfo object.
const arma::vec & center
The center of the node.