Feedforward Closedloop Learning
Neuron Class Reference

Neuron which calculates the output and performs learning. More...

#include <neuron.h>

Public Types

enum  WeightInitMethod { MAX_OUTPUT_RANDOM = 0, MAX_WEIGHT_RANDOM = 1, MAX_OUTPUT_CONST = 2, CONST_WEIGHTS = 3 }
 Constants how to init the weights in the neuron. More...
 
enum  ActivationFunction {
  LINEAR = 0, TANH = 1, RELU = 2, REMAXLU = 3,
  TANHLIMIT = 4
}
 Activation functions on offer LINEAR: linear unit, TANH: tangens hyperbolicus, RELU: linear rectifier, REMAXLU: as RELU but limits to one.
 

Public Member Functions

 Neuron (int _nInputs)
 Constructor. More...
 
 ~Neuron ()
 Destructor Tidies up any memory allocations. More...
 
void calcOutput ()
 Calculate the output of the neuron This runs the filters, activation functions, sum it all up.
 
void doLearning ()
 Performs the learning Performs ICO learning in the neuron: pre * error. More...
 
void doMaxDet ()
 Detects max of an input Switches the highest weight to 1 and the others to 0. More...
 
void initWeights (double _max=1, int initBias=1, WeightInitMethod _wm=MAX_OUTPUT_RANDOM)
 Inits the weights in the neuron. More...
 
void setActivationFunction (ActivationFunction _activationFunction)
 Sets the activation function. More...
 
double dActivation ()
 Returns the output of the neuron fed through the derivative of the activation. More...
 
double getMinWeightValue ()
 Minimum weight value. More...
 
double getMaxWeightValue ()
 Maximum weight value. More...
 
double getWeightDistanceFromInitialWeights ()
 Weight development. More...
 
double getOutput ()
 Gets the output of the neuron. More...
 
double getSum ()
 Gets the weighted sum of all inputs pre-activation function. More...
 
double getWeight (int _index)
 Gets one weight. More...
 
void setWeight (int _index, double _weight)
 Sets one weight. More...
 
void setError (double _error)
 Sets the error in the neuron If the derivative is activated then the derivative of the error is calculated. More...
 
double getError ()
 Gets the error as set by setError. More...
 
void setInput (int _index, double _value)
 Sets one input. More...
 
double getInput (int _index)
 Get the value at one input. More...
 
double getBiasWeight ()
 Gets the bias weight. More...
 
void setBiasWeight (double _biasweight)
 Sets the bias weight. More...
 
void setBias (double _bias)
 Sets the bias input value. More...
 
void setLearningRate (double _learningrate)
 Sets the learning rate. More...
 
void setMomentum (double _momentum)
 Sets the momentum. More...
 
void setDecay (double _decay)
 Sets the weight decay over time. More...
 
double getDecay ()
 Gets the weight decay over time. More...
 
int getNinputs ()
 Get the number of inputs to the neuron. More...
 
void setGeometry (int _width, int _height)
 Tells the layer that it's been a 2D array originally to be a convolutional layer. More...
 
void setMask (int x, int y, unsigned char c)
 Boundary safe manipulation of the convolution mask. More...
 
void setMask (unsigned char c)
 Init the whole mask with a single value. More...
 
unsigned char getMask (int x, int y)
 Boundary safe return of the mask in (x,y) coordinates. More...
 
unsigned char getMask (int index)
 Boundary safe return of the mask in flat form. More...
 
double getSumOfSquaredWeightVector ()
 Calculates the sum of the squared weight vector values. More...
 
double getEuclideanNormOfWeightVector ()
 Calculates the Eucledian length of the weight vector. More...
 
double getManhattanNormOfWeightVector ()
 Calculates the Manhattan length of the weight vector /return Manhattan length of the weight vector.
 
double getInfinityNormOfWeightVector ()
 Calculates the Infinity norm of the vector. More...
 
double getAverageOfWeightVector ()
 Calculates the average of the weight values. More...
 
void normaliseWeights (double norm)
 Normalises the weights with a divisor. More...
 
void saveInitialWeights ()
 Save the initial weights. More...
 
void setDebugInfo (int _layerIndex, int _neuronIndex)
 Sets debug info populated from Layer. More...
 
