-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeepnet.c
77 lines (67 loc) · 2.03 KB
/
deepnet.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
///Multipurpose deep learning neural network
///author: Jacob Potter (jmp1617)
//
#include "deepnet.h"
#include <string.h>
int main( int argc, char* argv[] ){
if( argc != 7){
fprintf( stderr, "Incorrect argument amount\n\n" );
print_usage();
return 1;
}
if( check_args( argv ) ){
return 1;
}
//set options
Options o = malloc( sizeof( Options_s ) );
o->mode = argv[1][0];
o->numdata = strtol( argv[2], NULL, 10 );
o->size = strtol( argv[3], NULL, 10 );
o->file = malloc( sizeof( char ) * 50 );
memcpy( o->file, argv[4], strlen( argv[4] ) + 1 );
o->visualize = strtol( argv[5], NULL, 10 );
o->rotate = strtol( argv[6], NULL, 10 );
//prepare synapse storage
SynStore s = malloc( sizeof( SynStore_s ) );
s->synapse2 = malloc( sizeof( double ) * 4 );
//init synapse 0
s->synapse0 = malloc( sizeof( double* ) * o->size );
s->synapse0[0] = malloc( sizeof( double ) * o->size * 4 );
for( int i = 0; i < o->size; i++ )
s->synapse0[i] = ( *s->synapse0 + 4 * i );
//init synapse 1
s->synapse1 = malloc( sizeof( double*) * 4 );
s->synapse1[0] = malloc( sizeof( double ) * 16 );
for( int i = 0; i < 4; i++ )
s->synapse1[i] = ( *s->synapse1 + 4 * i );
//select runtype
if( o->mode == 't' ){ //train
//init synapses
init_syn2( s->synapse2, 4 );
init_syn1( s->synapse0, o->size - 1, 4 );
init_syn1( s->synapse1, 4, 4 );
train_mode( o, s );
#ifndef DEBUG
printf( "\033[2J" );
fflush( stdout );
printf( "\033[%d;%dH", 1, 0 );
printf("%f%%\n",(double)100);
printf("%d of %d\n",o->numdata,o->numdata);
#endif
export_brain( s, o );
}
else{
import_brain( s, o );
analyze_mode( o, s );
}
//cleanup
free( o->file );
free( o );
free( s->synapse2 );
free( s->synapse1[0] );
free( s->synapse1 );
free( s->synapse0[0] );
free( s->synapse0 );
free( s );
return 0;
}