Deep Neuronal Filter
Layer.h
1 #pragma once
2 
3 
4 #include <stdio.h>
5 #include <assert.h>
6 #include <iostream>
7 #include <ctgmath>
8 #include <cstdlib>
9 #include <cstdio>
10 #include <cassert>
11 #include <fstream>
12 #include <iostream>
13 #include <math.h>
14 #include <fstream>
15 #include <iostream>
16 #include <string>
17 #include <numeric>
18 #include <vector>
19 
20 #include "Neuron.h"
21 
27 class Layer {
28 public:
34  Layer(int _nNeurons, int _nInputs, int _subject, string _trial);
39  ~Layer();
40 
44  enum whichGradient {exploding = 0, average = 1, vanishing = 2};
45 
56  void initLayer(int _layerIndex, Neuron::weightInitMethod _wim, Neuron::biasInitMethod _bim, Neuron::actMethod _am);
57 
61  void setlearningRate(double _w_learningRate, double _b_learningRate);
62 
67  void setInputs(const double *_inputs, const double scale = 1.0, const unsigned int offset = 0, const int n = -1);
68 
74  void propInputs(int _index, double _value);
75 
79  void calcOutputs();
80 
85  void setError(double _error);
86 
92  double getGradient(whichGradient _whichGradient);
93 
97  void updateWeights();
98 
104  Neuron *getNeuron(int _neuronIndex);
105 
110  int getnNeurons();
111 
117  double getOutput(int _neuronIndex);
118 
124  double getSumOutput(int _neuronIndex);
125 
132  double getWeights(int _neuronIndex, int _weightIndex);
133 
138  double getWeightChange();
139 
144  double getWeightDistance();
145 
151  double getGlobalError(int _neuronIndex);
152 
159  double getInitWeight(int _neuronIndex, int _weightIndex);
160 
164  void saveWeights();
165 
170  void snapWeights(string prefix, string _trial, int _subject);
171 
172  void snapWeightsMatrixFormat(string prefix);
173 
177  void printLayer();
178 
179 private:
180  // initialisation:
181  int nNeurons = 0;
182  int nInputs = 0;
183  double learningRate = 0;
184  int myLayerIndex = 0;
185  Neuron **neurons = 0;
186 
187  int layerHasReported = 0;
188 
189  //back propagation of error:
190  double backwardError = 0;
191 
192  //exploding vasnishing gradient:
193  double averageError = 0;
194  double maxError = 0;
195  double minError = 0;
196 
197  int subject = 0;
198  string trial = "0";
199 
200  //learning:
201  double weightChange=0;
202 };
Neuron::actMethod
actMethod
Options for activation functions of the neuron 0 for using the logistic function 1 for using the hype...
Definition: Neuron.h:62
Layer::snapWeights
void snapWeights(string prefix, string _trial, int _subject)
Snaps the final distribution of weights in a specific layer, this is overwritten every time the funct...
Layer::setlearningRate
void setlearningRate(double _w_learningRate, double _b_learningRate)
Sets the learning rate.
Layer::getGlobalError
double getGlobalError(int _neuronIndex)
Reports the global error that is assigned to a specific neuron in this layer.
Layer::saveWeights
void saveWeights()
Saves the temporal weight change of all weights in all neurons into files.
Layer::whichGradient
whichGradient
Options for what gradient of a chosen error to monitor.
Definition: Layer.h:44
Layer
This is the class for creating layers that are contained inside the Net class.
Definition: Layer.h:27
Layer::getWeightChange
double getWeightChange()
Accesses the total sum of weight changes of all the neurons in this layer.
Layer::setInputs
void setInputs(const double *_inputs, const double scale=1.0, const unsigned int offset=0, const int n=-1)
Sets the inputs to all neurons in the first hidden layer only.
Layer::calcOutputs
void calcOutputs()
Demands that all neurons in this layer calculate their output.
Layer::propInputs
void propInputs(int _index, double _value)
Sets the inputs to all neurons in the deeper layers (excluding the first hidden layer)
Layer::Layer
Layer(int _nNeurons, int _nInputs, int _subject, string _trial)
Constructor for Layer: it initialises the neurons internally.
Neuron::biasInitMethod
biasInitMethod
Options for method of initialising biases 0 for initialising all weights to zero 1 for initialising a...
Definition: Neuron.h:48
Layer::initLayer
void initLayer(int _layerIndex, Neuron::weightInitMethod _wim, Neuron::biasInitMethod _bim, Neuron::actMethod _am)
Initialises each layer with specific methods for weight/bias initialisation and activation function o...
Layer::getNeuron
Neuron * getNeuron(int _neuronIndex)
Allows access to a specific neuron.
Layer::~Layer
~Layer()
Destructor De-allocated any memory.
Layer::getWeights
double getWeights(int _neuronIndex, int _weightIndex)
Allows for accessing any specific weights in the layer.
Layer::getSumOutput
double getSumOutput(int _neuronIndex)
Allows for accessing the sum output of any specific neuron.
Layer::printLayer
void printLayer()
Prints on the console a full tree of this layer with the values of all weights and outputs for all ne...
Neuron
This is the class for creating neurons inside the Layer class.
Definition: Neuron.h:28
Layer::setError
void setError(double _error)
Sets the error to be propagated backward at all neurons in the output layer only.
Layer::updateWeights
void updateWeights()
Requests that all neurons perform one iteration of learning.
Neuron::weightInitMethod
weightInitMethod
Options for method of initialising weights 0 for initialising all weights to zero 1 for initialising ...
Definition: Neuron.h:55
Layer::getGradient
double getGradient(whichGradient _whichGradient)
Allows for accessing the error that propagates backward in the network.
Layer::getOutput
double getOutput(int _neuronIndex)
Allows for accessing the activation of a specific neuron.
Layer::getnNeurons
int getnNeurons()
Reports the number of neurons in this layer.
Layer::getInitWeight
double getInitWeight(int _neuronIndex, int _weightIndex)
Reports the initial value that was assigned to a specific weight at the initialisatin of the network.
Layer::getWeightDistance
double getWeightDistance()
Performs squared root on the weight change.