-
Notifications
You must be signed in to change notification settings - Fork 0
/
neural_network.h
108 lines (87 loc) · 3.19 KB
/
neural_network.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include "settings.h"
#include "Arduino.h"
class NeuralNetwork {
public:
/*
The method permits to initialize the internal state for the neural network.
*/
void init();
/*
The method permits to execute the learning phase using the passed training
set as sample records for the process.
*/
void learn(float trainingSet[TRAINING_SET_SIZE][INPUT_FEATURES], float resultSet[TRAINING_SET_SIZE][OUTPUT_NODES]);
/*
TODO: Currently not implemented
*/
void load();
/*
The method permits to predict the result of certain input array following
the weights extracted from the learning process.
*/
void predict(float* input, float* output);
private:
/*
The method permits to get the result of the sigmoid function.
*/
float sigmoid(float x);
/*
The method permits to get the result of the derivative for the sigmoid function.
*/
float dSigmoid(float x);
/*
The method permits to execute a debug logging, writing all information
about the intermediate state of the neural network.
*/
void debug(long epoch, bool includeConnections);
/*
The method permits to execute the feedforwarding process, i.e. the action
of trying to predict certain value based on bias and weighten connections.
*/
void feedforwarding(float input[INPUT_FEATURES]);
/*
The method permits to execute the backpropagation process, i.e. the action
of adjusting the bias and the weights of the connections and of the nodes
propagating an error value calculated by the difference between obtained
and expected result value.
*/
void backpropagating(float input[INPUT_FEATURES], float expectedOutput[OUTPUT_NODES]);
// ---------------------------------------------------------------------------
// -------------------------- VARIABLES --------------------------------------
// ---------------------------------------------------------------------------
/*
The array that contains the abstraction of the hidden layer, where each position
is the value assigned to the node in this layer.
*/
float hiddenLayer[HIDDEN_NODES];
/*
The array that contains the bias to be applied to the corresponding node in
the hidden layer.
*/
float hiddenLayerBias[HIDDEN_NODES];
/*
The array that contains the abstraction of the output layer, where each position
is the value assigned to the node in this layer.
*/
float outputLayer[OUTPUT_NODES];
/*
The array that contains the bias to be applied to the corresponding node in
the output layer.
*/
float outputLayerBias[OUTPUT_NODES];
/*
The matrix that contains the weights of the connections that
connect input node to hidden node.
*/
float inputToHiddenConnections[INPUT_FEATURES][HIDDEN_NODES];
/*
The matrix that contains the weights of the connections that
connect hidden node to output node.
*/
float hiddenToOutputConnections[HIDDEN_NODES][OUTPUT_NODES];
/*
The value that permits to get the mean square error calculated from the
learning proess.
*/
float error;
};