/*------------------------------------------------------------------------*/ /* xtdnn: A Time-Delay Neural Network program with an X-Window front-end for real-time graphics. Author: R. Timothy Edwards Date: March 29, 1991 -- April 12, 1991 (Version 0.0) Revisions: Version 1.0 completed April 25, 1991 (I/O graphs added) */ /*------------------------------------------------------------------------*/ /* Global definitions and variables */ /*-----------------------------------------------------------------------*/ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define MAXPATTERNS 150 /* Maximum number of presented patterns */ #define MAXLAYERS 5 /* Maximum number of network layers allowed */ #define MAXNODES 13 /* Maximum number of nodes per layer */ #define MAXTAPS 45 /* Maximum number of taps per node */ #define MAXACCUM 60 /* Maximum number of virtual taps per node */ #define NODSIZ 25 /* Pixel size of a node */ #define SIGWIDTH 10 #define SIGHEIGHT 14 #define DELWIDTH 10 #define DELHEIGHT 13 Widget form, pix, graph, message; /* Widgets used by many routines */ Widget recnet; Display *dpy; Colormap cmap; XFontStruct *textstruct, *graphtext; int symbfont; /* ID of symbol font */ void (*function)(); /* Global function pointer */ void (*drawtype)(); /* Global function pointer */ void (*learntype)(); /* Pointer to training algorithm */ float (*Sigmoid)(); /* Pointer to tanh or 1/1+e... */ float (*DSig)(); /* Pointer to derivative of above. */ float (*Limiter)(); /* Pointer to hard limiter function */ char buf[BUFSIZ*2]; /* input buffer for piped child process */ unsigned long RANDVAL = 0x3c6915d7; /* A random number seed */ struct NetStruct { /* A time-delay neural network */ int layers; int nodes[MAXLAYERS]; int taps[MAXLAYERS]; float weight[MAXLAYERS-1][MAXTAPS][MAXNODES][MAXNODES]; float state[MAXLAYERS][MAXACCUM][MAXNODES]; float threshold[MAXLAYERS-1][MAXNODES]; } Network; float traininput[MAXPATTERNS][MAXNODES]; float sampleinput[MAXPATTERNS][MAXNODES]; float traindesired[MAXPATTERNS][MAXNODES]; float outputhistory[MAXPATTERNS][MAXNODES]; int pattern, no_patterns, no_samples; Boolean Interrupt, Step, LRunTrain, LRunSample, Recurrent; Boolean trainsamp; /* TRUE for sample run, FALSE during training */ Boolean LLastPat, LSelf; char msgstring[250]; char pixtitle[100]; float weightnorm, RanMag; float eta, epsilon, eps_eff; int starteps, endeps; int update, count; Boolean Digital; /* Output restricted to binary values */ char weightfile[50], trainfile[50], samplefile[50]; char TrainProg[50], SampProg[50]; GC gc, linegc, textgc, graphgc; long int redpixcolorpos[3], greenpixcolorpos[3], bluepixcolorpos[3]; long int redpixcolorneg[3], greenpixcolorneg[3], bluepixcolorneg[3]; long int colorvals[53];