mlpack  master
rp_tree_max_split.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_CORE_TREE_BINARY_SPACE_TREE_RP_TREE_MAX_SPLIT_HPP
14 #define MLPACK_CORE_TREE_BINARY_SPACE_TREE_RP_TREE_MAX_SPLIT_HPP
15 
16 #include <mlpack/prereqs.hpp>
18 
19 namespace mlpack {
20 namespace tree {
21 
31 template<typename BoundType, typename MatType = arma::mat>
33 {
34  public:
36  typedef typename MatType::elem_type ElemType;
38  struct SplitInfo
39  {
41  arma::Col<ElemType> direction;
43  ElemType splitVal;
44  };
45 
57  static bool SplitNode(const BoundType& /*bound*/,
58  MatType& data,
59  const size_t begin,
60  const size_t count,
61  SplitInfo& splitInfo);
62 
76  static size_t PerformSplit(MatType& data,
77  const size_t begin,
78  const size_t count,
79  const SplitInfo& splitInfo)
80  {
81  return split::PerformSplit<MatType, RPTreeMaxSplit>(data, begin, count,
82  splitInfo);
83  }
84 
101  static size_t PerformSplit(MatType& data,
102  const size_t begin,
103  const size_t count,
104  const SplitInfo& splitInfo,
105  std::vector<size_t>& oldFromNew)
106  {
107  return split::PerformSplit<MatType, RPTreeMaxSplit>(data, begin, count,
108  splitInfo, oldFromNew);
109  }
110 
117  template<typename VecType>
118  static bool AssignToLeftNode(const VecType& point, const SplitInfo& splitInfo)
119  {
120  return (arma::dot(point, splitInfo.direction) <= splitInfo.splitVal);
121  }
122 
123  private:
135  static bool GetSplitVal(const MatType& data,
136  const size_t begin,
137  const size_t count,
138  const arma::Col<ElemType>& direction,
139  ElemType& splitVal);
140 };
141 
142 } // namespace tree
143 } // namespace mlpack
144 
145 // Include implementation.
146 #include "rp_tree_max_split_impl.hpp"
147 
148 #endif // MLPACK_CORE_TREE_BINARY_SPACE_TREE_RP_TREE_MAX_SPLIT_HPP
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.
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: binarize.hpp:18
arma::Col< ElemType > direction
The normal vector to the hyperplane that splits the node.
The core includes that mlpack expects; standard C++ includes and Armadillo.
This class splits a node by a random hyperplane.
static bool SplitNode(const BoundType &, MatType &data, const size_t begin, const size_t count, SplitInfo &splitInfo)
Split the node by a random hyperplane.
static bool AssignToLeftNode(const VecType &point, const SplitInfo &splitInfo)
Indicates that a point should be assigned to the left subtree.
static bool GetSplitVal(const MatType &data, const size_t begin, const size_t count, const arma::Col< ElemType > &direction, ElemType &splitVal)
This method finds the position of the hyperplane that will split the node.
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...
MatType::elem_type ElemType
The element type held by the matrix type.
An information about the partition.
ElemType splitVal
The value according to which the node is being split.