-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
45 lines (39 loc) · 919 Bytes
/
main.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
#include <stdio.h>
#include "neural_net.h"
int main() {
int neuron_count[4] = {2,5,4,1};
create_neural_net(4, neuron_count);
double inputs[4][2];
double target[4];
int data_num = 4;
int input_size = 2;
int target_size = 1;
FILE *file = fopen("input.txt","r");
if(!file) return 1;
char buff[7];
for (int i = 0; i < data_num; ++i) {
fgets(buff,7,file);
char *ch = buff;
for (int j = 0; j < input_size; ++j) {
while (*ch == ',') ch++;
inputs[i][j] = *ch -'0';
}
for (int j = 0; j < target_size; ++j) {
while (*ch == ',') ch++;
target[i] = *ch -'0';
}
}
for (int j = 0; j < 1000000; ++j) {
for (int i = 0; i < 4; ++i) {
run(inputs[i]);
backpropagate(&target[i]);
}
}
printf("\nSaidas:\n");
for (int i = 0; i < 4; ++i) {
run(inputs[i]);
double *out = get_network_output();
printf("Entrada: %f %f - Saida: %f\n",inputs[i][0],inputs[i][1],*out);
}
return 0;
}