void setStep (long int _step)
 Sets the simulation step for debugging and logging. More...
 

Static Public Member Functions

static void * calcOutputThread (void *object)
 Wrapper for thread callback for output calc. More...
 
static void * doLearningThread (void *object)
 Wrapper for thread callback for learning. More...
 
static void * doMaxDetThread (void *object)
 Wrapper for thread callback for maxdet. More...
 

Detailed Description

Neuron which calculates the output and performs learning.

Member Enumeration Documentation

◆ WeightInitMethod

Constants how to init the weights in the neuron.

Constructor & Destructor Documentation

◆ Neuron()

Neuron::Neuron ( int  _nInputs)

Constructor.

Parameters
_nInputsNumber of inputs to the Neuron

◆ ~Neuron()

Neuron::~Neuron ( )

Destructor Tidies up any memory allocations.

Member Function Documentation

◆ calcOutputThread()

static void* Neuron::calcOutputThread ( void *  object)
inlinestatic

Wrapper for thread callback for output calc.

◆ dActivation()

double Neuron::dActivation ( )

Returns the output of the neuron fed through the derivative of the activation.

Returns
Result

◆ doLearning()

void Neuron::doLearning ( )

Performs the learning Performs ICO learning in the neuron: pre * error.

◆ doLearningThread()

static void* Neuron::doLearningThread ( void *  object)
inlinestatic

Wrapper for thread callback for learning.

◆ doMaxDet()

void Neuron::doMaxDet ( )

Detects max of an input Switches the highest weight to 1 and the others to 0.

◆ doMaxDetThread()

static void* Neuron::doMaxDetThread ( void *  object)
inlinestatic

Wrapper for thread callback for maxdet.

◆ getAverageOfWeightVector()

double Neuron::getAverageOfWeightVector ( )

Calculates the average of the weight values.

Returns
average of the weight values.

◆ getBiasWeight()

double Neuron::getBiasWeight ( )
inline

Gets the bias weight.

Returns
Bias weight value

◆ getDecay()

double Neuron::getDecay ( )
inline

Gets the weight decay over time.

Returns
The weight decay value. The larger the faster the weight decay.

◆ getError()

double Neuron::getError ( )
inline

Gets the error as set by setError.

Returns
The error value stored in the neuron

◆ getEuclideanNormOfWeightVector()

double Neuron::getEuclideanNormOfWeightVector ( )
inline

Calculates the Eucledian length of the weight vector.

Returns
Eucledian length of the weight vector.

◆ getInfinityNormOfWeightVector()

double Neuron::getInfinityNormOfWeightVector ( )

Calculates the Infinity norm of the vector.

/return Infinity norm of the vector.

◆ getInput()

double Neuron::getInput ( int  _index)
inline

Get the value at one input.

Parameters
_indexIndex of the input
Returns
Returns the input value

◆ getMask() [1/2]

unsigned char Neuron::getMask ( int  index)
inline

Boundary safe return of the mask in flat form.

Parameters
indexMask index.
Returns
The mask at the index: 0 = ignore underlying value, 1 = process underlying value.

◆ getMask() [2/2]

unsigned char Neuron::getMask ( int  x,
int  y 
)

Boundary safe return of the mask in (x,y) coordinates.

Parameters
xSets the mask value at coordinate x (0 .. width).
ySets the mask value at coordinate y (0 .. height).
Returns
The mask at x,y: 0 = ignore underlying value, 1 = process underlying value.

◆ getMaxWeightValue()

double Neuron::getMaxWeightValue ( )

Maximum weight value.

Returns
The maximum weight value in this neuron

◆ getMinWeightValue()

double Neuron::getMinWeightValue ( )

Minimum weight value.

Returns
The minimum weight value in this neuron

◆ getNinputs()

int Neuron::getNinputs ( )
inline

Get the number of inputs to the neuron.

Returns
The numer of inputs

◆ getOutput()

double Neuron::getOutput ( )
inline

Gets the output of the neuron.

Returns
The overall output of the neuron after the activation function

◆ getSum()

double Neuron::getSum ( )
inline

Gets the weighted sum of all inputs pre-activation function.

Returns
Weighted sum (linear)

◆ getSumOfSquaredWeightVector()

