-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNeuron.h
48 lines (40 loc) · 1.3 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
#ifndef NEURON_H
#define NEURON_H
/******************************************************************************
* Neuron is a class for neurons in the network. This is where the math is
* done for the weights of each neuron and the gradient descent to converge
* towards correctness.
******************************************************************************/
#include <vector>
#include <cmath>
using namespace std;
struct Connection
{
double weight;
double deltaWeight;
};
class Neuron;
typedef vector<Neuron> Layer;
class Neuron
{
public:
Neuron(unsigned numOutputs, unsigned myIndex);
void setOutputVal(double val);
double getOutputVal(void) const;
void feedForward(const Layer &prevLayer);
void calcOutputGradients(double targetVal);
void calcHiddenGradients(const Layer &nextLayer);
void updateInputWeights(Layer &prevLayer);
private:
static double eta;
static double alpha;
static double transferFunction(double x);
static double transferFunctionDerivative(double x);
static double randomWeight(void);
double sumDOW(const Layer &nextLayer) const;
double m_outputVal;
vector<Connection> m_outputWeights;
unsigned m_myIndex;
double m_gradient;
};
#endif