mlpack 3.4.2
vantage_point_split.hpp
Go to the documentation of this file.
1
13#ifndef MLPACK_CORE_TREE_BINARY_SPACE_TREE_VANTAGE_POINT_SPLIT_HPP
14#define MLPACK_CORE_TREE_BINARY_SPACE_TREE_VANTAGE_POINT_SPLIT_HPP
15
16#include <mlpack/prereqs.hpp>
19
20namespace mlpack {
21namespace tree {
22
29template<typename BoundType,
30 typename MatType = arma::mat,
31 size_t MaxNumSamples = 100>
33{
34 public:
36 typedef typename MatType::elem_type ElemType;
38 typedef typename BoundType::MetricType MetricType;
40 struct SplitInfo
41 {
43 arma::Col<ElemType> vantagePoint;
48
50 mu(0),
51 metric(NULL)
52 { }
53
54 template<typename VecType>
55 SplitInfo(const MetricType& metric, const VecType& vantagePoint,
56 ElemType mu) :
58 mu(mu),
60 { }
61 };
62
74 static bool SplitNode(const BoundType& bound,
75 MatType& data,
76 const size_t begin,
77 const size_t count,
78 SplitInfo& splitInfo);
79
92 static size_t PerformSplit(MatType& data,
93 const size_t begin,
94 const size_t count,
95 const SplitInfo& splitInfo)
96 {
97 return split::PerformSplit<MatType, VantagePointSplit>(data, begin, count,
98 splitInfo);
99 }
100
116 static size_t PerformSplit(MatType& data,
117 const size_t begin,
118 const size_t count,
119 const SplitInfo& splitInfo,
120 std::vector<size_t>& oldFromNew)
121 {
122 return split::PerformSplit<MatType, VantagePointSplit>(data, begin, count,
123 splitInfo, oldFromNew);
124 }
125
135 template<typename VecType>
136 static bool AssignToLeftNode(const VecType& point,
137 const SplitInfo& splitInfo)
138 {
139 return (splitInfo.metric->Evaluate(splitInfo.vantagePoint, point) <
140 splitInfo.mu);
141 }
142
143 private:
161 static void SelectVantagePoint(const MetricType& metric,
162 const MatType& data,
163 const size_t begin,
164 const size_t count,
165 size_t& vantagePoint,
166 ElemType& mu);
167};
168
169} // namespace tree
170} // namespace mlpack
171
172// Include implementation.
173#include "vantage_point_split_impl.hpp"
174
175#endif // MLPACK_CORE_TREE_BINARY_SPACE_TREE_VANTAGE_POINT_SPLIT_HPP
The class splits a binary space partitioning tree node according to the median distance to the vantag...
MatType::elem_type ElemType
The matrix element type.
BoundType::MetricType MetricType
The bounding shape type.
static size_t PerformSplit(MatType &data, const size_t begin, const size_t count, const SplitInfo &splitInfo)
Perform the split process according to the information about the split.
static bool SplitNode(const BoundType &bound, MatType &data, const size_t begin, const size_t count, SplitInfo &splitInfo)
Split the node according to the distance to a vantage point.
static bool AssignToLeftNode(const VecType &point, const SplitInfo &splitInfo)
Indicates that a point should be assigned to the left subtree.
static size_t PerformSplit(MatType &data, const size_t begin, const size_t count, const SplitInfo &splitInfo, std::vector< size_t > &oldFromNew)
Perform the split process according to the information about the split and return the list of changed...
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
The core includes that mlpack expects; standard C++ includes and Armadillo.
Miscellaneous math random-related routines.
A struct that contains an information about the split.
arma::Col< ElemType > vantagePoint
The vantage point.
ElemType mu
The median distance according to which the node will be split.
const MetricType * metric
An instance of the MetricType class.
SplitInfo(const MetricType &metric, const VecType &vantagePoint, ElemType mu)