-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMlpNetwork.cpp
More file actions
56 lines (48 loc) · 1.17 KB
/
MlpNetwork.cpp
File metadata and controls
56 lines (48 loc) · 1.17 KB
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
//
// Created by anna_seli on 13/06/2021.
//
#include "MlpNetwork.h"
#define FINAL_DIM 10
/*
* MlpNetwork class constructor
*/
MlpNetwork::MlpNetwork(Matrix weights[], Matrix biases[])
{
w1 = weights[0];
w2 = weights[1];
w3 = weights[2];
w4 = weights[3];
b1 = biases[0];
b2 = biases[1];
b3 = biases[2];
b4 = biases[3];
}
/*
* parenthesis operator which activates the network by using the 4 layers.
* @param input matrix fot this network
* @return the digit that the network predicted after calculating all layers
*/
digit MlpNetwork::operator()(Matrix &input)
{
Dense dense1 (w1, b1, RELU);
Matrix r1 = dense1(input);
Dense dense2 (w2, b2, RELU);
Matrix r2 = dense2(r1);
Dense dense3 (w3, b3, RELU);
Matrix r3 = dense3(r2);
Dense dense4 (w4, b4, SOFTMAX);
//Matrix r4 = dense4(dense3(dense2(dense1(input)))));
Matrix r4 = dense4(r3);
int max_index = 0;
for (int i = 1; i < FINAL_DIM; i++)
{
if (r4.matrix_data[i] > r4.matrix_data[max_index])
{
max_index = i;
}
}
digit d;
d.value = max_index;
d.probability = r4.matrix_data[max_index];
return d;
}