61 fprintf(stdout,
"\nUSAGE OPTIONS:\n"
67 " training mode: BATCH (default)\n"
70 " tollerance ( default 0. )\n"
72 " max number of training iteration (default) 1000\n"
74 " printing output step (default 1)\n"
76 " saving ANN trained step (default 1)\n"
78 " filename of initialized neural network (default data/ann.dat)\n"
80 " filename of network training input (default data/Input.dat)\n"
82 " filename of network desired output (default data/DOutput.dat)\n"
84 " filename where to save trained neural network (default data/ann_tr.dat)\n"
86 " filename where to save trained neural network output (default data/NNOutput.dat)\n"
92 main(
int argc,
char *argv[])
95 matrix INPUT, DES_OUTPUT, NN_OUTPUT;
96 matrix INPUT2, DES_OUTPUT2;
109 #ifdef HAVE_GETOPT_LONG
110 static struct option options[] = {
111 {
"usage", 0, 0,
'u' },
112 {
"verbose", 0, 0,
'v' },
113 {
"mode", 1, 0,
'm' },
114 {
"toll", 1, 0,
't' },
115 {
"maxiter", 1, 0,
'i' },
116 {
"print", 1, 0,
'p' },
117 {
"save", 1, 0,
's' },
118 {
"ann_init", 1, 0,
'A' },
119 {
"input", 1, 0,
'I' },
120 {
"des_output", 1, 0,
'O' },
121 {
"ann_tr", 1, 0,
'T' },
122 {
"nn_output", 1, 0,
'N' }
124 opt = getopt_long(argc, argv,
"uvm:t:i:p:s:A:I:O:T:N:", options, NULL);
126 opt =
getopt(argc, argv,
"uvm:t:i:p:s:A:I:O:T:N:");
131 case 'v': verbose = 1;
134 if (strcasecmp(optarg,
"batch") == 0) {
136 }
else if (strcasecmp(optarg,
"sequential") == 0) {
139 fprintf(stderr,
"unknown training mode \"%s\" {batch|sequential}\n", optarg);
144 case 't':
TOLL = atof(optarg);
146 case 'i': MAXITER = atoi(optarg);
148 case 'p': PRINTSTEP = atoi(optarg);
150 case 's': SAVESTEP = atoi(optarg);
168 printf(
"LOADING DATA...\n");
170 fprintf(stdout,
"Error in ANN initialization\n");
175 fprintf(stderr,
"Initialization error\n");
179 fprintf(stderr,
"Initialization error\n");
183 fprintf(stderr,
"Initialization error\n");
187 fprintf(stderr,
"Initialization error\n");
195 fprintf(stderr,
"Error in Input data acquisition\n");
199 fprintf(stderr,
"Error in Output data acquisition\n");
203 fprintf(stderr,
"Error in NN_output matrix initialization\n");
207 fprintf(stderr,
"Error in NN_output matrix initialization\n");
211 fprintf(stderr,
"Error in NN_output matrix initialization\n");
215 fprintf(stderr,
"Error in NN_output matrix initialization\n");
220 fprintf(stdout,
"TRAINING....\n");
230 fprintf(stderr,
"Error in ....\n");
233 fprintf(stderr,
"Error in ....\n");
239 fprintf(stderr,
"Error: ANN_TrainingEpoch@main ppp\n");
251 while (err2 > err1) {
255 fprintf(stdout,
"Network's learning rate decreasing (eta = %lf)\n", net.
eta);
264 fprintf(stderr,
"Error: ANN_TrainingEpoch@main\n");
273 fprintf(stdout,
"Network's learning rate increasing (eta = %lf)\n", net.
eta);
283 for ( i=0; i<N_sample; i++ ){
284 ind = floor(rand()%(N_sample-i));
285 for ( j=0; j< INPUT2.
Ncolumn; j++){
286 INPUT.
mat[i][j] = INPUT2.
mat[ind][j];
287 INPUT2.
mat[ind][j] = INPUT2.
mat[N_sample-1-i][j];
289 for ( j=0; j< DES_OUTPUT2.
Ncolumn; j++){
291 DES_OUTPUT.
mat[i][j] = DES_OUTPUT2.
mat[ind][j];
292 DES_OUTPUT2.
mat[ind][j] = DES_OUTPUT2.
mat[N_sample-1-i][j];
299 if (!(Niter%PRINTSTEP)) {
300 fprintf(stdout,
"TRAINING: iter:%d ", Niter);
301 fprintf(stdout,
"Square error: :%le\n", err2);
304 if( !(Niter%SAVESTEP) ){
306 fprintf( stdout,
"SAVING DATA...\n");
308 fprintf(stderr,
"Error in data saving\n");
313 ERR2.
vec[Niter-1] = err2;
315 }
while ((err2>
TOLL) && (Niter<MAXITER));
318 fprintf(stdout,
"SAVING DATA...\n");
321 fprintf(stderr,
"Error: ANN_save@main\n");
326 fh = fopen(
"ERR.txt",
"w");
338 for (i = 0; i < net.
N_layer + 1; i++) {
351 fprintf(stdout,
"END.......\n");
mat_res_t vector_write(vector *VEC, FILE *fh, unsigned flags)
ann_res_t ANN_DataWrite(matrix *MAT, char *FileName)
ann_res_t ANN_write(ANN *net, FILE *fh, unsigned flags)
ann_res_t ANN_WeightUpdate(ANN *net, ANN_vector_matrix DW, double K)
static void print_usage(void)
ann_res_t ANN_vector_matrix_ass(ANN_vector_matrix *vm1, ANN_vector_matrix *vm2, int *N_neuron, int N_layer, double K)
ann_res_t ANN_DataRead(matrix *MAT, int *N_sample, char *FileName)
mat_res_t matrix_copy(matrix *MAT1, matrix *MAT2, double K)
mat_res_t vector_init(vector *VEC, unsigned dimension)
ann_res_t ANN_init(ANN *net, const char *FileName)
ann_res_t ANN_vector_matrix_init(ANN_vector_matrix *vm, int *N_neuron, int N_layer)
ann_res_t ANN_TrainingEpoch(ANN *net, matrix *INPUT, matrix *DES_OUTPUT, matrix *NN_OUTPUT, int N_sample, ann_training_mode_t mode)
mat_res_t matrix_destroy(matrix *MAT)
ann_res_t ANN_reset(ANN *net)
static char * DOUTPUTfile
ann_res_t ANN_TotalError(matrix *DES_OUTPUT, matrix *NN_OUTPUT, double *err)
static char * NN_OUTPUTfile
int getopt(int argc, char *const argv[], const char *opts)
mat_res_t vector_destroy(vector *VEC)
int main(int argc, char *argv[])
static ann_training_mode_t TRAINING_MODE
mat_res_t matrix_init(matrix *MAT, unsigned Nrow, unsigned Ncolumn)
ann_res_t ANN_destroy(ANN *net)