double Neuron::getSumOfSquaredWeightVector ( )

Calculates the sum of the squared weight vector values.

Returns
The squared weight vector values.

◆ getWeight()

double Neuron::getWeight ( int  _index)
inline

Gets one weight.

Parameters
_indexThe input index
Returns
The weight value at one input and one filter

◆ getWeightDistanceFromInitialWeights()

double Neuron::getWeightDistanceFromInitialWeights ( )

Weight development.

Returns
Returns the Euclidean distance of the weights from their starting position

◆ initWeights()

void Neuron::initWeights ( double  _max = 1,
int  initBias = 1,
WeightInitMethod  _wm = MAX_OUTPUT_RANDOM 
)

Inits the weights in the neuron.

Parameters
_maxMaximum value of the weights.
initBiasIf one also the bias weight is initialised.
_wmMethod how to init the weights as defined by WeightInitMethod.

◆ normaliseWeights()

void Neuron::normaliseWeights ( double  norm)

Normalises the weights with a divisor.

Parameters
normDivisor which normalises the weights.

◆ saveInitialWeights()

void Neuron::saveInitialWeights ( )

Save the initial weights.

This saves the initial weights for later comparisons. For internal use.

◆ setActivationFunction()

void Neuron::setActivationFunction ( ActivationFunction  _activationFunction)
inline

Sets the activation function.

Parameters
_activationFunctionSets the activiation function according to ActivationFunction.

◆ setBias()

void Neuron::setBias ( double  _bias)
inline

Sets the bias input value.

Parameters
_biasBias value.

◆ setBiasWeight()

void Neuron::setBiasWeight ( double  _biasweight)
inline

Sets the bias weight.

Parameters
_biasweightBias value.

◆ setDebugInfo()

void Neuron::setDebugInfo ( int  _layerIndex,
int  _neuronIndex 
)
inline

Sets debug info populated from Layer.

Parameters
_layerIndexThe layer the neuron is in.
_neuronIndexThe index of the neuron in the layer.

◆ setDecay()

void Neuron::setDecay ( double  _decay)
inline

Sets the weight decay over time.

Parameters
_decayThe larger the faster the weight decay.

◆ setError()

void Neuron::setError ( double  _error)

Sets the error in the neuron If the derivative is activated then the derivative of the error is calculated.

Parameters
_errorSets the error of the neuron.

◆ setGeometry()

void Neuron::setGeometry ( int  _width,
int  _height 
)
inline

Tells the layer that it's been a 2D array originally to be a convolutional layer.

_width * _height == nInputs. Otherwise an exception is triggered. The geometry entered here is then used in the mask operations so that every neuron is able to process a subset of the input space, for example an image and thus becomes a localised receptive field.

Parameters
_widthThe width of the layer
_heightof the layer

◆ setInput()

void Neuron::setInput ( int  _index,
double  _value 
)
inline

Sets one input.

Parameters
_indexIndex of the input.
_valueof the input.

◆ setLearningRate()

void Neuron::setLearningRate ( double  _learningrate)
inline

Sets the learning rate.

Parameters
_learningrateThe learning rate

◆ setMask() [1/2]

void Neuron::setMask ( int  x,
int  y,
unsigned char  c 
)

Boundary safe manipulation of the convolution mask.

Sets the convolution mask using the geometry defined by setGeometry.

Parameters
xSets the mask value at coordinate x (0 .. width).
ySets the mask value at coordinate y (0 .. height).
cSets the mask: 0 = ignore underlying value, 1 = process underlying value.

◆ setMask() [2/2]

void Neuron::setMask ( unsigned char  c)

Init the whole mask with a single value.

Parameters
cSets the mask for the whole array. 0 = ignore the entire input, 1 = process every input.

◆ setMomentum()

void Neuron::setMomentum ( double  _momentum)
inline

Sets the momentum.

Sets the inertia of the learning.

Parameters
_momentumThe new momentum

◆ setStep()

void Neuron::setStep ( long int  _step)
inline

Sets the simulation step for debugging and logging.

Parameters
_stepCurrent simulation step.

◆ setWeight()

void Neuron::setWeight ( int  _index,
double  _weight 
)
inline

Sets one weight.

Parameters
_indexThe input index
_weightThe weight value

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