diff options
author | IOhannes m zmölnig <zmoelnig@users.sourceforge.net> | 2003-05-24 16:15:53 +0000 |
---|---|---|
committer | IOhannes m zmölnig <zmoelnig@users.sourceforge.net> | 2003-05-24 16:15:53 +0000 |
commit | fb86c4da1890858f5b048ca172dfb0d714e27e10 (patch) | |
tree | f7bebcb69d0ced26392a92e869485a1522157a72 /src/ann_som.c | |
parent | 21dbdef1fcf5169ade95e05aed35ff361f4d3cc2 (diff) |
added "cinit" for centered initialization (preliminary)
svn path=/trunk/externals/ann/; revision=654
Diffstat (limited to 'src/ann_som.c')
-rw-r--r-- | src/ann_som.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/ann_som.c b/src/ann_som.c index 2bd2b4a..b4a0947 100644 --- a/src/ann_som.c +++ b/src/ann_som.c @@ -285,6 +285,54 @@ static void som_init(t_som *x, t_symbol *s, int argc, t_atom *argv) } } +/* centered initialization: + * the "first" neuron will be set to all zeros + * the "middle" neuron will be set to the given data + * the "last" neuron will be set to teh double of the given data + */ +static void som_cinit(t_som *x, t_symbol *s, int argc, t_atom *argv){ + /* initialize the neuron-weights */ + int i, j; + t_float f; + t_float v = 1.0f; + + switch (argc) { + case 0: + case 1: + f = (argc)?atom_getfloat(argv):0; + for (i=0; i<x->num_neurons; i++){ + v=i*2.0/x->num_neurons; + for (j=0; j<x->num_sensors; j++) + x->weights[i][j]=f*v; + } + break; + default: + if (argc == x->num_sensors) { + for (i=0; i<x->num_neurons; i++){ + v=i*2.0/x->num_neurons; + for (j=0; j<x->num_sensors; j++) + x->weights[i][j]=v*atom_getfloat(&argv[j]); + } + } else + error("som_init: you should pass a list of expected mean-values for each sensor to the SOM"); + } +} + +/* dump the weights of the queried neuron to the output */ +static void som_dump(t_som *x, t_float nf){ + int n=nf; + int i=x->num_sensors; + t_atom*ap=0; + if (n<0 || n>=x->num_neurons)return; + ap=(t_atom*)getbytes(sizeof(t_atom)*x->num_sensors); + while(i--)SETFLOAT(&ap[i], x->weights[n][i]); + 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) { /* create a new SOM */ @@ -697,6 +745,7 @@ static void som_setup(void) class_addmethod(som_class, (t_method)som_makenewsom, gensym("new"), A_GIMME, 0); class_addmethod(som_class, (t_method)som_init, gensym("init"), A_GIMME, 0); + class_addmethod(som_class, (t_method)som_cinit, gensym("cinit"), A_GIMME, 0); class_addmethod(som_class, (t_method)som_learn, gensym("learn"), A_GIMME, 0); class_addmethod(som_class, (t_method)som_neighbour, gensym("neighbour"), A_GIMME, 0); |