-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
218 lines (205 loc) · 6.88 KB
/
Main.cpp
File metadata and controls
218 lines (205 loc) · 6.88 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
/*
Author: Adriaan Tijsseling (AGT)
Copyright: (c) Copyright 2002-3 Adriaan Tijsseling. All rights reserved.
Description: Main file for using the Sequence API
This code creates an executable that uses the SequenceNet API.
The user has to provide the functions InitNetwork() and DoSimulation().
*/
#include <stdlib.h>
#include "SeqGlobal.h" // SeqGlobal.h contains project wide definitions and the like
#include "Sequence.h" // the interface file to the Seq API Library
// defined in user-provided simulation file
extern bool InitNetwork( void );
extern void DoSimulation( void );
// PROTOTYPE
void Usage( void );
// GLOBALS
SequenceAPI* gSequenceAPI; // pointer to API interface
int main( int argc, char *argv[] )
{
int arg;
// initialize the API instance. This MUST be called at the start of the program!
gSequenceAPI = new SequenceAPI;
// set default parameters for the SequenceNet API
gSequenceAPI->SequenceSetRuns( 1 );
gSequenceAPI->SequenceSetEpochs( 500 );
gSequenceAPI->SequenceSetIterations( 10 );
gSequenceAPI->SequenceSetRecallLen( 100 );
gSequenceAPI->SequenceSetNumFiles( 1 );
gSequenceAPI->SequenceSetFileIndex( 0 );
gSequenceAPI->SequenceSetVerbosity( 0x00 );
gSequenceAPI->SequenceSetErrCrit( 0.05 );
gSequenceAPI->SequenceSetAlphaCrit( 0.01 );
gSequenceAPI->SequenceSetRecallCrit( 0.05 );
// process command-line arguments to get custom values for the above parameters
if( argc > 1 )
{
// run down each argument
arg = 1;
while( arg < argc )
{
// check if -h is called
if( strcmp( argv[arg], "-h") == 0 )
{
arg++;
Usage();
}
// perhaps -r : number of runs
if( strcmp( argv[arg], "-r") == 0 )
{
arg++;
if( argv[arg] == nil ) Usage();
gSequenceAPI->SequenceSetRuns( atoi( argv[arg] ) );
goto loop;
}
// perhaps -e : number of epochs
if( strcmp( argv[arg], "-e") == 0 )
{
arg++;
if( argv[arg] == nil ) Usage();
gSequenceAPI->SequenceSetEpochs( atoi( argv[arg] ) );
goto loop;
}
// perhaps -i : number of iterations
if( strcmp( argv[arg], "-i") == 0 )
{
arg++;
if( argv[arg] == nil ) Usage();
gSequenceAPI->SequenceSetIterations( atoi( argv[arg] ) );
goto loop;
}
// perhaps -l : number of iterations for recall
if( strcmp( argv[arg], "-l") == 0 )
{
arg++;
if( argv[arg] == nil ) Usage();
gSequenceAPI->SequenceSetRecallLen( atoi( argv[arg] ) );
goto loop;
}
// perhaps -f : number of files (i.e. sequences) to train
// (only for offline training method, see MultiSequence.h and .cpp)
if( strcmp( argv[arg], "-f") == 0 )
{
arg++;
if( argv[arg] == nil ) Usage();
gSequenceAPI->SequenceSetNumFiles( atoi( argv[arg] ) );
goto loop;
}
// perhaps -F : index of first file to train
// (only for offline training method, see MultiSequence.h and .cpp)
if( strcmp( argv[arg], "-f") == 0 )
{
arg++;
if( argv[arg] == nil ) Usage();
gSequenceAPI->SequenceSetFileIndex( atoi( argv[arg] ) );
goto loop;
}
// perhaps -p : linear or permuted presentation of sequences
if( strcmp( argv[arg], "-p") == 0 )
{
arg++;
if( argv[arg] == nil ) Usage();
gSequenceAPI->SequenceSetOrder( atoi( argv[arg] ) );
goto loop;
}
// perhaps -t : sequence type (cyclic or terminated)
if( strcmp( argv[arg], "-t") == 0 )
{
arg++;
if( argv[arg] == nil ) Usage();
gSequenceAPI->SequenceSetOverrideType( atoi( argv[arg] ) );
goto loop;
}
// verbosity -v
if( strcmp( argv[arg], "-v") == 0 )
{
arg++;
if( argv[arg] == nil ) Usage();
gSequenceAPI->SequenceSetVerbosity( atoi( argv[arg] ) );
goto loop;
}
// error criteria : training error
if( strcmp( argv[arg], "-E") == 0 )
{
arg++;
if( argv[arg] == nil ) Usage();
gSequenceAPI->SequenceSetErrCrit( atof( argv[arg] ) );
goto loop;
}
// error criteria : learning rate
if( strcmp( argv[arg], "-a") == 0 )
{
arg++;
if( argv[arg] == nil ) Usage();
gSequenceAPI->SequenceSetAlphaCrit( atof( argv[arg] ) );
goto loop;
}
// error criteria for correct recall
if( strcmp( argv[arg], "-R") == 0 )
{
arg++;
if( argv[arg] == nil ) Usage();
gSequenceAPI->SequenceSetRecallCrit( atof( argv[arg] ) );
goto loop;
}
// base file name -b
if( strcmp( argv[arg], "-b") == 0 )
{
arg++;
if( argv[arg] == nil ) Usage();
gSequenceAPI->SequenceSetBasename( argv[arg] );
goto loop;
}
// directory -d for files
if( strcmp( argv[arg], "-d") == 0 )
{
arg++;
if( argv[arg] == nil ) Usage();
gSequenceAPI->SequenceSetDirectory( argv[arg] );
goto loop;
}
loop:
arg++;
}
}
// initialize network
if ( InitNetwork() )
{
// run simulation (defined in simulation code file)
DoSimulation();
}
// clean the API instance
delete gSequenceAPI;
return 0;
}
// show the command line options if incorrectly engaged or if the user uses the -h flag
void Usage( void )
{
cerr << "Usage: seqnet (-OPTIONS) [default]" << endl;
cerr << " -h = display this help and exit" << endl;
cerr << " -r [1] = number of simulations to run" << endl;
cerr << " -e [5000] = maximum number of epochs to present each set of sequences" << endl;
cerr << " -i [10] = number of iterations to train a single pattern" << endl;
cerr << " -l [100] = number of iterations for single recall" << endl;
cerr << " -p [1] = presentation order: 0 (linear) or 1 (permuted)" << endl;
cerr << " -t [0] = sequence type: 0 (cyclic), 1 (end-terminating), 2 (noise terminating)" << endl;
cerr << " -E [0.1] = error criterium" << endl;
cerr << " -a [0.01] = learning rate criterium" << endl;
cerr << " -R [0.05] = criterium for correct recall" << endl;
cerr << " -b [seq] = base file name for network files. Files should be suffixed as:" << endl;
cerr << " .net : network definition" << endl;
cerr << " -x.pat : pattern file with index x (online for offline multi-sequence training)" << endl;
cerr << " -d [.] = directory containing the network files" << endl;
cerr << " -f [1] = number of pattern files to train" << endl;
cerr << " -F [0] = index of first pattern file to train" << endl;
cerr << " -v [1] = verbosity level, defined as a bitwise operation of:" << endl;
cerr << " 0 : silent mode" << endl;
cerr << " 1 : activations" << endl;
cerr << " 2 : formatted activations" << endl;
cerr << " 4 : detailed learning progress" << endl;
cerr << " 8 : coincidence detection layer output" << endl;
cerr << " 16 : display detailed progress multi sequence learning" << endl;
cerr << " 32 : save weight-changes" << endl;
cerr << " 64 : save total activation-changes" << endl;
exit(0);
}