mlpack
best_binary_numeric_split.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_METHODS_DECISION_TREE_BEST_BINARY_NUMERIC_SPLIT_HPP
13 #define MLPACK_METHODS_DECISION_TREE_BEST_BINARY_NUMERIC_SPLIT_HPP
14 
15 #include <mlpack/prereqs.hpp>
16 #include "mse_gain.hpp"
17 
19 
20 namespace mlpack {
21 namespace tree {
22 
23 // This gives us a HasBinaryGains<T, U> type (where U is a function pointer)
24 // we can use with SFINAE to catch when a type has a BinaryGains(...) function.
25 HAS_MEM_FUNC(BinaryGains, HasBinaryGains);
26 
27 // This struct will have `value` set to `true` if a BinaryGains() function of
28 // the right signature is detected. We only check for BinaryGains(), and not
29 // BinaryScanInitialize() or BinaryStep(), because those two are template
30 // members functions and would make this check far more difficult.
31 //
32 // The unused UseWeights template parameter is necessary to ensure that the
33 // compiler thinks the result `value` depends on a parameter specific to the
34 // SplitIfBetter() function in BestBinaryNumericSplit().
35 template<typename T, bool /* UseWeights */>
37 {
38  const static bool value = HasBinaryGains<T,
39  std::tuple<double, double>(T::*)()>::value;
40 };
41 
48 template<typename FitnessFunction>
50 {
51  public:
52  // No extra info needed for split.
53  class AuxiliarySplitInfo { };
54 
76  template<bool UseWeights, typename VecType, typename WeightVecType>
77  static double SplitIfBetter(
78  const double bestGain,
79  const VecType& data,
80  const arma::Row<size_t>& labels,
81  const size_t numClasses,
82  const WeightVecType& weights,
83  const size_t minimumLeafSize,
84  const double minimumGainSplit,
85  arma::vec& splitInfo,
86  AuxiliarySplitInfo& aux);
87 
108  template<bool UseWeights, typename VecType, typename ResponsesType,
109  typename WeightVecType>
110  static typename std::enable_if<
112  double>::type
113  SplitIfBetter(
114  const double bestGain,
115  const VecType& data,
116  const ResponsesType& responses,
117  const WeightVecType& weights,
118  const size_t minimumLeafSize,
119  const double minimumGainSplit,
120  double& splitInfo,
121  AuxiliarySplitInfo& aux);
122 
144  template<bool UseWeights, typename VecType, typename ResponsesType,
145  typename WeightVecType>
146  static typename std::enable_if<
148  double>::type
149  SplitIfBetter(
150  const double bestGain,
151  const VecType& data,
152  const ResponsesType& responses,
153  const WeightVecType& weights,
154  const size_t minimumLeafSize,
155  const double minimumGainSplit,
156  double& splitInfo,
157  AuxiliarySplitInfo& /* aux */);
158 
162  static size_t NumChildren(const double& /* splitInfo */,
163  const AuxiliarySplitInfo& /* aux */)
164  {
165  return 2;
166  }
167 
175  template<typename ElemType>
176  static size_t CalculateDirection(
177  const ElemType& point,
178  const double& splitInfo,
179  const AuxiliarySplitInfo& /* aux */);
180 };
181 
182 } // namespace tree
183 } // namespace mlpack
184 
185 // Include implementation.
187 
188 #endif
The BestBinaryNumericSplit is a splitting function for decision trees that will exhaustively search a...
Definition: best_binary_numeric_split.hpp:49
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.
static size_t NumChildren(const double &, const AuxiliarySplitInfo &)
Returns 2, since the binary split always has two children.
Definition: best_binary_numeric_split.hpp:162
Definition: best_binary_numeric_split.hpp:36
Definition: best_binary_numeric_split.hpp:53