mlpack 3.4.2
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
21namespace mlpack {
22namespace perceptron {
23
33template<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
83 Perceptron(const Perceptron& other,
84 const MatType& data,
85 const arma::Row<size_t>& labels,
86 const size_t numClasses,
87 const arma::rowvec& instanceWeights);
88
104 void Train(const MatType& data,
105 const arma::Row<size_t>& labels,
106 const size_t numClasses,
107 const arma::rowvec& instanceWeights = arma::rowvec());
108
117 void Classify(const MatType& test, arma::Row<size_t>& predictedLabels);
118
122 template<typename Archive>
123 void serialize(Archive& ar, const unsigned int /* version */);
124
126 size_t MaxIterations() const { return maxIterations; }
128 size_t& MaxIterations() { return maxIterations; }
129
131 size_t NumClasses() const { return weights.n_cols; }
132
134 const arma::mat& Weights() const { return weights; }
136 arma::mat& Weights() { return weights; }
137
139 const arma::vec& Biases() const { return biases; }
141 arma::vec& Biases() { return biases; }
142
143 private:
145 size_t maxIterations;
146
153 arma::mat weights;
154
156 arma::vec biases;
157};
158
159} // namespace perceptron
160} // namespace mlpack
161
162#include "perceptron_impl.hpp"
163
164#endif
This class implements a simple perceptron (i.e., a single layer neural network).
Definition: perceptron.hpp:37
size_t NumClasses() const
Get the number of classes this perceptron has been trained for.
Definition: perceptron.hpp:131
arma::vec & Biases()
Modify the biases. You had better know what you are doing!
Definition: perceptron.hpp:141
void Classify(const MatType &test, arma::Row< size_t > &predictedLabels)
Classification function.
size_t MaxIterations() const
Get the maximum number of iterations.
Definition: perceptron.hpp:126
arma::mat & Weights()
Modify the weight matrix. You had better know what you are doing!
Definition: perceptron.hpp:136
size_t & MaxIterations()
Modify the maximum number of iterations.
Definition: perceptron.hpp:128
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...
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 classif...
const arma::mat & Weights() const
Get the weight matrix.
Definition: perceptron.hpp:134
void serialize(Archive &ar, const unsigned int)
Serialize the perceptron.
Perceptron(const Perceptron &other, const MatType &data, const arma::Row< size_t > &labels, const size_t numClasses, const arma::rowvec &instanceWeights)
Alternate constructor which copies parameters from an already initiated perceptron.
const arma::vec & Biases() const
Get the biases.
Definition: perceptron.hpp:139
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,...
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
The core includes that mlpack expects; standard C++ includes and Armadillo.