adaboost.hpp
Go to the documentation of this file.
1 
28 #ifndef MLPACK_METHODS_ADABOOST_ADABOOST_HPP
29 #define MLPACK_METHODS_ADABOOST_ADABOOST_HPP
30 
31 #include <mlpack/prereqs.hpp>
34 
35 namespace mlpack {
36 namespace adaboost {
37 
79 template<typename WeakLearnerType = mlpack::perceptron::Perceptron<>,
80  typename MatType = arma::mat>
81 class AdaBoost
82 {
83  public:
96  AdaBoost(const MatType& data,
97  const arma::Row<size_t>& labels,
98  const size_t numClasses,
99  const WeakLearnerType& other,
100  const size_t iterations = 100,
101  const double tolerance = 1e-6);
102 
107  AdaBoost(const double tolerance = 1e-6);
108 
110  double Tolerance() const { return tolerance; }
112  double& Tolerance() { return tolerance; }
113 
115  size_t NumClasses() const { return numClasses; }
116 
118  size_t WeakLearners() const { return alpha.size(); }
119 
121  double Alpha(const size_t i) const { return alpha[i]; }
123  double& Alpha(const size_t i) { return alpha[i]; }
124 
126  const WeakLearnerType& WeakLearner(const size_t i) const { return wl[i]; }
128  WeakLearnerType& WeakLearner(const size_t i) { return wl[i]; }
129 
142  double Train(const MatType& data,
143  const arma::Row<size_t>& labels,
144  const size_t numClasses,
145  const WeakLearnerType& learner,
146  const size_t iterations = 100,
147  const double tolerance = 1e-6);
148 
158  void Classify(const MatType& test,
159  arma::Row<size_t>& predictedLabels,
160  arma::mat& probabilities);
161 
169  void Classify(const MatType& test,
170  arma::Row<size_t>& predictedLabels);
171 
175  template<typename Archive>
176  void serialize(Archive& ar, const unsigned int /* version */);
177 
178  private:
180  size_t numClasses;
181  // The tolerance for change in rt and when to stop.
182  double tolerance;
183 
185  std::vector<WeakLearnerType> wl;
187  std::vector<double> alpha;
188 }; // class AdaBoost
189 
190 } // namespace adaboost
191 } // namespace mlpack
192 
194 namespace boost {
195 namespace serialization {
196 
197 template<typename WeakLearnerType, typename MatType>
198 struct version<mlpack::adaboost::AdaBoost<WeakLearnerType, MatType>>
199 {
200  BOOST_STATIC_CONSTANT(int, value = 1);
201 };
202 
203 } // namespace serialization
204 } // namespace boost
205 
206 // Include implementation.
207 #include "adaboost_impl.hpp"
208 
209 #endif
const WeakLearnerType & WeakLearner(const size_t i) const
Get the given weak learner.
Definition: adaboost.hpp:126
Set the serialization version of the adaboost class.
Definition: adaboost.hpp:194
strip_type.hpp
Definition: add_to_po.hpp:21
double Tolerance() const
Get the tolerance for stopping the optimization during training.
Definition: adaboost.hpp:110
The core includes that mlpack expects; standard C++ includes and Armadillo.
The AdaBoost class.
Definition: adaboost.hpp:81
size_t WeakLearners() const
Get the number of weak learners in the model.
Definition: adaboost.hpp:118
size_t NumClasses() const
Get the number of classes this model is trained on.
Definition: adaboost.hpp:115
AdaBoost(const MatType &data, const arma::Row< size_t > &labels, const size_t numClasses, const WeakLearnerType &other, const size_t iterations=100, const double tolerance=1e-6)
Constructor.
double & Alpha(const size_t i)
Modify the weight for the given weak learner (be careful!).
Definition: adaboost.hpp:123
double Train(const MatType &data, const arma::Row< size_t > &labels, const size_t numClasses, const WeakLearnerType &learner, const size_t iterations=100, const double tolerance=1e-6)
Train AdaBoost on the given dataset.
void Classify(const MatType &test, arma::Row< size_t > &predictedLabels, arma::mat &probabilities)
Classify the given test points.
double & Tolerance()
Modify the tolerance for stopping the optimization during training.
Definition: adaboost.hpp:112
double Alpha(const size_t i) const
Get the weights for the given weak learner.
Definition: adaboost.hpp:121
void serialize(Archive &ar, const unsigned int)
Serialize the AdaBoost model.
WeakLearnerType & WeakLearner(const size_t i)
Modify the given weak learner (be careful!).
Definition: adaboost.hpp:128