perceptron.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_METHODS_PERCEPTRON_PERCEPTRON_HPP
13 #define MLPACK_METHODS_PERCEPTRON_PERCEPTRON_HPP
14 
15 #include <mlpack/prereqs.hpp>
16 
20 
21 namespace mlpack {
22 namespace perceptron {
23 
33 template<typename LearnPolicy = SimpleWeightUpdate,
34  typename WeightInitializationPolicy = ZeroInitialization,
35  typename MatType = arma::mat>
37 {
38  public:
49  Perceptron(const size_t numClasses = 0,
50  const size_t dimensionality = 0,
51  const size_t maxIterations = 1000);
52 
66  Perceptron(const MatType& data,
67  const arma::Row<size_t>& labels,
68  const size_t numClasses,
69  const size_t maxIterations = 1000);
70 
88  Perceptron(const MatType& data,
89  const arma::Row<size_t>& labels,
90  const size_t numClasses,
91  const arma::rowvec& instanceWeights,
92  const size_t maxIterations = 1000);
93 
106  Perceptron(const Perceptron& other,
107  const MatType& data,
108  const arma::Row<size_t>& labels,
109  const size_t numClasses,
110  const arma::rowvec& instanceWeights);
111 
127  void Train(const MatType& data,
128  const arma::Row<size_t>& labels,
129  const size_t numClasses,
130  const arma::rowvec& instanceWeights = arma::rowvec());
131 
140  void Classify(const MatType& test, arma::Row<size_t>& predictedLabels);
141 
145  template<typename Archive>
146  void serialize(Archive& ar, const uint32_t /* version */);
147 
149  size_t MaxIterations() const { return maxIterations; }
151  size_t& MaxIterations() { return maxIterations; }
152 
154  size_t NumClasses() const { return weights.n_cols; }
155 
157  const arma::mat& Weights() const { return weights; }
159  arma::mat& Weights() { return weights; }
160 
162  const arma::vec& Biases() const { return biases; }
164  arma::vec& Biases() { return biases; }
165 
166  private:
168  size_t maxIterations;
169 
176  arma::mat weights;
177 
179  arma::vec biases;
180 };
181 
182 } // namespace perceptron
183 } // namespace mlpack
184 
185 #include "perceptron_impl.hpp"
186 
187 #endif
arma::vec & Biases()
Modify the biases. You had better know what you are doing!
Definition: perceptron.hpp:164
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes, Armadillo, cereal, and a few basic mlpa...
const arma::vec & Biases() const
Get the biases.
Definition: perceptron.hpp:162
void serialize(Archive &ar, const uint32_t)
Serialize the perceptron.
size_t NumClasses() const
Get the number of classes this perceptron has been trained for.
Definition: perceptron.hpp:154
void Train(const MatType &data, const arma::Row< size_t > &labels, const size_t numClasses, 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...
constexpr auto data(Container const &container) noexcept -> decltype(container.data())
Definition: iterator.hpp:79
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...
size_t & MaxIterations()
Modify the maximum number of iterations.
Definition: perceptron.hpp:151
const arma::mat & Weights() const
Get the weight matrix.
Definition: perceptron.hpp:157
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:159
size_t MaxIterations() const
Get the maximum number of iterations.
Definition: perceptron.hpp:149
This class implements a simple perceptron (i.e., a single layer neural network).
Definition: perceptron.hpp:36