This repository has been archived by the owner on Sep 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
/
test_bpnn_train.c
executable file
·93 lines (72 loc) · 2.09 KB
/
test_bpnn_train.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
91
92
93
//
// Created by wcjzj on 2017/5/22.
//
#include <stdio.h>
#include <assert.h>
#include "bpnn.h"
static bool test_set_get(double *in, double *out);
static bool test_set_init(void);
static FILE *in_file = NULL;
static FILE *out_file = NULL;
int main(void) {
in_file = fopen(TEST_IN_PATH, "r");
if (in_file == NULL) {
fprintf(stderr, "open file %s failed.\n", TEST_IN_PATH);
return 0;
}
out_file = fopen(TEST_OUT_PATH, "r");
if (out_file == NULL) {
fprintf(stderr, "open file %s failed.\n", TEST_OUT_PATH);
return 0;
}
bpnn_init();
bpnn_train(test_set_get, test_set_init);
fclose(in_file);
fclose(out_file);
in_file = fopen(IN_PATH, "r");
if (in_file == NULL) {
fprintf(stderr, "open file %s failed.\n", IN_PATH);
return 0;
}
out_file = fopen(OUT_PATH, "r");
if (out_file == NULL) {
fprintf(stderr, "open file %s failed.\n", OUT_PATH);
return 0;
}
bpnn_sim(test_set_get);
fclose(in_file);
fclose(out_file);
return 0;
}
static bool test_set_get(double *in, double *out) {
assert(in && out);
#define BUFFER_SIZE 256
static char buffer[BUFFER_SIZE];
if (in_file && out_file) {
if (fgets(buffer, BUFFER_SIZE, in_file) != NULL) {
char *token = strtok(buffer, ",");
for (size_t i = 0; i < IN_N; i++) {
if (token == NULL) {
fprintf(stderr, "the format of input is not correct!\n");
return false;
}
in[i] = strtod(token, NULL);
token = strtok(NULL, ",");
}
} else {
return false;
}
if (fgets(buffer, BUFFER_SIZE, out_file) != NULL) {
out[0] = strtod(buffer, NULL);
} else {
return false;
}
return true;
}
return false;
}
static bool test_set_init(void) {
fseek(in_file, 0, SEEK_SET);
fseek(out_file, 0, SEEK_SET);
return true;
}