home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume28 / backprop / part03 / io.c < prev    next >
C/C++ Source or Header  |  1992-02-23  |  25KB  |  973 lines

  1. /* ************************************************ */
  2. /* file io.c:  contains most input/output functions */
  3. /*                                                  */
  4. /* Copyright (c) 1991 by Donald R. Tveter           */
  5. /*                                                  */
  6. /* ************************************************ */
  7.  
  8. #include <stdio.h>
  9. #ifdef INTEGER
  10. #include "ibp.h"
  11. #else
  12. #include "rbp.h"
  13. #endif
  14.  
  15. #ifdef UNIX
  16. #include <malloc.h>
  17. #define WRITEBIN "w"
  18. #define READBIN "r"
  19. #else
  20. #include <stdlib.h>
  21. #define WRITEBIN "wb"
  22. #define READBIN "rb"
  23. #endif
  24.  
  25. extern char buffer[buffsize], copyflag, *datafilename, echo, outformat;
  26. extern char outstr[OUTSTRSIZE], *wtfile, wtformat;
  27. extern int bufferend, bufferptr, filestackptr, format[maxformat];
  28. extern FILE *data, *filestack[];
  29. extern LAYER *start;
  30. extern int lastsave, pagesize, readerror, readingpattern, totaliter;
  31. extern INT32 lineno;
  32. extern short nlayers;
  33. extern WTTYPE qmark, toler;
  34. extern FILE *copy;
  35.  
  36. WTTYPE error;
  37. int bad;
  38.  
  39. #ifdef INTEGER
  40.  
  41. short scale(x)     /* returns x as a scaled 16-bit value */
  42. REAL x;
  43. {
  44.  short s;
  45.  
  46. if (x > 31.999 || x < -32.0)
  47.  {
  48.   sprintf(outstr,"magnitude of %f is too large for the integer",x);
  49.   pg(outstr);
  50.   pg(" representation\n");
  51.   readerror = 1;
  52.   if (x > 31.999) return(MAXSHORT); else return(MINSHORT);
  53.  };
  54. if (x > 0.0) s = x * 1024 + 0.5;
  55. else s = x * 1024 - 0.5;
  56. if (x != 0.0 && s == 0)
  57.  {
  58.   sprintf(outstr,"warning:  magnitude of %f is too small for",x);
  59.   pg(outstr);
  60.   pg(" the integer representation\n");
  61.   return(0);
  62.  };
  63. return(s);
  64. }
  65.  
  66. REAL unscale(x)  /* returns the REAL value of short x */
  67. short x;
  68. { return((REAL) x / 1024.0); }
  69.  
  70. REAL unscaleint(x)  /* returns the REAL value of INT32 x */
  71. INT32 x;
  72. { return((REAL) x / 1024.0); }
  73.  
  74. #endif
  75.  
  76. int pushfile(filename)
  77. char *filename;
  78. {
  79. FILE *file;
  80.  
  81. bufferptr = 0;
  82. bufferend = 0;
  83. buffer[0] = '\n';
  84. file = fopen(filename,"r");
  85. if (file == NULL)
  86.  {
  87.   sprintf(outstr,"cannot open:, %s\n",filename); pg(outstr);
  88.   return(0);
  89.  };
  90. filestackptr = filestackptr + 1;
  91. if (filestackptr > 3)
  92.  {
  93.   pg("can't stack up any more files\n");
  94.   filestackptr = filestackptr - 1;
  95.   return(0);
  96.  };
  97. filestack[filestackptr] = file;
  98. data = file;
  99. return(1);
  100.  
  101. void popfile()
  102. {
  103. bufferptr = 0;
  104. bufferend = 0;
  105. buffer[0] = '\n';
  106. if (filestackptr > 0)
  107.  {
  108.   fclose(data);
  109.   filestackptr = filestackptr - 1;
  110.  }
  111. else pg("\nunexpected EOF:  to quit the program, type q\n");
  112. data = filestack[filestackptr];
  113. }
  114.  
  115. int readch() /* returns the next character in the input buffer */
  116.  int i, ch2;
  117.  
  118. if (bufferptr > bufferend) /* then read next line into buffer */
  119.  {
  120.   ch2 = getc(data);
  121.   if (ch2 == EOF) return(ch2);
  122.   i = 0;
  123.   while(ch2 != '\n' && i < buffsize)
  124.    {
  125.     if (ch2 == 13) ch2 = ' '; /* turn a ctrl-M into a blank */
  126.     buffer[i] = ch2;
  127.     i = i + 1;
  128.     ch2 = getc(data);
  129.    };
  130.   if (i == buffsize) pg("line too long\n");
  131.   buffer[i] = '\n';
  132.   bufferend = i;
  133.   bufferptr = 0;
  134.   if (echo == '+') for(i = 0; i <= bufferend; i++) putchar(buffer[i]);
  135.   if (copy && ((data == stdin) || (echo == '+')))
  136.    for (i=0;i<=bufferend;i++) putc(buffer[i],copy);
  137.  }
  138. ch2 = buffer[bufferptr];
  139. bufferptr = bufferptr + 1;
  140. return(ch2);
  141. }
  142.  
  143. void texterror()
  144. {
  145. int ch2;
  146. pg("unexpected text:  ");
  147. bufferptr = bufferptr - 1;
  148. do {ch2 = readch(); putchar(ch2);} while (ch2 != '\n');
  149. putchar('\n');
  150. bufferptr = bufferptr - 1;
  151. }
  152.  
  153. char *readstr()
  154. {
  155. short i,start,end;
  156. char *addr, *addr2;
  157. i = bufferptr;
  158. while (buffer[i] == ' ') i = i + 1;
  159. start = i;
  160. while (buffer[i] != ' ' && buffer[i] != '\n') i = i + 1;
  161. end = i-1;
  162. addr = (char *) malloc((int) end-start+2);
  163. addr2 = addr;
  164. for (i=start;i<=end;i++) *addr++ = buffer[i];
  165. bufferptr = end + 1;
  166. *addr = '\0';
  167. return(addr2);
  168. }
  169.  
  170. int scanfordigit()
  171. {
  172. int sign, ch2;
  173.  
  174. sign = 1;
  175.  
  176. restart:
  177. do ch2 = readch(); while (ch2 == ' ' || ch2 == '\n');
  178. if (ch2 >= '0' && ch2 <= '9')
  179.  {
  180.   bufferptr = bufferptr - 1;
  181.   return(sign);
  182.  };
  183. if (ch2 >= 'h' && ch2 <= 'k')
  184.  {
  185.   bufferptr = bufferptr - 1;
  186.   return(0);
  187.  };
  188.           switch (ch2) {
  189. case EOF: readerror = 2;
  190.           return(0);
  191. case '*': while (ch2 != '\n') ch2 = readch();
  192.           goto restart;
  193. case '-': sign = -sign;
  194.           goto restart;
  195. case '?': bufferptr = bufferptr - 1;
  196.           return(0);
  197. default:  readerror = 1;
  198.           return(0);
  199.           };
  200. }
  201.  
  202. int readint(min,max,command)
  203. int min, max;
  204. char command;
  205. {
  206. int sign, number, ch2;
  207.  
  208. readerror = 0;
  209. sign = scanfordigit();
  210. if (readerror)
  211.  {
  212.   if (readerror == 1) texterror();
  213.   return(0);
  214.  };
  215. number = 0;
  216. do ch2 = readch(); while (ch2 == ' ');
  217. while (ch2 >= '0' && ch2 <= '9')
  218.  {
  219.   number = number * 10 + (ch2 - '0');
  220.   ch2 = readch();
  221.  };
  222. bufferptr = bufferptr - 1;
  223. number = sign * number;
  224. if (number < min || number > max)
  225.  {
  226.   sprintf(outstr,"out of range value: %d",number); pg(outstr);
  227.   if (data == stdin) pg("\n");
  228.   else {sprintf(outstr," in %c command\n",command); pg(outstr);};
  229.   readerror = 1;
  230.  };
  231. return(number);
  232. }
  233.  
  234. REAL readreal(op,min,command)
  235. int op;
  236. REAL min;
  237. int command;
  238. {
  239. REAL number, fractpart, divisor, intpart, sign;
  240. int ch2;
  241.  
  242. readerror = 0;
  243. sign = (REAL) scanfordigit();
  244. if (readerror || (sign == 0 && !readingpattern))
  245.  {
  246.   if (readerror == 1) texterror();
  247.   return(0);
  248.  };
  249. ch2 = readch();
  250. if (ch2 == 'h' && readingpattern) return(unscale(HCODE));
  251. else if (ch2 == 'i' && readingpattern && nlayers >= 3)
  252.   return(unscale(ICODE));
  253. else if (ch2 == 'j' && readingpattern && nlayers >= 4)
  254.   return(unscale(JCODE));
  255. else if (ch2 == 'k' && readingpattern && nlayers >= 5)
  256.   return(unscale(KCODE));
  257. else if (ch2 == '?' && readingpattern)
  258.   return(unscale(qmark));
  259. intpart = 0.0;
  260. while (ch2 >= '0' && ch2 <= '9')
  261.  {
  262.   intpart = 10.0 * intpart + (ch2 - '0');
  263.   ch2 = readch();
  264.  };
  265. fractpart = 0.0;
  266. divisor = 1.0;
  267. if (ch2 == '.')
  268.  {
  269.   ch2 = readch();
  270.   while (ch2 >= '0' && ch2 <= '9')
  271.    {
  272.     fractpart = fractpart * 10.0 + (ch2 - '0');
  273.     divisor = divisor * 10.0;
  274.     ch2 = readch();
  275.    };
  276.  };
  277. bufferptr = bufferptr - 1;
  278. number = sign * (((REAL) intpart) +
  279.                 ((REAL) fractpart) / ((REAL) divisor));
  280. if (op == GT && number > min) return(number);
  281. else if (op == GE && number >= min) return(number);
  282. else
  283.  {
  284.   sprintf(outstr,"erroneous value: %f",number); pg(outstr);
  285.   if (data == stdin) pg("\n");
  286.   else {sprintf(outstr," in %c command\n",command); pg(outstr);};
  287.   readerror = 1;
  288.   return(0.0);
  289.  };
  290. }
  291.  
  292. WTTYPE rdr(op,min,command) /* reads REAL real numbers and converts */
  293. int op;                    /* them to 16-bit integers if necessary */
  294. REAL min;
  295. int command;
  296. {
  297. REAL x;
  298. WTTYPE ix;
  299.  
  300. x = readreal(op,min,command);
  301. if (readerror) return(0);
  302. ix = scale(x);
  303. if (readerror) return(0);
  304. return(ix);
  305. }
  306.  
  307. REAL readchar()   /* reads data in compressed format */
  308. {
  309. int ch2;
  310. readerror = 0;
  311. ch2 = readch();
  312. do {
  313.           switch (ch2) {
  314. case '\n':
  315. case ' ': ch2 = readch();
  316.           break;
  317. case '1': return(1.0);
  318. case '0': return(0.0);
  319. case '?': return(unscale(qmark));
  320. case '*': do ch2 = readch(); while(ch2 != '\n');
  321.           break;
  322. case 'h': return(unscale(HCODE));
  323. case 'i': if (nlayers >= 3) return(unscale(ICODE));
  324. case 'j': if (nlayers >= 4) return(unscale(JCODE));
  325. case 'k': if (nlayers >= 5) return(unscale(KCODE));
  326. case EOF: readerror = 2;
  327.           return(0.0);
  328. default:  texterror();
  329.           readerror = 1;
  330.           return(0.0);};
  331. } while (0 == 0);
  332. }
  333.  
  334. int pg(str) /* paging and making a copy function */
  335. char *str;
  336. {
  337. char *ch3,action,cr;
  338. int copying;
  339.  
  340. copying = copyflag == '+';
  341. ch3 = str;
  342. while (*ch3 != '\0')
  343.    {
  344.      if (*ch3 == '\n')
  345.         {
  346.           putchar('\n');
  347.           if (copying) putc('\n',copy);
  348. #ifndef UNIX
  349.           putchar('\r');
  350.           if (copying) putc('\r',copy);
  351.           if (*ch3++ != '\r') ch3--;
  352. #endif
  353.           lineno = lineno + 1;
  354.           if (pagesize && lineno % pagesize == 0)
  355.              {
  356.                putchar(':');
  357.                action = getchar();
  358.                if (action == 'q')
  359.                   {
  360.                     cr = getchar();
  361.                     return(action);
  362.                   };
  363.              }
  364.         }
  365.      else {putchar(*ch3); if (copying) putc(*ch3,copy); };
  366.      ch3++;
  367.    };
  368. return(0);
  369. }
  370.  
  371. int printoutunits(printing,layer,printerr)  /* prints values of units */
  372. int printing;                               /* and computes errors */
  373. LAYER *layer;
  374. int printerr;
  375. {
  376. short unitno, fmtbreaknum, maxval, maxunit;
  377. UNIT *u;
  378. WTTYPE upper, middle, diff;
  379.  
  380. if (printing)
  381.  {
  382.   upper = scale(1.0) - toler;
  383.   middle = scale(0.5);
  384.   unitno = 0;
  385.   fmtbreaknum = 1;
  386.  };
  387. bad = 0;
  388. maxval = -scale(2.0);
  389. maxunit = 0;
  390. error = 0;
  391. u = (UNIT *) layer->units;
  392. while (u != NULL)
  393.  {
  394.   diff = u->tj - u->oj;
  395.   if (diff < 0) diff = -diff;
  396.   if (diff >= toler) bad = 1;
  397.   error = error +  diff;
  398.   if (printing)
  399.    {
  400.     unitno = unitno + 1;
  401.     if (outformat == 'r')
  402.      {
  403.       sprintf(outstr,"%5.2f ",unscale(u->oj)); pg(outstr);
  404.       if (format[fmtbreaknum] == unitno)
  405.        {
  406.         if (pg("\n    ")) return(1);
  407.         if (fmtbreaknum < maxformat - 1) fmtbreaknum = fmtbreaknum + 1;
  408.        }
  409.      }
  410.     else if (outformat == 'a' && printerr)
  411.      {
  412.       if (diff < toler) pg("c");
  413.       else if (u->oj > upper) pg("1");
  414.       else if (u->oj < toler) pg("0");
  415.       else if (u->oj > u->tj) pg("^");
  416.       else pg("v");
  417.       if (format[fmtbreaknum] == unitno)
  418.        {
  419.         pg(" ");
  420.         if (fmtbreaknum < maxformat - 1) fmtbreaknum = fmtbreaknum + 1;
  421.        }
  422.      }
  423.     else 
  424.      {
  425.       if (u->oj > upper) pg("1");
  426.       else if (u->oj > middle) pg("^");
  427.       else if (u->oj < toler) pg("0");
  428.       else pg("v");
  429.       if (format[fmtbreaknum] == unitno)
  430.        {
  431.         pg(" ");
  432.         if (fmtbreaknum < maxformat - 1) fmtbreaknum = fmtbreaknum + 1;
  433.        }
  434.      }
  435.    };
  436.   u = u->next;
  437.  };
  438. if (!printing) return(0);
  439. if (printerr) {sprintf(outstr," (%5.3f)",unscale(error)); pg(outstr);};
  440. if (printerr && !bad) pg(" ok");
  441. if (pg("\n")) return(1); else return(0);
  442. }
  443.  
  444. void saveweights()    /* saves weights on the file weights */
  445. {
  446. UNIT *u;
  447. LAYER *layer;
  448. WTNODE *w;
  449. WTTYPE wvalue, evalue, dvalue, svalue;
  450. int wtsize;
  451. FILE *weights;
  452.  
  453. wtsize = WTSIZE;
  454. weights = fopen(wtfile,WRITEBIN);
  455. if (weights == NULL)
  456.  {
  457.   sprintf(outstr,"cannot open: %s\n",wtfile); pg(outstr);
  458.   return;
  459.  };
  460. fprintf(weights,"%d%c",totaliter,wtformat);
  461. if (wtformat == 'b' || wtformat == 'B') fprintf(weights,"%1d",WTSIZE);
  462. fprintf(weights,"   file = %s\r\n",datafilename);
  463. layer = start->next;
  464. while (layer != NULL)
  465.  {
  466.   u = (UNIT *) layer->units;
  467.   while (u != NULL)
  468.    {
  469.     w = (WTNODE *) u->wtlist;
  470.     while (w != NULL)
  471.      {
  472. #ifdef SYMMETRIC
  473.       wvalue = *(w->weight);
  474.       evalue = *(w->eta);
  475.       dvalue = *(w->olddw);
  476.       svalue = 0; /* not worth having in the symmetric version */
  477. #else
  478.       wvalue = w->weight;
  479.       evalue = w->eta;
  480.       dvalue = w->olddw;
  481.       svalue = w->slope;
  482. #endif
  483.       if (wtformat == 'r' || wtformat == 'R')
  484.        {
  485.         fprintf(weights,"%16.10f",unscale(wvalue));
  486.         if (wtformat == 'R')
  487.          {
  488.           fprintf(weights," %16.10f",unscale(evalue));
  489.           fprintf(weights," %16.10f",unscale(dvalue));
  490. #ifdef NEXTVERSION
  491.           fprintf(weights," %16.10f",unscale(svalue));
  492. #endif
  493.          };
  494.         fprintf(weights,"\r\n");
  495.        }
  496.       else  /* binary format; uses the least space */
  497.        {
  498.         fwrite((char *) &wvalue,wtsize,1,weights);
  499.         if (wtformat == 'B')
  500.          {
  501.           fwrite((char *) &evalue,wtsize,1,weights);
  502.           fwrite((char *) &dvalue,wtsize,1,weights);
  503. #ifdef NEXTVERSION
  504.           fwrite((char *) &svalue,wtsize,1,weights);
  505. #endif
  506.          };
  507.        };
  508.       w = w->next;
  509.      };
  510.     u = u->next;
  511.    };
  512.   layer = layer->next;
  513.  };
  514. fflush(weights);
  515. fclose(weights);
  516. lastsave = totaliter;
  517. }
  518.  
  519. WTTYPE rdb(wtfile,wtsize) /* read binary and convert between sizes */
  520. FILE *wtfile;
  521. int wtsize;
  522. {
  523. int i, ch2;
  524. double dvalue;
  525. float fvalue;
  526. short ivalue;
  527. unsigned char *charptr;
  528.  
  529. if (wtsize == 2) charptr = (unsigned char *) &ivalue;
  530. else if (wtsize == 4) charptr = (unsigned char *) &fvalue;
  531. else if (wtsize == 8) charptr = (unsigned char *) &dvalue;
  532. else pg("bad weight size\n");
  533. for (i=1;i<=wtsize;i++)
  534.  {
  535.   ch2 = fgetc(wtfile);
  536.   *charptr = (unsigned char) ch2;
  537.   charptr++;
  538.  };
  539. if (WTSIZE == 2 && wtsize == 2) return(ivalue);
  540. else if (WTSIZE == 2 && wtsize == 4) return(scale(fvalue));
  541. else if (WTSIZE == 2 && wtsize == 8) return(scale(dvalue));
  542. else if (WTSIZE == 4 && wtsize == 2) return(ivalue / 1024.0);
  543. else if (WTSIZE == 4 && wtsize == 4) return(fvalue);
  544. else if (WTSIZE == 4 && wtsize == 8) return((float) dvalue);
  545. else if (WTSIZE == 8 && wtsize == 2) return(ivalue / 1024.0);
  546. else if (WTSIZE == 8 && wtsize == 4) return((double) fvalue);
  547. else if (WTSIZE == 8 && wtsize == 8) return(dvalue);
  548. }
  549.  
  550. void restoreweights()    /* restore weights from the file weights */
  551. {
  552. FILE *weights;
  553. UNIT *u;
  554. LAYER *layer;
  555. WTNODE *w;
  556. int ch2, fileformat, wtsize;
  557. WTTYPE wvalue, evalue, dvalue, svalue;
  558. double temp;
  559.  
  560. weights = fopen(wtfile,READBIN);
  561. if (weights == NULL)
  562.  {
  563.   pg("cannot open file weights\n");
  564.   return;
  565.  };
  566. fscanf(weights,"%d",&totaliter);
  567. fileformat = getc(weights);
  568. if (fileformat != wtformat) pg("note: weight format mismatch\n");
  569. if (fileformat == 'b' || fileformat == 'B')
  570.  {
  571.   wtsize = getc(weights) - '0';
  572.   if (WTSIZE != wtsize) pg("note: weight sizes mismatched\n");
  573.  }
  574. else wtsize = WTSIZE;
  575. do ch2 = getc(weights); while (ch2 != '\n'); /* skip rest of line */
  576. layer = start->next;
  577. while (layer != NULL)
  578.  {
  579.   u = (UNIT *) layer->units;
  580.   while (u != NULL)
  581.    {
  582.     w = (WTNODE *) u->wtlist;
  583.     while (w != NULL)
  584.      {
  585.       if (fileformat == 'r' || fileformat == 'R')
  586.        {
  587.         fscanf(weights,"%lf",&temp);
  588.         wvalue = scale((REAL) temp);
  589.         if (fileformat == 'R')
  590.          {
  591.           fscanf(weights,"%lf",&temp);
  592.           evalue = scale((REAL) temp);
  593.           fscanf(weights,"%lf",&temp);
  594.           dvalue = scale((REAL) temp);
  595. #ifdef NEXTVERSION
  596.           fscanf(weights,"%lf",&temp);
  597.           svalue = scale((REAL) temp);
  598. #endif
  599.          };
  600.        }
  601.       else
  602.        {
  603.         wvalue = rdb(weights,wtsize);
  604.         if (fileformat == 'B')
  605.          {
  606.           evalue = rdb(weights,wtsize);
  607.           dvalue = rdb(weights,wtsize);
  608. #ifdef NEXTVERSION
  609.           svalue = rdb(weights,wtsize);
  610. #endif
  611.          };
  612.        };
  613. #ifdef SYMMETRIC
  614.       *(w->weight) = wvalue;
  615.       if (fileformat == 'R' || fileformat == 'B')
  616.        {
  617.         *(w->olddw) = dvalue;
  618.         *(w->eta) = evalue;
  619.        }
  620.       else *(w->olddw) = 0;
  621. #else
  622.       w->weight = wvalue;
  623.       if (fileformat == 'R' || fileformat == 'B')
  624.        {
  625.         w->olddw = dvalue;
  626.         w->eta = evalue;
  627.         w->slope = svalue;
  628.        }
  629.       else w->olddw = 0;
  630. #endif
  631.       w = w->next;
  632.      };
  633.     u = u->next;
  634.    };
  635.   layer = layer->next;
  636.  };
  637. fclose(weights);
  638. }
  639.  
  640. void printweights(u)   /* print the weights leading into unit u */
  641. UNIT *u;
  642.  
  643. {
  644. WTNODE *w;
  645. UNIT *bunit;
  646. WTTYPE value;
  647. #ifdef INTEGER
  648. INT32 sum, input;
  649. #else
  650. REAL sum, input;
  651. #endif
  652.  
  653. w = (WTNODE *) u->wtlist;
  654. sum = 0;
  655. pg("layer unit  unit value     weight         input from unit\n");
  656. while (w != NULL)
  657.  {
  658.   bunit = (UNIT *) w->backunit;
  659. #ifdef SYMMETRIC
  660.   value = *(w->weight);
  661. #else
  662.   value = w->weight;
  663. #endif
  664.  
  665. #ifdef INTEGER
  666.   input = (INT32) value * bunit->oj;
  667.   input = input / 1024;
  668. #else
  669.   input = value * bunit->oj;
  670. #endif
  671.   sum = sum + input;
  672.   sprintf(outstr,"%3d   ",bunit->layernumber); pg(outstr);
  673.   if (bunit->unitnumber == 32767) pg("   t ");
  674.   else {sprintf(outstr,"%4d ",bunit->unitnumber); pg(outstr);};
  675.   sprintf(outstr,"%10.5f  %10.5f  ",unscale(bunit->oj),unscale(value));
  676.   pg(outstr);
  677.   sprintf(outstr,"%18.5f\n",unscaleint(input));
  678.   if (pg(outstr)) return;
  679.   w = w->next;
  680.  };
  681. pg("                                      ");
  682. sprintf(outstr,"sum = %9.5f\n\n",unscaleint(sum)); pg(outstr);
  683. }
  684.  
  685. void help()
  686. {
  687. int ch2;
  688. pg("\n");
  689. do ch2 = readch(); while (ch2 == ' ' && ch2 != '\n');
  690.         switch(ch2) {
  691.  
  692. default:
  693. pg("for help type h followed by the letter of the command\n");
  694. if (ch2 == '\n') bufferptr = bufferptr - 1;
  695. break;
  696.  
  697. case '?':
  698. pg("? prints program status and parameters.\n");
  699. break;
  700.  
  701. case '*':
  702. pg("* at the beginning of a line makes the line a comment.\n");
  703. break;
  704.  
  705. case '!':
  706. pg("Enter system commands after the !.\n");
  707. break;
  708.  
  709. case 'A':
  710. pg("A is used to set details of the algorithm.  One or more of \n");
  711. pg("the following commands can go on the same line as the 'A':\n\n");
  712. pg("a l sets the linear activation function.\n");
  713. pg("a p sets the piecewise linear activation function.\n");
  714. pg("a t sets the piecewise near tanh activation function.\n");
  715. #ifndef INTEGER
  716. pg("a s sets the smooth activation function.\n");
  717. pg("a T sets the smooth near tanh activation function.\n");
  718. #endif
  719. pg("\n");
  720. pg("b + will backpropagate errors even when a unit is close to ");
  721. pg("its target.\n");
  722. pg("b - will not backpropagate errors when a unit is close to its");
  723. pg(" target.\n\n");
  724. pg("D <real> will set the sharpness of the sigmoid to <real>.\n\n");
  725. pg("d d will use the derivatives from the differential step size");
  726. pg(" algorithm.\n");
  727. pg("d F uses Fahlman's derivative in the output layer.\n");
  728. pg("d f uses Fahlman's derivative in all layers.\n");
  729. pg("d o uses the original derivative.\n\n");
  730. pg("g <int> updates weights after every group of <int> patterns if <int> != 0.\n\n");
  731. pg("s <int> will skip for <int> iterations patterns that have been ");
  732. pg("learned.\n\n");
  733. pg("t <int> will take pattern <int> out of the training process.\n");
  734. pg("   To bring it back in, use t 0.\n\n");
  735. pg("u c gives the continuous update method.\n");
  736. #ifndef SYMMETRIC
  737. pg("u d gives the delta-bar-delta update method.\n");
  738. #endif
  739. pg("u p gives the periodic update method.\n");
  740. break;
  741.  
  742. case 'a':
  743. pg("a <real> sets the momentum parameter, alpha, to <real>.\n");
  744. break;
  745.  
  746. case 'B':
  747. pg("B <options> sets the following benchmarking options:\n\n");
  748. pg("g <int> sets <int> to be the goal for the number of");
  749. pg(" networks to converge.\n\n");
  750. pg("k <real> sets the range of the initial random");
  751. pg(" weights for each network.\n\n");
  752. pg("m <int> sets the maximum number of networks to try.\n\n");
  753. pg("r <int1> <int2> sets <int1> to be the maximum ");
  754. pg("number of iterations to run.\n  <int2>, if present,");
  755. pg(" sets the rate at which to sample the network.\n  ");
  756. pg("Using r in a B command will initiate benchmarking.\n\n");
  757. pg("t <int> will benchmark with pattern <int> removed");
  758. pg(" from the training set\n  and test it at the");
  759. pg(" sample rate given in the r command.\n");
  760. pg("t f <testfile> will test patterns on <testfile> at ");
  761. pg("the interval given for\n   the sample rate.\n");
  762. pg("t 0 turns off either type of testing.\n");
  763. break;
  764.  
  765. case 'b':
  766. pg("b <int1> <int2> ... <int20> puts a carriage break");
  767. pg(" after each <inti>\nvalues when the output format");
  768. pg(" is real and inserts a blank after each <inti>\n");
  769. pg("value if the format is condensed.\n");
  770. break;
  771.  
  772. case 'C':
  773. pg("C clears the network and other relevant parameters");
  774. pg(" so the problem can be re-run\nwith different");
  775. pg(" initial weights.  Added hidden units are not removed.\n");
  776. break;
  777.  
  778. #ifndef SYMMETRIC
  779. case 'c':
  780. pg("c <int1> <int2> <int3> <int4>  ");
  781. pg("Adds a connection from layer <int1> unit <int2>\n");
  782. pg("   to layer <int3> unit <int4>.\n");
  783. break;
  784. #endif
  785.  
  786. case 'd':
  787. pg("d is used to set parameters for the delta-bar-delta method.\n");
  788. pg("One or more of the following commands can go on the line:\n\n");
  789. pg("d <real> sets the decay factor to <real>.\n");
  790. pg("e <real> sets the initial eta value to <real>.\n");
  791. pg("k <real> sets kappa to <real>.\n");
  792. pg("m <real> limits the maximum value of each eta to <real>.\n");
  793. #ifdef INTEGER
  794. pg("n <real> sets some noise (integer versions only).");
  795. pg("   Try <real> around 0.005.\n");
  796. #endif
  797. pg("t <real> sets the theta parameter to <real>.\n");
  798. break;
  799.  
  800. case 'e':
  801. pg("e <real1> <real2> sets eta, the learning rate for the top layer");
  802. pg(" to <real1>\n   and eta2 for the lower layers to <real2>.  If ");
  803. pg("<real2> is not present,\n   eta2 is set to <real1>.\n");
  804. break;
  805.  
  806. case 'f':
  807. pg("f is used to set the input and output formats for data.\nOne ");
  808. pg("or more of the following commands can go on the line:\n\n");
  809. pg("b + will ring the bell when learning is complete.\n");
  810. pg("b - will not ring the bell when learning is complete.\n\n");
  811. pg("c + will copy i/o to the file, copy.\n");
  812. pg("c - will stop writing to the file, copy.\n\n");
  813. pg("e + echos the input.\ne - does not echo.\n\n");
  814. pg("i c will read pattern values using compressed format.\n");
  815. pg("i r will read pattern values as reals.\n\n");
  816. pg("o a will write node values as analog compressed.\n");
  817. pg("o c will write node values as compressed.\n");
  818. pg("o r will write node values as real.\n\n");
  819. pg("P <int> sets the page size to <int>; 0 means no paging.\n\n");
  820. pg("p c will read patterns in the classification format and ");
  821. pg("summarize the results\n    when testing.\n");
  822. pg("p C will read patterns in the classification format and ");
  823. pg("print every result\n    when testing.\n");
  824. pg("p g will accept general patterns and summarize results when ");
  825. pg("testing.\n");
  826. pg("p G will accept general patterns and print every result when ");
  827. pg("testing.\n\n");
  828. pg("s + will summarize learning status.\n");
  829. pg("s - will not summarize learning status and will");
  830. pg(" list each pattern.\n\n");
  831. pg("u + will give up-to-date statistics on learning.\n");
  832. pg("u - will give statistics one iteration out of date.\n\n");
  833. pg("w b will write the weights as binary.\n");
  834. pg("w B will write the weights, weight changes and etas as binary.\n");
  835. pg("w r will write the weights as real values.\n");
  836. pg("w R will write the weights, weight changes and etas as real");
  837. pg(" values.\n");
  838. break;
  839.  
  840. #ifndef SYMMETRIC
  841. case 'H':
  842. pg("H <int> <real> adds a hidden unit to layer <int>\n");
  843. pg("Weights are initialized to between -<real> and +<real>.\n");
  844. break;
  845. #endif
  846.  
  847. case 'h':
  848. pg("h <letter> gives help for command <letter>.\n");
  849. break;
  850.  
  851. case 'i':
  852. pg("i <inputfile> takes commands from the file.\n");
  853. pg("i takes commands from the current input file.\n");
  854. break;
  855.  
  856. case 'k':
  857. pg("k <real1> <real2> decreases all the weights in the ");
  858. pg("network whose values\nare greater than <real1> by a");
  859. pg(" random amount between 0 and <real2>.\nWeights ");
  860. pg("less than -<real1> are increased by an amount ");
  861. pg("between 0 and <real2>.\nIf <real1> = 0.0, and a ");
  862. pg("weight = 0.0 then the weight is changed to\na ");
  863. pg("random value between -<real2> and +<real2>.\n");
  864. break;
  865.  
  866. case 'l':
  867. pg("l <int> prints values of nodes on layer <int>.\n");
  868. break;
  869.  
  870. case 'm':
  871. pg("m <int1> <int2> ... <intn> makes a network with\n");
  872. pg("<int1> units in the first layer, <int2> units in\n");
  873. pg("the second layer, ... , <intn> units in the nth layer.\n");
  874. break;
  875.  
  876. case 'n':
  877. pg("n <int> <in1> <out1> ... <ini> <outi> ... <inN> <outN>");
  878. pg(" replaces all\n   training patterns with <int> new ones.\n");
  879. pg("n f <trainfile> reads however many patterns there are on");
  880. pg(" the file.\n");
  881. break;
  882.  
  883. case 'O':
  884. pg("O <int> will give the output targets for pattern, <int>.\n");
  885. break;
  886.  
  887. case 'o':
  888. pg("o a outputs node values in analog compressed form.");
  889. pg("\no c outputs node values in compressed form.\n");
  890. pg("o r outputs node values as real.\n");
  891. break;
  892.  
  893. case 'P':
  894. pg("P lists the outputs for all patterns.\n");
  895. pg("P <int> gives the output for pattern <int>.\n");
  896. pg("P0 gives an up-to-date summary of learning.\n");
  897. break;
  898.  
  899. case 'p':
  900. pg("p <pat> submits the pattern, <pat>, to the input units.\n");
  901. break;
  902.  
  903. case 'Q':
  904. pg("Q <real> sets the value of ? in input patterns to <real>.\n");
  905. break;
  906.  
  907. case 'q':
  908. pg("q ends the program.\n");
  909. break;
  910.  
  911. case 'R':
  912. pg("R restores weights from the current weights file\n");
  913. break;
  914.  
  915. case 'r':
  916. pg("r <int1> <int2> runs <int1> iterations thru the ");
  917. pg("patterns.  If <int2> is\npresent, the patterns are ");
  918. pg("printed (or summarized) every <int2> iterations.\n\n");
  919. pg("rw <filename> reads weights from the file, <filename> and sets ");
  920. pg("<filename>\n             to be the current weights file.\n");
  921. pg("rw reads weights from the current weights file.\n");
  922. break;
  923.  
  924. case 'S':
  925. pg("S <int> saves the weights on the current weights file every <int>");
  926. pg(" iterations.\nS or S 0 saves the weights immediately.\n");
  927. break;
  928.  
  929. case 's':
  930. pg("s <int1> <int2> ... <intn> sets the random number seeds.\n\n");
  931. pg("sw <filename> saves weights to the file, <filename> and sets ");
  932. pg("<filename>\n              to be the current weights file.\n");
  933. pg("sw saves weights to the current weights file.\n");
  934. break;
  935.  
  936. #ifdef SYMMETRIC
  937. case 'T':
  938. pg("T <real> freezes all threshold weights at <real>.\n");
  939. break;
  940. #endif
  941.  
  942. case 't':
  943. pg("t <real> sets <real> as the tolerance used in checking for");
  944. pg(" complete learning.\n");
  945. pg("t f <testfile> tests the patterns on the file.\n");
  946. pg("t f tests the patterns on the current test file.\n");
  947. pg("t tests the patterns on the current test file.\n");
  948. break;
  949.  
  950. #ifndef SYMMETRIC
  951. case 'W':
  952. pg("W <real> removes links whose weights are less than ");
  953. pg("the absolute value\nof <real>, except links to ");
  954. pg("threshold units are not removed.\n");
  955. break;
  956. #endif
  957.  
  958. case 'w':
  959. pg("w <int1> <int2>  ");
  960. pg("prints weights into unit <int2> in layer <int1>.\n");
  961. break;
  962.  
  963. case 'x':
  964. pg("x <int1> <in1> <out1> ... <ini> <outi> ... <inN> <outN>  adds");
  965. pg(" the extra\n   <int1> patterns.\n");
  966. pg("x f <trainfile> adds the extra patterns found on the file.\n");
  967. break;
  968.      }; /* end switch */
  969. pg("\n");
  970. }
  971.