Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

MultiLayerNetwork Class Reference

Abstraction of a multi-layer perceptron network. More...

#include <MultiLayerNetwork.h>

Inheritance diagram for MultiLayerNetwork:

Inheritance graph
[legend]
Collaboration diagram for MultiLayerNetwork:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 MultiLayerNetwork (uint inputs, uint neuronLabelOffset=0, PublicValues &pv=defaultControl)
 Create a multi-layer network.

 MultiLayerNetwork (uint inputs, PublicValues &pv)
 MultiLayerNetwork (MultiLayerNetwork &srcNet)
 Copy constructor, NOT YET IMPLEMENTED.

 MultiLayerNetwork (const std::string &filename)
 Loads a multi-layer network from the given filename.

virtual ~MultiLayerNetwork ()
virtual void addLayer (int size)
 Adds a layer of the given size to the network. This new layer becomes the output layer.

virtual void connectLayer (uint srcLlayer)
 Completely connects the given layer with the layer below it, i.e., all neurons in the given layer will give their output to all the neurons in the layer below.

virtual void connect (uint srcLlayer, int srcNrn, int destNrn)
 Connects two neurons, with random weight.

virtual void connect (uint srcLlayer, int srcNrn, int destNrn, real weight)
 Connects two neurons, with the weight provided.

virtual void setBias (uint layer, int nrn, real bias)
 Sets the bias of the given neuron.

virtual uint getLayerCount () const
 The number of layers in the network (does not count the input layer as a layer).

virtual Vector getOutput (const Vector &input)
 Returns the output of the network for the given input.

virtual Vector getOutput (real *input)
 Wrapper function to allow getOutput() to work for an array of real as input as well.

virtual void train (TrainingSet &T, uint epochs, real learningRate=DEFAULT_LEARNINGRATE, real momentum=DEFAULT_MOMENTUM)
 Trains the network with data from the given TrainingSet using the backpropagation algorithm.

virtual void train (TrainingSet &T, Creal epochs, Creal learningRate=CDEFAULT_LEARNINGRATE, Creal momentum=CDEFAULT_MOMENTUM)
virtual void train (TrainingSet &T, PublicValues &parameters)
 get epochs, learningRate and momentum from the supplied PublicValues

void getError (TrainingSet &ts)
 compute error for the given traning set. The "epoch error" and "normalized epoch error" are then stored in the _control

void getErrorGREN (TrainingSet &ts)
 compute error for the given traning set. The "epoch error" and "normalized epoch error" are then stored in the _control

Error getErrorGREN (const Vector &input, const Vector &desired)
 real error for one example

virtual void trainExample (const Vector &input, const Vector &desiredOutput, real learningRate=DEFAULT_LEARNINGRATE, real momentum=DEFAULT_MOMENTUM)
 Trains one example only.

virtual void save (const std::string &filename)
 Saves the network to the given filename.

virtual void setActivationFunction (uint layer, ActivationFunction f, ActivationFunction df)
 Sets the activation function used by the neurons in the provided layer.

virtual const char * getClassName () const
 Returns "MultiLayerNetwork".

void resetWeights ()
 initialize weights to small values

const LayergetLayer (uint layer) const
 Get a layer of the network (0=input)
Exceptions:
Exception if an invalid layer is given.


uint getNeuronsCount () const
 Get the total count of neurons in all layers (excluding input "layer").

uint getLinksCount () const
 Get count of all weights of all neurons.

LayergetLayer (uint layer)
 Warning: using this non-const version, you can change the network's behaviour.

 operator std::string () const
 get brief info about the topology, etc.

PublicValues & getControl ()
void setControl (PublicValues &ctrl)
void setLabelOffset (uint firstLabel)
virtual void trainGREN (MultiLayerNetwork &errorNetwork, TrainingSet &ts, uint epochs, real learningRate=DEFAULT_LEARNINGRATE, real momentum=DEFAULT_MOMENTUM)
 Train the network using the error network.


Static Public Attributes

const real DEFAULT_MOMENTUM
const real DEFAULT_LEARNINGRATE
const Creal CDEFAULT_MOMENTUM
const Creal CDEFAULT_LEARNINGRATE

Protected Member Functions

InputLayer_inputLayer ()
 The input layer.

Layer_outputLayer ()
 The output layer.

void _layerValid (uint layer) const
 impl detail - throws then layer is not valid

