-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSimpleNN.c
90 lines (74 loc) · 1.79 KB
/
SimpleNN.c
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
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <stdbool.h>
#include "NN.h"
void test1() {
printf("Test 1:\n");
// initialize random numbers
srand((unsigned int)time(NULL));
// initialize NN
struct NN nn;
initNN(&nn);
// data sets
struct DataSet dataset[NDATASETS];
dataset[0].xx[0] = 0;
dataset[0].xx[1] = 0;
dataset[0].xx[2] = 0;
dataset[0].xx[3] = 0;
dataset[0].yy[0] = 0;
dataset[0].yy[1] = 0;
dataset[0].yy[2] = 0;
dataset[1].xx[0] = 0;
dataset[1].xx[1] = 1;
dataset[1].xx[2] = 0;
dataset[1].xx[3] = 1;
dataset[1].yy[0] = 0;
dataset[1].yy[1] = 1;
dataset[1].yy[2] = 0;
dataset[2].xx[0] = 1;
dataset[2].xx[1] = 0;
dataset[2].xx[2] = 1;
dataset[2].xx[3] = 0;
dataset[2].yy[0] = 1;
dataset[2].yy[1] = 0;
dataset[2].yy[2] = 0;
dataset[3].xx[0] = 1;
dataset[3].xx[1] = 1;
dataset[3].xx[2] = 1;
dataset[3].xx[3] = 1;
dataset[3].yy[0] = 1;
dataset[3].yy[1] = 1;
dataset[3].yy[2] = 0;
// train the network
train1(&nn, dataset, 0.001, 15);
// test the network
double xx[NINPUTS];
xx[0] = 0;
xx[1] = 0;
xx[2] = 0;
xx[3] = 0;
// calculate output
calculateNN(xx, &nn);
printf("o1 = %f\n",nn.olayer[0].output);
printf("o1 = %f\n",nn.olayer[1].output);
printf("o2 = %f\n\n",nn.olayer[2].output);
xx[0] = 1;
xx[1] = 1;
xx[2] = 1;
xx[3] = 1;
// calculate output
calculateNN(xx, &nn);
printf("o1 = %f\n",nn.olayer[0].output);
printf("o1 = %f\n",nn.olayer[1].output);
printf("o2 = %f\n\n",nn.olayer[2].output);
}
int main() {
test1();
#ifdef WINDOWS
printf("Press Any Key to Continue\n");
getchar();
#endif // WINDOWS
return 0;
}