Deep Neuronal Filter
dnf.h
1 #ifndef _DNF_H
2 #define _DNF_H
3 
4 #include "dnf/Neuron.h"
5 #include "dnf/Layer.h"
6 #include "dnf/Net.h"
7 
13 class DNF {
14 public:
24  DNF(const int NLAYERS,
25  const int numTaps,
26  double fs,
27  Neuron::actMethod am = Neuron::Act_Tanh) : noiseDelayLineLength(numTaps),
28  signalDelayLineLength(noiseDelayLineLength / 2),
29  signal_delayLine(signalDelayLineLength),
30  nNeurons(new int[NLAYERS]),
31  noise_delayLine(new double[noiseDelayLineLength]) {
32  // calc an exp reduction of the numbers always reaching 1
33  double b = exp(log(noiseDelayLineLength)/(NLAYERS-1));
34  for(int i=0;i<NLAYERS;i++) {
35  nNeurons[i] = ceil(noiseDelayLineLength / pow(b,i));
36  if (i == (NLAYERS-1)) nNeurons[i] = 1;
37  }
38 
39  //create the neural network
40  NNO = new Net(NLAYERS, nNeurons, noiseDelayLineLength, 0, "");
41 
42  //setting up the neural networks
43  for(int i=0;i<NLAYERS;i++) {
44  NNO->getLayer(i)->initLayer(i,Neuron::W_RANDOM, Neuron::B_NONE, am);
45  fprintf(stderr,"Layer %d has %d neurons. act = %d\n",i,nNeurons[i],am);
46  }
47  }
48 
55  double filter(double signal, double noise) {
56  signal_delayLine.push_back(signal);
57  const double delayed_signal = signal_delayLine[0];
58 
59  for (int i = noiseDelayLineLength-1 ; i > 0; i--) {
60  noise_delayLine[i] = noise_delayLine[i-1];
61  }
62  noise_delayLine[0] = noise / (double)noiseDelayLineLength;
63 
64  // NOISE INPUT TO NETWORK
65  NNO->setInputs(noise_delayLine);
66  NNO->propInputs();
67 
68  // REMOVER OUTPUT FROM NETWORK
69  remover = NNO->getOutput(0);
70  f_nn = delayed_signal - remover;
71 
72  // FEEDBACK TO THE NETWORK
73  NNO->setError(f_nn);
74  NNO->propErrorBackward();
75  NNO->updateWeights();
76  return f_nn;
77  }
78 
83  inline Net& getNet() const {
84  return *NNO;
85  }
86 
92  inline const int getSignalDelaySteps() const {
93  return signalDelayLineLength;
94  }
95 
101  inline const double getDelayedSignal() const {
102  return signal_delayLine[0];
103  }
104 
109  inline const double getRemover() const {
110  return remover;
111  }
112 
118  inline const double getOutput() const {
119  return f_nn;
120  }
121 
125  ~DNF() {
126  delete NNO;
127  delete[] nNeurons;
128  delete[] noise_delayLine;
129  }
130 
131 private:
132  Net *NNO;
133  int noiseDelayLineLength;
134  int signalDelayLineLength;
135  boost::circular_buffer<double> signal_delayLine;
136  double* noise_delayLine;
137  int* nNeurons;
138  double remover = 0;
139  double f_nn = 0;
140 };
141 
142 #endif
DNF::DNF
DNF(const int NLAYERS, const int numTaps, double fs, Neuron::actMethod am=Neuron::Act_Tanh)
Constructor which sets up the delay lines, network layers and also calculates the number of neurons p...
Definition: dnf.h:24
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.
DNF::getSignalDelaySteps
const int getSignalDelaySteps() const
Returns the length of the delay line which delays the signal polluted with noise.
Definition: dnf.h:92
DNF::~DNF
~DNF()
Frees the memory used by the DNF.
Definition: dnf.h:125
DNF::getRemover
const double getRemover() const
Returns the remover signal.
Definition: dnf.h:109
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.
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...
DNF::getNet
Net & getNet() const
Returns a reference to the whole neural network.
Definition: dnf.h:83
Net::propErrorBackward
void propErrorBackward()
Propagates the error backward.
DNF::getOutput
const double getOutput() const
Returns the output of the DNF: the the noise free signal.
Definition: dnf.h:118
DNF::getDelayedSignal
const double getDelayedSignal() const
Returns the delayed with noise polluted signal by the delay indicated by getSignalDelaySteps().
Definition: dnf.h:101
Net::getLayer
Layer * getLayer(int _layerIndex)
Allows Net to access each layer.
DNF
Main Deep Neuronal Network main class.
Definition: dnf.h:13
DNF::filter
double filter(double signal, double noise)
Realtime sample by sample filtering operation.
Definition: dnf.h:55
Net::propInputs
void propInputs()
It propagates the inputs forward through the network.