void _connectLayer (Layer &srcLayer, Layer &destLayer)
void _attachGREN (MultiLayerNetwork &errorNetwork, bool detach)
 attach or detach the gren. TODO: detach doesn't yet restore the input links of GREN, so it's unusable after training standalone

void _trainExampleGREN (MultiLayerNetwork &errorNetwork, const Vector &input, real learningRate, real momentum)
 unlike _trainExample, _trainExampleGREN assumes that input was already presented


Protected Attributes

uint _nLayers
 Number of layers in the network.

std::vector< Layer * > _layers
 The layers.

PublicValues * _control
Error _exampleError
uint _neuronLabelOffset

Detailed Description

Abstraction of a multi-layer perceptron network.

Basically, layers of SimpleNeurons constitute this network. Training is done using the backpropagation technique which uses the gradient descent method.

The labels of the layers start from 0 (for the input layer) and then keep moving on. The labels of neurons in the layers is = *Layer::MAX_LAYER_SIZE +

All neurons in the layers are allowed to have a bias.

Todo:
The copy constructor


Constructor & Destructor Documentation

MultiLayerNetwork uint  inputs,
uint  neuronLabelOffset = 0,
PublicValues &  pv = defaultControl
 

Create a multi-layer network.

Parameters:
inputs The number of inputs taken in by the network

MultiLayerNetwork uint  inputs,
PublicValues &  pv
 

MultiLayerNetwork MultiLayerNetwork srcNet  ) 
 

Copy constructor, NOT YET IMPLEMENTED.

MultiLayerNetwork const std::string &  filename  ) 
 

Loads a multi-layer network from the given filename.

Parameters:
filename The name of the file from which to load the network
Exceptions:
Exception On any error

virtual ~MultiLayerNetwork  )  [virtual]
 


Member Function Documentation

void _attachGREN MultiLayerNetwork errorNetwork,
bool  detach
[protected]
 

attach or detach the gren. TODO: detach doesn't yet restore the input links of GREN, so it's unusable after training standalone

void _connectLayer Layer srcLayer,
Layer destLayer
[protected]
 

InputLayer* _inputLayer  )  [protected]
 

The input layer.

void _layerValid uint  layer  )  const [protected]
 

impl detail - throws then layer is not valid

Layer* _outputLayer  )  [protected]
 

The output layer.

void _trainExampleGREN MultiLayerNetwork errorNetwork,
const Vector input,
real  learningRate,
real  momentum
[protected]
 

unlike _trainExample, _trainExampleGREN assumes that input was already presented

virtual void addLayer int  size  )  [virtual]
 

Adds a layer of the given size to the network. This new layer becomes the output layer.

Reimplemented in TwoLayerNetwork.

virtual void connect uint  srcLlayer,
int  srcNrn,
int  destNrn,
real  weight
[virtual]
 

Connects two neurons, with the weight provided.

Parameters:
srcLayer The index of the layer in which the source neuron lies
srcNrn The index of the source neuron in the source layer
destNrn The index of the destination neuron (will be in the layer with index srcLayer+1)
weight The weight of the link
Exceptions:
Exception On any invalid argument values

virtual void connect uint  srcLlayer,
int  srcNrn,
int  destNrn
[virtual]
 

Connects two neurons, with random weight.

Parameters:
srcLayer The index of the layer in which the source neuron lies
srcNrn The index of the source neuron in the source layer
destNrn The index of the destination neuron (will be in the layer with index srcLayer+1)
Exceptions:
Exception On any invalid argument values

virtual void connectLayer uint  srcLlayer  )  [virtual]
 

Completely connects the given layer with the layer below it, i.e., all neurons in the given layer will give their output to all the neurons in the layer below.

Weights are random.

Parameters:
srcLayer The index of the source layer
Exceptions:
Exception If the layer index provided is invalid

virtual const char* getClassName  )  const [virtual]
 

Returns "MultiLayerNetwork".

Implements Network.

PublicValues& getControl  )  [inline]
 

void getError TrainingSet ts  ) 
 

compute error for the given traning set. The "epoch error" and "normalized epoch error" are then stored in the _control

Error getErrorGREN const Vector input,
const Vector desired
 

real error for one example

void getErrorGREN TrainingSet ts  ) 
 

compute error for the given traning set. The "epoch error" and "normalized epoch error" are then stored in the _control

Layer& getLayer uint  layer  ) 
 

Warning: using this non-const version, you can change the network's behaviour.

It's here because Neuron::getOutput() is not (yet) const

const Layer& getLayer uint  layer  )  const
 

