panann
Public Types | Public Member Functions | Protected Member Functions | List of all members
panann::Perceptron Class Reference

#include <Perceptron.h>

Inheritance diagram for panann::Perceptron:
Inheritance graph
[legend]
Collaboration diagram for panann::Perceptron:
Collaboration graph
[legend]

Public Types

enum  ErrorCostFunction : uint8_t { MeanSquareError = 1, MeanAbsoluteError }
 

Public Member Functions

 Perceptron (const Perceptron &)=delete
 
Perceptronoperator= (const Perceptron &)=delete
 
void SetErrorCostFunction (ErrorCostFunction mode)
 
ErrorCostFunction GetErrorCostFunction () const
 
void SetHiddenNeuronActivationFunctionType (ActivationFunctionType type)
 
ActivationFunctionType GetHiddenNeuronActivationFunctionType () const
 
void SetOutputNeuronActivationFunctionType (ActivationFunctionType type)
 
ActivationFunctionType GetOutputNeuronActivationFunctionType () const
 
void InitializeWeightsRandom (double min=-1.0, double max=1.0)
 
void InitializeWeights (const TrainingData &training_data)
 
virtual void RunForward (const std::vector< double > &input)
 
void RunBackward (const std::vector< double > &output)
 
double GetError (const std::vector< double > &output)
 
double GetError (const TrainingData &training_data)
 
std::vector< double > & GetWeights ()
 
void SetWeights (const std::vector< double > &weights)
 
void GetOutput (std::vector< double > *output) const
 
virtual void Construct ()
 
bool IsConstructed () const
 
void EnableErrorShaping ()
 
void DisableErrorShaping ()
 
- Public Member Functions inherited from panann::MultiLayerNeuralTopology
 MultiLayerNeuralTopology (const MultiLayerNeuralTopology &)=delete
 
MultiLayerNeuralTopologyoperator= (const MultiLayerNeuralTopology &)=delete
 
void AddHiddenLayer (size_t neuron_count)
 
void EnableShortcutConnections ()
 
void DisableShortcutConnections ()
 
void ConstructTopology ()
 
bool IsTopologyConstructed () const
 
size_t GetHiddenLayerCount () const
 
const LayerGetHiddenLayer (size_t layer_index) const
 
size_t GetInputConnectionCount () const
 
size_t GetOutputConnectionCount () const
 
const InputConnectionGetInputConnection (size_t index) const
 
const OutputConnectionGetOutputConnection (size_t index) const
 
- Public Member Functions inherited from panann::NeuronContainer
 NeuronContainer (const NeuronContainer &)=delete
 
NeuronContaineroperator= (const NeuronContainer &)=delete
 
void SetInputNeuronCount (size_t input_neuron_count)
 
size_t GetInputNeuronCount () const
 
void SetOutputNeuronCount (size_t output_neuron_count)
 
size_t GetOutputNeuronCount () const
 
size_t GetNeuronCount () const
 
const NeuronGetNeuron (size_t neuron_index) const
 

Protected Member Functions

void AllocateWeights ()
 
bool AreWeightsAllocated () const
 
void InitializeNeurons ()
 
virtual void InitializeHiddenNeurons ()
 
void ComputeNeuronValue (size_t neuron_index)
 
void ComputeNeuronValueRange (size_t neuron_start_index, size_t neuron_count)
 
void ComputeNeuronError (size_t neuron_index)
 
void ResetOutputLayerError ()
 
void CalculateOutputLayerError (const std::vector< double > &output)
 
double GetError () const
 
RandomWrapperGetRandom ()
 
size_t GetWeightCount () const
 
double & GetWeight (size_t index)
 
- Protected Member Functions inherited from panann::MultiLayerNeuralTopology
LayerGetHiddenLayer (size_t layer_index)
 
InputConnectionGetInputConnection (size_t index)
 
OutputConnectionGetOutputConnection (size_t index)
 
size_t AddInputConnections (size_t count)
 
size_t AddOutputConnections (size_t count)
 
virtual void FixNeuronConnectionIndices ()
 
void AllocateConnections ()
 
bool AreConnectionsAllocated () const
 
virtual void ConnectFully ()
 
void ConnectLayerToNeuron (size_t from_neuron_index, size_t from_neuron_count, size_t to_neuron_index)
 
void ConnectLayers (size_t from_neuron_index, size_t from_neuron_count, size_t to_neuron_index, size_t to_neuron_count)
 
void ConnectBiasNeuron (size_t bias_neuron_index, size_t to_neuron_index, size_t to_neuron_count)
 
void ConnectNeurons (size_t from_neuron_index, size_t to_neuron_index)
 
- Protected Member Functions inherited from panann::NeuronContainer
size_t GetHiddenNeuronStartIndex () const
 
size_t GetInputNeuronStartIndex () const
 
size_t GetOutputNeuronStartIndex () const
 
size_t GetBiasNeuronStartIndex () const
 
size_t GetHiddenNeuronCount () const
 
size_t GetBiasNeuronCount () const
 
size_t AddHiddenNeurons (size_t count)
 
