mlpack  master
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 
20 namespace mlpack {
21 namespace tree {
22 
29 template<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;
45  ElemType mu;
47  const MetricType* metric;
48 
50  mu(0),
51  metric(NULL)
52  { }
53 
54  template<typename VecType>
55  SplitInfo(const MetricType& metric, const VecType& vantagePoint,
56  ElemType mu) :
57  vantagePoint(vantagePoint),
58  mu(mu),
59  metric(&metric)
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 
93  static size_t PerformSplit(MatType& data,
94  const size_t begin,
95  const size_t count,
96  const SplitInfo& splitInfo)
97  {
98  return split::PerformSplit<MatType, VantagePointSplit>(data, begin, count,
99  splitInfo);
100  }
101 
118  static size_t PerformSplit(MatType& data,
119  const size_t begin,
120  const size_t count,
121  const SplitInfo& splitInfo,
122  std::vector<size_t>& oldFromNew)
123  {
124  return split::PerformSplit<MatType, VantagePointSplit>(data, begin, count,
125  splitInfo, oldFromNew);
126  }
127 
137  template<typename VecType>
138  static bool AssignToLeftNode(const VecType& point,
139  const SplitInfo& splitInfo)
140  {
141  return (splitInfo.metric->Evaluate(splitInfo.vantagePoint, point) <
142  splitInfo.mu);
143  }
144 
145  private:
163  static void SelectVantagePoint(const MetricType& metric,
164  const MatType& data,
165  const size_t begin,
166  const size_t count,
167  size_t& vantagePoint,
168  ElemType& mu);
169 };
170 
171 } // namespace tree
172 } // namespace mlpack
173 
174 // Include implementation.
175 #include "vantage_point_split_impl.hpp"
176 
177 #endif // MLPACK_CORE_TREE_BINARY_SPACE_TREE_VANTAGE_POINT_SPLIT_HPP
MatType::elem_type ElemType
The matrix element type.
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: binarize.hpp:18
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.
ElemType mu
The median distance according to which the node will be split.
The core includes that mlpack expects; standard C++ includes and Armadillo.
A struct that contains an information about the split.
static bool AssignToLeftNode(const VecType &point, const SplitInfo &splitInfo)
Indicates that a point should be assigned to the left subtree.
The class splits a binary space partitioning tree node according to the median distance to the vantag...
BoundType::MetricType MetricType
The bounding shape type.
const MetricType * metric
An instance of the MetricType class.
SplitInfo(const MetricType &metric, const VecType &vantagePoint, ElemType mu)
Miscellaneous math random-related routines.
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 void SelectVantagePoint(const MetricType &metric, const MatType &data, const size_t begin, const size_t count, size_t &vantagePoint, ElemType &mu)
Select the best vantage point, i.e., the point with the largest second moment of the distance from a ...
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...
arma::Col< ElemType > vantagePoint
The vantage point.