Get a layer of the network (0=input)

Exceptions:
Exception if an invalid layer is given.

virtual uint getLayerCount  )  const [virtual]
 

The number of layers in the network (does not count the input layer as a layer).

uint getLinksCount  )  const
 

Get count of all weights of all neurons.

uint getNeuronsCount  )  const
 

Get the total count of neurons in all layers (excluding input "layer").

virtual Vector getOutput real input  )  [virtual]
 

Wrapper function to allow getOutput() to work for an array of real as input as well.

Does exactly the same thing as Network::getOutput(real*).

Reimplemented from Network.

virtual Vector getOutput const Vector input  )  [virtual]
 

Returns the output of the network for the given input.

Parameters:
input A vector of getDimension() reals
Returns:
The corresponding output of the network

Implements Network.

operator std::string  )  const
 

get brief info about the topology, etc.

void resetWeights  ) 
 

initialize weights to small values

virtual void save const std::string &  filename  )  [virtual]
 

Saves the network to the given filename.

The file is a simple text file, open it up in a text editor to see the format, quite simple

Parameters:
filename The name of the file to save the network in.

Implements Network.

virtual void setActivationFunction uint  layer,
ActivationFunction  f,
ActivationFunction  df
[virtual]
 

Sets the activation function used by the neurons in the provided layer.

Parameters:
layer The layer whose activation function is to be changed. layer>0 (as input neurons don't have any activation function) and layer<getLayerCount()
f The activation function to be used
df The derivative of the activation function to be used. Required for training.
Exceptions:
Exception if an invalid layer is given

virtual void setBias uint  layer,
int  nrn,
real  bias
[virtual]
 

Sets the bias of the given neuron.

Parameters:
layer The index of the layer in which the neuron lies
nrn The index of the neuron in the layer
bias The bias to be given to the neuron

void setControl PublicValues &  ctrl  )  [inline]
 

void setLabelOffset uint  firstLabel  )  [inline]
 

virtual void train TrainingSet T,
PublicValues &  parameters
[virtual]
 

get epochs, learningRate and momentum from the supplied PublicValues

virtual void train TrainingSet T,
Creal  epochs,
Creal  learningRate = CDEFAULT_LEARNINGRATE,
Creal  momentum = CDEFAULT_MOMENTUM
[virtual]
 

virtual void train TrainingSet T,
uint  epochs,
real  learningRate = DEFAULT_LEARNINGRATE,
real  momentum = DEFAULT_MOMENTUM
[virtual]
 

Trains the network with data from the given TrainingSet using the backpropagation algorithm.

Parameters:
T The TrainingSet containing input/desired-output vector pairs
epochs The number of epochs to train the network. An epoch is a single iteration through all input/desired-output vector pairs in T.
learningRate The learning rate to be used for weight updation
momentum The momentum factor to be used during weight updation. 0 by default.

virtual void trainExample const Vector input,
const Vector desiredOutput,
real  learningRate = DEFAULT_LEARNINGRATE,
real  momentum = DEFAULT_MOMENTUM
[virtual]
 

Trains one example only.

Returns:
error for this example

virtual void trainGREN MultiLayerNetwork errorNetwork,
TrainingSet ts,
uint  epochs,
real  learningRate = DEFAULT_LEARNINGRATE,
real  momentum = DEFAULT_MOMENTUM
[virtual]
 

Train the network using the error network.

Generalized Relief Error Network - included in the MultiLayerNetwork, because it only provides new functions and can (better: must) be used together with MultiLayerNetwork The error network has getInputCount() + getOutputCount() inputs (in that order)

Parameters:
ts contains input patterns to be trained. May also contain outputs - in this case, "real output error" will be computed


Member Data Documentation

PublicValues* _control [protected]
 

Error _exampleError [protected]
 

std::vector<Layer *> _layers [protected]
 

The layers.

uint _neuronLabelOffset [protected]
 

uint _nLayers [protected]
 

Number of layers in the network.

If you derive your own network from this class, the onus of keeping _nLayers consistent lies on you! Doesn't count the input "layer"

const Creal CDEFAULT_LEARNINGRATE [static]
 

const Creal CDEFAULT_MOMENTUM [static]
 

const real DEFAULT_LEARNINGRATE [static]
 

const real DEFAULT_MOMENTUM [static]
 


The documentation for this class was generated from the following file:
Generated on Fri Jun 18 13:19:11 2004 for Annie by doxygen 1.3.5