---
name: "mlpack_perceptron_Perceptron"
section: "3"
platform: "linux"
package: "mlpack-doc"
version: "1.0.10-1"
release: "Debian 8 (Jessie)"
platforms: ["linux"]
url: "https://new.carta.tech/mlpack_perceptron_Perceptron"
---

# mlpack\_perceptron\_Perceptron(3)

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

## NAME

mlpack::perceptron::Perceptron\< LearnPolicy, WeightInitializationPolicy, MatType \> -

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

## SYNOPSIS

### Public Member Functions

**Perceptron** (const MatType &data, const arma::Row\< size\_t \> &labels, int iterations)\
 *Constructor - constructs the perceptron by building the weightVectors matrix, which is later used in Classification.*  **Perceptron** (const **Perceptron**\<\> &other, MatType &data, const arma::rowvec &D, const arma::Row\< size\_t \> &labels)\
 *Alternate constructor which copies parameters from an already initiated perceptron.*  void **Classify** (const MatType &test, arma::Row\< size\_t \> &predictedLabels)\
 *Classification function.*

### Private Member Functions

void **Train** (const arma::rowvec &D)\
 *Training Function.*

### Private Attributes

arma::Row\< size\_t \> **classLabels**\
 *Stores the class labels for the input data.*  size\_t **iter**\
 *To store the number of iterations.*  arma::mat **trainData**\
 *Stores the training data to be used later on in UpdateWeights.*  arma::mat **weightVectors**\
 *Stores the weight vectors for each of the input class labels.*

## 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:**

*LearnPolicy* Options of **SimpleWeightUpdate** and GradientDescent. \
 *WeightInitializationPolicy* Option of **ZeroInitialization** and **RandomInitialization**.

Definition at line 46 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 MatType &data, const arma::Row\< size\_t \> &labels, intiterations)

Constructor - constructs the perceptron by building the weightVectors matrix, which is later used in Classification. It adds a bias input vector of 1 to the input data to take care of the bias weights.

**Parameters:**

*data* Input, training data. \
 *labels* Labels of dataset. \
 *iterations* Maximum 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\<\> &other, MatType &data, const arma::rowvec &D, const arma::Row\< size\_t \> &labels)

Alternate constructor which copies parameters from an already initiated perceptron.

**Parameters:**

*other* The other initiated **Perceptron** object from which we copy the values from. \
 *data* The data on which to train this **Perceptron** object on. \
 *D* Weight vector to use while training. For boosting purposes. \
 *labels* The labels of data.

## Member Function Documentation

### 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 weightVectors matrix to classify test, and put the predicted classes in predictedLabels.

**Parameters:**

*test* Testing data or data to classify. \
 *predictedLabels* Vector to store the predicted classes after classifying test.

### template\<typename LearnPolicy = SimpleWeightUpdate, typename WeightInitializationPolicy = ZeroInitialization, typename MatType = arma::mat\> void mlpack::perceptron::Perceptron\< LearnPolicy, WeightInitializationPolicy, MatType \>::Train (const arma::rowvec &D)` [private]`

Training Function. It trains on trainData using the cost matrix D

**Parameters:**

*D* Cost matrix. Stores the cost of mispredicting instances

## Member Data Documentation

### template\<typename LearnPolicy = SimpleWeightUpdate, typename WeightInitializationPolicy = ZeroInitialization, typename MatType = arma::mat\> arma::Row\<size\_t\> mlpack::perceptron::Perceptron\< LearnPolicy, WeightInitializationPolicy, MatType \>::classLabels` [private]`

Stores the class labels for the input data.

Definition at line 88 of file perceptron.hpp.

### template\<typename LearnPolicy = SimpleWeightUpdate, typename WeightInitializationPolicy = ZeroInitialization, typename MatType = arma::mat\> size\_t mlpack::perceptron::Perceptron\< LearnPolicy, WeightInitializationPolicy, MatType \>::iter` [private]`

To store the number of iterations.

Definition at line 85 of file perceptron.hpp.

### template\<typename LearnPolicy = SimpleWeightUpdate, typename WeightInitializationPolicy = ZeroInitialization, typename MatType = arma::mat\> arma::mat mlpack::perceptron::Perceptron\< LearnPolicy, WeightInitializationPolicy, MatType \>::trainData` [private]`

Stores the training data to be used later on in UpdateWeights.

Definition at line 94 of file perceptron.hpp.

### template\<typename LearnPolicy = SimpleWeightUpdate, typename WeightInitializationPolicy = ZeroInitialization, typename MatType = arma::mat\> arma::mat mlpack::perceptron::Perceptron\< LearnPolicy, WeightInitializationPolicy, MatType \>::weightVectors` [private]`

Stores the weight vectors for each of the input class labels.

Definition at line 91 of file perceptron.hpp.

## Author

Generated automatically by Doxygen for MLPACK from the source code.
