/* Self-Organizing Map (1D): 2006.5.14 A.Date Last modified 1 May 2009 */ #include #include #include #define N_XUNITS 20 #define DIM_INPUT 1 /* dimension of input signal space */ double ALPHA=0.2; /* learning coefficients */ double SIGMA=0.8; /* control neighborhood learning */ int SLEEP=100000; /* set small number if slow */ int N_LEARNING = 500; int N_SUB_LEARNING = 10; double X_RANGE=1.0; double Y_RANGE=1.0; double S[DIM_INPUT]; /* input signal */ double RV[N_XUNITS][DIM_INPUT]; /* reference vectors */ FILE *gp; void som1d(); void init_reference(); void write_data_anim_d1(); /* gnuplot can read data from standard input (without data file). after "plot '-'", send data. gnuplot read data until 'e' appear. */ int main (int argc, char *argv[] ) { int i,j,k; double x,y; long seed = 1234567; /* set your favorite number */ for (i=1; i 0.5 ){ S[0] = 0.75 + 0.2*(drand48()-0.5); } else{ S[0] = 0.25 + 0.2*(drand48()-0.5); } */ // printf("%.5lf\n",S[0]); /* find the winner unit which has ref. vector closest to the input */ for (k=0; k