|
From: Herton R. K. <he...@us...> - 2005-04-07 06:20:05
|
Update of /cvsroot/kimageprocess/kimageprocess/testclass In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10371/testclass Modified Files: testclass.c Log Message: - Finished testclass, now generating res files also. Index: testclass.c =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/testclass/testclass.c,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- testclass.c 6 Apr 2005 04:32:11 -0000 1.14 +++ testclass.c 7 Apr 2005 06:19:56 -0000 1.15 @@ -6,6 +6,7 @@ #include <unistd.h> #include <lex.yy.c> #include <fann.h> +#include <time.h> #define TESTCLASS_VERSION "0.1" #define PARSER_ERROR 1 @@ -183,6 +184,9 @@ struct fann_train_data tfanndata; float connection_rate = 1; float learning_rate = 0.7; + float *result; + int npat; + time_t tempTime; if (argc == 1) usage(argv[0]); @@ -226,6 +230,9 @@ pc_file = fopen(c_file, "r"); if (pc_file == NULL) fatal(errno); + pr_file = fopen(r_file, "w"); + if (pr_file == NULL) + fatal(errno); loadNetwork(&c_patData, pc_file, c_file); tfann = fann_create(connection_rate, learning_rate, 3, t_patData.numInputUnits, @@ -241,9 +248,33 @@ tfanndata.input = t_patData.inputValues; tfanndata.output = t_patData.outputValues; fann_init_weights(tfann, &tfanndata); - /*fann_set_training_algorithm(ann, FANN_TRAIN_QUICKPROP);*/ fann_train_on_data(tfann, &tfanndata, 300000, 1000, 0.001); - /*fann_train_on_data_callback(ann, data, max_iterations, iterations_between_reports, desired_error, print_callback);*/ + if (fprintf(pr_file, "SNNS result file V1.4-3D\n") < 0) + fatal(errno); + tempTime = time(NULL); + if (fprintf(pr_file, "generated at %s\n\n", ctime(&tempTime)) < 0) + fatal(errno); + if (fprintf(pr_file, "No. of patterns : %d\n", c_patData.numPatterns) < 0) + fatal(errno); + if (fprintf(pr_file, "No. of input units : %d\n", t_patData.numInputUnits) < 0) + fatal(errno); + if (fprintf(pr_file, "No. of output units : %d\n", t_patData.numOutputUnits) < 0) + fatal(errno); + if (fprintf(pr_file, "startpattern : 1\n") < 0) + fatal(errno); + if (fprintf(pr_file, "endpattern : %d\n\n", c_patData.numPatterns) < 0) + fatal(errno); + for (npat = 0; npat < c_patData.numPatterns; npat++) + { + result = fann_run(tfann, c_patData.inputValues[npat]); + for (c = 0; c < t_patData.numOutputUnits; c++) + { + if (fprintf(pr_file, "%.5f ", result[c]) < 0) + fatal(errno); + } + fseek(pr_file, -1, SEEK_CUR); /* remove extra space */ + fprintf(pr_file, "\n"); + } fann_destroy(tfann); if (t_patData.inputValues != NULL) { @@ -281,5 +312,7 @@ fatal(errno); if (fclose(pc_file) != 0) fatal(errno); + if (fclose(pr_file) != 0) + fatal(errno); return 0; } |