-
Notifications
You must be signed in to change notification settings - Fork 1
/
Neuron.h
51 lines (35 loc) · 1.6 KB
/
Neuron.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//
// Created by Tommy Ludwig on 23.09.23.
//
#ifndef XORGATE_NEURALNETWORK_NEURON_H
#define XORGATE_NEURALNETWORK_NEURON_H
#include <vector>
#include "Connection.h"
using namespace std;
class Neuron {
public:
Neuron(unsigned numOutputs, unsigned myIndex);
void setOutputVal(double value);
[[nodiscard]] double getOutputVal() const;
// this function is used for calculating the output of the neurons
void feedForward(const vector<Neuron> &prevLayer);
// used by the backpropagation, calculate the gradient (Steigung) of the output neurons
void calculateOutputGradients(double targetValue);
// the difference to the output neurons is that the hidden neurons don't have a target value
void calculateHiddenGradients(const vector<Neuron> &nextLayer);
void updateInputWeights(vector<Neuron> &prevLayer) const;
[[nodiscard]] vector<Connection> getOutputWeights() const;
private:
unsigned m_myIndex;
double m_outputVal;
vector<Connection> m_outputWeights;
double m_gradient; // used by the backpropagation, gradient of the error function, which is the slope of the error function
static double eta;
static double alpha;
static double sigmoid(double x); // output range [0.0..1.0], smooth curve
static double ReLu(double x);
static double transferFunction(double x); // tanh - output range [-1.0..1.0], smooth curve
static double transferFunctionDerivative(double x); // tanh derivative
double sumDOW(const vector<Neuron> &nextLayer) const; // sum of the derivatives of the weights of the next layer
};
#endif //XORGATE_NEURALNETWORK_NEURON_H