mlpack  master
Public Member Functions | Private Attributes | List of all members
mlpack::perceptron::Perceptron< LearnPolicy, WeightInitializationPolicy, MatType > Class Template Reference

This class implements a simple perceptron (i.e., a single layer neural network). More...

Public Member Functions

 Perceptron (const size_t numClasses=0, const size_t dimensionality=0, const size_t maxIterations=1000)
 Constructor: create the perceptron with the given number of classes and initialize the weight matrix, but do not perform any training. More...
 
 Perceptron (const MatType &data, const arma::Row< size_t > &labels, const size_t numClasses, const size_t maxIterations=1000)
 Constructor: constructs the perceptron by building the weights matrix, which is later used in classification. More...
 
 Perceptron (const Perceptron &other, const MatType &data, const arma::Row< size_t > &labels, const arma::rowvec &instanceWeights)
 Alternate constructor which copies parameters from an already initiated perceptron. More...
 
const arma::vec & Biases () const
 Get the biases. More...
 
arma::vec & Biases ()
 Modify the biases. You had better know what you are doing! More...
 
void Classify (const MatType &test, arma::Row< size_t > &predictedLabels)
 Classification function. More...
 
size_t MaxIterations () const
 Get the maximum number of iterations. More...
 
size_t & MaxIterations ()
 Modify the maximum number of iterations. More...
 
size_t NumClasses () const
 Get the number of classes this perceptron has been trained for. More...
 
template<typename Archive >
void Serialize (Archive &ar, const unsigned int)
 Serialize the perceptron. More...
 
void Train (const MatType &data, const arma::Row< size_t > &labels, const arma::rowvec &instanceWeights=arma::rowvec())
 Train the perceptron on the given data for up to the maximum number of iterations (specified in the constructor or through MaxIterations()). More...
 
const arma::mat & Weights () const
 Get the weight matrix. More...
 
arma::mat & Weights ()
 Modify the weight matrix. You had better know what you are doing! More...
 

Private Attributes

arma::vec biases
 The biases for each class. More...
 
size_t maxIterations
 The maximum number of iterations during training. More...
 
arma::mat weights
 Stores the weights for each of the input class labels. More...
 

Detailed Description

template<typename LearnPolicy = SimpleWeightUpdate, typename WeightInitializationPolicy = ZeroInitialization, typename MatType = arma::mat>
class mlpack::perceptron::Perceptron< LearnPolicy, WeightInitializationPolicy, MatType >

This class implements a simple perceptron (i.e., a single layer neural network).

It converges if the supplied training dataset is linearly separable.

Template Parameters
LearnPolicyOptions of SimpleWeightUpdate and GradientDescent.
WeightInitializationPolicyOption of ZeroInitialization and RandomInitialization.

Definition at line 36 of file perceptron.hpp.

Constructor & Destructor Documentation

template<typename LearnPolicy = SimpleWeightUpdate, typename WeightInitializationPolicy = ZeroInitialization, typename MatType = arma::mat>
mlpack::perceptron::Perceptron< LearnPolicy, WeightInitializationPolicy, MatType >::Perceptron ( const size_t  numClasses = 0,
const size_t  dimensionality = 0,
const size_t  maxIterations = 1000 
)

Constructor: create the perceptron with the given number of classes and initialize the weight matrix, but do not perform any training.

(Call the Train() function to perform training.)

Parameters
numClassesNumber of classes in the dataset.
dimensionalityDimensionality of the dataset.
maxIterationsMaximum number of iterations for the perceptron learning algorithm.
template<typename LearnPolicy = SimpleWeightUpdate, typename WeightInitializationPolicy = ZeroInitialization, typename MatType = arma::mat>
mlpack::perceptron::Perceptron< LearnPolicy, WeightInitializationPolicy, MatType >::Perceptron ( const MatType &  data,
const arma::Row< size_t > &  labels,
const size_t  numClasses,
const size_t  maxIterations = 1000 
)

