From e5ec4c7486a51d35050466f2234102cb57f9cce5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?IOhannes=20m=20zm=C3=B6lnig?= Date: Thu, 19 May 2005 14:07:23 +0000 Subject: shut down the compiler... svn path=/trunk/externals/ann/; revision=3028 --- src/ann_mlp.c | 124 ++++++++++++++++++++++++------------------------- src/ann_som.c | 5 +- src/ann_td.c | 147 +++++++++++++++++++++++++++++----------------------------- 3 files changed, 137 insertions(+), 139 deletions(-) diff --git a/src/ann_mlp.c b/src/ann_mlp.c index e83aea3..e01b203 100755 --- a/src/ann_mlp.c +++ b/src/ann_mlp.c @@ -30,8 +30,8 @@ typedef struct _ann_mlp { int mode; // 0 = training, 1 = running t_symbol *filename; // name of the file where this ann is saved t_symbol *filenametrain; // name of the file with training data - float desired_error; - unsigned int max_iterations; + float desired_error; + unsigned int max_iterations; unsigned int iterations_between_reports; t_outlet *l_out, *f_out; } t_ann_mlp; @@ -49,48 +49,48 @@ void help(t_ann_mlp *x) } void createFann(t_ann_mlp *x, t_symbol *sl, int argc, t_atom *argv) -{ - unsigned int num_input = 2; - unsigned int num_output = 1; - unsigned int num_layers = 3; - unsigned int num_neurons_hidden = 3; - float connection_rate = 1; - float learning_rate = (float)0.7; - - if (argc>0) - num_input = atom_getint(argv++); - - if (argc>1) - num_output = atom_getint(argv++); - - if (argc>2) - num_layers = atom_getint(argv++); - - if (argc>3) - num_neurons_hidden = atom_getint(argv++); - - if (argc>4) - connection_rate = atom_getfloat(argv++); - - if (argc>5) - learning_rate = atom_getfloat(argv++); - - if (num_input>=MAXINPUT) - { - error("too many inputs, maximum allowed is MAXINPUT"); - return; - } - - if (num_output>=MAXOUTPUT) - { - error("too many outputs, maximum allowed is MAXOUTPUT"); - return; - } - - x->ann = fann_create(connection_rate, learning_rate, num_layers, - num_input, num_neurons_hidden, num_output); - - fann_set_activation_function_hidden(x->ann, FANN_SIGMOID_SYMMETRIC); +{ + unsigned int num_input = 2; + unsigned int num_output = 1; + unsigned int num_layers = 3; + unsigned int num_neurons_hidden = 3; + float connection_rate = 1; + float learning_rate = (float)0.7; + + if (argc>0) + num_input = atom_getint(argv++); + + if (argc>1) + num_output = atom_getint(argv++); + + if (argc>2) + num_layers = atom_getint(argv++); + + if (argc>3) + num_neurons_hidden = atom_getint(argv++); + + if (argc>4) + connection_rate = atom_getfloat(argv++); + + if (argc>5) + learning_rate = atom_getfloat(argv++); + + if (num_input>=MAXINPUT) + { + error("too many inputs, maximum allowed is MAXINPUT"); + return; + } + + if (num_output>=MAXOUTPUT) + { + error("too many outputs, maximum allowed is MAXOUTPUT"); + return; + } + + x->ann = fann_create(connection_rate, learning_rate, num_layers, + num_input, num_neurons_hidden, num_output); + + fann_set_activation_function_hidden(x->ann, FANN_SIGMOID_SYMMETRIC); fann_set_activation_function_output(x->ann, FANN_SIGMOID_SYMMETRIC); if (x->ann == 0) @@ -150,25 +150,25 @@ void set_mode(t_ann_mlp *x, t_symbol *sl, int argc, t_atom *argv) void train_on_file(t_ann_mlp *x, t_symbol *sl, int argc, t_atom *argv) -{ +{ if (x->ann == 0) { error("ann not initialized"); return; - } - - if (argc<1) - { - error("you must specify the filename with training data"); - return; - } else - { - x->filenametrain = atom_gensym(argv); - } - - //post("nn: starting training on file %s, please be patient and wait for my next message (it could take severeal minutes to complete training)", x->filenametrain->s_name); - - fann_train_on_file(x->ann, x->filenametrain->s_name, x->max_iterations, + } + + if (argc<1) + { + error("you must specify the filename with training data"); + return; + } else + { + x->filenametrain = atom_gensym(argv); + } + + //post("nn: starting training on file %s, please be patient and wait for my next message (it could take severeal minutes to complete training)", x->filenametrain->s_name); + + fann_train_on_file(x->ann, x->filenametrain->s_name, x->max_iterations, x->iterations_between_reports, x->desired_error); post("nn: finished training on file %s", x->filenametrain->s_name); @@ -496,8 +496,8 @@ void *nn_new(t_symbol *s, int argc, t_atom *argv) x->l_out = outlet_new(&x->x_obj, &s_list); x->f_out = outlet_new(&x->x_obj, &s_float); - x->desired_error = (float)0.001; - x->max_iterations = 500000; + x->desired_error = (float)0.001; + x->max_iterations = 500000; x->iterations_between_reports = 1000; x->mode=RUN; @@ -562,4 +562,4 @@ void ann_mlp_setup(void) { class_sethelpsymbol(ann_mlp_class, gensym("help-ann_mlp")); -} \ No newline at end of file +} diff --git a/src/ann_som.c b/src/ann_som.c index f1da9fc..65a8682 100644 --- a/src/ann_som.c +++ b/src/ann_som.c @@ -329,9 +329,6 @@ static void som_dump(t_som *x, t_float nf){ outlet_list(x->x_obj.ob_outlet, &s_list, x->num_sensors, ap); freebytes(ap, x->num_sensors*sizeof(t_atom)); - - - } static void som_makenewsom(t_som *x, t_symbol *s, int argc, t_atom *argv) @@ -757,6 +754,8 @@ static void som_setup(void) class_addmethod(som_class, (t_method)som_read, gensym("read"), A_GIMME, 0); class_addmethod(som_class, (t_method)som_write, gensym("write"), A_GIMME, 0); + class_addmethod(som_class, (t_method)som_dump, gensym("dump"), A_FLOAT, 0); + class_addmethod(som_class, (t_method)som_print, gensym("print"), 0); class_addmethod(som_class, (t_method)som_help, gensym("help"), 0); class_sethelpsymbol(som_class, gensym("som")); diff --git a/src/ann_td.c b/src/ann_td.c index c2cf6b5..0184139 100755 --- a/src/ann_td.c +++ b/src/ann_td.c @@ -30,8 +30,8 @@ typedef struct _ann_td { int mode; // 0 = training, 1 = running t_symbol *filename; // name of the file where this ann is saved t_symbol *filenametrain; // name of the file with training data - float desired_error; - unsigned int max_iterations; + float desired_error; + unsigned int max_iterations; unsigned int iterations_between_reports; unsigned int frames; unsigned int num_input; @@ -71,59 +71,59 @@ void allocate_inputs(t_ann_td *x) } void createFann(t_ann_td *x, t_symbol *sl, int argc, t_atom *argv) -{ - unsigned int num_input = 2; - unsigned int num_output = 1; - unsigned int num_layers = 3; - unsigned int num_neurons_hidden = 3; - float connection_rate = 1; - float learning_rate = (float)0.7; - - if (argc<3) - { - error("you must provide at least num_input, num_output amd frames number"); - return; - } - if (argc>0) - num_input = atom_getint(argv++); - - if (argc>1) - num_output = atom_getint(argv++); - - if (argc>2) - { - x->frames = atom_getint(argv++); - x->ins_frames_set=1; - } - - if (argc>3) - num_layers = atom_getint(argv++); - - if (argc>4) - num_neurons_hidden = atom_getint(argv++); - - if (argc>5) - connection_rate = atom_getfloat(argv++); - - if (argc>6) - learning_rate = atom_getfloat(argv++); - - if ((num_input * x->frames)>=MAXINPUT) - { - error("too many inputs, maximum allowed is %f", MAXINPUT/x->frames); - return; - } - - if (num_output>=MAXOUTPUT) - { - error("too many outputs, maximum allowed is MAXOUTPUT"); - return; - } - - x->ann = fann_create(connection_rate, learning_rate, num_layers, - (num_input*x->frames), num_neurons_hidden, num_output); - - fann_set_activation_function_hidden(x->ann, FANN_SIGMOID_SYMMETRIC); +{ + unsigned int num_input = 2; + unsigned int num_output = 1; + unsigned int num_layers = 3; + unsigned int num_neurons_hidden = 3; + float connection_rate = 1; + float learning_rate = (float)0.7; + + if (argc<3) + { + error("you must provide at least num_input, num_output amd frames number"); + return; + } + if (argc>0) + num_input = atom_getint(argv++); + + if (argc>1) + num_output = atom_getint(argv++); + + if (argc>2) + { + x->frames = atom_getint(argv++); + x->ins_frames_set=1; + } + + if (argc>3) + num_layers = atom_getint(argv++); + + if (argc>4) + num_neurons_hidden = atom_getint(argv++); + + if (argc>5) + connection_rate = atom_getfloat(argv++); + + if (argc>6) + learning_rate = atom_getfloat(argv++); + + if ((num_input * x->frames)>=MAXINPUT) + { + error("too many inputs, maximum allowed is %f", MAXINPUT/x->frames); + return; + } + + if (num_output>=MAXOUTPUT) + { + error("too many outputs, maximum allowed is MAXOUTPUT"); + return; + } + + x->ann = fann_create(connection_rate, learning_rate, num_layers, + (num_input*x->frames), num_neurons_hidden, num_output); + + fann_set_activation_function_hidden(x->ann, FANN_SIGMOID_SYMMETRIC); fann_set_activation_function_output(x->ann, FANN_SIGMOID_SYMMETRIC); allocate_inputs(x); @@ -186,25 +186,25 @@ void set_mode(t_ann_td *x, t_symbol *sl, int argc, t_atom *argv) void train_on_file(t_ann_td *x, t_symbol *sl, int argc, t_atom *argv) -{ +{ if (x->ann == 0) { error("ann not initialized"); return; - } - - if (argc<1) - { - error("you must specify the filename with training data"); - return; - } else - { - x->filenametrain = atom_gensym(argv); - } - - //post("nn: starting training on file %s, please be patient and wait for my next message (it could take severeal minutes to complete training)", x->filenametrain->s_name); - - fann_train_on_file(x->ann, x->filenametrain->s_name, x->max_iterations, + } + + if (argc<1) + { + error("you must specify the filename with training data"); + return; + } else + { + x->filenametrain = atom_gensym(argv); + } + + //post("nn: starting training on file %s, please be patient and wait for my next message (it could take severeal minutes to complete training)", x->filenametrain->s_name); + + fann_train_on_file(x->ann, x->filenametrain->s_name, x->max_iterations, x->iterations_between_reports, x->desired_error); post("ann_td: finished training on file %s", x->filenametrain->s_name); @@ -277,7 +277,6 @@ void run_the_net(t_ann_td *x, t_symbol *sl, int argc, t_atom *argv) { int i=0; unsigned j=0; - unsigned k=0; //fann_type input[MAXINPUT]; fann_type *calc_out; t_atom lista[MAXOUTPUT]; @@ -575,8 +574,8 @@ void *nn_new(t_symbol *s, int argc, t_atom *argv) x->l_out = outlet_new(&x->x_obj, &s_list); x->f_out = outlet_new(&x->x_obj, &s_float); - x->desired_error = (float)0.001; - x->max_iterations = 500000; + x->desired_error = (float)0.001; + x->max_iterations = 500000; x->iterations_between_reports = 1000; x->mode=RUN; x->ins_frames_set=0; @@ -662,4 +661,4 @@ void ann_td_setup(void) { class_sethelpsymbol(ann_td_class, gensym("help-ann_td")); -} \ No newline at end of file +} -- cgit v1.2.1