mlpack  master
adaboost_model.hpp
Go to the documentation of this file.
1 
7 #ifndef MLPACK_METHODS_ADABOOST_ADABOOST_MODEL_HPP
8 #define MLPACK_METHODS_ADABOOST_ADABOOST_MODEL_HPP
9 
10 #include <mlpack/core.hpp>
11 #include "adaboost.hpp"
12 
13 namespace mlpack {
14 namespace adaboost {
15 
20 {
21  public:
23  {
26  };
27 
28  private:
30  arma::Col<size_t> mappings;
39 
40  public:
42  AdaBoostModel();
43 
45  AdaBoostModel(const arma::Col<size_t>& mappings,
46  const size_t weakLearnerType);
47 
49  AdaBoostModel(const AdaBoostModel& other);
50 
53 
55  AdaBoostModel& operator=(const AdaBoostModel& other);
56 
59 
61  const arma::Col<size_t>& Mappings() const { return mappings; }
63  arma::Col<size_t>& Mappings() { return mappings; }
64 
66  size_t WeakLearnerType() const { return weakLearnerType; }
68  size_t& WeakLearnerType() { return weakLearnerType; }
69 
71  size_t Dimensionality() const { return dimensionality; }
73  size_t& Dimensionality() { return dimensionality; }
74 
76  void Train(const arma::mat& data,
77  const arma::Row<size_t>& labels,
78  const size_t iterations,
79  const double tolerance);
80 
82  void Classify(const arma::mat& testData, arma::Row<size_t>& predictions);
83 
85  template<typename Archive>
86  void Serialize(Archive& ar, const unsigned int /* version */)
87  {
88  if (Archive::is_loading::value)
89  {
90  if (dsBoost)
91  delete dsBoost;
92  if (pBoost)
93  delete pBoost;
94 
95  dsBoost = NULL;
96  pBoost = NULL;
97  }
98 
99  ar & data::CreateNVP(mappings, "mappings");
100  ar & data::CreateNVP(weakLearnerType, "weakLearnerType");
101  if (weakLearnerType == WeakLearnerTypes::DECISION_STUMP)
102  ar & data::CreateNVP(dsBoost, "adaboost_ds");
103  else if (weakLearnerType == WeakLearnerTypes::PERCEPTRON)
104  ar & data::CreateNVP(pBoost, "adaboost_p");
105  ar & data::CreateNVP(dimensionality, "dimensionality");
106  }
107 };
108 
109 } // namespace adaboost
110 } // namespace mlpack
111 
112 #endif
arma::Col< size_t > mappings
The mappings for the labels.
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: binarize.hpp:18
AdaBoost< perceptron::Perceptron<> > * pBoost
Non-NULL if using perceptrons.
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.
The AdaBoost class.
Definition: adaboost.hpp:81
size_t weakLearnerType
The type of weak learner.
size_t & Dimensionality()
Modify the dimensionality of the model.
AdaBoostModel & operator=(const AdaBoostModel &other)
Copy assignment operator.
size_t & WeakLearnerType()
Modify the weak learner type.
void Train(const arma::mat &data, const arma::Row< size_t > &labels, const size_t iterations, const double tolerance)
Train the model.
size_t Dimensionality() const
Get the dimensionality of the model.
AdaBoostModel()
Create an empty AdaBoost model.
~AdaBoostModel()
Clean up memory.
arma::Col< size_t > & Mappings()
Modify the mappings.
The model to save to disk.
void Classify(const arma::mat &testData, arma::Row< size_t > &predictions)
Classify test points.
size_t WeakLearnerType() const
Get the weak learner type.
Include all of the base components required to write MLPACK methods, and the main MLPACK Doxygen docu...
size_t dimensionality
Number of dimensions in training data.
const arma::Col< size_t > & Mappings() const
Get the mappings.
AdaBoost< decision_stump::DecisionStump<> > * dsBoost
Non-NULL if using decision stumps.
void Serialize(Archive &ar, const unsigned int)
Serialize the model.