1 /* ************************************************** */
2 /* file io.c: contains most input/output functions */
4 /* Copyright (c) 1990-96 by Donald R. Tveter */
6 /* ************************************************** */
14 #if defined(UNIX) && defined(HOTKEYS)
17 struct termios raw
; /* characteristics for hotkeys */
18 struct termios noraw
; /* original characteristics */
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 */
27 char onechar
[1]; /* the buffer for the hotkey character */
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
;
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
;
59 extern REAL qpdecayh
, qpdecayo
;
60 extern REAL toloverall
, minimumsofar
;
64 extern int wtsinuse
, wttotal
;
65 extern char incrementseed
;
67 extern SEEDNODE
*seedstart
;
69 #if defined(UNIX) && defined(HOTKEYS)
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
];
84 raw
.c_ispeed
= noraw
.c_ispeed
;
85 raw
.c_ospeed
= noraw
.c_ospeed
;
90 tcsetattr(0,TCSANOW
,&raw
);
95 tcsetattr(0,TCSANOW
,&noraw
);
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 */
111 ioctl(0,TIOCSETD
,&raw
);
116 ioctl(0,TIOCSETD
,&noraw
);
119 #else /* System V code */
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
];
136 ioctl(0,TCSETA
,&raw
);
141 ioctl(0,TCSETA
,&noraw
);
143 #endif /* end of the System V code */
149 do ch
= read(0,onechar
,1); while (ch
!= 1);
153 #endif /* end of the if defined(UNIX) ... code */
156 short scale(x
) /* returns x as a scaled 16-bit value */
161 if (x
> 31.999 || x
< -32.0)
163 sprintf(outstr
,"magnitude of %f is too large for the integer",x
);
165 pg(stdout
," representation\n");
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
);
175 pg(stdout
," the integer representation\n");
181 REAL
unscale(x
) /* returns the REAL value of short x */
183 {return((REAL
) x
/ 1024.0);}
185 REAL
unscaleint(x
) /* returns the REAL value of INT32 x */
187 { return((REAL
) x
/ 1024.0); }
191 int pushfile(filename
,timestoread
)
200 file
= fopen(filename
,"r");
203 sprintf(outstr
,"cannot open: %s\n",filename
); pg(stdout
,outstr
);
206 filestackptr
= filestackptr
+ 1;
207 if (filestackptr
> MAXFILES
)
209 pg(stdout
,"can't stack up any more files\n");
210 filestackptr
= filestackptr
- 1;
214 filestack
[filestackptr
] = file
;
215 filetimes
[filestackptr
] = timestoread
;
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)
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 */
242 if (bufferptr
> bufferend
) /* then read next line into buffer */
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
;
258 goto entryfromhotkeys
;
260 else /* all other characters */
266 while (ch2
!= '\n' && i
< (BUFFSIZE
-1))
268 while (ch2
!= 13 && i
< (BUFFSIZE
-1))
272 if (ch2
== 8 && i
>= 0)
277 else if (ch2
== 8) {/* do nothing */}
279 else if (ch2
!= '\n')
291 goto entryfromhotkeys
;
297 if (ch2
== EOF
) return(ch2
);
299 while(ch2
!= '\n' && i
< (BUFFSIZE
-1))
302 if (ch2
== 13) ch2
= ' '; /* turn a ctrl-M into a blank */
304 if (ch2
== '\t') ch2
= ' ';
310 if (i
== (BUFFSIZE
-1)) pg(stdout
,"line too long\n");
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;
326 pg(stdout
,"unexpected text: ");
327 pg(stdout
,&buffer
[bufferptr
-1]);
328 bufferptr
= bufferend
;
336 while (buffer
[i
] == ' ') i
= i
+ 1;
338 while (buffer
[i
] != ' ' && buffer
[i
] != '\n') i
= i
+ 1;
340 addr
= (char *) malloc((int) end
-start
+2);
342 for (i
=start
;i
<=end
;i
++) *addr
++ = buffer
[i
];
355 do ch2
= readch(); while (ch2
== ' ' || ch2
== '\n');
356 if ((ch2
>= '0' && ch2
<= '9') || ch2
== '.')
358 bufferptr
= bufferptr
- 1;
362 case '}': readerror
= 3;
364 case EOF
: readerror
= 2;
366 case '*': while (ch2
!= '\n') ch2
= readch();
368 case '-': sign
= -sign
;
375 case 's': bufferptr
= bufferptr
- 1;
377 default: readerror
= 1;
382 int readint(min
,max
,command
)
386 int sign
, number
, ch2
;
389 sign
= scanfordigit();
392 if (readerror
== 1) texterror();
396 do ch2
= readch(); while (ch2
== ' ');
397 while (ch2
>= '0' && ch2
<= '9')
399 number
= number
* 10 + (ch2
- '0');
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
);};
414 REAL
readreal(op
,min
,command
)
419 REAL fractpart
, divisor
, intpart
, sign
;
424 sign
= (REAL
) scanfordigit();
425 if (readerror
|| (sign
== 0 && !readingpattern
))
427 if (readerror
== 1) texterror();
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
));
440 while ((ch2
>= '0' && ch2
<='9') || ch2
== '+' || ch2
== '-' ||
441 ch2
== 'e' || ch2
== 'E' || ch2
== '.')
448 bufferptr
= bufferptr
- 1;
449 numread
= sscanf(outstr
,"%lf",&number
);
452 pg(stdout
,"bad real value\n");
456 number
= sign
* number
;
457 if (op
== GT
&& number
> min
) return(number
);
458 else if (op
== GE
&& number
>= min
) return(number
);
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
);};
469 WTTYPE
rdr(op
,min
,command
) /* reads REAL real numbers and converts */
470 int op
; /* them to 16-bit integers if necessary */
477 x
= readreal(op
,min
,command
);
478 if (readerror
) return(0);
480 if (readerror
) return(0);
484 REAL
readchar() /* reads data in compressed format */
492 case ' ': ch2
= readch();
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');
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;
506 case '}': readerror
= 3;
508 default: texterror();
514 void readapat(pn
,relation
,minimum
,command
,informat
)
524 if (informat
== 'r') val
= rdr(relation
,minimum
,command
);
525 else val
= scale(readchar());
531 unitnumber
= readint(1,start
->unitcount
,'r');
532 if (readerror
!= 0) return;
533 pn
->unitno
= unitnumber
;
534 u
= locateunit(1,unitnumber
);
537 else if (val
== HCODE
)
540 pn
->addr
= (WTTYPE
*) -1;
545 else if (val
== CAPXCODE
)
547 pn
->addr
= (WTTYPE
*) -1;
550 pn
->unitno
= CAPXCODE
;
552 else if (val
== CAPHCODE
)
555 pn
->addr
= (WTTYPE
*) -1;
558 pn
->unitno
= CAPHCODE
;
560 else if (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
);
571 else if (val
== SKIPCODE
)
573 pn
->addr
= (WTTYPE
*) -1;
576 pn
->unitno
= SKIPCODE
;
578 else if (val
== DIFFCODE
)
580 pn
->addr
= (WTTYPE
*) -1;
583 pn
->unitno
= DIFFCODE
;
589 pn
->layer
= 0; /* unused */
590 pn
->unitno
= 0; /* unused */
594 void readpatson(layer
,list
,command
)
601 int i
, answer
, veclength
;
603 pl
= (PATLIST
*) malloc(sizeof(PATLIST
));
605 pl
->pats
= NULL
; /* no patterns read yet */
606 if (layer
->patstart
[list
] == NULL
)
609 layer
->patstart
[list
] = pl
;
613 prev
= layer
->currentpat
[list
];
616 layer
->currentpat
[list
] = pl
;
618 veclength
= layer
->unitcount
;
619 pn
= (PATNODE
*) malloc(veclength
* sizeof(PATNODE
));
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
;
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
;
643 readerror
= readerror
+ 2;
646 else if (readerror
!= 0) return;
647 if (pn
->unitno
== CAPHCODE
|| pn
->unitno
== CAPXCODE
) return; else pn
++;
652 int readpats(list
,command
)
657 /* look for scaling parameters, if any, in a TRAINing set */
663 int ch1
, ch2
, k
, col
, nfactors
;
666 if (ch1
== '\n') ch1
= 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');
674 for (k
=1;k
<=nfactors
;k
++)
678 pg(stdout
,"not enough input units for these patterns\n");
683 if (ch1
!= '*' || ch2
!= '$')
685 pg(stdout
,"error in input scaling list\n");
686 goto readthepatterns
;
690 col
= readint(k
,k
,'r');
693 pg(stdout
,"error in scaling list\n");
694 goto readthepatterns
;
696 trans
= rdr(GE
,(REAL
) -MAXINT
,'r');
699 pg(stdout
,"error in scaling list\n");
700 goto readthepatterns
;
702 else u
->translate
= trans
;
703 sca
= rdr(GE
,(REAL
) -MAXINT
,'r');
706 pg(stdout
,"error in scaling list\n");
707 goto readthepatterns
;
709 else u
->userscale
= sca
;
711 do ch1
= readch(); while (ch1
!= '\n');
714 /* do the output unit scaling factors if its not a classification problem */
718 for (k
=1;k
<=last
->unitcount
;k
++)
722 if (ch1
!= '*' || ch2
!= '$')
724 pg(stdout
,"error in output scaling list\n");
725 goto readthepatterns
;
729 col
= readint(k
,k
,'r');
732 pg(stdout
,"error in scaling list\n");
733 goto readthepatterns
;
735 trans
= rdr(GE
,(REAL
) -MAXINT
,'r');
738 pg(stdout
,"error in scaling list\n");
739 goto readthepatterns
;
741 else u
->translate
= trans
;
742 sca
= rdr(GE
,(REAL
) -MAXINT
,'r');
745 pg(stdout
,"error in scaling list\n");
746 goto readthepatterns
;
748 else u
->userscale
= sca
;
750 do ch1
= readch(); while (ch1
!= '\n');
753 }; /* ends prob type */
754 }; /* else there are scaling parameters */
755 }; /* if its a training set file */
760 while (readerror
== 0)
762 readpatson(start
,list
,command
);
763 if (readerror
) break;
764 readpatson(last
,list
,command
);
765 if (readerror
) break;
768 if (readerror
== 5) return(i
);
769 else if (readerror
== 4)
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();
784 pl
= (PATLIST
*) start
->patstart
[list
];
785 for (j
=1;j
<=prevnpats
+ i
- 1;j
++) pl
= pl
->next
;
787 pl
= (PATLIST
*) last
->patstart
[list
];
788 for (j
=1;j
<=prevnpats
+ i
- 1;j
++) pl
= pl
->next
;
794 int pg(f
,str
) /* paging and making a copy function */
800 long clockbefore
, clockafter
;
803 if (f
!= stdout
) {fprintf(f
,"%s",str
); return(0);};
804 clockbefore
= clock();
812 if (copyflag
== '+') putc('\n',copy
);
814 if (pagesize
> 0 && lineno
> 0 && lineno
% pagesize
== 0)
821 if (action
!= '\n') cr
= getchar();
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
;
829 else if (action
== '\n') lineno
= lineno
- 1;
831 else if (action
== 13) lineno
= lineno
- 1;
833 else if (action
== 4) lineno
= pagesize
/ 2;
837 else {putchar(*ch3
); if (copyflag
== '+') putc(*ch3
,copy
); };
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 */
853 sprintf(outstr
," %1d+%1d",p
->unitcount
-stmsize
,stmsize
);
859 sprintf(outstr
," %1d",p
->unitcount
);
863 if (ioconnects
) pg(f
," x");
864 if (pccnet
) pg(f
," p");
875 sprintf(outstr
," %1d",s
->val
); pg(f
,outstr
);
880 int printoutunits(patnum
,layer
,list
,error
,tok
,mok
)
887 short unitno
, fmtbreaknum
;
889 WTTYPE upper
, middle
, diff
;
898 upper
= scale(1.0) - toler
;
903 if (layer == last && patnum > 0)
905 pl = last->currentpat[list];
907 u = (UNIT *) layer->units;
908 for (i=1;i<=last->unitcount;i++)
915 if (patnum
) {sprintf(outstr
,"%5d ",patnum
); pg(stdout
,outstr
);}
917 u
= (UNIT
*) layer
->units
;
920 diff
= u
->tj
- u
->oj
;
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
,"^");
947 if (format
[fmtbreaknum
] == unitno
)
950 if (fmtbreaknum
< MAXFORMAT
- 1) fmtbreaknum
= fmtbreaknum
+ 1;
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");
959 if (format
[fmtbreaknum
] == unitno
)
962 if (fmtbreaknum
< MAXFORMAT
- 1) fmtbreaknum
= fmtbreaknum
+ 1;
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 */
983 WTTYPE wvalue
, evalue
, dvalue
, svalue
;
984 int wtsize
, unitno
, layerno
, i
;
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
);
996 fprintf(wtfileptr
,"%d%c",totaliter
,wtformat
);
998 fprintf(wtfileptr
," m %1d",layer
->unitcount
);
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
);
1016 fputc('\n',wtfileptr
);
1018 layer
= start
->next
;
1019 while (layer
!= NULL
)
1021 u
= (UNIT
*) layer
->units
;
1024 w
= (WTNODE
*) u
->wtlist
;
1028 wvalue
= *(w
->weight
);
1030 dvalue
= *(w
->olddw
);
1031 svalue
= *(w
->slope
);
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
));
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
);
1056 fputc('\r',wtfileptr
);
1058 fputc('\n',wtfileptr
);
1064 layer
= layer
->next
;
1068 lastsave
= totaliter
;
1071 void restoreweights() /* restore weights */
1077 int ch2
, fileformat
, wtsize
, numread
, i
, layerno
, unitno
;
1078 WTTYPE wvalue
, evalue
, dvalue
, svalue
;
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
);
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");
1101 do ch2
= fgetc(wtfileptr
); while (ch2
!= '\n');
1102 layer
= start
->next
;
1103 while (layer
!= NULL
)
1105 u
= (UNIT
*) layer
->units
;
1109 w
= (WTNODE
*) u
->wtlist
;
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
);
1120 do ch2
= fgetc(wtfileptr
); while (ch2
== ' ');
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");
1133 numread
= fscanf(wtfileptr
,"%d",&wtinuse
);
1134 if (numread
== EOF
) goto unexpectedeof
;
1135 if (numread
== 0) goto badread
;
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');
1155 ch2
= fgetc(wtfileptr
);
1156 if (ch2
!= '\r') ungetc(ch2
,wtfileptr
);
1160 *(w
->weight
) = wvalue
;
1161 if (fileformat
== 'R')
1163 *(w
->olddw
) = dvalue
;
1166 else *(w
->olddw
) = 0;
1170 if (fileformat
== 'R')
1182 layer
= layer
->next
;
1185 lastsave
= totaliter
;
1187 badread
: pg(stdout
,"\n>>>>> scanf read error <<<<<\n\n");
1190 unexpectedeof
: pg(stdout
,"\n>>>>> ran out of weights <<<<<\n\n");
1194 void printweights(u
,layerno
) /* print the weights leading into unit u */
1204 short wtinuse
, unitinuse
;
1211 w
= (WTNODE
*) u
->wtlist
;
1213 pg(stdout
,"layer unit inuse unit value weight inuse input from unit\n");
1216 bunit
= (UNIT
*) w
->backunit
;
1217 unitinuse
= w
->backunit
->inuse
;
1219 value
= *(w
->weight
);
1227 if (wtinuse
&& unitinuse
)
1229 input
= (INT32
) value
* bunit
->oj
;
1230 input
= input
/ 1024;
1234 if (wtinuse
&& unitinuse
) input
= value
* bunit
->oj
; else input
= 0;
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
));
1243 sprintf(outstr
," %3d ",wtinuse
); pg(stdout
,outstr
);
1244 sprintf(outstr
,"%14.5f\n",unscaleint(input
));
1245 if (pg(stdout
,outstr
)) return;
1249 sprintf(outstr
,"sum = %9.5f\n",unscaleint(sum
));
1250 if (pg(stdout
,outstr
)) return;
1252 for (i
=2;i
<=layerno
;i
++) layer
= layer
->next
;
1253 if (layer
->D
!= scale(1.0))
1256 sum
= sum
* layer
->D
/ 1024;
1258 sum
= sum
* layer
->D
;
1261 sprintf(outstr
,"sum = %9.5f with D = %7.3f\n",unscaleint(sum
),unscale(layer
->D
));
1262 if (pg(stdout
,outstr
)) return;
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");
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
);
1281 if (wtlimithit
) pg(f
,"*>>>>> WEIGHT LIMIT HIT <<<<<*\n");
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
);
1288 if (offby1
== '+') pg(f
," O+"); else pg(f
," O-");
1289 sprintf(outstr
," o%c P %d p%c ",outformat
,pagesize
,probtype
);
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
);
1296 for (i
=1;i
<=MAXFORMAT
-1;i
++)
1297 {sprintf(outstr
," %1d",format
[i
]); pg(f
,outstr
);};
1299 sprintf(outstr
,"! %s ",sysstr
); pg(f
,outstr
);
1300 if (f
!= stdout
) pg(f
,"\"\n"); else pg(f
,"\n");
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
);
1311 sprintf(outstr
,"d d %8.5f e %8.5f ",unscale(decay
),unscale(dbdeta
));
1313 sprintf(outstr
,"k %8.5f m %8.5f ",unscale(kappa
),unscale(etamax
));
1315 sprintf(outstr
,"t %8.5f\n",unscale(theta1
));
1317 sprintf(outstr
,"qp dh %8.6f do %8.6f e %8.5f ",qpdecayh
,qpdecayo
,unscale(qpeta
));
1319 sprintf(outstr
,"m %8.5f n %8.5f s%c\n",unscale(mu
),unscale(qpnoise
),qpslope
);
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
);
1332 sprintf(outstr
,"z %e",minimumsofar
); pg(f
,outstr
);
1342 case '?': parameters(stdout
); return;
1345 pg(stdout
,"\nAlgorithm Parameters\n\n");
1346 pg(stdout
,"a a <char> sets all act. functions to <char>; {ls} h aa\n");
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");
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");
1373 pg(stdout
," D delta-bar-delta parameters\n");
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");
1382 pg(stdout
," Q quickprop parameters\n");
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");
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");
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");
1437 for (i
=1;i
<=MAXFORMAT
-1;i
++)
1438 {sprintf(outstr
," %1d",format
[i
]); pg(stdout
,outstr
);};};
1440 pg(stdout
," h fB\n");
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");
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
));
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");
1493 pg(stdout
,"\nNetwork Information\n\n");
1494 printnetsize(stdout
);
1496 sprintf(outstr
," total weights: %1d\n",wttotal
);
1499 pg(stdout
,"l <layer> print the unit values in layer <layer>\n\n");
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
);
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");
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");
1569 pg(stdout
,"\nWeights Related Commands\n\n");
1570 pg(stdout
,"rw reads weights from the file "); pg(stdout
,wtfilename
);
1572 pg(stdout
,"sw saves weights to the file "); pg(stdout
,wtfilename
);
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
);
1579 pg(stdout
,"w <layer> <unit> list weights leading into this unit\n\n");
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
);
1590 sprintf(outstr
," total weights: %1d\n",wttotal
);
1594 if (wtlimithit
== 1)
1595 pg(stdout
,"\n >>>>> WEIGHT LIMIT HIT <<<<<\n");
1600 default: pg(stdout
,"not a screen item\n");
1609 do ch2
= readch(); while (ch2
== ' ' && ch2
!= '\n');
1612 default: menus('C'); return;
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");
1625 pg(stdout
,"bp xor\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");
1633 pg(stdout
,"se new\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");
1638 pg(stdout
,"bp new\n");
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");
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");
1656 pg(stdout
,"More?\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");
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");
1700 default: pg(stdout
,"not a help item\n\n");
1702 }; /* end the inner switch */
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");
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");
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");
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");
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");
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");
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");
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");
1821 pg(stdout
,"ci * ci for clear and initialize\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");
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");
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");
1844 do ch2
= readch(); while (ch2
== ' ');
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");
1869 pg(stdout
,"a u d gives the delta-bar-delta update method.\n");
1871 pg(stdout
,"a u p gives the periodic update method.\n");
1873 pg(stdout
,"a u q gives the quickprop update method.\n");
1876 else texterror(); /* end of the 'a' case */
1880 do ch2
= readch(); while (ch2
== ' ');
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");
1909 do ch2
= readch(); while (ch2
== ' ');
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");