Merge /pub/main
[educational.data.git] / AI01 / rbp / io.c
bloba46aff23c4c053c936b5250fbecdbeb2d22fd90e
1 /* ************************************************** */
2 /* file io.c: contains most input/output functions */
3 /* */
4 /* Copyright (c) 1990-96 by Donald R. Tveter */
5 /* */
6 /* ************************************************** */
8 #ifdef INTEGER
9 #include "ibp.h"
10 #else
11 #include "rbp.h"
12 #endif
14 #if defined(UNIX) && defined(HOTKEYS)
16 #ifdef BSD
17 struct termios raw; /* characteristics for hotkeys */
18 struct termios noraw; /* original characteristics */
19 #elif defined NEXT
20 struct sgttyb raw; /* characteristics for hotkeys */
21 struct sgttyb noraw; /* original characteristics */
22 #else /* the System V solution */
23 struct termio raw; /* characteristics for hotkeys */
24 struct termio noraw; /* original characteristics */
25 #endif
27 char onechar[1]; /* the buffer for the hotkey character */
28 #endif
30 extern UNIT *locateunit();
31 extern WTTYPE userscaleup();
33 extern char buffer[], outstr[], *inputfile, sysstr[];
34 extern char copyflag,deriv,*datafile,echo,informat;
35 extern char outformat, probtype, update, *wtfile, wtformat, zeroderiv;
36 extern char offby1, ringbell, up_to_date_stats, summary, biasset;
37 extern char wtlimithit, runningflag, seednote;
38 extern char saveonminimum, wtfilename[], trfiles[];
39 extern char recurinit;
40 extern int bufferend, bufferptr, filestackptr, format[];
41 extern int filetimes[], wtfilecount, timestoread, maxiter;
42 extern FILE *data, *filestack[];
43 extern LAYER *last, *start;
44 extern int extraconnect,ioconnects,lastsave,pagesize,pccnet,prevnpats;
45 extern int readerror, readingpattern, totaliter;
46 extern int printrate, saverate;
47 extern int lineno, stmsize;
48 extern long iotime;
49 extern short nlayers;
50 extern WTTYPE unknown, toler, toosmall, stdthresh;
51 extern WTTYPE initrange, kickrange, kicksize;
52 extern WTTYPE alpha, eta, eta2;
53 extern WTTYPE decay, dbdeta, kappa, etamax, theta1;
54 extern WTTYPE qpeta, qpnoise, mu;
55 extern WTTYPE classoff, classon;
56 extern WTTYPE hbiasact, obiasact;
57 extern char qpslope;
58 extern FILE *copy;
59 extern REAL qpdecayh, qpdecayo;
60 extern REAL toloverall, minimumsofar;
61 extern DATA s[2][2];
62 extern WTTYPE Dh, Do;
63 extern char ah, ao;
64 extern int wtsinuse, wttotal;
65 extern char incrementseed;
66 extern unsigned seed;
67 extern SEEDNODE *seedstart;
69 #if defined(UNIX) && defined(HOTKEYS)
71 #ifdef BSD
72 void initraw()
74 int i;
75 tcgetattr(0,&noraw);
76 raw.c_iflag = noraw.c_iflag;
77 raw.c_oflag = noraw.c_oflag;
78 raw.c_cflag = noraw.c_cflag;
79 raw.c_lflag = noraw.c_lflag & ~ ECHO;
80 raw.c_lflag = raw.c_lflag & ~ ICANON;
81 for (i=0;i<NCCS;i++) raw.c_cc[i] = noraw.c_cc[i];
82 raw.c_cc[VMIN] = 1;
83 raw.c_cc[VTIME] = 0;
84 raw.c_ispeed = noraw.c_ispeed;
85 raw.c_ospeed = noraw.c_ospeed;
88 void setraw()
90 tcsetattr(0,TCSANOW,&raw);
93 void setnoraw()
95 tcsetattr(0,TCSANOW,&noraw);
98 #elif defined NEXT
99 void initraw()
101 ioctl(0,TIOCGETD,&noraw);
102 raw.sg_ispeed = noraw.sg_ispeed;
103 raw.sg_ospeed = noraw.sg_ospeed;
104 raw.sg_erase = noraw.sg_erase;
105 raw.sg_kill = noraw.sg_kill;
106 raw.sg_flags = noraw.sg_flags & 0000040; /* turn on raw mode */
109 void setraw()
111 ioctl(0,TIOCSETD,&raw);
114 void setnoraw()
116 ioctl(0,TIOCSETD,&noraw);
119 #else /* System V code */
120 void initraw()
122 int i;
123 ioctl(0,TCGETA,&noraw);
124 raw.c_iflag = noraw.c_iflag;
125 raw.c_oflag = noraw.c_oflag;
126 raw.c_cflag = noraw.c_cflag;
127 raw.c_lflag = noraw.c_lflag & ~ 0x02; /* hot key bit */
128 raw.c_lflag = raw.c_lflag & ~ 010; /* echo bit */
129 raw.c_line = noraw.c_line;
130 for (i=0;i<=7;i++) raw.c_cc[i] = noraw.c_cc[i];
131 raw.c_cc[4] = 1;
134 void setraw()
136 ioctl(0,TCSETA,&raw);
139 void setnoraw()
141 ioctl(0,TCSETA,&noraw);
143 #endif /* end of the System V code */
145 int getch()
147 int ch;
148 setraw();
149 do ch = read(0,onechar,1); while (ch != 1);
150 setnoraw();
151 return(onechar[0]);
153 #endif /* end of the if defined(UNIX) ... code */
155 #ifdef INTEGER
156 short scale(x) /* returns x as a scaled 16-bit value */
157 REAL x;
159 short s;
161 if (x > 31.999 || x < -32.0)
163 sprintf(outstr,"magnitude of %f is too large for the integer",x);
164 pg(stdout,outstr);
165 pg(stdout," representation\n");
166 readerror = 1;
167 if (x > 31.999) return(MAXSHORT); else return(MINSHORT);
169 if (x > 0.0) s = x * 1024 + 0.5;
170 else s = x * 1024 - 0.5;
171 if (x != 0.0 && s == 0)
173 sprintf(outstr,"warning: magnitude of %f is too small for",x);
174 pg(stdout,outstr);
175 pg(stdout," the integer representation\n");
176 return(0);
178 return(s);
181 REAL unscale(x) /* returns the REAL value of short x */
182 short x;
183 {return((REAL) x / 1024.0);}
185 REAL unscaleint(x) /* returns the REAL value of INT32 x */
186 INT32 x;
187 { return((REAL) x / 1024.0); }
189 #endif
191 int pushfile(filename,timestoread)
192 char *filename;
193 int timestoread;
195 FILE *file;
197 bufferptr = 0;
198 bufferend = 0;
199 buffer[0] = '\n';
200 file = fopen(filename,"r");
201 if (file == NULL)
203 sprintf(outstr,"cannot open: %s\n",filename); pg(stdout,outstr);
204 return(0);
206 filestackptr = filestackptr + 1;
207 if (filestackptr > MAXFILES)
209 pg(stdout,"can't stack up any more files\n");
210 filestackptr = filestackptr - 1;
211 fclose(file);
212 return(0);
214 filestack[filestackptr] = file;
215 filetimes[filestackptr] = timestoread;
216 data = file;
217 return(1);
220 void popfile()
222 bufferptr = 0;
223 bufferend = 0;
224 buffer[0] = '\n';
225 if (s[TOL][TRAIN].wrong == 0) /* break the "loop" */
226 filetimes[filestackptr] = 1;
227 filetimes[filestackptr] = filetimes[filestackptr] - 1;
228 if (filetimes[filestackptr] > 0) rewind(data);
229 else if (filestackptr > 0)
231 fclose(data);
232 filestackptr = filestackptr - 1;
234 else pg(stdout,"\nunexpected EOF: to quit the program, type q\n");
235 data = filestack[filestackptr];
238 int readch() /* returns the next character in the input buffer */
240 int i, ch2;
242 if (bufferptr > bufferend) /* then read next line into buffer */
244 #ifdef HOTKEYS
245 if (data == stdin)
247 ch2 = getch();
248 if (ch2 <= 26 || (ch2 >= 63 && ch2 <= 90)) /* HOTKEY characters */
250 if (ch2 == 2) buffer[0] = 'b';
251 else if (ch2 == 9) buffer[0] = 'i';
252 else if (ch2 == 18) buffer[0] = 'r';
253 else buffer[0] = ch2;
254 buffer[1] = '\n';
255 buffer[2] = '\0';
256 i = 1;
257 printf("%s",buffer);
258 goto entryfromhotkeys;
260 else /* all other characters */
262 putchar(ch2);
263 i = 0;
264 buffer[i] = ch2;
265 #ifdef UNIX
266 while (ch2 != '\n' && i < (BUFFSIZE-1))
267 #else
268 while (ch2 != 13 && i < (BUFFSIZE-1))
269 #endif
271 ch2 = getch();
272 if (ch2 == 8 && i >= 0)
274 i = i - 1;
275 putchar(8);
277 else if (ch2 == 8) {/* do nothing */}
278 #ifdef UNIX
279 else if (ch2 != '\n')
280 #else
281 else if (ch2 != 13)
282 #endif
284 putchar(ch2);
285 i = i + 1;
286 buffer[i] = ch2;
289 putchar('\n');
290 i = i + 1;
291 goto entryfromhotkeys;
294 else
295 #endif
296 ch2 = getc(data);
297 if (ch2 == EOF) return(ch2);
298 i = 0;
299 while(ch2 != '\n' && i < (BUFFSIZE-1))
301 #ifdef UNIX
302 if (ch2 == 13) ch2 = ' '; /* turn a ctrl-M into a blank */
303 #endif
304 if (ch2 == '\t') ch2 = ' ';
305 buffer[i] = ch2;
306 i = i + 1;
307 ch2 = getc(data);
309 entryfromhotkeys:
310 if (i == (BUFFSIZE-1)) pg(stdout,"line too long\n");
311 buffer[i] = '\n';
312 buffer[i+1] = '\0';
313 bufferend = i;
314 bufferptr = 0;
315 if (echo == '+') for(i = 0; i <= bufferend; i++) putchar(buffer[i]);
316 if (copy && ((data == stdin) || (echo == '+')))
317 for (i=0;i<=bufferend;i++) putc(buffer[i],copy);
319 ch2 = buffer[bufferptr];
320 bufferptr = bufferptr + 1;
321 return(ch2);
324 void texterror()
326 pg(stdout,"unexpected text: ");
327 pg(stdout,&buffer[bufferptr-1]);
328 bufferptr = bufferend;
331 char *readstr()
333 short i,start,end;
334 char *addr, *addr2;
335 i = bufferptr;
336 while (buffer[i] == ' ') i = i + 1;
337 start = i;
338 while (buffer[i] != ' ' && buffer[i] != '\n') i = i + 1;
339 end = i-1;
340 addr = (char *) malloc((int) end-start+2);
341 addr2 = addr;
342 for (i=start;i<=end;i++) *addr++ = buffer[i];
343 bufferptr = end + 1;
344 *addr = '\0';
345 return(addr2);
348 int scanfordigit()
350 int sign, ch2;
352 sign = 1;
354 restart:
355 do ch2 = readch(); while (ch2 == ' ' || ch2 == '\n');
356 if ((ch2 >= '0' && ch2 <= '9') || ch2 == '.')
358 bufferptr = bufferptr - 1;
359 return(sign);
361 switch (ch2) {
362 case '}': readerror = 3;
363 return(0);
364 case EOF: readerror = 2;
365 return(0);
366 case '*': while (ch2 != '\n') ch2 = readch();
367 goto restart;
368 case '-': sign = -sign;
369 goto restart;
370 case 'h':
371 case 'x':
372 case 'X':
373 case 'H':
374 case 'd':
375 case 's': bufferptr = bufferptr - 1;
376 return(0);
377 default: readerror = 1;
378 return(0);
382 int readint(min,max,command)
383 int min, max;
384 char command;
386 int sign, number, ch2;
388 readerror = 0;
389 sign = scanfordigit();
390 if (readerror)
392 if (readerror == 1) texterror();
393 return(0);
395 number = 0;
396 do ch2 = readch(); while (ch2 == ' ');
397 while (ch2 >= '0' && ch2 <= '9')
399 number = number * 10 + (ch2 - '0');
400 ch2 = readch();
402 bufferptr = bufferptr - 1;
403 number = sign * number;
404 if (number < min || number > max)
406 sprintf(outstr,"out of range value: %d",number); pg(stdout,outstr);
407 if (data == stdin) pg(stdout,"\n");
408 else {sprintf(outstr," in %c command\n",command); pg(stdout,outstr);};
409 readerror = 1;
411 return(number);
414 REAL readreal(op,min,command)
415 int op;
416 REAL min;
417 int command;
419 REAL fractpart, divisor, intpart, sign;
420 double number;
421 int ch2, numread, i;
423 readerror = 0;
424 sign = (REAL) scanfordigit();
425 if (readerror || (sign == 0 && !readingpattern))
427 if (readerror == 1) texterror();
428 return(0);
430 ch2 = readch();
431 if (ch2 == 'H' && readingpattern) return(unscale(CAPHCODE));
432 else if (ch2 == 'X' && readingpattern) return(unscale(CAPXCODE));
433 else if (ch2 == 'h' && readingpattern) return(unscale(HCODE));
434 else if (ch2 == 'i' && readingpattern) return(unscale(ICODE));
435 else if (ch2 == 'o' && readingpattern) return(unscale(OCODE));
436 else if (ch2 == 'd' && readingpattern) return(unscale(DIFFCODE));
437 else if (ch2 == 's' && readingpattern) return(unscale(SKIPCODE));
438 else if (ch2 == 'x' && readingpattern) return(unscale(unknown));
439 i = 0;
440 while ((ch2 >= '0' && ch2 <='9') || ch2 == '+' || ch2 == '-' ||
441 ch2 == 'e' || ch2 == 'E' || ch2 == '.')
443 outstr[i] = ch2;
444 i = i+1;
445 ch2 = readch();
447 outstr[i] = 0;
448 bufferptr = bufferptr - 1;
449 numread = sscanf(outstr,"%lf",&number);
450 if (numread == 0)
452 pg(stdout,"bad real value\n");
453 readerror = 1;
454 return(0.0);
456 number = sign * number;
457 if (op == GT && number > min) return(number);
458 else if (op == GE && number >= min) return(number);
459 else
461 sprintf(outstr,"erroneous value: %f",number); pg(stdout,outstr);
462 if (data == stdin) pg(stdout,"\n");
463 else {sprintf(outstr," in %c command\n",command); pg(stdout,outstr);};
464 readerror = 1;
465 return(0.0);
469 WTTYPE rdr(op,min,command) /* reads REAL real numbers and converts */
470 int op; /* them to 16-bit integers if necessary */
471 REAL min;
472 int command;
474 REAL x;
475 WTTYPE ix;
477 x = readreal(op,min,command);
478 if (readerror) return(0);
479 ix = scale(x);
480 if (readerror) return(0);
481 return(ix);
484 REAL readchar() /* reads data in compressed format */
486 int ch2;
487 readerror = 0;
488 ch2 = readch();
489 do {
490 switch (ch2) {
491 case '\n':
492 case ' ': ch2 = readch();
493 break;
494 case '1': return(1.0);
495 case '0': return(0.0);
496 case 'X': return(unscale(CAPXCODE));
497 case 'x': return(unscale(unknown));
498 case '*': do ch2 = readch(); while(ch2 != '\n');
499 break;
500 case 'H': return(unscale(CAPHCODE));
501 case 'h': return(unscale(HCODE));
502 case 's': return(unscale(SKIPCODE));
503 case 'd': return(unscale(DIFFCODE));
504 case EOF: readerror = 2;
505 return(0.0);
506 case '}': readerror = 3;
507 return(0.0);
508 default: texterror();
509 readerror = 1;
510 return(0.0);};
511 } while (0 == 0);
514 void readapat(pn,relation,minimum,command,informat)
515 PATNODE *pn;
516 int relation;
517 REAL minimum;
518 int command;
519 char informat;
521 REAL val;
522 int unitnumber;
523 UNIT *u;
524 if (informat == 'r') val = rdr(relation,minimum,command);
525 else val = scale(readchar());
526 if (val == ICODE)
528 recurinit = '+';
529 pn->layer = 1;
530 pn->val = ICODE;
531 unitnumber = readint(1,start->unitcount,'r');
532 if (readerror != 0) return;
533 pn->unitno = unitnumber;
534 u = locateunit(1,unitnumber);
535 pn->addr = &(u->oj);
537 else if (val == HCODE)
539 recurinit = '+';
540 pn->addr = (WTTYPE *) -1;
541 pn->layer = 2;
542 pn->val = HCODE;
543 pn->unitno = HCODE;
545 else if (val == CAPXCODE)
547 pn->addr = (WTTYPE *) -1;
548 pn->layer = 2;
549 pn->val = CAPXCODE;
550 pn->unitno = CAPXCODE;
552 else if (val == CAPHCODE)
554 recurinit = '+';
555 pn->addr = (WTTYPE *) -1;
556 pn->layer = 2;
557 pn->val = CAPHCODE;
558 pn->unitno = CAPHCODE;
560 else if (val == OCODE)
562 recurinit = '+';
563 pn->layer = nlayers;
564 pn->val = OCODE;
565 unitnumber = readint(1,last->unitcount,'r');
566 if (readerror != 0) return;
567 pn->unitno = unitnumber;
568 u = locateunit((int) pn->layer,unitnumber);
569 pn->addr = &(u->oj);
571 else if (val == SKIPCODE)
573 pn->addr = (WTTYPE *) -1;
574 pn->layer = 0;
575 pn->val = SKIPCODE;
576 pn->unitno = SKIPCODE;
578 else if (val == DIFFCODE)
580 pn->addr = (WTTYPE *) -1;
581 pn->layer = nlayers;
582 pn->val = DIFFCODE;
583 pn->unitno = DIFFCODE;
585 else
587 pn->addr = NULL;
588 pn->val = val;
589 pn->layer = 0; /* unused */
590 pn->unitno = 0; /* unused */
594 void readpatson(layer,list,command)
595 LAYER *layer;
596 int list;
597 int command;
599 {PATLIST *pl, *prev;
600 PATNODE *pn;
601 int i, answer, veclength;
603 pl = (PATLIST *) malloc(sizeof(PATLIST));
604 pl->next = NULL;
605 pl->pats = NULL; /* no patterns read yet */
606 if (layer->patstart[list] == NULL)
608 prev = NULL;
609 layer->patstart[list] = pl;
611 else
613 prev = layer->currentpat[list];
614 prev->next = pl;
616 layer->currentpat[list] = pl;
618 veclength = layer->unitcount;
619 pn = (PATNODE *) malloc(veclength * sizeof(PATNODE));
620 pl->pats = pn;
621 if (layer == last && probtype == 'c')
623 answer = readint(1,veclength,command);
624 if (readerror != 0) return;
625 for (i=1;i<=veclength;i++)
627 if (i == answer) pn->val = classon; else pn->val = classoff;
628 pn->addr = NULL;
629 pn->layer = nlayers;
630 pn->unitno = i;
631 pn++;
633 return;
635 for (i=1;i<=veclength;i++)
637 readapat(pn,GE,(REAL) HCODE,command,informat);
638 if ((readerror == 3 || readerror == 2) && i == 1 && layer == start)
640 if (prev != NULL) prev->next = NULL;
641 free(pn);
642 free(pl);
643 readerror = readerror + 2;
644 return;
646 else if (readerror != 0) return;
647 if (pn->unitno == CAPHCODE || pn->unitno == CAPXCODE) return; else pn++;
649 return;
652 int readpats(list,command)
653 int list, command;
654 { int i, j;
655 PATLIST *pl;
657 /* look for scaling parameters, if any, in a TRAINing set */
659 if (list == TRAIN)
661 REAL temp;
662 WTTYPE trans, sca;
663 int ch1, ch2, k, col, nfactors;
664 UNIT *u;
665 ch1 = readch();
666 if (ch1 == '\n') ch1 = readch();
667 ch2 = readch();
668 if (ch1 != '*' || ch2 != '$') bufferptr = bufferptr - 2;
669 else /* there are scaling parameters */
671 nfactors = readint(0,MAXINT,'r');
672 do ch1 = readch(); while (ch1 != '\n');
673 u = start->units;
674 for (k=1;k<=nfactors;k++)
676 if (u == NULL)
678 pg(stdout,"not enough input units for these patterns\n");
679 exit(99);
681 ch1 = readch();
682 ch2 = readch();
683 if (ch1 != '*' || ch2 != '$')
685 pg(stdout,"error in input scaling list\n");
686 goto readthepatterns;
688 else
690 col = readint(k,k,'r');
691 if (readerror == 1)
693 pg(stdout,"error in scaling list\n");
694 goto readthepatterns;
696 trans = rdr(GE,(REAL) -MAXINT,'r');
697 if (readerror == 1)
699 pg(stdout,"error in scaling list\n");
700 goto readthepatterns;
702 else u->translate = trans;
703 sca = rdr(GE,(REAL) -MAXINT,'r');
704 if (readerror == 1)
706 pg(stdout,"error in scaling list\n");
707 goto readthepatterns;
709 else u->userscale = sca;
710 u = u->next;
711 do ch1 = readch(); while (ch1 != '\n');
714 /* do the output unit scaling factors if its not a classification problem */
715 if (probtype != 'c')
717 u = last->units;
718 for (k=1;k<=last->unitcount;k++)
720 ch1 = readch();
721 ch2 = readch();
722 if (ch1 != '*' || ch2 != '$')
724 pg(stdout,"error in output scaling list\n");
725 goto readthepatterns;
727 else
729 col = readint(k,k,'r');
730 if (readerror == 1)
732 pg(stdout,"error in scaling list\n");
733 goto readthepatterns;
735 trans = rdr(GE,(REAL) -MAXINT,'r');
736 if (readerror == 1)
738 pg(stdout,"error in scaling list\n");
739 goto readthepatterns;
741 else u->translate = trans;
742 sca = rdr(GE,(REAL) -MAXINT,'r');
743 if (readerror == 1)
745 pg(stdout,"error in scaling list\n");
746 goto readthepatterns;
748 else u->userscale = sca;
749 u = u->next;
750 do ch1 = readch(); while (ch1 != '\n');
751 }; /* end else */
752 }; /* end for */
753 }; /* ends prob type */
754 }; /* else there are scaling parameters */
755 }; /* if its a training set file */
757 readthepatterns:
758 i = 0;
759 readerror = 0;
760 while (readerror == 0)
762 readpatson(start,list,command);
763 if (readerror) break;
764 readpatson(last,list,command);
765 if (readerror) break;
766 i = i + 1;
768 if (readerror == 5) return(i);
769 else if (readerror == 4)
771 popfile();
772 return(i);
775 /* failure for some reason */
777 sprintf(outstr,"error while reading pattern %d",i+1); pg(stdout,outstr);
778 if (readerror == 1) pg(stdout,"\n");
779 else if (readerror == 2) pg(stdout,": unexpected end of file\n");
780 else if (readerror == 3) pg(stdout,": unexpected }\n");
781 if (readerror == 2) popfile();
782 if (i > 0)
784 pl = (PATLIST *) start->patstart[list];
785 for (j=1;j<=prevnpats + i - 1;j++) pl = pl->next;
786 pl->next = NULL;
787 pl = (PATLIST *) last->patstart[list];
788 for (j=1;j<=prevnpats + i - 1;j++) pl = pl->next;
789 pl->next = NULL;
791 return(i);
794 int pg(f,str) /* paging and making a copy function */
795 FILE *f;
796 char *str;
798 char *ch3,action,cr;
799 int i;
800 long clockbefore, clockafter;
801 int nbackspaces = 5;
803 if (f != stdout) {fprintf(f,"%s",str); return(0);};
804 clockbefore = clock();
805 action = 0;
806 ch3 = str;
807 while (*ch3 != '\0')
809 if (*ch3 == '\n')
811 putchar('\n');
812 if (copyflag == '+') putc('\n',copy);
813 lineno = lineno + 1;
814 if (pagesize > 0 && lineno > 0 && lineno % pagesize == 0)
816 printf("More?");
817 #ifdef HOTKEYS
818 action = getch();
819 #else
820 action = getchar();
821 if (action != '\n') cr = getchar();
822 #endif
823 for(i=1;i<=nbackspaces;i++) putchar(8);
824 for(i=1;i<=nbackspaces;i++) putchar(' ');
825 for(i=1;i<=nbackspaces;i++) putchar(8);
826 if (action == 'q') goto stoppaging;
827 else if (action == 'c') lineno = -MAXINT;
828 #ifdef UNIX
829 else if (action == '\n') lineno = lineno - 1;
830 #else
831 else if (action == 13) lineno = lineno - 1;
832 #endif
833 else if (action == 4) lineno = pagesize / 2;
834 else lineno = 0;
837 else {putchar(*ch3); if (copyflag == '+') putc(*ch3,copy); };
838 ch3++;
840 stoppaging:
841 clockafter = clock();
842 iotime = iotime + clockafter - clockbefore;
843 if (action == 'q') return(1); else return(0);
846 void printnetsize(f) /* the size of the network */
847 FILE *f;
848 {LAYER *p;
849 pg(f,"m ");
850 p = start;
851 if (stmsize > 0)
853 sprintf(outstr," %1d+%1d",p->unitcount-stmsize,stmsize);
854 pg(f,outstr);
855 p = p->next;
857 while (p != NULL)
859 sprintf(outstr," %1d",p->unitcount);
860 pg(f,outstr);
861 p = p->next;
863 if (ioconnects) pg(f," x");
864 if (pccnet) pg(f," p");
867 void listseeds(f)
868 FILE *f;
870 SEEDNODE *s;
871 s = seedstart->next;
872 pg(f,"s");
873 while (s != NULL)
875 sprintf(outstr," %1d",s->val); pg(f,outstr);
876 s = s->next;
880 int printoutunits(patnum,layer,list,error,tok,mok)
881 int patnum;
882 LAYER *layer;
883 int list;
884 REAL error;
885 char tok,mok;
887 short unitno, fmtbreaknum;
888 UNIT *u;
889 WTTYPE upper, middle, diff;
891 int i;
892 WTTYPE *target;
893 PATLIST *pl;
894 #ifdef INTEGER
895 float tempreal;
896 #endif
898 upper = scale(1.0) - toler;
899 middle = scale(0.5);
900 unitno = 0;
901 fmtbreaknum = 1;
903 if (layer == last && patnum > 0)
905 pl = last->currentpat[list];
906 target = pl->pats;
907 u = (UNIT *) layer->units;
908 for (i=1;i<=last->unitcount;i++)
910 u->tj = *target++;
911 u = u->next;
915 if (patnum) {sprintf(outstr,"%5d ",patnum); pg(stdout,outstr);}
916 else pg(stdout," ");
917 u = (UNIT *) layer->units;
918 while (u != NULL)
920 diff = u->tj - u->oj;
921 unitno = unitno + 1;
922 if (outformat == 'r' || outformat == 's')
924 sprintf(outstr,"%6.3f ",unscale(u->oj)); pg(stdout,outstr);
925 if (format[fmtbreaknum] == unitno)
927 if (pg(stdout,"\n ")) return(1);
928 if (fmtbreaknum < MAXFORMAT - 1) fmtbreaknum = fmtbreaknum + 1;
931 else if (outformat == 'e')
933 sprintf(outstr,"%12.4e ",unscale(u->oj)); pg(stdout,outstr);
934 if (format[fmtbreaknum] == unitno)
936 if (pg(stdout,"\n ")) return(1);
937 if (fmtbreaknum < MAXFORMAT - 1) fmtbreaknum = fmtbreaknum + 1;
940 else if (outformat == 'a')
942 if (diff < toler) pg(stdout,"c");
943 else if (u->oj > upper) pg(stdout,"1");
944 else if (u->oj < toler) pg(stdout,"0");
945 else if (u->oj > u->tj) pg(stdout,"^");
946 else pg(stdout,"v");
947 if (format[fmtbreaknum] == unitno)
949 pg(stdout," ");
950 if (fmtbreaknum < MAXFORMAT - 1) fmtbreaknum = fmtbreaknum + 1;
953 else
955 if (u->oj > upper) pg(stdout,"1");
956 else if (u->oj > middle) pg(stdout,"^");
957 else if (u->oj < toler) pg(stdout,"0");
958 else pg(stdout,"v");
959 if (format[fmtbreaknum] == unitno)
961 pg(stdout," ");
962 if (fmtbreaknum < MAXFORMAT - 1) fmtbreaknum = fmtbreaknum + 1;
965 u = u->next;
967 if (patnum > 0)
969 sprintf(outstr," e %5.3f",error); pg(stdout,outstr);
970 if (tok) pg(stdout," ok"); else pg(stdout," ");
971 if (mok) pg(stdout," ok");
972 if (pg(stdout,"\n")) return(1); else return(0);
974 if (pg(stdout,"\n")) return(1);
975 if (pg(stdout,"\n")) return(1); else return(0);
978 void saveweights() /* saves weights on the file weights */
980 UNIT *u, *bu;
981 LAYER *layer;
982 WTNODE *w;
983 WTTYPE wvalue, evalue, dvalue, svalue;
984 int wtsize, unitno, layerno, i;
985 short wtinuse;
986 FILE *wtfileptr;
988 wtsize = WTSIZE;
989 sprintf(wtfilename,"%s",wtfile);
990 wtfileptr = fopen(wtfilename,"wb");
991 if (wtfileptr == NULL)
993 sprintf(outstr,"cannot open: %s\n",wtfilename); pg(stdout,outstr);
994 return;
996 fprintf(wtfileptr,"%d%c",totaliter,wtformat);
997 layer = start;
998 fprintf(wtfileptr," m %1d",layer->unitcount);
999 layer = layer->next;
1000 while (layer != NULL)
1002 fprintf(wtfileptr," %1d",layer->unitcount);
1003 layer = layer->next;
1005 if (ioconnects) fprintf(wtfileptr," x");
1006 fprintf(wtfileptr," aah%c",start->next->activation);
1007 fprintf(wtfileptr," ao%c",last->activation);
1008 fprintf(wtfileptr," bh %f",unscale(start->next->biasact));
1009 fprintf(wtfileptr," bo %f",unscale(last->biasact));
1010 fprintf(wtfileptr," Dh %f",unscale(start->next->D));
1011 fprintf(wtfileptr," Do %f",unscale(last->D));
1012 fprintf(wtfileptr," file = %s",datafile);
1013 #ifdef DOSMOD /* I don't remember this */
1014 fputc('\r',wtfileptr);
1015 #endif
1016 fputc('\n',wtfileptr);
1018 layer = start->next;
1019 while (layer != NULL)
1021 u = (UNIT *) layer->units;
1022 while (u != NULL)
1024 w = (WTNODE *) u->wtlist;
1025 while (w != NULL)
1027 #ifdef SYMMETRIC
1028 wvalue = *(w->weight);
1029 evalue = *(w->eta);
1030 dvalue = *(w->olddw);
1031 svalue = *(w->slope);
1032 wtinuse = w->inuse;
1033 #else
1034 wvalue = w->weight;
1035 evalue = w->eta;
1036 dvalue = w->olddw;
1037 svalue = w->slope;
1038 wtinuse = w->inuse;
1039 #endif
1040 if (wtformat == 'r' || wtformat == 'R')
1042 fprintf(wtfileptr,"%14.6e",unscale(wvalue));
1043 fprintf(wtfileptr,"%3d",w->inuse);
1044 if (wtformat == 'R')
1046 fprintf(wtfileptr," %14.6e",unscale(evalue));
1047 fprintf(wtfileptr," %14.6e",unscale(dvalue));
1048 fprintf(wtfileptr," %14.6e",unscale(svalue));
1050 bu = w->backunit;
1051 fprintf(wtfileptr," %1d ",bu->layernumber);
1052 if (bu->unitnumber == 32767) fprintf(wtfileptr,"b to ");
1053 else fprintf(wtfileptr,"%1d to ",bu->unitnumber);
1054 fprintf(wtfileptr,"%1d %1d",u->layernumber,u->unitnumber);
1055 #ifdef DOSMOD
1056 fputc('\r',wtfileptr);
1057 #endif
1058 fputc('\n',wtfileptr);
1060 w = w->next;
1062 u = u->next;
1064 layer = layer->next;
1066 fflush(wtfileptr);
1067 fclose(wtfileptr);
1068 lastsave = totaliter;
1071 void restoreweights() /* restore weights */
1073 FILE *wtfileptr;
1074 UNIT *u;
1075 LAYER *layer;
1076 WTNODE *w;
1077 int ch2, fileformat, wtsize, numread, i, layerno, unitno;
1078 WTTYPE wvalue, evalue, dvalue, svalue;
1079 int wtinuse;
1080 double temp;
1081 unsigned char *cptr;
1084 if (numwtfiles == '+') sprintf(wtfilename,"%s.%1d",wtfile,wtfilecount);
1085 else sprintf(wtfilename,"%s",wtfile);
1087 wtfileptr = fopen(wtfilename,"rb");
1088 if (wtfileptr == NULL)
1090 sprintf(outstr,"cannot open: %s\n",wtfilename);
1091 pg(stdout,outstr);
1092 return;
1094 numread = fscanf(wtfileptr,"%d",&totaliter);
1095 if (numread == EOF) goto unexpectedeof;
1096 if (numread == 0) goto badread;
1097 fileformat = fgetc(wtfileptr);
1098 if (fileformat == EOF) goto unexpectedeof;
1099 if (fileformat != wtformat) pg(stdout,"note: weight format mismatch\n");
1100 wtsize = WTSIZE;
1101 do ch2 = fgetc(wtfileptr); while (ch2 != '\n');
1102 layer = start->next;
1103 while (layer != NULL)
1105 u = (UNIT *) layer->units;
1106 while (u != NULL)
1108 u->inuse = 1;
1109 w = (WTNODE *) u->wtlist;
1110 while (w != NULL)
1112 if (fileformat == 'r' || fileformat == 'R')
1114 numread = fscanf(wtfileptr,"%lf",&temp);
1115 if (numread == EOF) goto unexpectedeof;
1116 if (numread == 0) goto badread;
1117 wvalue = scale((REAL) temp);
1118 #ifdef ALTCODE
1120 do ch2 = fgetc(wtfileptr); while (ch2 == ' ');
1121 wtinuse = 1;
1122 if (ch2 == '-')
1124 wtinuse = -1;
1125 ch2 = fgetc(wtfileptr);
1127 if (ch2 == 0) wtinuse = 0;
1128 else if (ch2 == '1') wtinuse = wtinuse;
1129 else if (ch2 == '2') wtinuse = wtinuse * 2;
1130 else pg(stdout,"bad weight in use flag\n");
1132 #else
1133 numread = fscanf(wtfileptr,"%d",&wtinuse);
1134 if (numread == EOF) goto unexpectedeof;
1135 if (numread == 0) goto badread;
1136 #endif
1137 if (fileformat == 'R')
1139 numread = fscanf(wtfileptr,"%lf",&temp);
1140 if (numread == EOF) goto unexpectedeof;
1141 if (numread == 0) goto badread;
1142 evalue = scale((REAL) temp);
1143 numread = fscanf(wtfileptr,"%lf",&temp);
1144 if (numread == EOF) goto unexpectedeof;
1145 if (numread == 0) goto badread;
1146 dvalue = scale((REAL) temp);
1147 numread = fscanf(wtfileptr,"%lf",&temp);
1148 if (numread == EOF) goto unexpectedeof;
1149 if (numread == 0) goto badread;
1150 svalue = scale((REAL) temp);
1152 do ch2 = fgetc(wtfileptr); while (ch2 != '\n');
1153 if (ch2 == '\n')
1155 ch2 = fgetc(wtfileptr);
1156 if (ch2 != '\r') ungetc(ch2,wtfileptr);
1159 #ifdef SYMMETRIC
1160 *(w->weight) = wvalue;
1161 if (fileformat == 'R')
1163 *(w->olddw) = dvalue;
1164 *(w->eta) = evalue;
1166 else *(w->olddw) = 0;
1167 #else
1168 w->weight = wvalue;
1169 w->inuse = wtinuse;
1170 if (fileformat == 'R')
1172 w->olddw = dvalue;
1173 w->eta = evalue;
1174 w->slope = svalue;
1176 else w->olddw = 0;
1177 #endif
1178 w = w->next;
1180 u = u->next;
1182 layer = layer->next;
1184 fclose(wtfileptr);
1185 lastsave = totaliter;
1186 return;
1187 badread: pg(stdout,"\n>>>>> scanf read error <<<<<\n\n");
1188 fclose(wtfileptr);
1189 return;
1190 unexpectedeof: pg(stdout,"\n>>>>> ran out of weights <<<<<\n\n");
1191 fclose(wtfileptr);
1194 void printweights(u,layerno) /* print the weights leading into unit u */
1195 UNIT *u;
1196 int layerno;
1199 WTNODE *w;
1200 UNIT *bunit;
1201 WTTYPE value;
1202 LAYER *layer;
1203 int i;
1204 short wtinuse, unitinuse;
1205 #ifdef INTEGER
1206 INT32 sum, input;
1207 #else
1208 REAL sum, input;
1209 #endif
1211 w = (WTNODE *) u->wtlist;
1212 sum = 0;
1213 pg(stdout,"layer unit inuse unit value weight inuse input from unit\n");
1214 while (w != NULL)
1216 bunit = (UNIT *) w->backunit;
1217 unitinuse = w->backunit->inuse;
1218 #ifdef SYMMETRIC
1219 value = *(w->weight);
1220 wtinuse = 1;
1221 #else
1222 value = w->weight;
1223 wtinuse = w->inuse;
1224 #endif
1226 #ifdef INTEGER
1227 if (wtinuse && unitinuse)
1229 input = (INT32) value * bunit->oj;
1230 input = input / 1024;
1232 else input = 0;
1233 #else
1234 if (wtinuse && unitinuse) input = value * bunit->oj; else input = 0;
1235 #endif
1236 sum = sum + input;
1237 sprintf(outstr,"%3d ",bunit->layernumber); pg(stdout,outstr);
1238 if (bunit->unitnumber == 32767) pg(stdout," b ");
1239 else {sprintf(outstr,"%3d ",bunit->unitnumber); pg(stdout,outstr);};
1240 sprintf(outstr,"%4d ",unitinuse); pg(stdout,outstr);
1241 sprintf(outstr,"%10.5f %10.5f ",unscale(bunit->oj),unscale(value));
1242 pg(stdout,outstr);
1243 sprintf(outstr," %3d ",wtinuse); pg(stdout,outstr);
1244 sprintf(outstr,"%14.5f\n",unscaleint(input));
1245 if (pg(stdout,outstr)) return;
1246 w = w->next;
1248 pg(stdout," ");
1249 sprintf(outstr,"sum = %9.5f\n",unscaleint(sum));
1250 if (pg(stdout,outstr)) return;
1251 layer = start;
1252 for (i=2;i<=layerno;i++) layer = layer->next;
1253 if (layer->D != scale(1.0))
1255 #ifdef INTEGER
1256 sum = sum * layer->D / 1024;
1257 #else
1258 sum = sum * layer->D;
1259 #endif
1260 pg(stdout," ");
1261 sprintf(outstr,"sum = %9.5f with D = %7.3f\n",unscaleint(sum),unscale(layer->D));
1262 if (pg(stdout,outstr)) return;
1264 pg(stdout,"\n");
1267 void parameters(f)
1268 FILE *f;
1269 {int i;
1270 printnetsize(f);
1271 sprintf(outstr," * %1d weights; ",wttotal); pg(f,outstr);
1272 sprintf(outstr,"data file = %s",datafile); pg(f,outstr);
1273 if (zeroderiv) pg(f,"*>>>>> 0 deriv <<<<<*\n"); else pg(f,"\n");
1274 if (toosmall != 0)
1276 sprintf(outstr,"pw %4.2f",unscale(toosmall)); pg(f,outstr);
1277 sprintf(outstr," * weights in use: %1d\n",wtsinuse); pg(f,outstr);
1279 sprintf(outstr,"sb %f\n", unscale(stdthresh)); pg(f,outstr);
1280 #ifdef INTEGER
1281 if (wtlimithit) pg(f,"*>>>>> WEIGHT LIMIT HIT <<<<<*\n");
1282 #endif
1283 listseeds(f); pg(f,"\n");
1284 sprintf(outstr,"r %1d %1d ",maxiter,printrate); pg(f,outstr);
1285 if (f != stdout) pg(f,"\"\n"); else pg(f,"\n");
1286 sprintf(outstr,"f b%c c%c e%c i%c",ringbell,copyflag,echo,informat);
1287 pg(f,outstr);
1288 if (offby1 == '+') pg(f," O+"); else pg(f," O-");
1289 sprintf(outstr," o%c P %d p%c ",outformat,pagesize,probtype);
1290 pg(f,outstr);
1291 sprintf(outstr,"R%c ",runningflag); pg(f,outstr);
1292 sprintf(outstr," s%c ",summary); pg(f,outstr);
1293 sprintf(outstr,"u%c ",up_to_date_stats); pg(f,outstr);
1294 sprintf(outstr,"x% f\n",unscale(unknown)); pg(f,outstr);
1295 pg(f,"f B ");
1296 for (i=1;i<=MAXFORMAT-1;i++)
1297 {sprintf(outstr," %1d",format[i]); pg(f,outstr);};
1298 pg(f,"\n");
1299 sprintf(outstr,"! %s ",sysstr); pg(f,outstr);
1300 if (f != stdout) pg(f,"\"\n"); else pg(f,"\n");
1301 pg(f,"a ");
1302 if (nlayers > 2)
1303 {sprintf(outstr,"ah %c ",ah); pg(f,outstr);};
1304 sprintf(outstr,"ao %c ",ao); pg(f,outstr);
1305 sprintf(outstr,"d%c ",deriv); pg(f,outstr);
1306 sprintf(outstr,"u%c\n",update); pg(f,outstr);
1307 sprintf(outstr,"e %7.5f %7.5f\n",unscale(eta),unscale(eta2));pg(f,outstr);
1308 sprintf(outstr,"a %7.5f\n",unscale(alpha)); pg(f,outstr);
1310 #ifndef SYMMETRIC
1311 sprintf(outstr,"d d %8.5f e %8.5f ",unscale(decay),unscale(dbdeta));
1312 pg(f,outstr);
1313 sprintf(outstr,"k %8.5f m %8.5f ",unscale(kappa),unscale(etamax));
1314 pg(f,outstr);
1315 sprintf(outstr,"t %8.5f\n",unscale(theta1));
1316 pg(f,outstr);
1317 sprintf(outstr,"qp dh %8.6f do %8.6f e %8.5f ",qpdecayh,qpdecayo,unscale(qpeta));
1318 pg(f,outstr);
1319 sprintf(outstr,"m %8.5f n %8.5f s%c\n",unscale(mu),unscale(qpnoise),qpslope);
1320 pg(f,outstr);
1321 #endif
1323 sprintf(outstr,"* last save at: %d\n",lastsave); pg(f,outstr);
1324 sprintf(outstr,"rw %s\n",wtfilename); pg(f,outstr);
1326 sprintf(outstr,"t %4.2f\n",unscale(toler)); pg(f,outstr);
1328 printstats(f,TRAIN,1,s);
1329 if (s[TOL][TEST].npats > 0) printstats(f,TEST,1,s);
1330 if (f != stdout)
1332 sprintf(outstr,"z %e",minimumsofar); pg(f,outstr);
1334 pg(f,"\n");
1337 void menus(ch)
1338 char ch;
1340 switch (ch) {
1342 case '?': parameters(stdout); return;
1344 case 'A':
1345 pg(stdout,"\nAlgorithm Parameters\n\n");
1346 pg(stdout,"a a <char> sets all act. functions to <char>; {ls} h aa\n");
1347 if (nlayers > 2)
1349 sprintf(outstr,"a ah %c ",ah); pg(stdout,outstr);
1350 pg(stdout,"hidden layer(s) act. function; {ls} h aa\n");
1352 sprintf(outstr,"a ao %c ",ao); pg(stdout,outstr);
1353 pg(stdout,"output layer act. function; {ls} h aa\n");
1354 sprintf(outstr,"a d %c ",deriv); pg(stdout,outstr);
1355 pg(stdout,"the output layer derivative term; {cdf} h ad\n");
1356 sprintf(outstr,"a u %c ",update); pg(stdout,outstr);
1357 pg(stdout,"the weight update algorithm; {Ccdpq} h au\n");
1359 sprintf(outstr,"t %4.3f ",unscale(toler)); pg(stdout,outstr);
1360 pg(stdout,"tolerance/unit for successful learning; (0..1)\n");
1361 sprintf(outstr,"\nf O %c ",offby1); pg(stdout,outstr);
1362 pg(stdout,"allows out-of-date statistics to print; {+-}\n");
1363 sprintf(outstr,"f u %c ",up_to_date_stats); pg(stdout,outstr);
1364 pg(stdout,"compute up-to-date statistics; {+-}\n");
1365 pg(stdout,"\n");
1366 return;
1368 case 'C':
1369 pg(stdout,"\nScreen Includes Information and Parameters on:\n\n");
1370 pg(stdout," A algorithm parameters and tolerance\n");
1371 pg(stdout," C this listing of major command groups\n");
1372 #ifndef SYMMETRIC
1373 pg(stdout," D delta-bar-delta parameters\n");
1374 #endif
1375 pg(stdout," F formats: patterns, output, paging, copying screen i/o\n");
1376 pg(stdout," G gradient descent (plain backpropagation)\n");
1377 pg(stdout," M miscellaneous commands: shell escape, seed values, clear,\n");
1378 pg(stdout," clear and initialize, quit, save almost everything\n");
1379 pg(stdout," N making a network, listing network unit values\n");
1380 pg(stdout," P pattern commands: reading patterns, testing patterns,\n");
1381 #ifndef SYMMETRIC
1382 pg(stdout," Q quickprop parameters\n");
1383 #endif
1384 pg(stdout," T a short tutorial\n");
1385 pg(stdout," W weight commands: listing, saving, restoring, set bias unit weights\n");
1386 pg(stdout," ? a compact listing of everything\n");
1387 pg(stdout,"\n");
1388 return;
1390 #ifndef SYMMETRIC
1391 case 'D':
1392 pg(stdout,"\nThe Delta-Bar-Delta Paramters (d)\n\n");
1394 sprintf(outstr,"d d %4.2f ",unscale(decay)); pg(stdout,outstr);
1395 pg(stdout,"decay rate for each eta; (0..1)\n");
1396 sprintf(outstr,"d e %5.3f ",unscale(dbdeta)); pg(stdout,outstr);
1397 pg(stdout,"initial eta for each weight; (0..inf)\n");
1398 sprintf(outstr,"d k %6.4f ",unscale(kappa)); pg(stdout,outstr);
1399 pg(stdout,"kappa, the eta increment; (0..inf)\n");
1400 sprintf(outstr,"d m %6.3f ",unscale(etamax)); pg(stdout,outstr);
1401 pg(stdout,"maximum value for eta; (0..inf)\n");
1402 sprintf(outstr,"d t %3.1f ",unscale(theta1)); pg(stdout,outstr);
1403 pg(stdout,"the theta parameter; (0..1)\n");
1404 pg(stdout,"\na u d use this to get the delta-bar-delta update method\n");
1405 pg(stdout,"\n");
1406 return;
1407 #endif
1409 case 'F':
1410 pg(stdout,"\nThe Format Command (f)\n\n");
1411 sprintf(outstr,"f b %c ",ringbell); pg(stdout,outstr);
1412 pg(stdout,"ring the bell when training is finished; {+-}\n");
1413 sprintf(outstr,"f c %c ",copyflag); pg(stdout,outstr);
1414 pg(stdout,"make a copy of screen i/o on the file copy; {+-}\n");
1415 sprintf(outstr,"f e %c ",echo); pg(stdout,outstr);
1416 pg(stdout,"echo input; {+-}\n");
1417 sprintf(outstr,"f i %c ",informat); pg(stdout,outstr);
1418 pg(stdout,"format for reading input and output patterns; {cr} h fi\n");
1419 sprintf(outstr,"f O %c ",offby1); pg(stdout,outstr);
1420 pg(stdout,"give off by 1 statistics for training set; {+-}\n");
1421 sprintf(outstr,"f o %c ",outformat); pg(stdout,outstr);
1422 pg(stdout,"format for outputing network's unit values; {acer} h fo\n");
1423 sprintf(outstr,"f P %2d ",pagesize); pg(stdout,outstr);
1424 pg(stdout,"lines per page; 0 = no paging; [0..inf]\n");
1425 sprintf(outstr,"f p %c ",probtype); pg(stdout,outstr);
1426 pg(stdout,"problem type; {cg} h fp\n");
1427 sprintf(outstr,"f R %c ",runningflag); pg(stdout,outstr);
1428 pg(stdout,"print the \"running . . .\" message; {+-}\n");
1429 sprintf(outstr,"f s %c ",summary); pg(stdout,outstr);
1430 pg(stdout,"summarize learning status while running; {+-}\n");
1431 sprintf(outstr,"f u %c ",up_to_date_stats); pg(stdout,outstr);
1432 pg(stdout,"get up-to-date status of training patterns; {+-}\n");
1433 sprintf(outstr,"f x %5.2f ",unknown); pg(stdout,outstr);
1434 pg(stdout,"the value of x in patterns\n");
1435 pg(stdout,"f B ");
1436 {int i;
1437 for (i=1;i<=MAXFORMAT-1;i++)
1438 {sprintf(outstr," %1d",format[i]); pg(stdout,outstr);};};
1439 pg(stdout,"\n ");
1440 pg(stdout," h fB\n");
1441 pg(stdout,"\n");
1442 return;
1444 case 'G':
1445 pg(stdout,"\nGradient Descent (Plain Backpropagation)\n\n");
1446 sprintf(outstr,"e %8.5f %8.5f ",unscale(eta),unscale(eta2));pg(stdout,outstr);
1447 pg(stdout,"eta for weights into the output layer is");
1448 sprintf(outstr,"%8.5f\n",unscale(eta)); pg(stdout,outstr);
1449 pg(stdout," eta for weights into the hidden layer(s) is");
1450 sprintf(outstr,"%8.5f\n",unscale(eta2)); pg(stdout,outstr);
1451 pg(stdout,"e <real> sets both etas to <real>\n\n");
1453 sprintf(outstr,"a %4.2f ",unscale(alpha)); pg(stdout,outstr);
1454 pg(stdout,"the momentum parameter, alpha, for all layers; [0..1)\n\n");
1456 pg(stdout,"a u C use this for the right continuous update method\n");
1457 pg(stdout,"a u c use this for the wrong continuous update method\n");
1458 pg(stdout,"a u p use this for the periodic update method\n");
1459 pg(stdout,"\n");
1460 return;
1462 case 'M':
1463 pg(stdout,"\nMiscellaneous Commands\n\n");
1465 if (sysstr[0] != '\0')
1466 {pg(stdout,"! "); pg(stdout,sysstr); pg(stdout,"\n");};
1467 pg(stdout,"! <string> pass <string> to the operating system\n\n");
1469 pg(stdout,"q q by itself quits the program\n\n");
1471 pg(stdout,"c clear the network weights\n");
1472 pg(stdout,"ci same as c except the weights are initialized to\n");
1473 sprintf(outstr," between -%4.2f ",unscale(initrange));
1474 pg(stdout,outstr);
1475 sprintf(outstr,"and %4.2f\n",unscale(initrange)); pg(stdout,outstr);
1476 pg(stdout,"ci <real> same as ci except the weights are initialized to\n");
1477 pg(stdout," between - <real> and + <real>\n\n");
1479 sprintf(outstr,"r run %d iterations",maxiter); pg(stdout,outstr);
1480 pg(stdout," and print a summary every\n");
1481 sprintf(outstr," %d iterations\n",printrate); pg(stdout,outstr);
1482 pg(stdout,"^R same as r\n");
1483 pg(stdout,"r <int1> <int2> run <int1> iterations and print a summary every\n");
1484 pg(stdout," <int2> iterations\n");
1486 sprintf(outstr,"s %5d",seed); pg(stdout,outstr);
1487 sprintf(outstr," random number seed: %1d\n",seed); pg(stdout,outstr);
1488 pg(stdout,"\nse <filename> save everything to <filename>\n");
1489 pg(stdout,"\n");
1490 return;
1492 case 'N':
1493 pg(stdout,"\nNetwork Information\n\n");
1494 printnetsize(stdout);
1495 pg(stdout,"\n");
1496 sprintf(outstr," total weights: %1d\n",wttotal);
1497 pg(stdout,outstr);
1499 pg(stdout,"l <layer> print the unit values in layer <layer>\n\n");
1500 return;
1502 case 'P':
1503 pg(stdout,"\nPattern Related Commands\n\n");
1504 pg(stdout,"f p g the problem type; {gc} h fp\n");
1505 pg(stdout,"f i r format to input patterns; {cr} h fi\n");
1506 pg(stdout,"f o r format to output network values; {acer} h fo\n\n");
1508 pg(stdout,"rt {patterns} reads the patterns between { and }\n");
1509 pg(stdout,"rt <filename> read training patterns from <filename>\n");
1510 pg(stdout,"rx <filename> read more training patterns from <filename>\n");
1511 pg(stdout,"tf <filename> test file is <filename>\n\n");
1513 pg(stdout,"p list all training set pattern values\n");
1514 pg(stdout,"pa same as p\n");
1515 pg(stdout,"p <pat. no.> evaluate the training pattern\n");
1516 pg(stdout,"p0 summarize training pattern learning\n\n");
1518 pg(stdout,"t list all test set pattern values\n");
1519 pg(stdout,"ta same as t\n");
1520 pg(stdout,"tr <int> test recurrent patterns h tr\n");
1521 pg(stdout,"trp <int> test recurrent patterns and print results h trp\n");
1522 pg(stdout,"t <pat. no.> evaluate the test pattern\n");
1523 pg(stdout,"t0 summarize test pattern learning\n\n");
1525 pg(stdout,"o <int> prints the target for training pattern <int>\n\n");
1527 printstats(stdout,TRAIN,1,s);
1528 if (s[TOL][TEST].npats > 0) printstats(stdout,TEST,1,s);
1529 pg(stdout,"\n");
1530 return;
1532 case 'Q':
1533 pg(stdout,"\nThe Quickprop Parameters (qp)\n\n");
1534 pg(stdout,"qp d <real> sets quickprop weight decay to <real> in all layers\n");
1535 sprintf(outstr,"qp dh %8.6f ",unscale(qpdecayh)); pg(stdout,outstr);
1536 pg(stdout,"quickprop decay for the hidden layer weights; [0..1)\n");
1537 sprintf(outstr,"qp do %8.6f ",unscale(qpdecayo)); pg(stdout,outstr);
1538 pg(stdout,"quickprop decay for the output layer weights; [0..1)\n");
1539 sprintf(outstr,"qp e %6.4f ",unscale(qpeta)); pg(stdout,outstr);
1540 pg(stdout,"quickprop eta; (0..inf)\n");
1541 sprintf(outstr,"qp m %4.2f ",unscale(mu)); pg(stdout,outstr);
1542 pg(stdout,"quickprop acceleration (mu); (1..inf)\n");
1543 sprintf(outstr,"qp n %5.3f ",unscale(qpnoise)); pg(stdout,outstr);
1544 pg(stdout,"quickprop noise (ibp only); [0..inf)\n");
1545 sprintf(outstr,"qp s %c ",qpslope); pg(stdout,outstr);
1546 pg(stdout,"include or exclude extra slope term; {+-}\n");
1547 pg(stdout,"\na u q use this to set the quickprop update method\n");
1548 pg(stdout,"\n");
1549 return;
1551 case 'T':
1552 pg(stdout,"\nA Tutorial\n\n");
1553 pg(stdout,"The following topics are designed to be read in the order listed.\n\n");
1554 pg(stdout,"To get help on a topic type the code on the right at the prompt.\n\n");
1555 pg(stdout,"Understanding the Menus h1\n");
1556 pg(stdout,"Formatting Data for a Classification Problem h2\n");
1557 pg(stdout,"Formatting Data for Function Approximation h3\n");
1558 pg(stdout,"Formatting Data for a Recurrent Problem h4\n");
1559 pg(stdout,"Making a Network for Classification or Function Approximation h5\n");
1560 pg(stdout,"Making a Recurrent Network h6\n");
1561 pg(stdout,"Reading the Data h7\n");
1562 pg(stdout,"Setting Algorithms and Parameters h8\n");
1563 pg(stdout,"Running the Program h9\n");
1564 pg(stdout,"Saving Almost Everything h10\n");
1565 pg(stdout,"To Quit the Program h11\n\n");
1566 return;
1568 case 'W':
1569 pg(stdout,"\nWeights Related Commands\n\n");
1570 pg(stdout,"rw reads weights from the file "); pg(stdout,wtfilename);
1571 pg(stdout,"\n");
1572 pg(stdout,"sw saves weights to the file "); pg(stdout,wtfilename);
1573 pg(stdout,"\n");
1574 pg(stdout,"rw <filename> reads weights from <filename>\n");
1575 pg(stdout,"sw <filename> save weights to <filename>\n");
1576 sprintf(outstr," last save at: %1d\n\n",lastsave);
1577 pg(stdout,outstr);
1579 pg(stdout,"w <layer> <unit> list weights leading into this unit\n\n");
1581 if (biasset == 1)
1583 sprintf(outstr,"sb %5.2f ",unscale(stdthresh)); pg(stdout,outstr);
1584 pg(stdout,"bias units set to this value\n\n");
1586 else pg(stdout,"sb <real> set bias weights to <real>\n\n");
1588 printnetsize(stdout);
1589 pg(stdout,"\n");
1590 sprintf(outstr," total weights: %1d\n",wttotal);
1591 pg(stdout,outstr);
1593 #ifdef INTEGER
1594 if (wtlimithit == 1)
1595 pg(stdout,"\n >>>>> WEIGHT LIMIT HIT <<<<<\n");
1596 #endif
1597 pg(stdout,"\n");
1598 return;
1600 default: pg(stdout,"not a screen item\n");
1601 return;
1602 }; /* end switch */
1605 void help()
1607 int ch2;
1608 pg(stdout,"\n");
1609 do ch2 = readch(); while (ch2 == ' ' && ch2 != '\n');
1610 switch(ch2) {
1612 default: menus('C'); return;
1614 case '1':
1615 ch2 = readch();
1616 switch(ch2) {
1617 case '0':
1618 pg(stdout,"\n");
1619 pg(stdout,"It is possible to use the program by typing in all the commands at the\n");
1620 pg(stdout,"keyboard yet it is more convenient to have the basic set up commands for\n");
1621 pg(stdout,"a particular problem in a file, have the program read the file and then\n");
1622 pg(stdout,"have it take commands from the keyboard. So if you have a file named\n");
1623 pg(stdout,"xor set up you can start the program with:\n");
1624 pg(stdout,"\n");
1625 pg(stdout,"bp xor\n");
1626 pg(stdout,"\n");
1627 pg(stdout,"After working with the problem you may reset many parameters. To save\n");
1628 pg(stdout,"the current set of parameters and weights (but not the patterns which\n");
1629 pg(stdout,"are normally in files of their own) use the save everything command,\n");
1630 pg(stdout,"`se'. So to save the current state of the program to a file called,\n");
1631 pg(stdout,"say, new, do:\n");
1632 pg(stdout,"\n");
1633 pg(stdout,"se new\n");
1634 pg(stdout,"\n");
1635 pg(stdout,"The file new will be virtually identical to the listing you get with\n");
1636 pg(stdout,"the `?' command. Later on you can restart the problem with:\n");
1637 pg(stdout,"\n");
1638 pg(stdout,"bp new\n");
1639 pg(stdout,"\n");
1640 return;
1642 case '1':
1643 pg(stdout,"In DOS and UNIX type `q' at the command line prompt.\n\n");
1644 pg(stdout,"In DOS you can hit the escape key to stop a training run.\n\n");
1645 pg(stdout,"In DOS and UNIX you can hit ctrl-C to stop anything and get to the\n");
1646 pg(stdout,"command prompt. When used in a DOS window under Windows this may\n");
1647 pg(stdout,"produce an error message as well as stopping the program.\n\n");
1648 return;
1650 case '\n':
1651 bufferptr = bufferptr - 1;
1652 pg(stdout,"Understanding the Menus\n\n");
1653 pg(stdout,"First, this program includes a paging algorithm similar to more. When\n");
1654 pg(stdout,"you get the string:\n");
1655 pg(stdout,"\n");
1656 pg(stdout,"More?\n");
1657 pg(stdout,"\n");
1658 pg(stdout,"at the bottom of the screen you can get one more page by hitting the\n");
1659 pg(stdout,"space bar, one more line by hitting the carriage return, half a page\n");
1660 pg(stdout,"with ctrl-D, a c will continue without paging and in most cases typing\n");
1661 pg(stdout,"a q will stop the paging. There is no scrolling backwards.\n\n");
1662 pg(stdout,"While the program does not use a mouse or windows it does have menus to\n");
1663 pg(stdout,"make it easy to see what the commands are. One typical menu is the F\n");
1664 pg(stdout,"for format menu, so if you type F at the command prompt you get:\n\n");
1665 pg(stdout,"The Format Command (f)\n\n");
1666 pg(stdout,"f b - ring the bell when training is finished; {+-}\n");
1667 pg(stdout,"f c + make a copy of screen i/o on the file copy; {+-}\n");
1668 pg(stdout,"f e - echo input; {+-}\n");
1669 pg(stdout,"f i r format for reading input and output patterns; {cr} h fi\n\n");
1670 pg(stdout,"plus there is more that has been deleted but these four lines show enough.\n");
1671 pg(stdout,"The first column gives the command and the current value of the parameter.\n");
1672 pg(stdout,"In the `f b -' string, the `f' is the general format command that\n");
1673 pg(stdout,"includes many sub-commands. The `b' sub-command controls the ringing\n");
1674 pg(stdout,"of the bell when the program finishes learning. With the `-' it is off.\n");
1675 pg(stdout,"The middle portion of the screen gives the function involved with the\n");
1676 pg(stdout,"command. Characters at the end within { and } list the possible options.\n");
1677 pg(stdout,"For ringing the bell it is on or off, `+' or `-'. In the `f i r' the\n");
1678 pg(stdout,"explanation for c and r within the { and } can be found by typing `h f i'\n");
1679 pg(stdout,"at the normal command prompt. To change the settings you only have to\n");
1680 pg(stdout,"type the command string in the left column but with the new parameter\n");
1681 pg(stdout,"setting.\n\n");
1682 pg(stdout,"In many cases the command parameters are numbers. The range of values\n");
1683 pg(stdout,"that the parameter can take on are given using [, ], (, and ). If the\n");
1684 pg(stdout,"range listed is: [0..1) the [ next to 0 means that the lowest possible\n");
1685 pg(stdout,"value allowed is exactly 0 while the ) indicates that you can get very\n");
1686 pg(stdout,"close to 1 but never exactly 1.\n\n");
1687 pg(stdout,"In some cases the leftmost column will code a possible command parameter\n");
1688 pg(stdout,"using some name within < and >. For instance there are these two\n");
1689 pg(stdout,"examples:\n\n");
1690 pg(stdout,"qp d <real> sets quickprop weight decay to <real> in all layers\n\n");
1691 pg(stdout,"sw <filename> save weights to <filename>\n");
1692 pg(stdout,"\n");
1693 pg(stdout,"In the first case it means that to set the quickprop decay in all layers\n");
1694 pg(stdout,"to some value you type `qp d' and some real number as in:\n\n");
1695 pg(stdout,"qp d 0.0001\n\n");
1696 pg(stdout,"In the second example the command means save the weight to some filename\n");
1697 pg(stdout,"so type the name in place of `<filename>'.\n\n");
1698 return;
1700 default: pg(stdout,"not a help item\n\n");
1701 return;
1702 }; /* end the inner switch */
1704 case '2':
1705 pg(stdout,"The normal way to operate this program is to have the training data\n");
1706 pg(stdout,"in one file and if there is test set data it should be in another file.\n\n");
1707 pg(stdout,"For a plain classification program, with say four inputs and 3 possible\n");
1708 pg(stdout,"classes the data file will look like:\n\n");
1709 pg(stdout,"0.4 0.3 0.33 0.21 1 * this is a class 1 pattern\n");
1710 pg(stdout,"0.55 0.32 -0.09 0.20 2 * this is a class 2 pattern\n");
1711 pg(stdout,"0.11 0.23 -0.97 0.45 3 * this is a class 3 pattern\n\n");
1712 pg(stdout,"where the first four numbers are the input and the last number is the\n");
1713 pg(stdout,"class number. If there are a large number of inputs you can use more\n");
1714 pg(stdout,"than one line for each pattern but you should start every new pattern\n");
1715 pg(stdout,"on a new line. The asterisk at the end of the line begins a comment.\n\n");
1716 pg(stdout,"It is also possible to type the data in as commands but this is\n");
1717 pg(stdout,"generally not a good idea unless you have a very small data set\n");
1718 pg(stdout,"because you will probably make many mistakes when typing the data\n");
1719 pg(stdout,"in.\n\n");
1720 return;
1722 case '3':
1723 pg(stdout,"The normal way to operate this program is to have the training data\n");
1724 pg(stdout,"in one file and if there is test set data it should be in another file.\n\n");
1725 pg(stdout,"For a function approximation program with say five inputs and 1 output\n");
1726 pg(stdout,"the data should look like:\n\n");
1727 pg(stdout," -1.588 -1.650 0.365 0.188 0.962 -1.543\n");
1728 pg(stdout," -1.182 -0.926 0.992 0.188 1.140 -1.372\n");
1729 pg(stdout," -2.650 -1.650 3.501 0.188 -0.566 -1.201\n\n");
1730 pg(stdout,"where the first five numbers are the input and the last number is the\n");
1731 pg(stdout,"answer. If there are a large number of inputs you can use more\n");
1732 pg(stdout,"than one line for each pattern but you should start every new pattern\n");
1733 pg(stdout,"on a new line.\n\n");
1734 pg(stdout,"It is also possible to type the data in as commands but this is\n");
1735 pg(stdout,"generally not a good idea unless you have a very small data set because\n");
1736 pg(stdout,"you will probably make many mistakes when typing the data in.\n\n");
1737 return;
1739 case '4':
1740 pg(stdout,"The normal way to operate this program is to have the training data\n");
1741 pg(stdout,"in one file and if there is test set data it should be in another file.\n\n");
1742 pg(stdout,"For a recurrent network problem, with say four inputs and 4 possible\n");
1743 pg(stdout,"outputs the data file will look like:\n\n");
1744 pg(stdout,"1 0 0 0 H 0 0 1 0\n");
1745 pg(stdout,"0 0 1 0 H 0 1 0 0\n");
1746 pg(stdout,"0 1 0 0 H 0 0 1 0\n");
1747 pg(stdout,"0 0 1 0 H 0 0 0 1\n\n");
1748 pg(stdout,"where the first four numbers are the input, the H stands for the values\n");
1749 pg(stdout,"of the hidden layer units that are copied down to the input and the last\n");
1750 pg(stdout,"four numbers are the output. If there are a large number of inputs you\n");
1751 pg(stdout,"can use more than one line for each pattern but you should start every\n");
1752 pg(stdout,"new pattern on a new line.\n\n");
1753 pg(stdout,"It is also possible to type the data in as commands but this is\n");
1754 pg(stdout,"generally not a good idea unless you have a very small data set\n");
1755 pg(stdout,"because you will probably make many mistakes when typing the data in.\n\n");
1756 return;
1758 case '5':
1759 pg(stdout,"The command to type in to make a network with four inputs, three\n");
1760 pg(stdout,"hidden layer units and two output units is:\n\n");
1761 pg(stdout,"m 4 3 2\n\n");
1762 pg(stdout,"In many cases adding extra connections from the input units to the\n");
1763 pg(stdout,"output units will produce faster training. If you wanted to use the\n");
1764 pg(stdout,"extra connections type in:\n\n");
1765 pg(stdout,"m 4 3 2 x\n\n");
1766 pg(stdout,"NOTE: there is no way to know ahead of time how many hidden units will\n");
1767 pg(stdout,"be needed or if hidden units will be needed at all.\n\n");
1768 pg(stdout,"NOTE: when patterns are read in they are attached to the network\n");
1769 pg(stdout,"structure so if you make a different size network, such as a 4-5-2\n");
1770 pg(stdout,"network after the patterns are read in the patterns will be lost and\n");
1771 pg(stdout,"you will have to read them in again.\n\n");
1772 return;
1774 case '6':
1775 pg(stdout,"The command to type in to make a recurrent network with four normal\n");
1776 pg(stdout,"input units and three more input units that have values copied from\n");
1777 pg(stdout,"the three hidden layer units and with two output units is:\n\n");
1778 pg(stdout,"m 4+3 3 2\n\n");
1779 pg(stdout,"The 3 in the `4+3' portion must be the same value as the 3 following it.\n\n");
1780 return;
1782 case '7':
1783 pg(stdout,"If you're doing a classification type problem it is important to first\n");
1784 pg(stdout,"let the program know that using the `f' (format) command so the last\n");
1785 pg(stdout,"number can be interpreted as the class number, use:\n\n");
1786 pg(stdout,"f p c * the problem type is classification\n\n");
1787 pg(stdout,"If you're doing a function approximation type of problem, do nothing\n");
1788 pg(stdout,"since the default setting (g, for general) will work.\n\n");
1789 pg(stdout,"To read in the training set data from some file called, say train is:\n\n");
1790 pg(stdout,"rt train * rt is for read training\n\n\n");
1791 pg(stdout,"To read in any test set data from some file called, say, test is:\n\n");
1792 pg(stdout,"tf test * tf is for test file\n\n\n");
1793 pg(stdout,"For other ways to read in data see the manual.\n\n");
1794 return;
1796 case '8':
1797 pg(stdout,"There are many algorithms that can be tried and there are many\n");
1798 pg(stdout,"parameters for each algorithm that can be varied, some algorithms and\n");
1799 pg(stdout,"values produce faster training while others may produce better\n");
1800 pg(stdout,"generalization. So far there is no way to know ahead of time which\n");
1801 pg(stdout,"algorithms and values are best. The fastest training algorithm in this\n");
1802 pg(stdout,"program is quickprop. To get fairly good results set the quickprop eta\n");
1803 pg(stdout,"parameter to about 1 / n where n is the number of patterns in the\n");
1804 pg(stdout,"training set. So if n = 100 type in:\n\n");
1805 pg(stdout,"qp e 0.01 * sets the quickprop eta to 0.01\n\n");
1806 pg(stdout,"and set the algorithm to use to quickprop with the algorithm command:\n\n");
1807 pg(stdout,"a uq * sets the update algorithm to quickprop.\n\n");
1808 pg(stdout,"This will probably work well (NO GUARANTEE) with the other default\n");
1809 pg(stdout,"parameters in the program.\n\n");
1811 pg(stdout,"If you need outputs beyond the range of 0 to 1 use the algorithm\n");
1812 pg(stdout,"command to make the output layer linear:\n\n");
1813 pg(stdout,"a aol * activation function for the output layer is linear\n\n");
1814 return;
1816 case '9':
1817 pg(stdout,"\n");
1818 pg(stdout,"Normally you want to initialize the weights in the network with small random\n");
1819 pg(stdout,"values. This is done with the clear and initialize command, type in:\n");
1820 pg(stdout,"\n");
1821 pg(stdout,"ci * ci for clear and initialize\n");
1822 pg(stdout,"\n");
1823 pg(stdout,"Having done that you can run the training program by typing `r' and a\n");
1824 pg(stdout,"carriage return or by typing ctrl-R. Doing this applies the training\n");
1825 pg(stdout,"algorithm for up to 100 passes through the training set data and lists\n");
1826 pg(stdout,"the status of the training set and the test set if it exists. For the\n");
1827 pg(stdout,"sonar data included in the sample data the listing will look like:\n");
1828 pg(stdout,"\n");
1829 pg(stdout," 10 49.04 % 49.04 % 0.47063 62.50 % 62.50 % 0.38221 \n");
1830 pg(stdout," 20 70.19 % 73.08 % 0.38548 77.88 % 77.88 % 0.38063 \n");
1831 pg(stdout," 30 76.92 % 76.92 % 0.34943 77.88 % 80.77 % 0.33282 \n");
1832 pg(stdout,"\n");
1833 pg(stdout,"The first column is the iteration number, the second column gives the\n");
1834 pg(stdout,"percentage of training set patterns right based on the tolerance the\n");
1835 pg(stdout,"third column gives the percentage right based on the maximum value, the\n");
1836 pg(stdout,"fourth column gives the abs (not RMS!) error. The fifth column is the\n");
1837 pg(stdout,"percentage of test set patterns right based on the tolerance, the sixth\n");
1838 pg(stdout,"column gives the percentage right based on maximum value and the last\n");
1839 pg(stdout,"column gives the abs error.\n");
1840 pg(stdout,"\n");
1841 return;
1843 case 'a':
1844 do ch2 = readch(); while (ch2 == ' ');
1845 if (ch2 == 'd')
1847 pg(stdout,"a d c uses the original (correct) derivative.\n\n");
1848 pg(stdout,"a d d uses the differential step derivative in the output layer.\n");
1849 pg(stdout,"a d f uses Fahlman's derivative in the output layer.\n");
1850 pg(stdout,"a d o uses the original (correct) derivative.\n\n");
1852 else if (ch2 == 'a')
1854 pg(stdout,"a a <char> sets every activation function to <char>.\n");
1855 pg(stdout,"a ah <char> sets the hidden layer activation function to <char>.\n");
1856 pg(stdout,"a ao <char> sets the output layer activation function to <char>,\n");
1857 pg(stdout,"<char> can be any of the following:\n\n");
1859 pg(stdout,"<char> Function Range\n\n");
1861 pg(stdout," l linear function, x (-inf..+inf)\n");
1862 pg(stdout," s standard sigmoid, 1 / (1 + exp(-x)) (0..+1)\n");
1864 else if (ch2 == 'u')
1866 pg(stdout,"a u C gives the \"right\" continuous update method.\n");
1867 pg(stdout,"a u c gives the \"wrong\" continuous update method.\n");
1868 #ifndef SYMMETRIC
1869 pg(stdout,"a u d gives the delta-bar-delta update method.\n");
1870 #endif
1871 pg(stdout,"a u p gives the periodic update method.\n");
1872 #ifndef SYMMETRIC
1873 pg(stdout,"a u q gives the quickprop update method.\n");
1874 #endif
1876 else texterror(); /* end of the 'a' case */
1877 break;
1879 case 'f':
1880 do ch2 = readch(); while (ch2 == ' ');
1881 if (ch2 == 'B')
1883 pg(stdout,"B <int1> <int2> ... <inti> ... <int20> puts a carriage return\n");
1884 pg(stdout," after each <inti> values when the output format is real\n");
1885 pg(stdout," and inserts a blank after each <inti> value if the\n");
1886 pg(stdout," format is condensed.\n\n");
1888 else if (ch2 == 'i')
1890 pg(stdout,"i c will read pattern values using compressed format.\n");
1891 pg(stdout,"i r will read pattern values as reals.\n\n");
1893 else if (ch2 == 'o')
1895 pg(stdout,"o a will write node values as analog compressed.\n");
1896 pg(stdout,"o c will write node values as compressed.\n");
1897 pg(stdout,"o e will write node values with e notation.\n");
1898 pg(stdout,"o r will write node values as real.\n\n");
1900 else if (ch2 == 'p')
1902 pg(stdout,"p c will read patterns in the classification format.\n");
1903 pg(stdout,"p g will accept general patterns.\n\n");
1905 else texterror();
1906 break;
1908 case 't':
1909 do ch2 = readch(); while (ch2 == ' ');
1910 if (ch2 == 'r')
1912 pg(stdout,"tr <int> in a recurrent network takes each training set pattern\n");
1913 pg(stdout," and its <int> - 1 following patterns and predicts the\n");
1914 pg(stdout," <int> + 1st pattern\n");
1915 pg(stdout,"trp <int> does the same and prints the predicted patterns\n");
1917 else texterror();
1918 break;
1919 }; /* end switch */
1920 pg(stdout,"\n");