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 
109  // Return the value of ztProduct.
110  double ZtProduct() { return ztProduct; }
111 
113  double Tolerance() const { return tolerance; }
115  double& Tolerance() { return tolerance; }
116 
118  size_t NumClasses() const { return numClasses; }
119 
121  size_t WeakLearners() const { return alpha.size(); }
122 
124  double Alpha(const size_t i) const { return alpha[i]; }
126  double& Alpha(const size_t i) { return alpha[i]; }
127 
129  const WeakLearnerType& WeakLearner(const size_t i) const { return wl[i]; }
131  WeakLearnerType& WeakLearner(const size_t i) { return wl[i]; }
132 
144  void Train(const MatType& data,
145  const arma::Row<size_t>& labels,
146  const size_t numClasses,
147  const WeakLearnerType& learner,
148  const size_t iterations = 100,
149  const double tolerance = 1e-6);
150 
158  void Classify(const MatType& test, arma::Row<size_t>& predictedLabels);
159 
163  template<typename Archive>
164  void serialize(Archive& ar, const unsigned int /* version */);
165 
166  private:
168  size_t numClasses;
169  // The tolerance for change in rt and when to stop.
170  double tolerance;
171 
173  std::vector<WeakLearnerType> wl;
175  std::vector<double> alpha;
176 
178  double ztProduct;
179 }; // class AdaBoost
180 
181 } // namespace adaboost
182 } // namespace mlpack
183 
184 #include "adaboost_impl.hpp"
185 
186 #endif
const WeakLearnerType & WeakLearner(const size_t i) const
Get the given weak learner.
Definition: adaboost.hpp:129
.hpp
Definition: add_to_po.hpp:21
double Tolerance() const
Get the tolerance for stopping the optimization during training.
Definition: adaboost.hpp:113
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:121
size_t NumClasses() const
Get the number of classes this model is trained on.
Definition: adaboost.hpp:118
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:126
double & Tolerance()
Modify the tolerance for stopping the optimization during training.
Definition: adaboost.hpp:115
double Alpha(const size_t i) const
Get the weights for the given weak learner.
Definition: adaboost.hpp:124
void 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 serialize(Archive &ar, const unsigned int)
Serialize the AdaBoost model.
void Classify(const MatType &test, arma::Row< size_t > &predictedLabels)
Classify the given test points.
WeakLearnerType & WeakLearner(const size_t i)
Modify the given weak learner (be careful!).
Definition: adaboost.hpp:131