Constructor: constructs the perceptron by building the weights matrix, which is later used in classification.

The number of classes should be specified separately, and the labels vector should contain values in the range [0, numClasses - 1]. The data::NormalizeLabels() function can be used if the labels vector does not contain values in the required range.

Parameters
dataInput, training data.
labelsLabels of dataset.
numClassesNumber of classes in the dataset.
maxIterationsMaximum number of iterations for the perceptron learning algorithm.
template<typename LearnPolicy = SimpleWeightUpdate, typename WeightInitializationPolicy = ZeroInitialization, typename MatType = arma::mat>
mlpack::perceptron::Perceptron< LearnPolicy, WeightInitializationPolicy, MatType >::Perceptron ( const Perceptron< LearnPolicy, WeightInitializationPolicy, MatType > &  other,
const MatType &  data,
const arma::Row< size_t > &  labels,
const arma::rowvec &  instanceWeights 
)

Alternate constructor which copies parameters from an already initiated perceptron.

Parameters
otherThe other initiated Perceptron object from which we copy the values from.
dataThe data on which to train this Perceptron object on.
DWeight vector to use while training. For boosting purposes.
labelsThe labels of data.

Member Function Documentation

template<typename LearnPolicy = SimpleWeightUpdate, typename WeightInitializationPolicy = ZeroInitialization, typename MatType = arma::mat>
const arma::vec& mlpack::perceptron::Perceptron< LearnPolicy, WeightInitializationPolicy, MatType >::Biases ( ) const
inline
template<typename LearnPolicy = SimpleWeightUpdate, typename WeightInitializationPolicy = ZeroInitialization, typename MatType = arma::mat>
arma::vec& mlpack::perceptron::Perceptron< LearnPolicy, WeightInitializationPolicy, MatType >::Biases ( )
inline

Modify the biases. You had better know what you are doing!

Definition at line 137 of file perceptron.hpp.

References mlpack::perceptron::Perceptron< LearnPolicy, WeightInitializationPolicy, MatType >::biases.

template<typename LearnPolicy = SimpleWeightUpdate, typename WeightInitializationPolicy = ZeroInitialization, typename MatType = arma::mat>
void mlpack::perceptron::Perceptron< LearnPolicy, WeightInitializationPolicy, MatType >::Classify ( const MatType &  test,
arma::Row< size_t > &  predictedLabels 
)

Classification function.

After training, use the weights matrix to classify test, and put the predicted classes in predictedLabels.

Parameters
testTesting data or data to classify.
predictedLabelsVector to store the predicted classes after classifying test.
template<typename LearnPolicy = SimpleWeightUpdate, typename WeightInitializationPolicy = ZeroInitialization, typename MatType = arma::mat>
size_t mlpack::perceptron::Perceptron< LearnPolicy, WeightInitializationPolicy, MatType >::MaxIterations ( ) const
inline

Get the maximum number of iterations.

Definition at line 122 of file perceptron.hpp.

References mlpack::perceptron::Perceptron< LearnPolicy, WeightInitializationPolicy, MatType >::maxIterations.

template<typename LearnPolicy = SimpleWeightUpdate, typename WeightInitializationPolicy = ZeroInitialization, typename MatType = arma::mat>
size_t& mlpack::perceptron::Perceptron< LearnPolicy, WeightInitializationPolicy, MatType >::MaxIterations ( )
inline

Modify the maximum number of iterations.

Definition at line 124 of file perceptron.hpp.

References mlpack::perceptron::Perceptron< LearnPolicy, WeightInitializationPolicy, MatType >::maxIterations.

template<typename LearnPolicy = SimpleWeightUpdate, typename WeightInitializationPolicy = ZeroInitialization, typename MatType = arma::mat>
size_t mlpack::perceptron::Perceptron< LearnPolicy, WeightInitializationPolicy, MatType >::NumClasses ( ) const
inline

Get the number of classes this perceptron has been trained for.

Definition at line 127 of file perceptron.hpp.

References mlpack::perceptron::Perceptron< LearnPolicy, WeightInitializationPolicy, MatType >::weights.

template<typename LearnPolicy = SimpleWeightUpdate, typename WeightInitializationPolicy = ZeroInitialization, typename MatType = arma::mat>
template<typename Archive >
void mlpack::perceptron::Perceptron< LearnPolicy, WeightInitializationPolicy, MatType >::Serialize ( Archive &  ar,
const unsigned  int 
)

Serialize the perceptron.

template<typename LearnPolicy = SimpleWeightUpdate, typename WeightInitializationPolicy = ZeroInitialization, typename MatType = arma::mat>
void mlpack::perceptron::Perceptron< LearnPolicy, WeightInitializationPolicy, MatType >::Train ( const MatType &  data,
const arma::Row< size_t > &  labels,
const arma::rowvec &  instanceWeights = arma::rowvec() 
)

Train the perceptron on the given data for up to the maximum number of iterations (specified in the constructor or through MaxIterations()).

A single iteration corresponds to a single pass through the data, so if you want to pass through the dataset only once, set MaxIterations() to 1.

This training does not reset the model weights, so you can call Train() on multiple datasets sequentially.

Parameters
dataDataset on which training should be performed.
labelsLabels of the dataset. Make sure that these labels don't contain any values greater than NumClasses()!
instanceWeightsCost matrix. Stores the cost of mispredicting instances. This is useful for boosting.
template<typename LearnPolicy = SimpleWeightUpdate, typename WeightInitializationPolicy = ZeroInitialization, typename MatType = arma::mat>
const arma::mat& mlpack::perceptron::Perceptron< LearnPolicy, WeightInitializationPolicy, MatType >::Weights ( ) const
inline
template<typename LearnPolicy = SimpleWeightUpdate, typename WeightInitializationPolicy = ZeroInitialization, typename MatType = arma::mat>
arma::mat& mlpack::perceptron::Perceptron< LearnPolicy, WeightInitializationPolicy, MatType >::Weights ( )
inline

Modify the weight matrix. You had better know what you are doing!

Definition at line 132 of file perceptron.hpp.

References mlpack::perceptron::Perceptron< LearnPolicy, WeightInitializationPolicy, MatType >::weights.

Member Data Documentation

template<typename LearnPolicy = SimpleWeightUpdate, typename WeightInitializationPolicy = ZeroInitialization, typename MatType = arma::mat>
arma::vec mlpack::perceptron::Perceptron< LearnPolicy, WeightInitializationPolicy, MatType >::biases
private

The biases for each class.

Definition at line 152 of file perceptron.hpp.

Referenced by mlpack::perceptron::Perceptron< LearnPolicy, WeightInitializationPolicy, MatType >::Biases().

template<typename LearnPolicy = SimpleWeightUpdate, typename WeightInitializationPolicy = ZeroInitialization, typename MatType = arma::mat>
size_t mlpack::perceptron::Perceptron< LearnPolicy, WeightInitializationPolicy, MatType >::maxIterations
private

The maximum number of iterations during training.

Definition at line 141 of file perceptron.hpp.

Referenced by mlpack::perceptron::Perceptron< LearnPolicy, WeightInitializationPolicy, MatType >::MaxIterations().

template<typename LearnPolicy = SimpleWeightUpdate, typename WeightInitializationPolicy = ZeroInitialization, typename MatType = arma::mat>
arma::mat mlpack::perceptron::Perceptron< LearnPolicy, WeightInitializationPolicy, MatType >::weights
private

Stores the weights for each of the input class labels.

Each column corresponds to the weights for one class label, and each row corresponds to the weights for one dimension of the input data. The biases are held in a separate vector.

Definition at line 149 of file perceptron.hpp.

Referenced by mlpack::perceptron::Perceptron< LearnPolicy, WeightInitializationPolicy, MatType >::NumClasses(), and mlpack::perceptron::Perceptron< LearnPolicy, WeightInitializationPolicy, MatType >::Weights().


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