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

Neuron Class Reference

One of the fundamental annie classes - the basic Neuron. More...

#include <Neuron.h>

Inheritance diagram for Neuron:

Inheritance graph
[legend]
List of all members.

Public Member Functions

 Neuron (int label)
 Creates a Neuron with the given label, sets activation, output and error to 0.

 Neuron (Neuron &neuron)
virtual ~Neuron ()
 Destroys all input and output links.

virtual real getActivation () const
 Returns the activation of this neuron.

virtual real getOutput () const
 Returns the output of this neuron Calls _recacheOutput() and then returns _outputCache.

virtual real getError () const
 Returns the error of this neuron Calls _recacheError() and then returns _errorCache.

virtual int getLabel () const
 The label of this neuron.

virtual uint getInputCount () const
 The size of the input vector taken in by this neuron, ie, the number of neurons that give input to this neuron.

virtual uint getOutputCount () const
 The number of neurons that take the output of this neuron as input.

virtual void invalidateOutputCache ()
 Invalidates the output cache of this neuron.

virtual void invalidateErrorCache ()
 Invalidates the error cache of this neuron.

virtual int getInputs (std::vector< int > &labels, Vector &weights)
 Returns a list of neurons which provide this neuron with input and their weights.

void getWeights (Vector &out) const
 Returns input connection weights.

virtual void disconnect (Neuron *from)
 Removes the link between the given neuron and this neuron.

virtual real getWeight (Neuron *from) const
 Returns the weight of the link between the given neuron and this neuron.

virtual operator std::string () const
 Formatted string displaying details of this neuron.

virtual const char * getClassName () const=0
 Returns the name of the class that the neuron is an instance of.

bool instanceOf (const char *className) const
 Given a string, tells if this object is an instance of that class.


Public Attributes

LINKS _outputLinks
 Set of output links, i.e., links in which this neuron provides output This really shouldn't be public, and thus USE THIS AS IF IT WAS PROTECTED.


Protected Member Functions

virtual void _recacheOutput () const=0
 This function recalculates output if necessary Every instantiable sub-class of the basic Neuron class MUST implement this function.

virtual void _recacheError () const=0
 This function recalculates error if necessary Every instantiable sub-class of the basic Neuron class MUST implement this function.


Protected Attributes

int _label
 The label of the neuron.

bool _outputCacheValid
 Flag, true if the cached activation and output are valid and hence calls to getActivation() and getOutput() can simply return the cached values and don't have to recalculate.

real _activationCache
 The previously cached activation.

real _outputCache
 The previously cached output.

bool _errorCacheValid
 Flag, true if the cached error is valid.

real _errorCache
 The previously cached error.

std::vector< char * > _classHeirarchy
 The class heirarchy of the neuron.

LINKS _inputLinks
 Set of input links, i.e., links in which this neuron received input.

ActivationFunction _activationFunction
 The function that is applied to the activation of the neuron to get the output.


Friends

class Link
std::ostream & operator<< (std::ostream &s, const Neuron &neuron)
 Prints (string) neuron to the provided output stream try
 cout<<neuron<<endl; 
to see what it does.


Detailed Description

One of the fundamental annie classes - the basic Neuron.

This class acts only as a template, and cannot be instantiated. Each neuron has a (unique) label which is specified when creating the neuron. Note that no effort has been made to ensure that the labels are indeed unique, you'll have to take care of that yourself. The MultiLayerNetwork and RadialBasisNetwork for example assign the label of the neuron as: * Layer::MAX_LAYER_SIZE +

Each Neuron caches the activation, output and error. The getOutput() and getActivation() functions merely check if the cache is valid, if so they return the value in the cache otherwise they force fresh calculation of the output and error. Different types of neurons will have different ways of calculating the output and error. Hence, the instantiable sub-classes of this class must implement the protected functions _recacheOutput() and _recacheError() which calculate the activation, output and error and update the cache.

Also, each sub-class must provide the getClassName() function. Since C++ doesn't have a good class reflection system, this has been provided for some primitive reflection

See also:
InputNeuron

SimpleNeuron

CenterNeuron

Todo:
why doesn't it have connect??

the link connecting is really slow...


Constructor & Destructor Documentation

Neuron int  label  ) 
 

Creates a Neuron with the given label, sets activation, output and error to 0.

Parameters:
label The label to be given to this neuron

Neuron Neuron neuron  ) 
 

virtual ~Neuron  )  [virtual]
 

Destroys all input and output links.


Member Function Documentation

virtual void _recacheError  )  const [protected, pure virtual]
 

This function recalculates error if necessary Every instantiable sub-class of the basic Neuron class MUST implement this function.

The implementation would first check if the cache is valid and if not then recalculate the error update the cache value. Such a function would typically look like:

 void _recacheError()
 {
        if (_errorCacheValid)
         return;
     //Calculate the error at the neuron
        _errorCache = error;
        _errorCacheValid = true;
 }

Implemented in AbstractNeuron, CenterNeuron, and SimpleNeuron.

virtual void _recacheOutput  )  const [protected, pure virtual]
 

This function recalculates output if necessary Every instantiable sub-class of the basic Neuron class MUST implement this function.

The implementation would first check if the cache is valid and if not then recalculate the activation and output and update the corresponding cache values. Such a function would typically look like:

 void _recacheOutput()
 {
        if (_outputCacheValid)
            return;
     //Calculate the activation of the neuron
     _activationCache = activation;
     _outputCache = _activationFunction(_activationCache);
     _outputCacheValid = true;
 }

