mlpack  master
Public Member Functions | Private Attributes | List of all members
mlpack::adaboost::AdaBoost< WeakLearnerType, MatType > Class Template Reference

The AdaBoost class. More...

Inheritance diagram for mlpack::adaboost::AdaBoost< WeakLearnerType, MatType >:
Inheritance graph
[legend]

Public Member Functions

 AdaBoost (const MatType &data, const arma::Row< size_t > &labels, const WeakLearnerType &other, const size_t iterations=100, const double tolerance=1e-6)
 Constructor. More...
 
 AdaBoost (const double tolerance=1e-6)
 Create the AdaBoost object without training. More...
 
double Alpha (const size_t i) const
 Get the weights for the given weak learner. More...
 
double & Alpha (const size_t i)
 Modify the weight for the given weak learner (be careful!). More...
 
size_t Classes () const
 Get the number of classes this model is trained on. More...
 
void Classify (const MatType &test, arma::Row< size_t > &predictedLabels)
 Classify the given test points. More...
 
template<typename Archive >
void Serialize (Archive &ar, const unsigned int)
 Serialize the AdaBoost model. More...
 
double Tolerance () const
 Get the tolerance for stopping the optimization during training. More...
 
double & Tolerance ()
 Modify the tolerance for stopping the optimization during training. More...
 
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. More...
 
const WeakLearnerType & WeakLearner (const size_t i) const
 Get the given weak learner. More...
 
WeakLearnerType & WeakLearner (const size_t i)
 Modify the given weak learner (be careful!). More...
 
size_t WeakLearners () const
 Get the number of weak learners in the model. More...
 
double ZtProduct ()
 

Private Attributes

std::vector< double > alpha
 The weights corresponding to each weak learner. More...
 
size_t classes
 The number of classes in the model. More...
 
double tolerance
 
std::vector< WeakLearnerType > wl
 The vector of weak learners. More...
 
double ztProduct
 To check for the bound for the Hamming loss. More...
 

Detailed Description

template<typename WeakLearnerType = mlpack::perceptron::Perceptron<>, typename MatType = arma::mat>
class mlpack::adaboost::AdaBoost< WeakLearnerType, MatType >

The AdaBoost class.

AdaBoost is a boosting algorithm, meaning that it combines an ensemble of weak learners to produce a strong learner. For more information on AdaBoost, see the following paper:

@article{schapire1999improved,
author = {Schapire, Robert E. and Singer, Yoram},
title = {Improved Boosting Algorithms Using Confidence-rated Predictions},
journal = {Machine Learning},
volume = {37},
number = {3},
month = dec,
year = {1999},
issn = {0885-6125},
pages = {297--336},
}

This class is general, and can be used with any type of weak learner, so long as the learner implements the following functions:

// A boosting constructor, which learns using the training parameters of the
// given other WeakLearner, but uses the given instance weights for training.
const MatType& data,
const arma::Row<size_t>& labels,
const arma::rowvec& weights);
// Given the test points, classify them and output predictions into
// predictedLabels.
void Classify(const MatType& data, arma::Row<size_t>& predictedLabels);

For more information on and examples of weak learners, see perceptron::Perceptron<> and decision_stump::DecisionStump<>.

Template Parameters
MatTypeData matrix type (i.e. arma::mat or arma::sp_mat).
WeakLearnerTypeType of weak learner to use.

Definition at line 81 of file adaboost.hpp.

Constructor & Destructor Documentation

template<typename WeakLearnerType = mlpack::perceptron::Perceptron<>, typename MatType = arma::mat>
mlpack::adaboost::AdaBoost< WeakLearnerType, MatType >::AdaBoost ( const MatType &  data,
const arma::Row< size_t > &  labels,
const WeakLearnerType &  other,
const size_t  iterations = 100,
const double  tolerance = 1e-6 
)

Constructor.

This runs the AdaBoost.MH algorithm to provide a trained boosting model. This constructor takes an already-initialized weak learner; all other weak learners will learn with the same parameters as the given weak learner.

Parameters
dataInput data.
labelsCorresponding labels.
iterationsNumber of boosting rounds.
tolThe tolerance for change in values of rt.
otherWeak learner that has already been initialized.
template<typename WeakLearnerType = mlpack::perceptron::Perceptron<>, typename MatType = arma::mat>
mlpack::adaboost::AdaBoost< WeakLearnerType, MatType >::AdaBoost ( const double  tolerance = 1e-6)

Create the AdaBoost object without training.

Be sure to call Train() before calling Classify()!

Member Function Documentation

template<typename WeakLearnerType = mlpack::perceptron::Perceptron<>, typename MatType = arma::mat>
double mlpack::adaboost::AdaBoost< WeakLearnerType, MatType >::Alpha ( const size_t  i) const
inline

Get the weights for the given weak learner.

Definition at line 123 of file adaboost.hpp.

template<typename WeakLearnerType = mlpack::perceptron::Perceptron<>, typename MatType = arma::mat>
double& mlpack::adaboost::AdaBoost< WeakLearnerType, MatType >::Alpha ( const size_t  i)
inline

Modify the weight for the given weak learner (be careful!).

Definition at line 125 of file adaboost.hpp.

