panann
|
#include <Perceptron.h>
Public Types | |
enum | ErrorCostFunction : uint8_t { MeanSquareError = 1, MeanAbsoluteError } |
Public Member Functions | |
Perceptron (const Perceptron &)=delete | |
Perceptron & | operator= (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 () |
![]() | |
MultiLayerNeuralTopology (const MultiLayerNeuralTopology &)=delete | |
MultiLayerNeuralTopology & | operator= (const MultiLayerNeuralTopology &)=delete |
void | AddHiddenLayer (size_t neuron_count) |
void | EnableShortcutConnections () |
void | DisableShortcutConnections () |
void | ConstructTopology () |
bool | IsTopologyConstructed () const |
size_t | GetHiddenLayerCount () const |
const Layer & | GetHiddenLayer (size_t layer_index) const |
size_t | GetInputConnectionCount () const |
size_t | GetOutputConnectionCount () const |
const InputConnection & | GetInputConnection (size_t index) const |
const OutputConnection & | GetOutputConnection (size_t index) const |
![]() | |
NeuronContainer (const NeuronContainer &)=delete | |
NeuronContainer & | operator= (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 Neuron & | GetNeuron (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 |
RandomWrapper & | GetRandom () |
size_t | GetWeightCount () const |
double & | GetWeight (size_t index) |
![]() | |
Layer & | GetHiddenLayer (size_t layer_index) |
InputConnection & | GetInputConnection (size_t index) |
OutputConnection & | GetOutputConnection (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) |
![]() | |
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) |
Neuron & | GetNeuron (size_t neuron_index) |
Neuron & | GetInputNeuron (size_t input_neuron_index) |
Neuron & | GetOutputNeuron (size_t output_neuron_index) |
Neuron & | GetBiasNeuron (size_t bias_neuron_index) |
Neuron & | GetHiddenNeuron (size_t hidden_neuron_index) |
const Neuron & | GetOutputNeuron (size_t output_neuron_index) const |
Simple feed-forward, multi-layer perceptron.
|
virtual |
Build the neural network.
After construction, the network topology may not be modified.
Reimplemented in panann::RecurrentNeuralNetwork.
void panann::Perceptron::EnableErrorShaping | ( | ) |
Enable to perform shaping of the error curve. Default: Disabled
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.
output | Expected 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. |
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.
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.
std::vector< double > & panann::Perceptron::GetWeights | ( | ) |
Get a writable vector containing all the weight values for the network.
|
protectedvirtual |
Set the default activation function etc for all hidden neurons in the network.
Reimplemented in panann::RecurrentNeuralNetwork.
|
protected |
Set the initial value, activation function, etc for all neurons in the network.
void panann::Perceptron::InitializeWeights | ( | const TrainingData & | training_data | ) |
Initialize the weight of each connection via Widrow-Nguyen's algorithm.
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.
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.
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.
output | Must have the same number of elements as this network has output neurons. |
|
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.
input | Must have the same number of elements as this network has input neurons. |
Reimplemented in panann::RecurrentNeuralNetwork.
void panann::Perceptron::SetErrorCostFunction | ( | ErrorCostFunction | mode | ) |
Set the cost function we will use to calculate the total network error.
Default: MeanSquareError
void panann::Perceptron::SetHiddenNeuronActivationFunctionType | ( | ActivationFunctionType | type | ) |
Set the default activation function we will use for hidden layer neurons.
Default: Sigmoid
void panann::Perceptron::SetOutputNeuronActivationFunctionType | ( | ActivationFunctionType | type | ) |
Set the default activation function we will use for output layer neurons.
Default: Sigmoid
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.