mlpack  2.0.1
adaboost.hpp
Go to the documentation of this file.
1 
30 #ifndef __MLPACK_METHODS_ADABOOST_ADABOOST_HPP
31 #define __MLPACK_METHODS_ADABOOST_ADABOOST_HPP
32 
33 #include <mlpack/core.hpp>
36 
37 namespace mlpack {
38 namespace adaboost {
39 
81 template<typename WeakLearnerType = mlpack::perceptron::Perceptron<>,
82  typename MatType = arma::mat>
83 class AdaBoost
84 {
85  public:
98  AdaBoost(const MatType& data,
99  const arma::Row<size_t>& labels,
100  const WeakLearnerType& other,
101  const size_t iterations = 100,
102  const double tolerance = 1e-6);
103 
108  AdaBoost(const double tolerance = 1e-6);
109 
110  // Return the value of ztProduct.
111  double ZtProduct() { return ztProduct; }
112 
114  double Tolerance() const { return tolerance; }
116  double& Tolerance() { return tolerance; }
117 
119  size_t Classes() const { return classes; }
120 
122  size_t WeakLearners() const { return alpha.size(); }
123 
125  double Alpha(const size_t i) const { return alpha[i]; }
127  double& Alpha(const size_t i) { return alpha[i]; }
128 
130  const WeakLearnerType& WeakLearner(const size_t i) const { return wl[i]; }
132  WeakLearnerType& WeakLearner(const size_t i) { return wl[i]; }
133 
145  void Train(const MatType& data,
146  const arma::Row<size_t>& labels,
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 classes;
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 
180 }; // class AdaBoost
181 
182 } // namespace adaboost
183 } // namespace mlpack
184 
185 #include "adaboost_impl.hpp"
186 
187 #endif
std::vector< WeakLearnerType > wl
The vector of weak learners.
Definition: adaboost.hpp:173
Linear algebra utility functions, generally performed on matrices or vectors.
WeakLearnerType & WeakLearner(const size_t i)
Modify the given weak learner (be careful!).
Definition: adaboost.hpp:132
size_t Classes() const
Get the number of classes this model is trained on.
Definition: adaboost.hpp:119
The AdaBoost class.
Definition: adaboost.hpp:83
double & Alpha(const size_t i)
Modify the weight for the given weak learner (be careful!).
Definition: adaboost.hpp:127
void Train(const MatType &data, const arma::Row< size_t > &labels, 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)
Classify the given test points.
size_t classes
The number of classes in the model.
Definition: adaboost.hpp:168
const WeakLearnerType & WeakLearner(const size_t i) const
Get the given weak learner.
Definition: adaboost.hpp:130
Include all of the base components required to write MLPACK methods, and the main MLPACK Doxygen docu...
double Alpha(const size_t i) const
Get the weights for the given weak learner.
Definition: adaboost.hpp:125
double Tolerance() const
Get the tolerance for stopping the optimization during training.
Definition: adaboost.hpp:114
double & Tolerance()
Modify the tolerance for stopping the optimization during training.
Definition: adaboost.hpp:116
std::vector< double > alpha
The weights corresponding to each weak learner.
Definition: adaboost.hpp:175
double ztProduct
To check for the bound for the Hamming loss.
Definition: adaboost.hpp:178
size_t WeakLearners() const
Get the number of weak learners in the model.
Definition: adaboost.hpp:122
AdaBoost(const MatType &data, const arma::Row< size_t > &labels, const WeakLearnerType &other, const size_t iterations=100, const double tolerance=1e-6)
Constructor.
void Serialize(Archive &ar, const unsigned int)
Serialize the AdaBoost model.