/***************************************************************************** FILE : $Source: /projects/higgs1/SNNS/CVS/SNNS/tools/sources/convert2snns.c,v $ SHORTNAME : convert2snns.c SNNS VERSION : 4.2 PURPOSE : Network Generator for n-Component Kohonen Networks NOTES : AUTHOR : Marc Seemann & Marcus Ritt DATE : 24.2.92 VERSION : 2.0 UPDATE : 13.7.93 CHANGED BY : RCS VERSION : $Revision: 2.10 $ LAST CHANGE : $Date: 1998/04/22 16:48:04 $ Copyright (c) 1990-1995 SNNS Group, IPVR, Univ. Stuttgart, FRG Copyright (c) 1996-1998 SNNS Group, WSI, Univ. Tuebingen, FRG ******************************************************************************/ #include #include #include #include #include /* SNNS-Kernel constants and data type definitions */ #include "glob_typ.h" /* SNNS-Kernel User-Interface Function Prototypes */ #include "kr_ui.h" /*######################################################################## PROTOTYPE - Section #########################################################################*/ void errChk (int); void quit (void); void control(FILE *); void create_network(char *); void create_patterns(char *,int); /*######################################################################## global definitions #########################################################################*/ /* Learning function name */ #define KOHONEN_LEARN_FUNC_NAME "Kohonen" /* Update function name */ #define KOHONEN_UPDATE_FUNC_NAME "Kohonen_Order" /* Init functionname */ #define KOHONEN_INIT_FUNC_NAME "Kohonen_Weights_v3.2" char *control_file,pattern_file[80],weight_file[80], string[80],name[50]; int no_of_exemplars,X,Y, ret, i, j, unit_no, IUnits, OUnits, HUnits; float initialize_params[5]; struct PosType unit_pos; char keywords[][20] = { "xsize", "ysize", "components", "patterns", "weightfile", "patternfile", "decrease", "height", "radius" }; #define NONE -1 #define XSIZE 0 #define YSIZE 1 #define COMPONENTS 2 #define PATTERNS 3 #define WEIGHTFILE 4 #define PATTERNFILE 5 #define DECREASE 6 #define HEIGHT 7 #define RADIUS 8 #define NKEYW 8 /* Number of Keywords */ /*######################################################################## FUNCTION - Section #########################################################################*/ /***************************************************************************** FUNCTION : errChk PURPOSE : Check whether an error occured during a process NOTES : UPDATE : june 15 1993 ******************************************************************************/ void errChk(int errNo ) { if (errNo != 0) { printf( "%s\n", krui_error( errNo )); exit( 1 ); } } /* end of errChk */ /***************************************************************************** FUNCTION : control PURPOSE : get information from the control file NOTES : UPDATE : july 13 1993 ******************************************************************************/ void control(FILE *fp) { int components=0, xsize=0, ysize=0, adapt_radius=0; int no_of_pus; float adapt_height=0, mul=0; char key[255]; short point; while (!feof(fp)) { fscanf(fp,"%s",key); for(point=0;key[point];point++) key[point]=tolower(key[point]); for(point=NKEYW;point>=0;point--) if (!strcmp(keywords[point],key)) break; switch(point) { case NONE : break; case XSIZE : fscanf(fp,"%d",&xsize); break; case YSIZE : fscanf(fp,"%d",&ysize); break; case COMPONENTS : fscanf(fp,"%d",&components); break; case PATTERNS : fscanf(fp,"%d",&no_of_exemplars); break; case WEIGHTFILE : fscanf(fp,"%s",weight_file); break; case PATTERNFILE: fscanf(fp,"%s",pattern_file); break; case HEIGHT : case DECREASE : case RADIUS : break; } fscanf(fp,"%[^\n]s",key); /* ignores comments at end of line */ } printf("\nThe File %s contains the following Datas:\n",control_file); printf("\nPattern File: %s ",pattern_file); printf("\nWeight File: %s ",weight_file); printf("\nX-Size: %d",xsize); printf("\nY-Size: %d",ysize); printf("\nComponents: %d",components); printf("\nNo. of Patterns: %d",no_of_exemplars); printf("\nAdaptation Height: %f",adapt_height); printf("\nAdaptation Radius: %d",adapt_radius); printf("\nDecrease Factor: %f",mul); no_of_pus=xsize*ysize; printf("\nNetwork consists of %d PUs",no_of_pus); fclose(fp); IUnits = components; OUnits = 0; X = xsize; Y = ysize; printf( "\nNo. of Components (No. of Input Units): " ); printf( "%i", IUnits ); printf( "\nNo. of Output Units(0 for don`t care): " ); printf( "%i",OUnits ); printf( "\nDimension of the Feature Map [X Y](No. of Hidden Units=X*Y): " ); printf( "%i %i", X, Y ); HUnits = X*Y; } /* end of control */ /***************************************************************************** FUNCTION : create_network PURPOSE : create the Kohonen Network with datas from control file NOTES : If no weight file is specified the weights will be set to zero UPDATE : june 15 1993 ******************************************************************************/ void create_network(char *weight_file) { FILE *fp; float val; /* Allocate units (the user may or may not use this function, there is no need to do this) */ ret = krui_allocateUnits( OUnits + HUnits + IUnits ); errChk( ret ); printf( "\n\nCreate Units now\n" ); /* Create standard (input) Units */ unit_pos.x = 1; for (i = 1; i <= IUnits; i++) { unit_no = krui_createDefaultUnit(); if (unit_no < 0) errChk( unit_no ); ret = krui_setUnitTType( unit_no, INPUT ); errChk( ret ); unit_pos.y = (IUnits