-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.c
More file actions
565 lines (431 loc) · 22.2 KB
/
test.c
File metadata and controls
565 lines (431 loc) · 22.2 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
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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
# 0 "/app/subjects/genann/test.c"
# 0 "<built-in>"
# 0 "<command-line>"
# 1 "/app/subjects/genann/test.c"
# 26 "/app/subjects/genann/test.c"
# 1 "/app/subjects/genann/genann.h" 1
# 30 "/app/subjects/genann/genann.h"
# 1 "/app/pipeline/preprocess/fake_libc_include/stdio.h" 1
# 1 "/app/pipeline/preprocess/fake_libc_include/_fake_defines.h" 1
# 2 "/app/pipeline/preprocess/fake_libc_include/stdio.h" 2
# 1 "/app/pipeline/preprocess/fake_libc_include/_fake_typedefs.h" 1
typedef int START_DELIMETER;
typedef int socklen_t;
typedef int size_t;
typedef int __builtin_va_list;
typedef int __gnuc_va_list;
typedef int va_list;
typedef int __int8_t;
typedef int __uint8_t;
typedef int __int16_t;
typedef int __uint16_t;
typedef int __int_least16_t;
typedef int __uint_least16_t;
typedef int __int32_t;
typedef int __uint32_t;
typedef int __int64_t;
typedef int __uint64_t;
typedef int __int_least32_t;
typedef int __uint_least32_t;
typedef int __s8;
typedef int __u8;
typedef int __s16;
typedef int __u16;
typedef int __s32;
typedef int __u32;
typedef int __s64;
typedef int __u64;
typedef int _LOCK_T;
typedef int _LOCK_RECURSIVE_T;
typedef int _off_t;
typedef int __dev_t;
typedef int __uid_t;
typedef int __gid_t;
typedef int _off64_t;
typedef int _fpos_t;
typedef int _ssize_t;
typedef int wint_t;
typedef int _mbstate_t;
typedef int _flock_t;
typedef int _iconv_t;
typedef int __ULong;
typedef int __FILE;
typedef int ptrdiff_t;
typedef int wchar_t;
typedef int char16_t;
typedef int char32_t;
typedef int __off_t;
typedef int __pid_t;
typedef int __loff_t;
typedef int u_char;
typedef int u_short;
typedef int u_int;
typedef int u_long;
typedef int ushort;
typedef int uint;
typedef int clock_t;
typedef int time_t;
typedef int daddr_t;
typedef int caddr_t;
typedef int ino_t;
typedef int off_t;
typedef int dev_t;
typedef int uid_t;
typedef int gid_t;
typedef int pid_t;
typedef int key_t;
typedef int ssize_t;
typedef int mode_t;
typedef int nlink_t;
typedef int fd_mask;
typedef int _types_fd_set;
typedef int clockid_t;
typedef int timer_t;
typedef int useconds_t;
typedef int suseconds_t;
typedef int FILE;
typedef int fpos_t;
typedef int cookie_read_function_t;
typedef int cookie_write_function_t;
typedef int cookie_seek_function_t;
typedef int cookie_close_function_t;
typedef int cookie_io_functions_t;
typedef int div_t;
typedef int ldiv_t;
typedef int lldiv_t;
typedef int sigset_t;
typedef int __sigset_t;
typedef int _sig_func_ptr;
typedef int sig_atomic_t;
typedef int __tzrule_type;
typedef int __tzinfo_type;
typedef int mbstate_t;
typedef int sem_t;
typedef int pthread_t;
typedef int pthread_attr_t;
typedef int pthread_mutex_t;
typedef int pthread_mutexattr_t;
typedef int pthread_cond_t;
typedef int pthread_condattr_t;
typedef int pthread_key_t;
typedef int pthread_once_t;
typedef int pthread_rwlock_t;
typedef int pthread_rwlockattr_t;
typedef int pthread_spinlock_t;
typedef int pthread_barrier_t;
typedef int pthread_barrierattr_t;
typedef int jmp_buf;
typedef int rlim_t;
typedef int sa_family_t;
typedef int sigjmp_buf;
typedef int stack_t;
typedef int siginfo_t;
typedef int z_stream;
typedef int int8_t;
typedef int uint8_t;
typedef int int16_t;
typedef int uint16_t;
typedef int int32_t;
typedef int uint32_t;
typedef int int64_t;
typedef int uint64_t;
typedef int int_least8_t;
typedef int uint_least8_t;
typedef int int_least16_t;
typedef int uint_least16_t;
typedef int int_least32_t;
typedef int uint_least32_t;
typedef int int_least64_t;
typedef int uint_least64_t;
typedef int int_fast8_t;
typedef int uint_fast8_t;
typedef int int_fast16_t;
typedef int uint_fast16_t;
typedef int int_fast32_t;
typedef int uint_fast32_t;
typedef int int_fast64_t;
typedef int uint_fast64_t;
typedef int intptr_t;
typedef int uintptr_t;
typedef int intmax_t;
typedef int uintmax_t;
typedef _Bool bool;
typedef void* MirEGLNativeWindowType;
typedef void* MirEGLNativeDisplayType;
typedef struct MirConnection MirConnection;
typedef struct MirSurface MirSurface;
typedef struct MirSurfaceSpec MirSurfaceSpec;
typedef struct MirScreencast MirScreencast;
typedef struct MirPromptSession MirPromptSession;
typedef struct MirBufferStream MirBufferStream;
typedef struct MirPersistentId MirPersistentId;
typedef struct MirBlob MirBlob;
typedef struct MirDisplayConfig MirDisplayConfig;
typedef struct xcb_connection_t xcb_connection_t;
typedef uint32_t xcb_window_t;
typedef uint32_t xcb_visualid_t;
typedef _Atomic(_Bool) atomic_bool;
typedef _Atomic(char) atomic_char;
typedef _Atomic(signed char) atomic_schar;
typedef _Atomic(unsigned char) atomic_uchar;
typedef _Atomic(short) atomic_short;
typedef _Atomic(unsigned short) atomic_ushort;
typedef _Atomic(int) atomic_int;
typedef _Atomic(unsigned int) atomic_uint;
typedef _Atomic(long) atomic_long;
typedef _Atomic(unsigned long) atomic_ulong;
typedef _Atomic(long long) atomic_llong;
typedef _Atomic(unsigned long long) atomic_ullong;
typedef _Atomic(uint_least16_t) atomic_char16_t;
typedef _Atomic(uint_least32_t) atomic_char32_t;
typedef _Atomic(wchar_t) atomic_wchar_t;
typedef _Atomic(int_least8_t) atomic_int_least8_t;
typedef _Atomic(uint_least8_t) atomic_uint_least8_t;
typedef _Atomic(int_least16_t) atomic_int_least16_t;
typedef _Atomic(uint_least16_t) atomic_uint_least16_t;
typedef _Atomic(int_least32_t) atomic_int_least32_t;
typedef _Atomic(uint_least32_t) atomic_uint_least32_t;
typedef _Atomic(int_least64_t) atomic_int_least64_t;
typedef _Atomic(uint_least64_t) atomic_uint_least64_t;
typedef _Atomic(int_fast8_t) atomic_int_fast8_t;
typedef _Atomic(uint_fast8_t) atomic_uint_fast8_t;
typedef _Atomic(int_fast16_t) atomic_int_fast16_t;
typedef _Atomic(uint_fast16_t) atomic_uint_fast16_t;
typedef _Atomic(int_fast32_t) atomic_int_fast32_t;
typedef _Atomic(uint_fast32_t) atomic_uint_fast32_t;
typedef _Atomic(int_fast64_t) atomic_int_fast64_t;
typedef _Atomic(uint_fast64_t) atomic_uint_fast64_t;
typedef _Atomic(intptr_t) atomic_intptr_t;
typedef _Atomic(uintptr_t) atomic_uintptr_t;
typedef _Atomic(size_t) atomic_size_t;
typedef _Atomic(ptrdiff_t) atomic_ptrdiff_t;
typedef _Atomic(intmax_t) atomic_intmax_t;
typedef _Atomic(uintmax_t) atomic_uintmax_t;
typedef struct atomic_flag { atomic_bool _Value; } atomic_flag;
typedef enum memory_order {
memory_order_relaxed,
memory_order_consume,
memory_order_acquire,
memory_order_release,
memory_order_acq_rel,
memory_order_seq_cst
} memory_order;
typedef struct __locale_struct *__locale_t;
typedef __locale_t locale_t;
typedef int END_DELIMETER;
# 3 "/app/pipeline/preprocess/fake_libc_include/stdio.h" 2
# 31 "/app/subjects/genann/genann.h" 2
# 42 "/app/subjects/genann/genann.h"
struct genann;
typedef double (*genann_actfun)(const struct genann *ann, double a);
typedef struct genann {
int inputs, hidden_layers, hidden, outputs;
genann_actfun activation_hidden;
genann_actfun activation_output;
int total_weights;
int total_neurons;
double *weight;
double *output;
double *delta;
} genann;
genann *genann_init(int inputs, int hidden_layers, int hidden, int outputs);
genann *genann_read(FILE *in);
void genann_randomize(genann *ann);
genann *genann_copy(genann const *ann);
void genann_free(genann *ann);
double const *genann_run(genann const *ann, double const *inputs);
void genann_train(genann const *ann, double const *inputs, double const *desired_outputs, double learning_rate);
void genann_write(genann const *ann, FILE *out);
void genann_init_sigmoid_lookup(const genann *ann);
double genann_act_sigmoid(const genann *ann, double a);
double genann_act_sigmoid_cached(const genann *ann, double a);
double genann_act_threshold(const genann *ann, double a);
double genann_act_linear(const genann *ann, double a);
# 27 "/app/subjects/genann/test.c" 2
# 1 "/app/subjects/genann/minctest.h" 1
# 62 "/app/subjects/genann/minctest.h"
# 1 "/app/pipeline/preprocess/fake_libc_include/stdio.h" 1
# 63 "/app/subjects/genann/minctest.h" 2
# 1 "/app/pipeline/preprocess/fake_libc_include/math.h" 1
# 64 "/app/subjects/genann/minctest.h" 2
# 1 "/app/pipeline/preprocess/fake_libc_include/time.h" 1
# 65 "/app/subjects/genann/minctest.h" 2
# 73 "/app/subjects/genann/minctest.h"
static int ltests = 0;
static int lfails = 0;
# 28 "/app/subjects/genann/test.c" 2
# 1 "/app/pipeline/preprocess/fake_libc_include/stdio.h" 1
# 29 "/app/subjects/genann/test.c" 2
# 1 "/app/pipeline/preprocess/fake_libc_include/math.h" 1
# 30 "/app/subjects/genann/test.c" 2
# 1 "/app/pipeline/preprocess/fake_libc_include/stdlib.h" 1
# 31 "/app/subjects/genann/test.c" 2
void basic() {
genann *ann = genann_init(1, 0, 0, 1);
do { ++ltests; if ((ann->total_weights) != (2)) { ++lfails; printf("%s:%d (%d != %d)\n", "/app/subjects/genann/test.c", 37, (ann->total_weights), (2)); }} while (0);
double a;
a = 0;
ann->weight[0] = 0;
ann->weight[1] = 0;
do { ++ltests; if (fabs((double)(0.5)-(double)(*genann_run(ann, &a))) > 0.001) { ++lfails; printf("%s:%d (%f != %f)\n", "/app/subjects/genann/test.c", 44, (double)(0.5), (double)(*genann_run(ann, &a))); }} while (0);
a = 1;
do { ++ltests; if (fabs((double)(0.5)-(double)(*genann_run(ann, &a))) > 0.001) { ++lfails; printf("%s:%d (%f != %f)\n", "/app/subjects/genann/test.c", 47, (double)(0.5), (double)(*genann_run(ann, &a))); }} while (0);
a = 11;
do { ++ltests; if (fabs((double)(0.5)-(double)(*genann_run(ann, &a))) > 0.001) { ++lfails; printf("%s:%d (%f != %f)\n", "/app/subjects/genann/test.c", 50, (double)(0.5), (double)(*genann_run(ann, &a))); }} while (0);
a = 1;
ann->weight[0] = 1;
ann->weight[1] = 1;
do { ++ltests; if (fabs((double)(0.5)-(double)(*genann_run(ann, &a))) > 0.001) { ++lfails; printf("%s:%d (%f != %f)\n", "/app/subjects/genann/test.c", 55, (double)(0.5), (double)(*genann_run(ann, &a))); }} while (0);
a = 10;
ann->weight[0] = 1;
ann->weight[1] = 1;
do { ++ltests; if (fabs((double)(1.0)-(double)(*genann_run(ann, &a))) > 0.001) { ++lfails; printf("%s:%d (%f != %f)\n", "/app/subjects/genann/test.c", 60, (double)(1.0), (double)(*genann_run(ann, &a))); }} while (0);
a = -10;
do { ++ltests; if (fabs((double)(0.0)-(double)(*genann_run(ann, &a))) > 0.001) { ++lfails; printf("%s:%d (%f != %f)\n", "/app/subjects/genann/test.c", 63, (double)(0.0), (double)(*genann_run(ann, &a))); }} while (0);
genann_free(ann);
}
void xor() {
genann *ann = genann_init(2, 1, 2, 1);
ann->activation_hidden = genann_act_threshold;
ann->activation_output = genann_act_threshold;
do { ++ltests; if ((ann->total_weights) != (9)) { ++lfails; printf("%s:%d (%d != %d)\n", "/app/subjects/genann/test.c", 74, (ann->total_weights), (9)); }} while (0);
ann->weight[0] = .5;
ann->weight[1] = 1;
ann->weight[2] = 1;
ann->weight[3] = 1;
ann->weight[4] = 1;
ann->weight[5] = 1;
ann->weight[6] = .5;
ann->weight[7] = 1;
ann->weight[8] = -1;
double input[4][2] = {{0, 0}, {0, 1}, {1, 0}, {1, 1}};
double output[4] = {0, 1, 1, 0};
do { ++ltests; if (fabs((double)(output[0])-(double)(*genann_run(ann, input[0]))) > 0.001) { ++lfails; printf("%s:%d (%f != %f)\n", "/app/subjects/genann/test.c", 95, (double)(output[0]), (double)(*genann_run(ann, input[0]))); }} while (0);
do { ++ltests; if (fabs((double)(output[1])-(double)(*genann_run(ann, input[1]))) > 0.001) { ++lfails; printf("%s:%d (%f != %f)\n", "/app/subjects/genann/test.c", 96, (double)(output[1]), (double)(*genann_run(ann, input[1]))); }} while (0);
do { ++ltests; if (fabs((double)(output[2])-(double)(*genann_run(ann, input[2]))) > 0.001) { ++lfails; printf("%s:%d (%f != %f)\n", "/app/subjects/genann/test.c", 97, (double)(output[2]), (double)(*genann_run(ann, input[2]))); }} while (0);
do { ++ltests; if (fabs((double)(output[3])-(double)(*genann_run(ann, input[3]))) > 0.001) { ++lfails; printf("%s:%d (%f != %f)\n", "/app/subjects/genann/test.c", 98, (double)(output[3]), (double)(*genann_run(ann, input[3]))); }} while (0);
genann_free(ann);
}
void backprop() {
genann *ann = genann_init(1, 0, 0, 1);
double input, output;
input = .5;
output = 1;
double first_try = *genann_run(ann, &input);
genann_train(ann, &input, &output, .5);
double second_try = *genann_run(ann, &input);
do { ++ltests; if (!(fabs(first_try - output) > fabs(second_try - output))) { ++lfails; printf("%s:%d error \n", "/app/subjects/genann/test.c", 114); }} while (0);
genann_free(ann);
}
void train_and() {
double input[4][2] = {{0, 0}, {0, 1}, {1, 0}, {1, 1}};
double output[4] = {0, 0, 0, 1};
genann *ann = genann_init(2, 0, 0, 1);
int i, j;
for (i = 0; i < 50; ++i) {
for (j = 0; j < 4; ++j) {
genann_train(ann, input[j], output + j, .8);
}
}
ann->activation_output = genann_act_threshold;
do { ++ltests; if (fabs((double)(output[0])-(double)(*genann_run(ann, input[0]))) > 0.001) { ++lfails; printf("%s:%d (%f != %f)\n", "/app/subjects/genann/test.c", 135, (double)(output[0]), (double)(*genann_run(ann, input[0]))); }} while (0);
do { ++ltests; if (fabs((double)(output[1])-(double)(*genann_run(ann, input[1]))) > 0.001) { ++lfails; printf("%s:%d (%f != %f)\n", "/app/subjects/genann/test.c", 136, (double)(output[1]), (double)(*genann_run(ann, input[1]))); }} while (0);
do { ++ltests; if (fabs((double)(output[2])-(double)(*genann_run(ann, input[2]))) > 0.001) { ++lfails; printf("%s:%d (%f != %f)\n", "/app/subjects/genann/test.c", 137, (double)(output[2]), (double)(*genann_run(ann, input[2]))); }} while (0);
do { ++ltests; if (fabs((double)(output[3])-(double)(*genann_run(ann, input[3]))) > 0.001) { ++lfails; printf("%s:%d (%f != %f)\n", "/app/subjects/genann/test.c", 138, (double)(output[3]), (double)(*genann_run(ann, input[3]))); }} while (0);
genann_free(ann);
}
void train_or() {
double input[4][2] = {{0, 0}, {0, 1}, {1, 0}, {1, 1}};
double output[4] = {0, 1, 1, 1};
genann *ann = genann_init(2, 0, 0, 1);
genann_randomize(ann);
int i, j;
for (i = 0; i < 50; ++i) {
for (j = 0; j < 4; ++j) {
genann_train(ann, input[j], output + j, .8);
}
}
ann->activation_output = genann_act_threshold;
do { ++ltests; if (fabs((double)(output[0])-(double)(*genann_run(ann, input[0]))) > 0.001) { ++lfails; printf("%s:%d (%f != %f)\n", "/app/subjects/genann/test.c", 160, (double)(output[0]), (double)(*genann_run(ann, input[0]))); }} while (0);
do { ++ltests; if (fabs((double)(output[1])-(double)(*genann_run(ann, input[1]))) > 0.001) { ++lfails; printf("%s:%d (%f != %f)\n", "/app/subjects/genann/test.c", 161, (double)(output[1]), (double)(*genann_run(ann, input[1]))); }} while (0);
do { ++ltests; if (fabs((double)(output[2])-(double)(*genann_run(ann, input[2]))) > 0.001) { ++lfails; printf("%s:%d (%f != %f)\n", "/app/subjects/genann/test.c", 162, (double)(output[2]), (double)(*genann_run(ann, input[2]))); }} while (0);
do { ++ltests; if (fabs((double)(output[3])-(double)(*genann_run(ann, input[3]))) > 0.001) { ++lfails; printf("%s:%d (%f != %f)\n", "/app/subjects/genann/test.c", 163, (double)(output[3]), (double)(*genann_run(ann, input[3]))); }} while (0);
genann_free(ann);
}
void train_xor() {
double input[4][2] = {{0, 0}, {0, 1}, {1, 0}, {1, 1}};
double output[4] = {0, 1, 1, 0};
genann *ann = genann_init(2, 1, 2, 1);
int i, j;
for (i = 0; i < 500; ++i) {
for (j = 0; j < 4; ++j) {
genann_train(ann, input[j], output + j, 3);
}
}
ann->activation_output = genann_act_threshold;
do { ++ltests; if (fabs((double)(output[0])-(double)(*genann_run(ann, input[0]))) > 0.001) { ++lfails; printf("%s:%d (%f != %f)\n", "/app/subjects/genann/test.c", 186, (double)(output[0]), (double)(*genann_run(ann, input[0]))); }} while (0);
do { ++ltests; if (fabs((double)(output[1])-(double)(*genann_run(ann, input[1]))) > 0.001) { ++lfails; printf("%s:%d (%f != %f)\n", "/app/subjects/genann/test.c", 187, (double)(output[1]), (double)(*genann_run(ann, input[1]))); }} while (0);
do { ++ltests; if (fabs((double)(output[2])-(double)(*genann_run(ann, input[2]))) > 0.001) { ++lfails; printf("%s:%d (%f != %f)\n", "/app/subjects/genann/test.c", 188, (double)(output[2]), (double)(*genann_run(ann, input[2]))); }} while (0);
do { ++ltests; if (fabs((double)(output[3])-(double)(*genann_run(ann, input[3]))) > 0.001) { ++lfails; printf("%s:%d (%f != %f)\n", "/app/subjects/genann/test.c", 189, (double)(output[3]), (double)(*genann_run(ann, input[3]))); }} while (0);
genann_free(ann);
}
void persist() {
genann *first = genann_init(1000, 5, 50, 10);
FILE *out = fopen("persist.txt", "w");
genann_write(first, out);
fclose(out);
FILE *in = fopen("persist.txt", "r");
genann *second = genann_read(in);
fclose(in);
do { ++ltests; if ((first->inputs) != (second->inputs)) { ++lfails; printf("%s:%d (%d != %d)\n", "/app/subjects/genann/test.c", 208, (first->inputs), (second->inputs)); }} while (0);
do { ++ltests; if ((first->hidden_layers) != (second->hidden_layers)) { ++lfails; printf("%s:%d (%d != %d)\n", "/app/subjects/genann/test.c", 209, (first->hidden_layers), (second->hidden_layers)); }} while (0);
do { ++ltests; if ((first->hidden) != (second->hidden)) { ++lfails; printf("%s:%d (%d != %d)\n", "/app/subjects/genann/test.c", 210, (first->hidden), (second->hidden)); }} while (0);
do { ++ltests; if ((first->outputs) != (second->outputs)) { ++lfails; printf("%s:%d (%d != %d)\n", "/app/subjects/genann/test.c", 211, (first->outputs), (second->outputs)); }} while (0);
do { ++ltests; if ((first->total_weights) != (second->total_weights)) { ++lfails; printf("%s:%d (%d != %d)\n", "/app/subjects/genann/test.c", 212, (first->total_weights), (second->total_weights)); }} while (0);
int i;
for (i = 0; i < first->total_weights; ++i) {
do { ++ltests; if (!(first->weight[i] == second->weight[i])) { ++lfails; printf("%s:%d error \n", "/app/subjects/genann/test.c", 216); }} while (0);
}
genann_free(first);
genann_free(second);
}
void copy() {
genann *first = genann_init(1000, 5, 50, 10);
genann *second = genann_copy(first);
do { ++ltests; if ((first->inputs) != (second->inputs)) { ++lfails; printf("%s:%d (%d != %d)\n", "/app/subjects/genann/test.c", 229, (first->inputs), (second->inputs)); }} while (0);
do { ++ltests; if ((first->hidden_layers) != (second->hidden_layers)) { ++lfails; printf("%s:%d (%d != %d)\n", "/app/subjects/genann/test.c", 230, (first->hidden_layers), (second->hidden_layers)); }} while (0);
do { ++ltests; if ((first->hidden) != (second->hidden)) { ++lfails; printf("%s:%d (%d != %d)\n", "/app/subjects/genann/test.c", 231, (first->hidden), (second->hidden)); }} while (0);
do { ++ltests; if ((first->outputs) != (second->outputs)) { ++lfails; printf("%s:%d (%d != %d)\n", "/app/subjects/genann/test.c", 232, (first->outputs), (second->outputs)); }} while (0);
do { ++ltests; if ((first->total_weights) != (second->total_weights)) { ++lfails; printf("%s:%d (%d != %d)\n", "/app/subjects/genann/test.c", 233, (first->total_weights), (second->total_weights)); }} while (0);
int i;
for (i = 0; i < first->total_weights; ++i) {
do { ++ltests; if (fabs((double)(first->weight[i])-(double)(second->weight[i])) > 0.001) { ++lfails; printf("%s:%d (%f != %f)\n", "/app/subjects/genann/test.c", 237, (double)(first->weight[i]), (double)(second->weight[i])); }} while (0);
}
genann_free(first);
genann_free(second);
}
void sigmoid() {
double i = -20;
const double max = 20;
const double d = .0001;
while (i < max) {
do { ++ltests; if (fabs((double)(genann_act_sigmoid(0, i))-(double)(genann_act_sigmoid_cached(0, i))) > 0.001) { ++lfails; printf("%s:%d (%f != %f)\n", "/app/subjects/genann/test.c", 251, (double)(genann_act_sigmoid(0, i)), (double)(genann_act_sigmoid_cached(0, i))); }} while (0);
i += d;
}
}
int main(int argc, char *argv[])
{
printf("GENANN TEST SUITE\n");
srand(100);
do { const int ts = ltests; const int fs = lfails; const clock_t start = clock(); printf("\t%-14s", "basic"); basic(); printf("pass:%2d fail:%2d %4dms\n", (ltests-ts)-(lfails-fs), lfails-fs, (int)((clock() - start) * 1000 / CLOCKS_PER_SEC));} while (0);
do { const int ts = ltests; const int fs = lfails; const clock_t start = clock(); printf("\t%-14s", "xor"); xor(); printf("pass:%2d fail:%2d %4dms\n", (ltests-ts)-(lfails-fs), lfails-fs, (int)((clock() - start) * 1000 / CLOCKS_PER_SEC));} while (0);
do { const int ts = ltests; const int fs = lfails; const clock_t start = clock(); printf("\t%-14s", "backprop"); backprop(); printf("pass:%2d fail:%2d %4dms\n", (ltests-ts)-(lfails-fs), lfails-fs, (int)((clock() - start) * 1000 / CLOCKS_PER_SEC));} while (0);
do { const int ts = ltests; const int fs = lfails; const clock_t start = clock(); printf("\t%-14s", "train and"); train_and(); printf("pass:%2d fail:%2d %4dms\n", (ltests-ts)-(lfails-fs), lfails-fs, (int)((clock() - start) * 1000 / CLOCKS_PER_SEC));} while (0);
do { const int ts = ltests; const int fs = lfails; const clock_t start = clock(); printf("\t%-14s", "train or"); train_or(); printf("pass:%2d fail:%2d %4dms\n", (ltests-ts)-(lfails-fs), lfails-fs, (int)((clock() - start) * 1000 / CLOCKS_PER_SEC));} while (0);
do { const int ts = ltests; const int fs = lfails; const clock_t start = clock(); printf("\t%-14s", "train xor"); train_xor(); printf("pass:%2d fail:%2d %4dms\n", (ltests-ts)-(lfails-fs), lfails-fs, (int)((clock() - start) * 1000 / CLOCKS_PER_SEC));} while (0);
do { const int ts = ltests; const int fs = lfails; const clock_t start = clock(); printf("\t%-14s", "persist"); persist(); printf("pass:%2d fail:%2d %4dms\n", (ltests-ts)-(lfails-fs), lfails-fs, (int)((clock() - start) * 1000 / CLOCKS_PER_SEC));} while (0);
do { const int ts = ltests; const int fs = lfails; const clock_t start = clock(); printf("\t%-14s", "copy"); copy(); printf("pass:%2d fail:%2d %4dms\n", (ltests-ts)-(lfails-fs), lfails-fs, (int)((clock() - start) * 1000 / CLOCKS_PER_SEC));} while (0);
do { const int ts = ltests; const int fs = lfails; const clock_t start = clock(); printf("\t%-14s", "sigmoid"); sigmoid(); printf("pass:%2d fail:%2d %4dms\n", (ltests-ts)-(lfails-fs), lfails-fs, (int)((clock() - start) * 1000 / CLOCKS_PER_SEC));} while (0);
do { if (lfails == 0) { printf("ALL TESTS PASSED (%d/%d)\n", ltests, ltests); } else { printf("SOME TESTS FAILED (%d/%d)\n", ltests-lfails, ltests); }} while (0);
return lfails != 0;
}