-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathneuralnetwork.h
87 lines (66 loc) · 1.54 KB
/
neuralnetwork.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <vector>
using namespace std;
class Neuron;
class NeuralInput {
public:
Neuron* fromNeuron;
Neuron* toNeuron;
float weight = 0;
float deriv = 0;
float changespeed = 1.0;
NeuralInput(Neuron* from_, Neuron* to_, float weight_) {
fromNeuron = from_;
toNeuron = to_;
weight = weight_;
}
};
class Neuron {
public:
int layer;
int index;
float bias = 0.0;
vector<NeuralInput*> inputs;
float outputActivation;
NeuralInput* findInputFrom(Neuron*);
void calculateActivation();
};
class BiasNeuron : Neuron {
public:
void calculateActivation();
};
class Layer {
public:
int ind = 0;
vector<Neuron*> neurons;
Layer(int, int);
void activateAll();
void connectTo(Layer*);
void print();
void randomWeights();
void printWeights();
};
class NeuralNetwork {
public:
Layer* inputs = NULL;
Layer* hidden;
Layer* outputs = NULL;
void randomWeights();
void assignInput(size_t,float);
void assignInputs(vector<float>);
void connectLayers();
void randomizeHidden();
void computeOutputs();
int classify();
void print();
};
class MNISTNetwork: public NeuralNetwork {
};
class Trainer {
public:
NeuralNetwork* network = 0;
float learningRate = 0;
Trainer(NeuralNetwork*, float rate);
void compare(std::vector<float> expected);
float meanSquaredError(vector<vector<float>>, vector<vector<float>>);
void calcGradients(vector<vector<float>> inputs, vector<vector<float>> expected);
};