mlpack  master
numeric_split_info.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_METHODS_HOEFFDING_TREES_NUMERIC_SPLIT_INFO_HPP
13 #define MLPACK_METHODS_HOEFFDING_TREES_NUMERIC_SPLIT_INFO_HPP
14 
15 #include <mlpack/prereqs.hpp>
16 
17 namespace mlpack {
18 namespace tree {
19 
20 template<typename ObservationType = double>
22 {
23  public:
24  NumericSplitInfo() { /* Nothing to do. */ }
25  NumericSplitInfo(const arma::Col<ObservationType>& splitPoints) :
26  splitPoints(splitPoints) { /* Nothing to do. */ }
27 
28  template<typename eT>
29  size_t CalculateDirection(const eT& value) const
30  {
31  // What bin does the point fall into?
32  size_t bin = 0;
33  while (bin < splitPoints.n_elem && value > splitPoints[bin])
34  ++bin;
35 
36  return bin;
37  }
38 
40  template<typename Archive>
41  void Serialize(Archive& ar, const unsigned int /* version */)
42  {
43  ar & data::CreateNVP(splitPoints, "splitPoints");
44  }
45 
46  private:
47  arma::Col<ObservationType> splitPoints;
48 };
49 
50 } // namespace tree
51 } // namespace mlpack
52 
53 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: binarize.hpp:18
size_t CalculateDirection(const eT &value) const
The core includes that mlpack expects; standard C++ includes and Armadillo.
FirstShim< T > CreateNVP(T &t, const std::string &name, typename std::enable_if_t< HasSerialize< T >::value > *=0)
Call this function to produce a name-value pair; this is similar to BOOST_SERIALIZATION_NVP(), but should be used for types that have a Serialize() function (or contain a type that has a Serialize() function) instead of a serialize() function.
arma::Col< ObservationType > splitPoints
void Serialize(Archive &ar, const unsigned int)
Serialize the split (save/load the split points).
NumericSplitInfo(const arma::Col< ObservationType > &splitPoints)