-
Notifications
You must be signed in to change notification settings - Fork 1
/
Load_Fin2.ino
345 lines (308 loc) · 20.1 KB
/
Load_Fin2.ino
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
#include <math.h>
#define learning_rate 0.01
#define epoch 20
#define samples 48
float X[][24] = {
{1.2970001, 0.977, 0.783, 0.711, 0.775, 2.1159999, 1.7970001, 1.368, 1.367, 2.6140001, 1.772, 1.416, 2.5810001, 2.0999999, 2.2320001, 2.1570001, 2.822, 3.47, 2.5090001, 2.497, 1.311, 1.029, 1.505, 0.699},
{0.977, 0.783, 0.711, 0.775, 2.1159999, 1.7970001, 1.368, 1.367, 2.6140001, 1.772, 1.416, 2.5810001, 2.0999999, 2.2320001, 2.1570001, 2.822, 3.47, 2.5090001, 2.497, 1.311, 1.029, 1.505, 0.699, 0.609},
{0.783, 0.711, 0.775, 2.1159999, 1.7970001, 1.368, 1.367, 2.6140001, 1.772, 1.416, 2.5810001, 2.0999999, 2.2320001, 2.1570001, 2.822, 3.47, 2.5090001, 2.497, 1.311, 1.029, 1.505, 0.699, 0.609, 0.544},
{0.711, 0.775, 2.1159999, 1.7970001, 1.368, 1.367, 2.6140001, 1.772, 1.416, 2.5810001, 2.0999999, 2.2320001, 2.1570001, 2.822, 3.47, 2.5090001, 2.497, 1.311, 1.029, 1.505, 0.699, 0.609, 0.544, 0.53},
{0.775, 2.1159999, 1.7970001, 1.368, 1.367, 2.6140001, 1.772, 1.416, 2.5810001, 2.0999999, 2.2320001, 2.1570001, 2.822, 3.47, 2.5090001, 2.497, 1.311, 1.029, 1.505, 0.699, 0.609, 0.544, 0.53, 0.54},
{2.1159999, 1.7970001, 1.368, 1.367, 2.6140001, 1.772, 1.416, 2.5810001, 2.0999999, 2.2320001, 2.1570001, 2.822, 3.47, 2.5090001, 2.497, 1.311, 1.029, 1.505, 0.699, 0.609, 0.544, 0.53, 0.54, 0.544},
{1.7970001, 1.368, 1.367, 2.6140001, 1.772, 1.416, 2.5810001, 2.0999999, 2.2320001, 2.1570001, 2.822, 3.47, 2.5090001, 2.497, 1.311, 1.029, 1.505, 0.699, 0.609, 0.544, 0.53, 0.54, 0.544, 0.541},
{1.368, 1.367, 2.6140001, 1.772, 1.416, 2.5810001, 2.0999999, 2.2320001, 2.1570001, 2.822, 3.47, 2.5090001, 2.497, 1.311, 1.029, 1.505, 0.699, 0.609, 0.544, 0.53, 0.54, 0.544, 0.541, 0.542},
{1.367, 2.6140001, 1.772, 1.416, 2.5810001, 2.0999999, 2.2320001, 2.1570001, 2.822, 3.47, 2.5090001, 2.497, 1.311, 1.029, 1.505, 0.699, 0.609, 0.544, 0.53, 0.54, 0.544, 0.541, 0.542, 0.53},
{2.6140001, 1.772, 1.416, 2.5810001, 2.0999999, 2.2320001, 2.1570001, 2.822, 3.47, 2.5090001, 2.497, 1.311, 1.029, 1.505, 0.699, 0.609, 0.544, 0.53, 0.54, 0.544, 0.541, 0.542, 0.53, 0.535},
{1.772, 1.416, 2.5810001, 2.0999999, 2.2320001, 2.1570001, 2.822, 3.47, 2.5090001, 2.497, 1.311, 1.029, 1.505, 0.699, 0.609, 0.544, 0.53, 0.54, 0.544, 0.541, 0.542, 0.53, 0.535, 0.535},
{1.416, 2.5810001, 2.0999999, 2.2320001, 2.1570001, 2.822, 3.47, 2.5090001, 2.497, 1.311, 1.029, 1.505, 0.699, 0.609, 0.544, 0.53, 0.54, 0.544, 0.541, 0.542, 0.53, 0.535, 0.535, 0.549},
{2.5810001, 2.0999999, 2.2320001, 2.1570001, 2.822, 3.47, 2.5090001, 2.497, 1.311, 1.029, 1.505, 0.699, 0.609, 0.544, 0.53, 0.54, 0.544, 0.541, 0.542, 0.53, 0.535, 0.535, 0.549, 0.601},
{2.0999999, 2.2320001, 2.1570001, 2.822, 3.47, 2.5090001, 2.497, 1.311, 1.029, 1.505, 0.699, 0.609, 0.544, 0.53, 0.54, 0.544, 0.541, 0.542, 0.53, 0.535, 0.535, 0.549, 0.601, 0.666},
{2.2320001, 2.1570001, 2.822, 3.47, 2.5090001, 2.497, 1.311, 1.029, 1.505, 0.699, 0.609, 0.544, 0.53, 0.54, 0.544, 0.541, 0.542, 0.53, 0.535, 0.535, 0.549, 0.601, 0.666, 0.62},
{2.1570001, 2.822, 3.47, 2.5090001, 2.497, 1.311, 1.029, 1.505, 0.699, 0.609, 0.544, 0.53, 0.54, 0.544, 0.541, 0.542, 0.53, 0.535, 0.535, 0.549, 0.601, 0.666, 0.62, 0.581},
{2.822, 3.47, 2.5090001, 2.497, 1.311, 1.029, 1.505, 0.699, 0.609, 0.544, 0.53, 0.54, 0.544, 0.541, 0.542, 0.53, 0.535, 0.535, 0.549, 0.601, 0.666, 0.62, 0.581, 0.574},
{3.47, 2.5090001, 2.497, 1.311, 1.029, 1.505, 0.699, 0.609, 0.544, 0.53, 0.54, 0.544, 0.541, 0.542, 0.53, 0.535, 0.535, 0.549, 0.601, 0.666, 0.62, 0.581, 0.574, 0.544},
{2.5090001, 2.497, 1.311, 1.029, 1.505, 0.699, 0.609, 0.544, 0.53, 0.54, 0.544, 0.541, 0.542, 0.53, 0.535, 0.535, 0.549, 0.601, 0.666, 0.62, 0.581, 0.574, 0.544, 1.017},
{2.497, 1.311, 1.029, 1.505, 0.699, 0.609, 0.544, 0.53, 0.54, 0.544, 0.541, 0.542, 0.53, 0.535, 0.535, 0.549, 0.601, 0.666, 0.62, 0.581, 0.574, 0.544, 1.017, 1.2970001},
{1.311, 1.029, 1.505, 0.699, 0.609, 0.544, 0.53, 0.54, 0.544, 0.541, 0.542, 0.53, 0.535, 0.535, 0.549, 0.601, 0.666, 0.62, 0.581, 0.574, 0.544, 1.017, 1.2970001, 1.704},
{1.029, 1.505, 0.699, 0.609, 0.544, 0.53, 0.54, 0.544, 0.541, 0.542, 0.53, 0.535, 0.535, 0.549, 0.601, 0.666, 0.62, 0.581, 0.574, 0.544, 1.017, 1.2970001, 1.704, 1.888},
{1.505, 0.699, 0.609, 0.544, 0.53, 0.54, 0.544, 0.541, 0.542, 0.53, 0.535, 0.535, 0.549, 0.601, 0.666, 0.62, 0.581, 0.574, 0.544, 1.017, 1.2970001, 1.704, 1.888, 1.665},
{0.699, 0.609, 0.544, 0.53, 0.54, 0.544, 0.541, 0.542, 0.53, 0.535, 0.535, 0.549, 0.601, 0.666, 0.62, 0.581, 0.574, 0.544, 1.017, 1.2970001, 1.704, 1.888, 1.665, 1.6900001},
{0.609, 0.544, 0.53, 0.54, 0.544, 0.541, 0.542, 0.53, 0.535, 0.535, 0.549, 0.601, 0.666, 0.62, 0.581, 0.574, 0.544, 1.017, 1.2970001, 1.704, 1.888, 1.665, 1.6900001, 1.446},
{0.544, 0.53, 0.54, 0.544, 0.541, 0.542, 0.53, 0.535, 0.535, 0.549, 0.601, 0.666, 0.62, 0.581, 0.574, 0.544, 1.017, 1.2970001, 1.704, 1.888, 1.665, 1.6900001, 1.446, 1.4119999},
{0.53, 0.54, 0.544, 0.541, 0.542, 0.53, 0.535, 0.535, 0.549, 0.601, 0.666, 0.62, 0.581, 0.574, 0.544, 1.017, 1.2970001, 1.704, 1.888, 1.665, 1.6900001, 1.446, 1.4119999, 1.5829999},
{0.54, 0.544, 0.541, 0.542, 0.53, 0.535, 0.535, 0.549, 0.601, 0.666, 0.62, 0.581, 0.574, 0.544, 1.017, 1.2970001, 1.704, 1.888, 1.665, 1.6900001, 1.446, 1.4119999, 1.5829999, 1.432},
{0.544, 0.541, 0.542, 0.53, 0.535, 0.535, 0.549, 0.601, 0.666, 0.62, 0.581, 0.574, 0.544, 1.017, 1.2970001, 1.704, 1.888, 1.665, 1.6900001, 1.446, 1.4119999, 1.5829999, 1.432, 1.217},
{0.541, 0.542, 0.53, 0.535, 0.535, 0.549, 0.601, 0.666, 0.62, 0.581, 0.574, 0.544, 1.017, 1.2970001, 1.704, 1.888, 1.665, 1.6900001, 1.446, 1.4119999, 1.5829999, 1.432, 1.217, 0.632},
{0.542, 0.53, 0.535, 0.535, 0.549, 0.601, 0.666, 0.62, 0.581, 0.574, 0.544, 1.017, 1.2970001, 1.704, 1.888, 1.665, 1.6900001, 1.446, 1.4119999, 1.5829999, 1.432, 1.217, 0.632, 0.511},
{0.53, 0.535, 0.535, 0.549, 0.601, 0.666, 0.62, 0.581, 0.574, 0.544, 1.017, 1.2970001, 1.704, 1.888, 1.665, 1.6900001, 1.446, 1.4119999, 1.5829999, 1.432, 1.217, 0.632, 0.511, 1.214},
{0.535, 0.535, 0.549, 0.601, 0.666, 0.62, 0.581, 0.574, 0.544, 1.017, 1.2970001, 1.704, 1.888, 1.665, 1.6900001, 1.446, 1.4119999, 1.5829999, 1.432, 1.217, 0.632, 0.511, 1.214, 0.648},
{0.535, 0.549, 0.601, 0.666, 0.62, 0.581, 0.574, 0.544, 1.017, 1.2970001, 1.704, 1.888, 1.665, 1.6900001, 1.446, 1.4119999, 1.5829999, 1.432, 1.217, 0.632, 0.511, 1.214, 0.648, 0.55},
{0.549, 0.601, 0.666, 0.62, 0.581, 0.574, 0.544, 1.017, 1.2970001, 1.704, 1.888, 1.665, 1.6900001, 1.446, 1.4119999, 1.5829999, 1.432, 1.217, 0.632, 0.511, 1.214, 0.648, 0.55, 1.446},
{0.601, 0.666, 0.62, 0.581, 0.574, 0.544, 1.017, 1.2970001, 1.704, 1.888, 1.665, 1.6900001, 1.446, 1.4119999, 1.5829999, 1.432, 1.217, 0.632, 0.511, 1.214, 0.648, 0.55, 1.446, 0.779},
{0.666, 0.62, 0.581, 0.574, 0.544, 1.017, 1.2970001, 1.704, 1.888, 1.665, 1.6900001, 1.446, 1.4119999, 1.5829999, 1.432, 1.217, 0.632, 0.511, 1.214, 0.648, 0.55, 1.446, 0.779, 0.508},
{0.62, 0.581, 0.574, 0.544, 1.017, 1.2970001, 1.704, 1.888, 1.665, 1.6900001, 1.446, 1.4119999, 1.5829999, 1.432, 1.217, 0.632, 0.511, 1.214, 0.648, 0.55, 1.446, 0.779, 0.508, 0.884},
{0.581, 0.574, 0.544, 1.017, 1.2970001, 1.704, 1.888, 1.665, 1.6900001, 1.446, 1.4119999, 1.5829999, 1.432, 1.217, 0.632, 0.511, 1.214, 0.648, 0.55, 1.446, 0.779, 0.508, 0.884, 2.5139999},
{0.574, 0.544, 1.017, 1.2970001, 1.704, 1.888, 1.665, 1.6900001, 1.446, 1.4119999, 1.5829999, 1.432, 1.217, 0.632, 0.511, 1.214, 0.648, 0.55, 1.446, 0.779, 0.508, 0.884, 2.5139999, 2.602},
{0.544, 1.017, 1.2970001, 1.704, 1.888, 1.665, 1.6900001, 1.446, 1.4119999, 1.5829999, 1.432, 1.217, 0.632, 0.511, 1.214, 0.648, 0.55, 1.446, 0.779, 0.508, 0.884, 2.5139999, 2.602, 2.7409999},
{1.017, 1.2970001, 1.704, 1.888, 1.665, 1.6900001, 1.446, 1.4119999, 1.5829999, 1.432, 1.217, 0.632, 0.511, 1.214, 0.648, 0.55, 1.446, 0.779, 0.508, 0.884, 2.5139999, 2.602, 2.7409999, 2.6630001},
{1.2970001, 1.704, 1.888, 1.665, 1.6900001, 1.446, 1.4119999, 1.5829999, 1.432, 1.217, 0.632, 0.511, 1.214, 0.648, 0.55, 1.446, 0.779, 0.508, 0.884, 2.5139999, 2.602, 2.7409999, 2.6630001, 2.582},
{1.704, 1.888, 1.665, 1.6900001, 1.446, 1.4119999, 1.5829999, 1.432, 1.217, 0.632, 0.511, 1.214, 0.648, 0.55, 1.446, 0.779, 0.508, 0.884, 2.5139999, 2.602, 2.7409999, 2.6630001, 2.582, 2.6700001},
{1.888, 1.665, 1.6900001, 1.446, 1.4119999, 1.5829999, 1.432, 1.217, 0.632, 0.511, 1.214, 0.648, 0.55, 1.446, 0.779, 0.508, 0.884, 2.5139999, 2.602, 2.7409999, 2.6630001, 2.582, 2.6700001, 2.6210001},
{1.665, 1.6900001, 1.446, 1.4119999, 1.5829999, 1.432, 1.217, 0.632, 0.511, 1.214, 0.648, 0.55, 1.446, 0.779, 0.508, 0.884, 2.5139999, 2.602, 2.7409999, 2.6630001, 2.582, 2.6700001, 2.6210001, 2.5769999},
{1.6900001, 1.446, 1.4119999, 1.5829999, 1.432, 1.217, 0.632, 0.511, 1.214, 0.648, 0.55, 1.446, 0.779, 0.508, 0.884, 2.5139999, 2.602, 2.7409999, 2.6630001, 2.582, 2.6700001, 2.6210001, 2.5769999, 2.802},
{1.446, 1.4119999, 1.5829999, 1.432, 1.217, 0.632, 0.511, 1.214, 0.648, 0.55, 1.446, 0.779, 0.508, 0.884, 2.5139999, 2.602, 2.7409999, 2.6630001, 2.582, 2.6700001, 2.6210001, 2.5769999, 2.802, 2.7409999},
};
float ytrue[] = {0.609, 0.544, 0.53, 0.54, 0.544, 0.541, 0.542, 0.53, 0.535, 0.535, 0.549, 0.601, 0.666, 0.62, 0.581, 0.574, 0.544, 1.017, 1.2970001, 1.704, 1.888, 1.665, 1.6900001, 1.446, 1.4119999, 1.5829999,
1.432, 1.217, 0.632, 0.511, 1.214, 0.648, 0.55, 1.446, 0.779, 0.508, 0.884, 2.5139999, 2.602, 2.7409999, 2.6630001, 2.582, 2.6700001, 2.6210001, 2.5769999, 2.802, 2.7409999, 2.7509999};
float w1[24][16] = {
{0.04571867, -0.28588802, 0.1496852 , 0.414347 , -0.20929576,
-0.11612818, -0.0369947 , -0.01543742, 0.2794151 , 0.14748847,
0.14730191, 0.361658 , -0.08981299, 0.33622935, 0.02899596,
-0.0581653},
{-0.29145357, -0.18579508, 0.31240952, -0.03048192, 0.19619457,
-0.33985138, -0.17280921, 0.31695497, -0.15204793, 0.30442858,
0.2417713 , 0.39854044, -0.25044218, 0.3387262 , -0.05211842,
-0.00858297},
{-0.01574141, -0.3730024 , -0.22829284, 0.35997537, 0.36806756,
-0.18242083, -0.19625261, -0.08044308, 0.3459612 , 0.33021766,
0.25843823, 0.2140793 , 0.23166259, -0.3463265 , 0.12816983,
0.2891759},
{-0.04916227, -0.35773155, -0.02092918, 0.12624955, 0.3713193 ,
-0.1364269 , -0.2733005 , 0.34684116, 0.2105722 , -0.04824913,
0.23016964, 0.2613722 , -0.09855174, 0.32808858, -0.09726441,
0.2526577},
{ 0.2649839 , -0.05772054, 0.2143489 , -0.15812337, 0.20562154,
-0.09685829, -0.10785381, -0.3284424 , -0.19846694, 0.22093184,
-0.23168953, -0.33120403, -0.32044306, 0.36868367, -0.3810827 ,
-0.228129},
{-0.12229329, -0.15644546, -0.01776305, 0.34833902, 0.47207767,
-0.31887957, 0.08566335, -0.15215364, 0.13887693, -0.08162638,
-0.28430235, 0.18230572, 0.23094818, 0.22550675, 0.3173461 ,
0.20562086},
{-0.08438188, 0.23209965, -0.01347352, -0.28575447, 0.14689422,
0.14110756, -0.08007011, -0.3129252 , -0.21600312, 0.01485155,
0.02521847, 0.017098 , -0.18699872, 0.05142532, 0.04363632,
0.06957327},
{-0.20569204, -0.13512343, -0.09657799, 0.32059222, 0.27298096,
0.3382311 , 0.24355957, -0.34331465, 0.39908683, 0.21698675,
-0.1530202 , 0.1847984 , 0.3604597 , -0.19041175, -0.34301323,
-0.33978966},
{-0.22744751, 0.04744023, -0.21904035, 0.29452512, -0.12459867,
-0.13722008, -0.30189207, -0.28435758, 0.37689608, -0.34729558,
-0.3217342 , 0.082064 , -0.21555777, 0.28068393, -0.2689134 ,
-0.26453194},
{-0.19543788, 0.3431914 , -0.34551084, 0.14172304, -0.16792578,
-0.27317163, -0.16537118, -0.27589148, -0.08754476, -0.16538242,
-0.21063645, -0.03053753, 0.0174435 , -0.2224205 , 0.13819337,
-0.32613105},
{-0.11787808, -0.16695097, -0.24668019, -0.2111796 , -0.3205625 ,
-0.13063595, -0.35677767, 0.13539457, -0.15175328, -0.01748233,
-0.25410318, 0.25083598, 0.17429762, 0.0708399 , -0.22081183,
0.30625838},
{-0.23097551, -0.0048227 , 0.2912494 , 0.1268731 , 0.11261477,
-0.25210243, 0.28660348, -0.3038656 , -0.07214444, 0.2643024 ,
-0.19377397, -0.03886091, -0.15403605, -0.21091558, -0.33584642,
-0.09986081},
{-0.14566377, -0.28476065, 0.07501285, 0.23129092, 0.14114937,
-0.33968312, 0.34732008, 0.0405584 , -0.35705397, -0.24393289,
-0.06904232, 0.25076362, 0.27789664, 0.06583071, 0.21665537,
-0.07276294},
{ 0.07358384, -0.0944199 , 0.3472196 , -0.269639 , 0.12318484,
-0.28760645, -0.06118496, 0.2069788 , -0.26189762, 0.25498375,
-0.1272801 , -0.02387789, 0.02230781, -0.32619095, -0.33685255,
-0.15966287},
{0.10250327, -0.12715209, 0.01163147, 0.03601846, -0.00999772,
0.2889881 , -0.18529856, 0.14886665, 0.35692462, 0.26596835,
0.08249708, 0.30192053, -0.22892234, 0.11380721, 0.01875415,
0.17540483},
{-0.03042713, 0.08071178, 0.1104868 , 0.3353749 , -0.17010953,
0.00627813, -0.12080181, -0.04973441, -0.22137785, -0.12306335,
0.24726166, -0.11504491, 0.07364287, 0.4000008 , -0.02883723,
0.22300562},
{-0.03937718, -0.01297688, 0.3307438 , -0.0508519 , -0.1347533 ,
0.12681586, 0.29744798, -0.10925159, 0.27322415, 0.1266247 ,
-0.2116335 , 0.18444103, -0.03333547, -0.08344184, 0.2859388 ,
-0.0807454},
{-0.07801521, -0.1431551 , 0.11356269, -0.0656855 , 0.14341278,
-0.22312114, -0.3400851 , -0.22296879, 0.36147332, -0.23526847,
-0.2804396 , 0.37396815, -0.14251764, 0.18173452, -0.35309952,
-0.30510432},
{0.02491051, -0.25666952, 0.30034804, 0.27751106, -0.10369673,
0.04406238, -0.18427597, 0.15342313, 0.40153274, 0.01870069,
0.0139254 , 0.08076639, 0.16389015, -0.3058229 , -0.06982711,
-0.12963465},
{0.12129629, 0.06398925, 0.26749524, 0.34668148, 0.45755532,
0.14003807, 0.14946555, 0.30876362, 0.19439472, -0.24652494,
-0.08117145, -0.17831832, 0.23018752, -0.16421427, -0.34902638,
-0.05466748},
{-0.23652583, -0.0227626 , 0.18049791, 0.34213302, 0.45306852,
0.28747457, -0.14124799, 0.30866283, 0.12106842, 0.23830022,
-0.11249286, 0.10158601, -0.1491808 , -0.00219082, 0.07511842,
-0.03327082},
{0.17259532, 0.167274 , -0.28653857, -0.26519457, 0.23269832,
-0.26092607, 0.29043254, -0.07211196, -0.339975 , 0.17904156,
0.13870932, 0.31396425, 0.2425104 , 0.18328407, 0.17099357,
-0.11722264},
{ 0.15657723, -0.13566989, -0.14148891, -0.08389573, -0.2580416 ,
0.00756192, 0.14280161, 0.3634473 , -0.3504523 , 0.1986515 ,
0.07299324, 0.388716 , 0.35975403, 0.02318577, 0.12088048,
0.03992429},
{-0.16424055, 0.16744012, -0.00155312, -0.27493292, -0.14903857,
-0.03910831, -0.16447698, -0.03512138, 0.3201809 , -0.25402945,
0.21754211, -0.06236481, 0.1300866 , 0.23748548, -0.26987058,
0.17506051}
};
float b1[16] = {-0.8426701 , -1.2063264 , 0.84967184, -0.03819728, -0.1956037 ,
-0.24682507, -0.17439188, 1.0817604 , -0.1718891 , -0.03174727,
-1.3907765 , -0.43032795, -0.39354268, -0.91513354, -0.41141748,
1.6554158};
float w2[16][8] = {
{-0.47978, 0.24338, -0.16739, -0.29351, -0.10887, -0.01629, -0.56227, -1.11433},
{-0.49115, -0.20232, 0.13890, -0.13006, 0.06229, -1.54101, 0.12816, -0.12974},
{-1.70996, 0.17742, 0.68328, -0.26831, 0.17161, 1.79208, 0.35652, 0.38867},
{0.08372, -0.16913, -0.02059, -0.33799, -0.56965, 0.99943, 0.17341, 0.09388},
{-0.16473, 0.10942, -0.19502, -0.49039, -0.11299, 0.03226, -0.28699, -0.49320},
{0.25783, -0.13108, -0.26140, 0.25141, -0.36998, 0.15955, 0.27423, -0.12251},
{1.14762, -0.63773, -0.48508, 0.14921, -0.15454, -2.69305, -1.63449, 1.14315},
{-0.27884, -0.44071, -0.14883, 0.11273, 0.05723, -1.60124, -1.07413, 0.12312},
{-0.80891, -0.57034, 0.11648, -0.38360, -0.03038, -0.47594, -1.41799, -0.17888},
{-0.32529, 0.04361, 0.13339, -0.04957, -0.00964, -0.26045, -0.34767, -0.07876},
{-0.05668, -0.16520, 0.00369, 0.04132, 0.13128, -1.76365, -1.61581, -0.09528},
{-0.16798, -0.51756, 0.64410, -0.18774, -0.66084, -0.04214, -0.14464, -1.54481},
{0.30451, -0.53028, -0.42480, -0.15175, 0.06547, -2.28800, -0.65639, 0.91281},
{-0.15962, -0.05694, 0.00568, 0.03442, 0.20127, -0.89632, -0.25669, -0.02212},
{0.61351, 0.28635, 0.23131, -0.32772, -0.08646, -0.60108, -0.95123, 0.05561},
{-0.17533, -0.24870, -0.11369, -0.04302, -0.20964, -0.80346, 0.00031, 0.28354}
};
float b2[8] = {0.04251663, 0. , 0. , 0. , 0. ,
-0.03973839, -0.01701125, 0.04194813};
float w3[8][1] = {
{0.03314754},
{0.57035553},
{0.25222716},
{-0.23551092},
{0.01840131},
{0.1013294},
{-0.01976894},
{-0.09281101}
};
float b3[1] = {0.03867633};
float tmp[24][1];
float dw1[24][16], dw2[16][8], dw3[8][1];
float db1[16], db2[8], db3[1];
float relu(float x) {
return (x > 0) ? x : 0;
}
float mean_absolute_error(float ytrue, float ypred) {
return fabs(ytrue - ypred);
}
float neuron(float W[][16], float B[], float X[][1]) {
float z, y = 0.0;
for (int i = 0; i < 16; i++) {
for (int j = 0; j < 24; j++) {
y += W[j][i] * X[j][0];
}
y += B[i];
z = relu(y);
}
return z;
}
void gradient_descent(float ytrue[], float ypred) {
float dy = ypred - ytrue[0];
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 1; j++) {
dw3[i][j] = dy * relu(dy);
}
db3[i] = dy * relu(dy);
}
for (int i = 0; i < 16; i++) {
for (int j = 0; j < 8; j++) {
float drelu = (ytrue[j] > 0) ? 1 : 0;
float dz = dy * drelu;
float da = dz * relu(dz);
dw2[i][j] = da;
db2[i] = da;
}
}
for (int i = 0; i < 24; i++) {
for (int j = 0; j < 16; j++) {
float drelu = (ytrue[j] > 0) ? 1 : 0;
float dz = dy * drelu;
float da = dz * relu(dz);
float dx = da * w2[j][0];
dw1[i][j] = dx;
db1[i] = dx;
}
}
}
void setup() {
float y[samples];
int n = 0;
Serial.begin(9600);
delay(1000);
Serial.println(F("Training the model..."));
unsigned int t1 = millis();
float t2 = 0;
while (n <= epoch) {
int j = 0;
for (int i = 0; i < samples; i++) {
for (int k = 0; k < 24; k++) {
tmp[k][0] = X[i][k];
}
y[i] = neuron(w1, b1, tmp);
}
float loss = 0;
for (int i = 0; i < samples; i++) {
loss += mean_absolute_error(ytrue[i], y[i]);
}
loss /= samples;
Serial.print(F("\nNumber of Epoch: "));
Serial.print(n);
Serial.print(F("\nTraining Loss: "));
Serial.print(loss, 5);
gradient_descent(ytrue, y[0]);
for (int i = 0; i < 24; i++) {
for (int j = 0; j < 16; j++) {
w1[i][j] -= learning_rate * dw1[i][j];
}
}
for (int i = 0; i < 16; i++) {
for (int j = 0; j < 8; j++) {
w2[i][j] -= learning_rate * dw2[i][j];
}
}
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 1; j++) {
w3[i][j] -= learning_rate * dw3[i][j];
}
}
n += 1;
}
Serial.print(F("\nTraining Completed Successfully... "));
t2 = (millis() - t1) / 1000;
Serial.print(F("\nTime elapsed: "));
Serial.print(t2, 2);
Serial.print(F(" Sec"));
//****** Prediction using the evaluated model **//
Serial.println(F("\nPredicted values: "));
int j = 0;
for (int l = 0; l < 366; l++) {
Serial.print(F("Day "));
Serial.print(l + 1);
Serial.println(F(" Reading"));
for (int i = 0; i < samples; i++) {
for (int k = 0; k < 24; k++) {
tmp[k][0] = X[i][k];
}
y[i] = neuron(w1, b1, tmp);
Serial.print(F("Half Hourly Prediction "));
Serial.print(i + 1);
Serial.print(F(": "));
Serial.println(y[i], 2);
delay(5000);
}
}
}
void loop() {
// Empty loop, not used in this code
}