void AddBiasNeurons (size_t count)
 
void AllocateNeurons ()
 
bool AreNeuronsAllocated () const
 
void SetNeuronActivationFunction (size_t neuron_index, ActivationFunctionType type)
 
NeuronGetNeuron (size_t neuron_index)
 
NeuronGetInputNeuron (size_t input_neuron_index)
 
NeuronGetOutputNeuron (size_t output_neuron_index)
 
NeuronGetBiasNeuron (size_t bias_neuron_index)
 
NeuronGetHiddenNeuron (size_t hidden_neuron_index)
 
const NeuronGetOutputNeuron (size_t output_neuron_index) const
 

Detailed Description

Simple feed-forward, multi-layer perceptron.

Member Function Documentation

◆ Construct()

void panann::Perceptron::Construct ( )
virtual

Build the neural network.
After construction, the network topology may not be modified.

Reimplemented in panann::RecurrentNeuralNetwork.

◆ EnableErrorShaping()

void panann::Perceptron::EnableErrorShaping ( )

Enable to perform shaping of the error curve. Default: Disabled

◆ GetError() [1/2]

double panann::Perceptron::GetError ( const std::vector< double > &  output)

Get the total network error by calculating the average of the difference between each output neuron value and each value in the output parameter.
The difference between the expected value and the output neuron value will be modified according to the error cost function.

Parameters
outputExpected output values. Difference between this and the value of each output neuron is our total network error. The number of values in output must be the same as the number of output neurons in this network.
See also
ErrorCostFunction
SetErrorCostFunction

◆ GetError() [2/2]

double panann::Perceptron::GetError ( const TrainingData training_data)

Get the total network error against a set of examples.
For each example, we run the network forward on the input and compute the difference between the output and the values stored in each output neuron.
The total network error is computed as the average of all of those computed differences.
The difference between the expected value and the output neuron value will be modified according to the error cost function.

See also
ErrorCostFunction
SetErrorCostFunction

◆ GetOutput()

void panann::Perceptron::GetOutput ( std::vector< double > *  output) const

Writes all of the output neuron values into |output|.
Existing values in |output| will be discarded.

◆ GetWeights()

std::vector< double > & panann::Perceptron::GetWeights ( )

Get a writable vector containing all the weight values for the network.

◆ InitializeHiddenNeurons()

void panann::Perceptron::InitializeHiddenNeurons ( )
protectedvirtual

Set the default activation function etc for all hidden neurons in the network.

Reimplemented in panann::RecurrentNeuralNetwork.

◆ InitializeNeurons()

void panann::Perceptron::InitializeNeurons ( )
protected

Set the initial value, activation function, etc for all neurons in the network.

◆ InitializeWeights()

void panann::Perceptron::InitializeWeights ( const TrainingData training_data)

Initialize the weight of each connection via Widrow-Nguyen's algorithm.

◆ InitializeWeightsRandom()

void panann::Perceptron::InitializeWeightsRandom ( double  min = -1.0,
double  max = 1.0 
)

Reset every weight in the network to a random value between min and max.

◆ IsConstructed()

bool panann::Perceptron::IsConstructed ( ) const

Returns true if the network has been constructed and false otherwise.
Note: Once constructed, the network topology is fixed and cannot be changed.

◆ RunBackward()

void panann::Perceptron::RunBackward ( const std::vector< double > &  output)

Compute the error attributed to each neuron in the network.
Begins by calculating the difference between each output neuron value and each element in the output parameter.
Next we pull that neuron error backwards through the network, computing the partial error contributed by each neuron in the network.

Parameters
outputMust have the same number of elements as this network has output neurons.

◆ RunForward()

void panann::Perceptron::RunForward ( const std::vector< double > &  input)
virtual

Run the network forward on a set of inputs.
The values computed by running the network will be stored in the output neurons.
Works by assigning the values in the input parameter into each input neuron and pulling those values through the hidden layers, calculating the output of each neuron as the result of executing the activation function on the sum of the incoming values multiplied by their connection weights.

Parameters
inputMust have the same number of elements as this network has input neurons.

Reimplemented in panann::RecurrentNeuralNetwork.

◆ SetErrorCostFunction()

void panann::Perceptron::SetErrorCostFunction ( ErrorCostFunction  mode)

Set the cost function we will use to calculate the total network error.
Default: MeanSquareError

See also
GetError
ErrorCostFunction

◆ SetHiddenNeuronActivationFunctionType()

void panann::Perceptron::SetHiddenNeuronActivationFunctionType ( ActivationFunctionType  type)

Set the default activation function we will use for hidden layer neurons.
Default: Sigmoid

◆ SetOutputNeuronActivationFunctionType()

void panann::Perceptron::SetOutputNeuronActivationFunctionType ( ActivationFunctionType  type)

Set the default activation function we will use for output layer neurons.
Default: Sigmoid

◆ SetWeights()

void panann::Perceptron::SetWeights ( const std::vector< double > &  weights)

Set the weight values for the network based on an input vector |weights|.
The weight values will be copied from the provided vector which must contain exactly the number of values for which this network has weights.


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