12 #ifndef MLPACK_CORE_TREE_OCTREE_OCTREE_HPP 13 #define MLPACK_CORE_TREE_OCTREE_OCTREE_HPP 16 #include "../hrectbound.hpp" 17 #include "../statistic.hpp" 22 template<
typename MetricType = metric::EuclideanDistance,
23 typename StatisticType = EmptyStatistic,
24 typename MatType = arma::mat>
34 template<
typename RuleType>
38 template<
typename RuleType>
43 std::vector<Octree*> children;
61 ElemType parentDistance;
63 ElemType furthestDescendantDistance;
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>
245 const typename std::enable_if_t<cereal::is_loading<Archive>()>* = 0);
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>
401 void serialize(Archive& ar,
const uint32_t );
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)
StatisticType & Stat()
Modify the statistic object for this node.
Definition: octree.hpp:268
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.
Definition: octree_impl.hpp:516
MetricType Metric() const
Return the metric that this tree uses.
Definition: octree.hpp:274
math::RangeType< ElemType > RangeDistance(const Octree &other) const
Return the minimum and maximum distance to another node.
Definition: octree_impl.hpp:671
A dual-tree traverser; see dual_tree_traverser.hpp.
Definition: dual_tree_traverser.hpp:25
bound::HRectBound< MetricType > & Bound()
Modify the bound object for this node.
Definition: octree.hpp:263
const MatType & Dataset() const
Return the dataset used by this node.
Definition: octree.hpp:253
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
void Center(arma::vec ¢er) const
Store the center of the bounding region in the given vector.
Definition: octree.hpp:397
~Octree()
Destroy the tree.
Definition: octree_impl.hpp:496
size_t NumPoints() const
Return the number of points in this node (0 if not a leaf).
Definition: octree_impl.hpp:627
Octree()
A default constructor.
Definition: octree_impl.hpp:472
The core includes that mlpack expects; standard C++ includes and Armadillo.
MatType Mat
So other classes can use TreeType::Mat.
Definition: octree.hpp:29
size_t NumChildren() const
Return the number of children in this node.
Definition: octree_impl.hpp:509
friend class cereal::access
Friend access is given for the default constructor.
Definition: octree.hpp:413
ElemType MaxDistance(const Octree &other) const
Return the maximum distance to another node.
Definition: octree_impl.hpp:663
ElemType MinDistance(const Octree &other) const
Return the minimum distance to another node.
Definition: octree_impl.hpp:655
ElemType & ParentDistance()
Modify the distance from the center of this node to the center of the parent node.
Definition: octree.hpp:334
const StatisticType & Stat() const
Return the statistic object for this node.
Definition: octree.hpp:266
Octree *& Parent()
Modify the pointer to the parent (be careful!).
Definition: octree.hpp:258
MatType::elem_type ElemType
The type of element held in MatType.
Definition: octree.hpp:31
SplitInfo(const size_t d, const arma::vec &c)
Create the SplitInfo object.
Definition: octree.hpp:450
size_t Descendant(const size_t index) const
Return the index (with reference to the dataset) of a particular descendant.
Definition: octree_impl.hpp:640
Octree & operator=(const Octree &other)
Copy the given Octree.
Definition: octree_impl.hpp:370
size_t d
The dimension we are splitting on.
Definition: octree.hpp:453
ElemType ParentDistance() const
Return the distance from the center of this node to the center of the parent node.
Definition: octree.hpp:331
size_t Point(const size_t index) const
Return the index (with reference to the dataset) of a particular point in this node.
Definition: octree_impl.hpp:647
Octree & Child(const size_t child)
Return the specified child.
Definition: octree.hpp:346
void Center(arma::Col< ElemType > ¢er) const
Calculates the center of the range, placing it into the given vector.
Definition: hrectbound_impl.hpp:153
A single-tree traverser; see single_tree_traverser.hpp.
Definition: octree.hpp:35
bool IsLeaf() const
Return whether or not the node is a leaf.
Definition: octree.hpp:297
const Octree & Child(const size_t child) const
Return the specified child.
Definition: octree.hpp:340
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.
Definition: octree_impl.hpp:539
Definition: octree.hpp:447
ElemType MinimumBoundDistance() const
Return the minimum distance from the center of the node to any bound edge.
Definition: octree_impl.hpp:621
const bound::HRectBound< MetricType > & Bound() const
Return the bound object for this node.
Definition: octree.hpp:261
void serialize(Archive &ar, const uint32_t)
Serialize the tree.
Definition: octree_impl.hpp:711
size_t NumDescendants() const
Return the number of descendants of this node.
Definition: octree_impl.hpp:634
Octree *& ChildPtr(const size_t child)
Return the pointer to the given child.
Definition: octree.hpp:352
Definition: octree.hpp:25
ElemType FurthestPointDistance() const
Return the furthest distance to a point held in this node.
Definition: octree_impl.hpp:604
Octree * Parent() const
Get the pointer to the parent.
Definition: octree.hpp:256
const arma::vec & center
The center of the node.
Definition: octree.hpp:455
If value == true, then VecType is some sort of Armadillo vector or subview.
Definition: arma_traits.hpp:35
ElemType FurthestDescendantDistance() const
Return the furthest possible descendant distance.
Definition: octree_impl.hpp:614