Implemented in AbstractNeuron, CenterNeuron, KohonenNeuron, and SimpleNeuron.

virtual void disconnect Neuron from  )  [virtual]
 

Removes the link between the given neuron and this neuron.

Parameters:
from The neuron which provides input to this neuron Invalidates the cache as well

virtual real getActivation  )  const [virtual]
 

Returns the activation of this neuron.

Calls _recacheOutput() and then returns _activationCache. Most sub-classes will not need to override this function

Returns:
Activation at this neuron

virtual const char* getClassName  )  const [pure virtual]
 

Returns the name of the class that the neuron is an instance of.

This function should be provided by every sub-class

Implemented in AbstractNeuron, CenterNeuron, InputNeuron, RecurrentNeuron, and SimpleNeuron.

virtual real getError  )  const [virtual]
 

Returns the error of this neuron Calls _recacheError() and then returns _errorCache.

Most sub-classes will not need to override this function

Returns:
Error estimate at this neuron

virtual uint getInputCount  )  const [virtual]
 

The size of the input vector taken in by this neuron, ie, the number of neurons that give input to this neuron.

Returns:
_inputLinks.size()

virtual int getInputs std::vector< int > &  labels,
Vector weights
[virtual]
 

Returns a list of neurons which provide this neuron with input and their weights.

Parameters:
labels List of neurons (their labels) that provide input to this neuron returned here
weights Weights of the links returned here Thus, the pair (labels[i],weights[i]) specifies where this neuron gets input from and what the corresponding weights are

virtual int getLabel  )  const [virtual]
 

The label of this neuron.

virtual real getOutput  )  const [virtual]
 

Returns the output of this neuron Calls _recacheOutput() and then returns _outputCache.

Most sub-classes will not need to override this function

Returns:
Output of this neuron

Reimplemented in RecurrentNeuron.

virtual uint getOutputCount  )  const [virtual]
 

The number of neurons that take the output of this neuron as input.

Returns:
_outputLinks.size()

virtual real getWeight Neuron from  )  const [virtual]
 

Returns the weight of the link between the given neuron and this neuron.

Parameters:
from The neuron which provides input to this neuron.
Returns:
The weight of the corresponding link

Reimplemented in AbstractNeuron.

void getWeights Vector out  )  const
 

Returns input connection weights.

Parameters:
out - must be of getInputCount() size!

bool instanceOf const char *  className  )  const
 

Given a string, tells if this object is an instance of that class.

Basically, a work-around the absence of standardized class reflection techniques in C++. For example, consider the following:

 SimpleNeuron n(32);
 n.instanceOf("Neuron"); //returns true
 n.instanceOf("SimpleNeuron"); //returns true
 n.instanceOf("CenterNeuron"); //returns false
DO NOT override this function
Parameters:
className Name of the class to check this with
Returns:
true if the object is an instance of the given class, false otherwise

virtual void invalidateErrorCache  )  [virtual]
 

Invalidates the error cache of this neuron.

Causes the cache of all neurons who provide input to this neuron to be invalidated as well

virtual void invalidateOutputCache  )  [virtual]
 

Invalidates the output cache of this neuron.

Should be called on any structural change Structural changes such as changes to the input or output links and/or their weights should invalidate the cache of the neuron using this function. Causes the cache of all neurons who receive input from this neuron to be invalidated as well.

Reimplemented in RecurrentNeuron.

virtual operator std::string  )  const [virtual]
 

Formatted string displaying details of this neuron.

Useful for debugging. Sub-classes should implement this function as well in order to display their characteristics

Reimplemented in AbstractNeuron, CenterNeuron, and InputNeuron.


Friends And Related Function Documentation

friend class Link [friend]
 

std::ostream& operator<< std::ostream &  s,
const Neuron neuron
[friend]
 

Prints (string) neuron to the provided output stream try

 cout<<neuron<<endl; 
to see what it does.


Member Data Documentation

real _activationCache [mutable, protected]
 

The previously cached activation.

ActivationFunction _activationFunction [protected]
 

The function that is applied to the activation of the neuron to get the output.

std::vector<char *> _classHeirarchy [protected]
 

The class heirarchy of the neuron.

For example, if this list contains the string "Neuron", "A","B" then it tells you that the particular object is an instance of class "B", which is a sub-class of "A" which is a sub-class of Neuron.

If you ever derive your own Neuron from any of the existing types of neurons then you MUST add the class name of that neuron to this list.

See also:
instanceOf

real _errorCache [mutable, protected]
 

The previously cached error.

In the literature, this is typically : For MLP, this means difference of output from the desired output. (For hidden neurons, this is summed from errors node connects to * weight For output neuron: = (d_j - y_j) dy_j For hidden neuron: = ( ( w_jk)) * dy_j where d_j is desired output of neuron j

bool _errorCacheValid [mutable, protected]
 

Flag, true if the cached error is valid.

LINKS _inputLinks [protected]
 

Set of input links, i.e., links in which this neuron received input.

int _label [protected]
 

The label of the neuron.

real _outputCache [mutable, protected]
 

The previously cached output.

bool _outputCacheValid [mutable, protected]
 

Flag, true if the cached activation and output are valid and hence calls to getActivation() and getOutput() can simply return the cached values and don't have to recalculate.

Set to false by disconnect() and other functions in the sub-classes of this neuron

LINKS _outputLinks
 

Set of output links, i.e., links in which this neuron provides output This really shouldn't be public, and thus USE THIS AS IF IT WAS PROTECTED.

I had to keep this public because of an implementation issue.


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