Feedforward Closedloop Learning
|
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... | |
Neuron which calculates the output and performs learning.
Constants how to init the weights in the neuron.
Neuron::Neuron | ( | int | _nInputs | ) |
Constructor.
_nInputs | Number of inputs to the Neuron |
Neuron::~Neuron | ( | ) |
Destructor Tidies up any memory allocations.
|
inlinestatic |
Wrapper for thread callback for output calc.
double Neuron::dActivation | ( | ) |
Returns the output of the neuron fed through the derivative of the activation.
void Neuron::doLearning | ( | ) |
Performs the learning Performs ICO learning in the neuron: pre * error.
|
inlinestatic |
Wrapper for thread callback for learning.
void Neuron::doMaxDet | ( | ) |
Detects max of an input Switches the highest weight to 1 and the others to 0.
|
inlinestatic |
Wrapper for thread callback for maxdet.
double Neuron::getAverageOfWeightVector | ( | ) |
Calculates the average of the weight values.
|
inline |
Gets the bias weight.
|
inline |
Gets the weight decay over time.
|
inline |
Gets the error as set by setError.
|
inline |
Calculates the Eucledian length of the weight vector.
double Neuron::getInfinityNormOfWeightVector | ( | ) |
Calculates the Infinity norm of the vector.
/return Infinity norm of the vector.
|
inline |
Get the value at one input.
_index | Index of the input |
|
inline |
Boundary safe return of the mask in flat form.
index | Mask index. |
unsigned char Neuron::getMask | ( | int | x, |
int | y | ||
) |
Boundary safe return of the mask in (x,y) coordinates.
x | Sets the mask value at coordinate x (0 .. width). |
y | Sets the mask value at coordinate y (0 .. height). |
double Neuron::getMaxWeightValue | ( | ) |
Maximum weight value.
double Neuron::getMinWeightValue | ( | ) |
Minimum weight value.
|
inline |
Get the number of inputs to the neuron.
|
inline |
Gets the output of the neuron.
|
inline |
Gets the weighted sum of all inputs pre-activation function.
double Neuron::getSumOfSquaredWeightVector | ( | ) |
Calculates the sum of the squared weight vector values.
|
inline |
Gets one weight.
_index | The input index |
double Neuron::getWeightDistanceFromInitialWeights | ( | ) |
Weight development.
void Neuron::initWeights | ( | double | _max = 1 , |
int | initBias = 1 , |
||
WeightInitMethod | _wm = MAX_OUTPUT_RANDOM |
||
) |
Inits the weights in the neuron.
_max | Maximum value of the weights. |
initBias | If one also the bias weight is initialised. |
_wm | Method how to init the weights as defined by WeightInitMethod. |
void Neuron::normaliseWeights | ( | double | norm | ) |
Normalises the weights with a divisor.
norm | Divisor which normalises the weights. |
void Neuron::saveInitialWeights | ( | ) |
Save the initial weights.
This saves the initial weights for later comparisons. For internal use.
|
inline |
Sets the activation function.
_activationFunction | Sets the activiation function according to ActivationFunction. |
|
inline |
Sets the bias input value.
_bias | Bias value. |
|
inline |
Sets the bias weight.
_biasweight | Bias value. |
|
inline |
Sets debug info populated from Layer.
_layerIndex | The layer the neuron is in. |
_neuronIndex | The index of the neuron in the layer. |
|
inline |
Sets the weight decay over time.
_decay | The larger the faster the weight decay. |
void Neuron::setError | ( | double | _error | ) |
Sets the error in the neuron If the derivative is activated then the derivative of the error is calculated.
_error | Sets the error of the neuron. |
|
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.
_width | The width of the layer |
_height | of the layer |
|
inline |
Sets one input.
_index | Index of the input. |
_value | of the input. |
|
inline |
Sets the learning rate.
_learningrate | The learning rate |
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.
x | Sets the mask value at coordinate x (0 .. width). |
y | Sets the mask value at coordinate y (0 .. height). |
c | Sets the mask: 0 = ignore underlying value, 1 = process underlying value. |
void Neuron::setMask | ( | unsigned char | c | ) |
Init the whole mask with a single value.
c | Sets the mask for the whole array. 0 = ignore the entire input, 1 = process every input. |
|
inline |
Sets the momentum.
Sets the inertia of the learning.
_momentum | The new momentum |
|
inline |
Sets the simulation step for debugging and logging.
_step | Current simulation step. |
|
inline |
Sets one weight.
_index | The input index |
_weight | The weight value |