#include <Neuron.h>
Inheritance diagram for Neuron:
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; |
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
the link connecting is really slow...
|
Creates a Neuron with the given label, sets activation, output and error to 0.
|
|
|
|
Destroys all input and output links.
|
|
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. |
|
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. |
|
Removes the link between the given neuron and this neuron.
|
|
Returns the activation of this neuron. Calls _recacheOutput() and then returns _activationCache. Most sub-classes will not need to override this function
|
|
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. |
|
Returns the error of this neuron Calls _recacheError() and then returns _errorCache. Most sub-classes will not need to override this function
|
|
The size of the input vector taken in by this neuron, ie, the number of neurons that give input to this neuron.
|
|
Returns a list of neurons which provide this neuron with input and their weights.
|
|
The label of this neuron.
|
|
Returns the output of this neuron Calls _recacheOutput() and then returns _outputCache. Most sub-classes will not need to override this function
Reimplemented in RecurrentNeuron. |
|
The number of neurons that take the output of this neuron as input.
|
|
Returns the weight of the link between the given neuron and this neuron.
Reimplemented in AbstractNeuron. |
|
Returns input connection weights.
|
|
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
|
|
Invalidates the error cache of this neuron. Causes the cache of all neurons who provide input to this neuron to be invalidated as well |
|
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. |
|
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. |
|
|
|
Prints (string) neuron to the provided output stream try cout<<neuron<<endl;
|
|
The previously cached activation.
|
|
The function that is applied to the activation of the neuron to get the output.
|
|
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.
|
|
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 |
|
Flag, true if the cached error is valid.
|
|
Set of input links, i.e., links in which this neuron received input.
|
|
The label of the neuron.
|
|
The previously cached output.
|
|
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 |
|
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. |