Deep Neuronal Filter
Net.h
1 #pragma once
2 
3 #include <stdio.h>
4 #include <assert.h>
5 #include <iostream>
6 #include <ctgmath>
7 #include <cstdlib>
8 #include <cstdio>
9 #include <cassert>
10 #include <fstream>
11 #include <iostream>
12 #include <math.h>
13 #include <fstream>
14 #include <iostream>
15 #include <string>
16 #include <numeric>
17 #include <vector>
18 
19 #include "Layer.h"
20 
30 class Net {
31 
32 public:
33 
40  Net(const int _nLayers,
41  const int * const _nNeurons,
42  const int _nInputs,
43  const int _subject,
44  const string _trial);
45 
50  ~Net();
51 
62 
67  void setLearningRate(double _w_learningRate, double _b_learningRate);
68 
73  void setInputs(const double *_inputs, const double scale = 1.0, const unsigned int offset = 0, const int n = -1);
77  void propInputs();
78 
82  void propErrorBackward();
83 
84 
89  void setError(double _leadError);
90 
99  double getGradient(Layer::whichGradient _whichGradient);
100 
104  void updateWeights();
105 
111  Layer *getLayer(int _layerIndex);
117  double getOutput(int _neuronIndex);
123  double getSumOutput(int _neuronIndex);
124 
129  int getnLayers();
134  int getnInputs();
135 
140  double getWeightDistance();
141 
147  double getLayerWeightDistance(int _layerIndex);
155  double getWeights(int _layerIndex, int _neuronIndex, int _weightIndex);
156 
161  int getnNeurons();
162 
166  void saveWeights();
171  void snapWeights(string prefix, string _trial, int _subject);
172  void snapWeightsMatrixFormat(string prefix);
176  void printNetwork();
177 
178 private:
179 
183  int nLayers = 0;
187  int nNeurons = 0;
191  int nWeights = 0;
195  int nInputs = 0;
199  int nOutputs = 0;
203  double w_learningRate = 0;
207  Layer **layers = 0;
211  const double *inputs = 0;
215  double leadForwardError = 0;
219  double theLeadError = 0;
223  int midLayerIndex = 0;
227  double theLeadMidError = 0;
231  double *errorGradient = NULL;
235  double globalError = 0;
239  double echoError = 0;
243  double theLeadLocalError = 0;
244 };
Net::initNetwork
void initNetwork(Neuron::weightInitMethod _wim, Neuron::biasInitMethod _bim, Neuron::actMethod _am)
Dictates the initialisation of the weights and biases and determines the activation function of the n...
Net::setError
void setError(double _leadError)
Sets the error at the output layer to be propagated backward.
Net
Net is the main class used to set up a neural network used for closed-loop Deep Learning.
Definition: Net.h:30
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
Net::updateWeights
void updateWeights()
Requests that all layers perform one iteration of learning.
Net::snapWeights
void snapWeights(string prefix, string _trial, int _subject)
Snaps the final distribution of all weights in a specific layer, this is overwritten every time the f...
Layer::whichGradient
whichGradient
Options for what gradient of a chosen error to monitor.
Definition: Layer.h:44
Net::getnLayers
int getnLayers()
Informs on the total number of hidden layers (excluding the input layer)
Layer
This is the class for creating layers that are contained inside the Net class.
Definition: Layer.h:27
Net::setInputs
void setInputs(const double *_inputs, const double scale=1.0, const unsigned int offset=0, const int n=-1)
Sets the inputs to the network in each iteration of learning, needs to be placed in an infinite loop.
Net::getOutput
double getOutput(int _neuronIndex)
Allows the user to access the activation output of a specific neuron in the output layer only.
Net::getSumOutput
double getSumOutput(int _neuronIndex)
Allows the user to access the weighted sum output of a specific neuron in output layer only.
Net::getLayerWeightDistance
double getLayerWeightDistance(int _layerIndex)
Allows for monitoring the weight change in a specific layer of the network.
Net::saveWeights
void saveWeights()
Saves the temporal changes of all weights in all neurons into files.
Net::getnNeurons
int getnNeurons()
Informs on the total number of neurons in the network.
Neuron::biasInitMethod
biasInitMethod
Options for method of initialising biases 0 for initialising all weights to zero 1 for initialising a...
Definition: Neuron.h:48
Net::propErrorBackward
void propErrorBackward()
Propagates the error backward.
Net::Net
Net(const int _nLayers, const int *const _nNeurons, const int _nInputs, const int _subject, const string _trial)
Constructor: The neural network that performs the learning.
Net::getLayer
Layer * getLayer(int _layerIndex)
Allows Net to access each layer.
Net::propInputs
void propInputs()
It propagates the inputs forward through the network.
Net::~Net
~Net()
Destructor De-allocated any memory.
Net::getnInputs
int getnInputs()
Informs on the total number of inputs to the network.
Net::getWeights
double getWeights(int _layerIndex, int _neuronIndex, int _weightIndex)
Grants access to a specific weight in the network.
Net::setLearningRate
void setLearningRate(double _w_learningRate, double _b_learningRate)
Sets the learning rate.
Net::getWeightDistance
double getWeightDistance()
Allows for monitoring the overall weight change of the network.
Neuron::weightInitMethod
weightInitMethod
Options for method of initialising weights 0 for initialising all weights to zero 1 for initialising ...
Definition: Neuron.h:55
Net::printNetwork
void printNetwork()
Prints on the console a full tree of the network with the values of all weights and outputs for all n...
Net::getGradient
double getGradient(Layer::whichGradient _whichGradient)
It provides a measure of how the magnitude of the error changes through the layers to alarm for vanis...