Offers a basic structure for recurrent networks. More...
#include <shark/Models/RecurrentStructure.h>
Public Types | |
enum | SigmoidType { Linear, Logistic, Tanh, FastSigmoid } |
type enum for the different variants of sigmoids More... | |
Public Member Functions | |
SHARK_EXPORT_SYMBOL | RecurrentStructure () |
const IntMatrix & | connections () const |
bool | connection (std::size_t i, std::size_t j) const |
returns whether the connection between neuron i and j exists More... | |
const RealMatrix & | weights () const |
returns the current weight matrix More... | |
double | weight (std::size_t i, std::size_t j) const |
returns the weight of the connection between neuron i and j More... | |
SigmoidType | sigmoidType () const |
returns the type of sigmoid used in this network More... | |
void | setSigmoidType (SigmoidType sigmoidType) |
SHARK_EXPORT_SYMBOL void | setWeights (const RealMatrix &weights) |
SHARK_EXPORT_SYMBOL void | setStructure (std::size_t inputs, std::size_t outputs, const IntMatrix &connections, SigmoidType sigmoidType=Logistic) |
Based on a given connection matrix a network is created. More... | |
SHARK_EXPORT_SYMBOL void | setStructure (std::size_t in, std::size_t hidden, std::size_t out, bool bias=true, SigmoidType sigmoidType=Logistic) |
Creates a fully connected topology for the network with optional bias. More... | |
SHARK_EXPORT_SYMBOL RealVector | parameterVector () const |
get internal parameters of the model More... | |
SHARK_EXPORT_SYMBOL void | setParameterVector (RealVector const &newParameters) |
set internal parameters of the model More... | |
SHARK_EXPORT_SYMBOL void | read (InArchive &archive) |
From ISerializable, reads the Network from an archive. More... | |
SHARK_EXPORT_SYMBOL void | write (OutArchive &archive) const |
From ISerializable, writes the Network to an archive. More... | |
std::size_t | inputs () const |
The number of input neurons of the network. More... | |
std::size_t | outputs () const |
The number of output neurons of the network. More... | |
std::size_t | numberOfNeurons () const |
std::size_t | numberOfUnits () const |
std::size_t | bias () const |
The index of the bias unit. More... | |
std::size_t | parameters () const |
number of parameters of the network More... | |
SHARK_EXPORT_SYMBOL double | neuron (double activation) |
Activation function for a neuron. More... | |
SHARK_EXPORT_SYMBOL double | neuronDerivative (double activation) |
Computes the derivative of the neuron. More... | |
Public Member Functions inherited from shark::ISerializable | |
virtual | ~ISerializable () |
Virtual d'tor. More... | |
void | load (InArchive &archive, unsigned int version) |
Versioned loading of components, calls read(...). More... | |
void | save (OutArchive &archive, unsigned int version) const |
Versioned storing of components, calls write(...). More... | |
BOOST_SERIALIZATION_SPLIT_MEMBER () | |
Protected Attributes | |
std::size_t | m_numberOfNeurons |
The total number of neurons of the network (input, output and hidden). More... | |
std::size_t | m_numberOfUnits |
total number units of the network (input, output, hidden and bias) More... | |
std::size_t | m_inputNeurons |
The number of input neurons of the network. More... | |
std::size_t | m_outputNeurons |
The number of output neurons of the network. More... | |
std::size_t | m_hidden |
The number of hidden neurons of the network. More... | |
std::size_t | m_bias |
index of the bias unit More... | |
SigmoidType | m_sigmoidType |
type of Sigmoid used by the network More... | |
std::size_t | m_numberOfParameters |
The absolute number of parameters of the network. More... | |
IntMatrix | m_connectionMatrix |
RealMatrix | m_weights |
Offers a basic structure for recurrent networks.
it is possible to define the tzpe of sigmoids and the form of the connection matrix. this structure can be shared between different types of ents like the RNNet and the OnlineRNNet
Definition at line 38 of file RecurrentStructure.h.
type enum for the different variants of sigmoids
Enumerator | |
---|---|
Linear | f(x) = x |
Logistic | f(x) = 1/(1+exp(-x)) |
Tanh | f(x) = tanh(x) |
FastSigmoid | f(x) = x/(1+|x|) |
Definition at line 47 of file RecurrentStructure.h.
SHARK_EXPORT_SYMBOL shark::RecurrentStructure::RecurrentStructure | ( | ) |
Creates an empty recurrent neural network. A call to setStructure is needed afterwards to configure the topology of the network
|
inline |
The index of the bias unit.
Definition at line 175 of file RecurrentStructure.h.
References m_bias.
Referenced by setSigmoidType().
|
inline |
returns whether the connection between neuron i and j exists
Definition at line 85 of file RecurrentStructure.h.
References m_connectionMatrix.
|
inline |
returns the connection Matrix of the network.
The format is best described with an example: given a Network with 2 inputs, 2 outputs and 2 hidden and no bias unit, where the inputs are only connected to the hidden units. The corresponding matrix looks like this:
1 2 3 4 5 6 7 1 1 0 1 1 1 1 first hidden 1 1 0 1 1 1 1 second hidden 0 0 0 1 1 1 1 first output 0 0 0 1 1 1 1 second output
The ith row stands for the ith neuron of the network and when an element (i,j) is 1, the ith unit will receive input from unit j. the first =0,..,inputs-1 columns are the input neurons followd by the column of the bias, which is completely zero in this example if j is a hidden or output neuron, the activation from the PREVIOUS time step is used. if j is an input neuron, the current input is used. input neurons can't receive activation. This is no limitation, since the hidden layer can be subdivided in arbitrary sublayers when the right topology is used. the last column of the matrix is reserved for the bias neuron. So the matrix has size NxN+1
Definition at line 81 of file RecurrentStructure.h.
References m_connectionMatrix.
Referenced by setSigmoidType().
|
inline |
The number of input neurons of the network.
Definition at line 160 of file RecurrentStructure.h.
References m_inputNeurons.
Referenced by shark::OnlineRNNet::inputSize(), shark::RNNet::inputSize(), and setSigmoidType().
SHARK_EXPORT_SYMBOL double shark::RecurrentStructure::neuron | ( | double | activation | ) |
Activation function for a neuron.
Referenced by parameters().
SHARK_EXPORT_SYMBOL double shark::RecurrentStructure::neuronDerivative | ( | double | activation | ) |
Computes the derivative of the neuron.
Referenced by parameters().
|
inline |
Definition at line 167 of file RecurrentStructure.h.
References m_numberOfNeurons.
|
inline |
Definition at line 170 of file RecurrentStructure.h.
References m_numberOfUnits.
Referenced by shark::OnlineRNNet::setOutputActivation().
|
inline |
The number of output neurons of the network.
Definition at line 164 of file RecurrentStructure.h.
References m_outputNeurons.
Referenced by shark::OnlineRNNet::outputSize(), shark::RNNet::outputSize(), and setSigmoidType().
|
inline |
number of parameters of the network
Definition at line 180 of file RecurrentStructure.h.
References m_numberOfParameters, neuron(), neuronDerivative(), and SHARK_EXPORT_SYMBOL.
Referenced by shark::OnlineRNNet::numberOfParameters(), and shark::RNNet::numberOfParameters().
SHARK_EXPORT_SYMBOL RealVector shark::RecurrentStructure::parameterVector | ( | ) | const |
get internal parameters of the model
Referenced by shark::OnlineRNNet::parameterVector(), shark::RNNet::parameterVector(), and setSigmoidType().
|
virtual |
From ISerializable, reads the Network from an archive.
Reimplemented from shark::ISerializable.
Referenced by setSigmoidType().
SHARK_EXPORT_SYMBOL void shark::RecurrentStructure::setParameterVector | ( | RealVector const & | newParameters | ) |
set internal parameters of the model
Referenced by shark::OnlineRNNet::setParameterVector(), shark::RNNet::setParameterVector(), and setSigmoidType().
|
inline |
sets the type of sigmoid used in this network
sigmoidType | the type of sigmoid |
Definition at line 105 of file RecurrentStructure.h.
References bias(), connections(), inputs(), Logistic, m_sigmoidType, outputs(), parameterVector(), read(), setParameterVector(), setStructure(), setWeights(), SHARK_EXPORT_SYMBOL, sigmoidType(), weights(), and write().
SHARK_EXPORT_SYMBOL void shark::RecurrentStructure::setStructure | ( | std::size_t | inputs, |
std::size_t | outputs, | ||
const IntMatrix & | connections, | ||
SigmoidType | sigmoidType = Logistic |
||
) |
Based on a given connection matrix a network is created.
This method needs to know how many inputs and outputs the network has and how the units are connected.
If a standard structure is needed, see the other version of this method. Also see connections for a quick explanation of the matrix format
The same mechanic applies alo to recurrentConnections but every element can be set, not only the lower triangular part.
After this operation, all weights are initialized to 0.
inputs | number of input neurons of the network |
outputs | number of output neurons of the network |
connections | feed-forward connections. default is true |
sigmoidType | the type of the sigmoid to be used. the default is the Logistic function |
Referenced by setSigmoidType().
SHARK_EXPORT_SYMBOL void shark::RecurrentStructure::setStructure | ( | std::size_t | in, |
std::size_t | hidden, | ||
std::size_t | out, | ||
bool | bias = true , |
||
SigmoidType | sigmoidType = Logistic |
||
) |
Creates a fully connected topology for the network with optional bias.
After a call, the network will have hidden+out units.
in | number of input neurons |
hidden | number of output neurons |
out | number of input neurons |
bias | enables bias neuron, default is true |
sigmoidType | the type of the sigmoid to be used. the default is the Logistic function |
SHARK_EXPORT_SYMBOL void shark::RecurrentStructure::setWeights | ( | const RealMatrix & | weights | ) |
Sets the weight matrix. It is not allowed that elements are non-zero when the element in the connection matrix is 0!
weights | the new weight matrix |
Referenced by setSigmoidType().
|
inline |
returns the type of sigmoid used in this network
Definition at line 99 of file RecurrentStructure.h.
References m_sigmoidType.
Referenced by setSigmoidType().
|
inline |
returns the weight of the connection between neuron i and j
Definition at line 94 of file RecurrentStructure.h.
References m_weights.
|
inline |
returns the current weight matrix
Definition at line 90 of file RecurrentStructure.h.
References m_weights.
Referenced by setSigmoidType().
|
virtual |
From ISerializable, writes the Network to an archive.
Reimplemented from shark::ISerializable.
Referenced by setSigmoidType().
|
protected |
|
protected |
stores the topology of the network. Element (i,j) is 1 if the ith neuron receives input from neuron j. The data for neuron i is stored in the ith row of the matrix.
Definition at line 219 of file RecurrentStructure.h.
Referenced by connection(), and connections().
|
protected |
The number of hidden neurons of the network.
Definition at line 204 of file RecurrentStructure.h.
|
protected |
The number of input neurons of the network.
Definition at line 200 of file RecurrentStructure.h.
Referenced by inputs().
|
protected |
The total number of neurons of the network (input, output and hidden).
Definition at line 194 of file RecurrentStructure.h.
Referenced by numberOfNeurons().
|
protected |
The absolute number of parameters of the network.
Definition at line 214 of file RecurrentStructure.h.
Referenced by parameters().
|
protected |
total number units of the network (input, output, hidden and bias)
Definition at line 197 of file RecurrentStructure.h.
Referenced by numberOfUnits().
|
protected |
The number of output neurons of the network.
Definition at line 202 of file RecurrentStructure.h.
Referenced by outputs().
|
protected |
type of Sigmoid used by the network
Definition at line 210 of file RecurrentStructure.h.
Referenced by setSigmoidType(), and sigmoidType().
|
protected |
stores the feed-forward part of the weights. the recurrent part is added via m_recurrentWeights. The weights for neuron i are stored in the ith row of the matrix
Definition at line 223 of file RecurrentStructure.h.