template<typename WeakLearnerType = mlpack::perceptron::Perceptron<>, typename MatType = arma::mat>
size_t mlpack::adaboost::AdaBoost< WeakLearnerType, MatType >::Classes ( ) const
inline

Get the number of classes this model is trained on.

Definition at line 117 of file adaboost.hpp.

template<typename WeakLearnerType = mlpack::perceptron::Perceptron<>, typename MatType = arma::mat>
void mlpack::adaboost::AdaBoost< WeakLearnerType, MatType >::Classify ( const MatType &  test,
arma::Row< size_t > &  predictedLabels 
)

Classify the given test points.

Parameters
testTesting data.
predictedLabelsVector in which to the predicted labels of the test set will be stored.

Referenced by mlpack::adaboost::AdaBoost< decision_stump::DecisionStump<> >::WeakLearner().

template<typename WeakLearnerType = mlpack::perceptron::Perceptron<>, typename MatType = arma::mat>
template<typename Archive >
void mlpack::adaboost::AdaBoost< WeakLearnerType, MatType >::Serialize ( Archive &  ar,
const unsigned  int 
)
template<typename WeakLearnerType = mlpack::perceptron::Perceptron<>, typename MatType = arma::mat>
double mlpack::adaboost::AdaBoost< WeakLearnerType, MatType >::Tolerance ( ) const
inline

Get the tolerance for stopping the optimization during training.

Definition at line 112 of file adaboost.hpp.

template<typename WeakLearnerType = mlpack::perceptron::Perceptron<>, typename MatType = arma::mat>
double& mlpack::adaboost::AdaBoost< WeakLearnerType, MatType >::Tolerance ( )
inline

Modify the tolerance for stopping the optimization during training.

Definition at line 114 of file adaboost.hpp.

template<typename WeakLearnerType = mlpack::perceptron::Perceptron<>, typename MatType = arma::mat>
void mlpack::adaboost::AdaBoost< WeakLearnerType, MatType >::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.

This method takes an initialized WeakLearnerType; the parameters for this weak learner will be used to train each of the weak learners during AdaBoost training. Note that this will completely overwrite any model that has already been trained with this object.

Parameters
dataDataset to train on.
labelsLabels for each point in the dataset.
learnerLearner to use for training.

Referenced by mlpack::adaboost::AdaBoost< decision_stump::DecisionStump<> >::WeakLearner().

template<typename WeakLearnerType = mlpack::perceptron::Perceptron<>, typename MatType = arma::mat>
const WeakLearnerType& mlpack::adaboost::AdaBoost< WeakLearnerType, MatType >::WeakLearner ( const size_t  i) const
inline

Get the given weak learner.

Definition at line 128 of file adaboost.hpp.

template<typename WeakLearnerType = mlpack::perceptron::Perceptron<>, typename MatType = arma::mat>
WeakLearnerType& mlpack::adaboost::AdaBoost< WeakLearnerType, MatType >::WeakLearner ( const size_t  i)
inline

Modify the given weak learner (be careful!).

Definition at line 130 of file adaboost.hpp.

template<typename WeakLearnerType = mlpack::perceptron::Perceptron<>, typename MatType = arma::mat>
size_t mlpack::adaboost::AdaBoost< WeakLearnerType, MatType >::WeakLearners ( ) const
inline

Get the number of weak learners in the model.

Definition at line 120 of file adaboost.hpp.

template<typename WeakLearnerType = mlpack::perceptron::Perceptron<>, typename MatType = arma::mat>
double mlpack::adaboost::AdaBoost< WeakLearnerType, MatType >::ZtProduct ( )
inline

Definition at line 109 of file adaboost.hpp.

Member Data Documentation

template<typename WeakLearnerType = mlpack::perceptron::Perceptron<>, typename MatType = arma::mat>
std::vector<double> mlpack::adaboost::AdaBoost< WeakLearnerType, MatType >::alpha
private
template<typename WeakLearnerType = mlpack::perceptron::Perceptron<>, typename MatType = arma::mat>
size_t mlpack::adaboost::AdaBoost< WeakLearnerType, MatType >::classes
private

The number of classes in the model.

Definition at line 166 of file adaboost.hpp.

Referenced by mlpack::adaboost::AdaBoost< decision_stump::DecisionStump<> >::Classes().

template<typename WeakLearnerType = mlpack::perceptron::Perceptron<>, typename MatType = arma::mat>
double mlpack::adaboost::AdaBoost< WeakLearnerType, MatType >::tolerance
private
template<typename WeakLearnerType = mlpack::perceptron::Perceptron<>, typename MatType = arma::mat>
std::vector<WeakLearnerType> mlpack::adaboost::AdaBoost< WeakLearnerType, MatType >::wl
private

The vector of weak learners.

Definition at line 171 of file adaboost.hpp.

Referenced by mlpack::adaboost::AdaBoost< decision_stump::DecisionStump<> >::WeakLearner().

template<typename WeakLearnerType = mlpack::perceptron::Perceptron<>, typename MatType = arma::mat>
double mlpack::adaboost::AdaBoost< WeakLearnerType, MatType >::ztProduct
private

To check for the bound for the Hamming loss.

Definition at line 176 of file adaboost.hpp.

Referenced by mlpack::adaboost::AdaBoost< decision_stump::DecisionStump<> >::ZtProduct().


The documentation for this class was generated from the following file: