mlpack  2.0.1
perceptron.hpp
Go to the documentation of this file.
1 
14 #ifndef __MLPACK_METHODS_PERCEPTRON_PERCEPTRON_HPP
15 #define __MLPACK_METHODS_PERCEPTRON_PERCEPTRON_HPP
16 
17 #include <mlpack/core.hpp>
18 
22 
23 namespace mlpack {
24 namespace perceptron {
25 
35 template<typename LearnPolicy = SimpleWeightUpdate,
36  typename WeightInitializationPolicy = ZeroInitialization,
37  typename MatType = arma::mat>
39 {
40  public:
51  Perceptron(const size_t numClasses = 0,
52  const size_t dimensionality = 0,
53  const size_t maxIterations = 1000);
54 
68  Perceptron(const MatType& data,
69  const arma::Row<size_t>& labels,
70  const size_t numClasses,
71  const size_t maxIterations = 1000);
72 
83  Perceptron(const Perceptron<>& other,
84  const MatType& data,
85  const arma::Row<size_t>& labels,
86  const arma::rowvec& instanceWeights);
87 
103  void Train(const MatType& data,
104  const arma::Row<size_t>& labels,
105  const arma::rowvec& instanceWeights = arma::rowvec());
106 
115  void Classify(const MatType& test, arma::Row<size_t>& predictedLabels);
116 
120  template<typename Archive>
121  void Serialize(Archive& ar, const unsigned int /* version */);
122 
124  size_t MaxIterations() const { return maxIterations; }
126  size_t& MaxIterations() { return maxIterations; }
127 
129  size_t NumClasses() const { return weights.n_cols; }
130 
132  const arma::mat& Weights() const { return weights; }
134  arma::mat& Weights() { return weights; }
135 
137  const arma::vec& Biases() const { return biases; }
139  arma::vec& Biases() { return biases; }
140 
141 private:
144 
151  arma::mat weights;
152 
154  arma::vec biases;
155 };
156 
157 } // namespace perceptron
158 } // namespace mlpack
159 
160 #include "perceptron_impl.hpp"
161 
162 #endif
arma::mat weights
Stores the weights for each of the input class labels.
Definition: perceptron.hpp:151
arma::vec biases
The biases for each class.
Definition: perceptron.hpp:154
Linear algebra utility functions, generally performed on matrices or vectors.
const arma::vec & Biases() const
Get the biases.
Definition: perceptron.hpp:137
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...
arma::vec & Biases()
Modify the biases. You had better know what you are doing!
Definition: perceptron.hpp:139
size_t maxIterations
The maximum number of iterations during training.
Definition: perceptron.hpp:143
size_t MaxIterations() const
Get the maximum number of iterations.
Definition: perceptron.hpp:124
size_t & MaxIterations()
Modify the maximum number of iterations.
Definition: perceptron.hpp:126
size_t NumClasses() const
Get the number of classes this perceptron has been trained for.
Definition: perceptron.hpp:129
const arma::mat & Weights() const
Get the weight matrix.
Definition: perceptron.hpp:132
Include all of the base components required to write MLPACK methods, and the main MLPACK Doxygen docu...
void Serialize(Archive &ar, const unsigned int)
Serialize the perceptron.
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 c...
void Classify(const MatType &test, arma::Row< size_t > &predictedLabels)
Classification function.
arma::mat & Weights()
Modify the weight matrix. You had better know what you are doing!
Definition: perceptron.hpp:134
This class implements a simple perceptron (i.e., a single layer neural network).
Definition: perceptron.hpp:38