panann
Classes | Public Member Functions | Protected Member Functions | List of all members
panann::RecurrentNeuralNetwork Class Reference

#include <RecurrentNeuralNetwork.h>

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

Classes

struct  CellLayer
 
struct  LongShortTermMemoryCell
 

Public Member Functions

 RecurrentNeuralNetwork (const RecurrentNeuralNetwork &)=delete
 
RecurrentNeuralNetworkoperator= (const RecurrentNeuralNetwork &)=delete
 
void SetCellMemorySize (size_t memory_size)
 
size_t GetCellMemorySize () const
 
void RunForward (const std::vector< double > &input) override
 
std::vector< double > & GetCellStates ()
 
void AddHiddenLayer (size_t neuron_count)=delete
 
void AddHiddenLayer (size_t cell_count, const std::vector< size_t > &cell_memory_sizes={})
 
void Construct () override
 
- Public Member Functions inherited from panann::Perceptron
 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)
 
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
 
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 ConnectFully () override
 
void FixNeuronConnectionIndices () override
 
void InitializeHiddenNeurons () override
 
void AllocateCellStates ()
 
bool AreCellStatesAllocated () const
 
void UpdateCellState (const LongShortTermMemoryCell &cell)
 
size_t AddCellMemoryStates (size_t count)
 
size_t GetCellCount () const
 
LongShortTermMemoryCellGetCell (size_t index)
 
size_t GetCellLayerCount () const
 
CellLayerGetCellLayer (size_t index)
 
void InitializeCellNeurons (const LongShortTermMemoryCell &cell, size_t input_connection_count, size_t output_connection_count)
 
void InitializeCellNeuronsOneGate (size_t neuron_start_index, size_t neurons_per_gate, ActivationFunctionType activation_function, size_t input_connection_count, size_t output_connection_count)
 
- Protected Member Functions inherited from panann::Perceptron
void AllocateWeights ()
 
bool AreWeightsAllocated () const
 
void InitializeNeurons ()
 
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)
 
void AllocateConnections ()
 
bool AreConnectionsAllocated () const
 
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
 

Additional Inherited Members

- Public Types inherited from panann::Perceptron
enum  ErrorCostFunction : uint8_t { MeanSquareError = 1, MeanAbsoluteError }
 

Detailed Description

A recurrent artificial neural network made out of long short term memory cells.

This network doesn't contain ordinary hidden neurons organized into layers. Instead, each layer contains a set of recurrent cells which are each made of a number of hidden units grouped into gates.

Note: RecurrentNeuralNetwork does not support any training algorithms, currently.

Member Function Documentation

◆ AddHiddenLayer()

void panann::RecurrentNeuralNetwork::AddHiddenLayer ( size_t  cell_count,
const std::vector< size_t > &  cell_memory_sizes = {} 
)

Add a hidden layer of LSTM cells.
Each cell may have a different cell memory size passed via |cell_memory_sizes|. If the vector doesn't contain an element for a cell or if that element is 0, the cell memory size for that cell will be the default returned via GetCellMemorySize().

See also
GetCellMemorySize()

◆ Construct()

void panann::RecurrentNeuralNetwork::Construct ( )
overridevirtual

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

Reimplemented from panann::Perceptron.

◆ FixNeuronConnectionIndices()

void panann::RecurrentNeuralNetwork::FixNeuronConnectionIndices ( )
overrideprotectedvirtual

Set the input and output connection indices assigned to each neuron into the neurons themselves.

Reimplemented from panann::MultiLayerNeuralTopology.

◆ GetCellStates()

std::vector< double > & panann::RecurrentNeuralNetwork::GetCellStates ( )

Get a writable vector of memory state for all cells in the network.

◆ InitializeCellNeurons()

void panann::RecurrentNeuralNetwork::InitializeCellNeurons ( const LongShortTermMemoryCell cell,
size_t  input_connection_count,
size_t  output_connection_count 
)
protected

Initialize all the neurons making up |cell|.
Each gate of the cell will be assigned |input_connection_count| input connections (and zero output connections).
The output layer of the cell will be assigned |output_connection_count| output connections (and zero input connections).

◆ InitializeCellNeuronsOneGate()

void panann::RecurrentNeuralNetwork::InitializeCellNeuronsOneGate ( size_t  neuron_start_index,
size_t  neurons_per_gate,
ActivationFunctionType  activation_function,
size_t  input_connection_count,
size_t  output_connection_count 
)
protected

Initialize the neurons in one gate of a cell.

◆ InitializeHiddenNeurons()

void panann::RecurrentNeuralNetwork::InitializeHiddenNeurons ( )
overrideprotectedvirtual

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

Reimplemented from panann::Perceptron.

◆ RunForward()

void panann::RecurrentNeuralNetwork::RunForward ( const std::vector< double > &  input)
overridevirtual

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 from panann::Perceptron.

◆ SetCellMemorySize()

void panann::RecurrentNeuralNetwork::SetCellMemorySize ( size_t  memory_size)

Set the number of memory states which each cell will contain by default.
This value has a quadratic effect on the size of the network topology. Increasing the number of cell memory states increases the number of neurons in each cell gate - effectively, increasing this value by one increases the number of hidden neurons in the network topology by 5 per LSTM cell. Default: 200


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