mlpack  3.4.2
adaboost_model.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_METHODS_ADABOOST_ADABOOST_MODEL_HPP
13 #define MLPACK_METHODS_ADABOOST_ADABOOST_MODEL_HPP
14 
15 #include <mlpack/core.hpp>
16 
17 // Use forward declaration instead of include to accelerate compilation.
18 class AdaBoost;
19 
20 namespace mlpack {
21 namespace adaboost {
22 
27 {
28  public:
30  {
33  };
34 
35  private:
37  arma::Col<size_t> mappings;
39  size_t weakLearnerType;
45  size_t dimensionality;
46 
47  public:
50 
52  AdaBoostModel(const arma::Col<size_t>& mappings,
53  const size_t weakLearnerType);
54 
57 
60 
63 
66 
68  const arma::Col<size_t>& Mappings() const { return mappings; }
70  arma::Col<size_t>& Mappings() { return mappings; }
71 
73  size_t WeakLearnerType() const { return weakLearnerType; }
75  size_t& WeakLearnerType() { return weakLearnerType; }
76 
78  size_t Dimensionality() const { return dimensionality; }
80  size_t& Dimensionality() { return dimensionality; }
81 
83  void Train(const arma::mat& data,
84  const arma::Row<size_t>& labels,
85  const size_t numClasses,
86  const size_t iterations,
87  const double tolerance);
88 
90  void Classify(const arma::mat& testData,
91  arma::Row<size_t>& predictions);
92 
94  void Classify(const arma::mat& testData,
95  arma::Row<size_t>& predictions,
96  arma::mat& probabilities);
97 
99  template<typename Archive>
100  void serialize(Archive& ar, const unsigned int /* version */)
101  {
102  if (Archive::is_loading::value)
103  {
104  if (dsBoost)
105  delete dsBoost;
106  if (pBoost)
107  delete pBoost;
108 
109  dsBoost = NULL;
110  pBoost = NULL;
111  }
112 
113  ar & BOOST_SERIALIZATION_NVP(mappings);
114  ar & BOOST_SERIALIZATION_NVP(weakLearnerType);
115  if (weakLearnerType == WeakLearnerTypes::DECISION_STUMP)
116  ar & BOOST_SERIALIZATION_NVP(dsBoost);
117  else if (weakLearnerType == WeakLearnerTypes::PERCEPTRON)
118  ar & BOOST_SERIALIZATION_NVP(pBoost);
119  ar & BOOST_SERIALIZATION_NVP(dimensionality);
120  }
121 };
122 
123 } // namespace adaboost
124 } // namespace mlpack
125 
126 #endif
mlpack::adaboost::AdaBoostModel::Classify
void Classify(const arma::mat &testData, arma::Row< size_t > &predictions, arma::mat &probabilities)
Classify test points.
mlpack::adaboost::AdaBoostModel::AdaBoostModel
AdaBoostModel()
Create an empty AdaBoost model.
mlpack::adaboost::AdaBoostModel::~AdaBoostModel
~AdaBoostModel()
Clean up memory.
mlpack::adaboost::AdaBoostModel::Classify
void Classify(const arma::mat &testData, arma::Row< size_t > &predictions)
Classify test points.
mlpack::adaboost::AdaBoostModel::DECISION_STUMP
@ DECISION_STUMP
Definition: adaboost_model.hpp:31
mlpack
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: add_to_cli11.hpp:21
mlpack::adaboost::AdaBoostModel::serialize
void serialize(Archive &ar, const unsigned int)
Serialize the model.
Definition: adaboost_model.hpp:100
mlpack::adaboost::AdaBoostModel::Dimensionality
size_t & Dimensionality()
Modify the dimensionality of the model.
Definition: adaboost_model.hpp:80
mlpack::adaboost::AdaBoostModel::PERCEPTRON
@ PERCEPTRON
Definition: adaboost_model.hpp:32
mlpack::adaboost::AdaBoostModel::WeakLearnerTypes
WeakLearnerTypes
Definition: adaboost_model.hpp:30
mlpack::adaboost::AdaBoostModel::Train
void Train(const arma::mat &data, const arma::Row< size_t > &labels, const size_t numClasses, const size_t iterations, const double tolerance)
Train the model, treat the data is all of the numeric type.
mlpack::adaboost::AdaBoostModel::operator=
AdaBoostModel & operator=(const AdaBoostModel &other)
Copy assignment operator.
mlpack::adaboost::AdaBoostModel::WeakLearnerType
size_t WeakLearnerType() const
Get the weak learner type.
Definition: adaboost_model.hpp:73
mlpack::adaboost::AdaBoostModel::Mappings
arma::Col< size_t > & Mappings()
Modify the mappings.
Definition: adaboost_model.hpp:70
mlpack::adaboost::AdaBoostModel::WeakLearnerType
size_t & WeakLearnerType()
Modify the weak learner type.
Definition: adaboost_model.hpp:75
mlpack::adaboost::AdaBoostModel
The model to save to disk.
Definition: adaboost_model.hpp:27
core.hpp
Include all of the base components required to write mlpack methods, and the main mlpack Doxygen docu...
mlpack::adaboost::AdaBoostModel::Mappings
const arma::Col< size_t > & Mappings() const
Get the mappings.
Definition: adaboost_model.hpp:68
mlpack::adaboost::AdaBoostModel::AdaBoostModel
AdaBoostModel(const AdaBoostModel &other)
Copy constructor.
mlpack::adaboost::AdaBoostModel::AdaBoostModel
AdaBoostModel(const arma::Col< size_t > &mappings, const size_t weakLearnerType)
Create the AdaBoost model with the given mappings and type.
mlpack::adaboost::AdaBoostModel::AdaBoostModel
AdaBoostModel(AdaBoostModel &&other)
Move constructor.
mlpack::adaboost::AdaBoost
The AdaBoost class.
Definition: adaboost.hpp:82
mlpack::adaboost::AdaBoostModel::Dimensionality
size_t Dimensionality() const
Get the dimensionality of the model.
Definition: adaboost_model.hpp:78