-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathneuron.h
60 lines (46 loc) · 1.56 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
52
53
54
55
56
57
58
59
60
//==============================================================================
// Project: Neural_network
// File: neuron.h
// Author: Alex Labontu
// Date: 2/22/2019 12:15:40 PM
/* Desc:
*/
//==============================================================================
#ifndef Neural_network_neuron_HEADER_INCLUDE
#define Neural_network_neuron_HEADER_INCLUDE
/*
code
*/
#include <vector>
#include <cstdlib>
class Neuron;
typedef std::vector<Neuron> Layer;
struct Connections{
Connections():weight(0.0),deltaWeight(0.0){}
Connections(double x, double y):weight(x),deltaWeight(y){}
double weight;
double deltaWeight;
};
extern double eta; // [0.0->1.0] overall net training rate
extern double alpha;// [0.0->n] multiplier of last weight change (momentum)
class Neuron{
public:
Neuron(unsigned numOutputs, unsigned myIndex);
void setOutputVal(double val) {m_outputVal = val;}
double getOutputVal(void) const {return m_outputVal;}
std::vector<Connections> & getOutputWeights(void) {return m_outputWeights;}
void feedForward(const Layer &prevLayer);
void calcOutputGradients(double targetVal);
void calcHiddenGradients(const Layer &nextLayer);
void updateInputWeights(Layer &prevLayer);
private:
static double transferFunction(double x);
static double transferFunctionDerivative(double x);
static double randomWeight(void) {return rand()/double(RAND_MAX);}
double m_outputVal;
unsigned m_myIndex;
double m_gradient;
double sumDOW(const Layer &nextLayer);
std::vector<Connections> m_outputWeights;
};
#endif