14#include <torch/torch.h>
20constexpr bool debugOutput =
false;
22constexpr bool debugOutput =
true;
44 struct Net :
public torch::nn::Module
46 std::vector<torch::nn::Linear> fc;
47 Net(
int nLayers,
int nInput,
bool withBias =
false);
48 torch::Tensor forward(torch::Tensor x,
ActMethod am);
61 DNF(
const int nLayers,
64 const bool tryGPU =
false);
80 float filter(
const float signal,
const float noise);
89 return signalDelayLineLength;
99 return signal_delayLine.get(0);
161 delaySamples = delay;
162 buffer = std::deque<float>(delaySamples, 0.0f);
165 inline float process(
float input)
167 float output = buffer.front();
169 buffer.push_back(input);
173 float get(
int i)
const
178 float getNewest()
const
180 return buffer.back();
184 int delaySamples = 0;
185 std::deque<float> buffer;
188 void saveInitialParameters()
190 for (
const auto &p : model.parameters())
192 initialParameters.push_back(p.detach().clone());
196 const int noiseDelayLineLength;
197 const int signalDelayLineLength;
200 torch::optim::SGD optimizer;
201 std::vector<torch::Tensor> initialParameters;
202 DelayLine signal_delayLine;
203 DelayLine noise_delayLine;
206 torch::Device device = torch::kCPU;
Deep Neuronal Filter https://journals.plos.org/plosone/article?id=10.1371/journal....
Definition dnf_torch.h:30
float getOutput() const
Returns the output of the DNF: the noise free signal.
Definition dnf_torch.h:116
float filter(const float signal, const float noise)
Realtime sample by sample filtering operation.
float getWeightDistance() const
Gets the overall weight distsance.
void setLearningRate(float mu)
Sets the learning rate of the entire network.
ActMethod
Options for activation functions of all neurons in the network.
Definition dnf_torch.h:36
int getSignalDelaySteps() const
Returns the length of the delay line which delays the signal polluted with noise.
Definition dnf_torch.h:87
DNF(const int nLayers, const int nTaps, const ActMethod am=Act_Tanh, const bool tryGPU=false)
Constructor which sets up the delay lines, network layers and also calculates the number of neurons p...
float getRemover() const
Returns the remover signal.
Definition dnf_torch.h:106
const std::vector< float > getLayerWeightDistances() const
Gets the weight distances per layer.
static constexpr double xavierGain
Xavier gain for the weight init.
Definition dnf_torch.h:153
const Net getModel() const
Gets the torch model, for example, to read out the weights.
Definition dnf_torch.h:145
const torch::Device getTorchDevice() const
Gets the torch device for example to determine if the GPU is being used.
Definition dnf_torch.h:137
float getDelayedSignal() const
Returns the delayed with noise polluted signal by the delay indicated by getSignalDelaySteps().
Definition dnf_torch.h:97