home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume14 / back-prop / part03 / io.c < prev    next >
C/C++ Source or Header  |  1990-09-15  |  24KB  |  774 lines

  1. /* ************************************************ */
  2. /* file io.c:  contains most input/output functions */
  3. /*                                                  */
  4. /* Copyright (c) 1990 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. extern char buffer[buffsize];
  16. extern int bufferend;
  17. extern int bufferptr;
  18. extern int ch;
  19. extern FILE *data;
  20. extern char datafilename[50];
  21. extern int echo;
  22. extern int format[maxformat];
  23. extern LAYER *last;
  24. extern int lastsave;
  25. extern short nlayers;
  26. extern char outformat;
  27. extern WTTYPE qmark;
  28. extern int readerror;
  29. extern int readingpattern;
  30. extern LAYER *start;
  31. extern WTTYPE toler;
  32. extern int totaliter;
  33. extern char wtformat;
  34.  
  35. #ifdef INTEGER
  36.  
  37. short scale(x)     /* returns x as a scaled 16-bit value */
  38. double x;
  39. {
  40.   short s;
  41.   if (x > 31.999 || x < -32.0)
  42.      {
  43.        printf("magnitude of %lf is too large for the integer",x);
  44.        printf(" representation\n",x);
  45.        readerror = 1;
  46.        return(0);
  47.      };
  48.   if (x > 0.0) s = x * 1024 + 0.5;
  49.   else s = x * 1024 - 0.5;
  50.   if (x != 0.0 && s == 0)
  51.      {
  52.        printf("warning:  magnitude of %lf is too small for",x);
  53.        printf(" the integer representation\n");
  54.        return(0);
  55.      };
  56.   return(s);
  57. }
  58.  
  59. double unscale(x)  /* returns the double value of short x */
  60. short x;
  61. {
  62.   double temp;
  63.   temp = (double) x / 1024.0; 
  64.   return(temp);
  65. }
  66.  
  67. double unscaleint(x)  /* returns the double value of int x */
  68. int x;
  69. {
  70.   double temp;
  71.   temp = (double) x / 1024.0; 
  72.   return(temp);
  73. }
  74.  
  75. #endif
  76.  
  77. int readch() /* returns the next character in the input buffer */
  78.   int i, ch2;
  79.   if (bufferptr > bufferend) /* then read next line into buffer */
  80.      {
  81.        ch2 = getc(data);
  82.        if (ch2 == EOF) return(ch2);
  83.        i = 0;
  84.        while(ch2 != '\n' && i < buffsize)
  85.           {
  86.             if (ch2 == 015) ch2 = ' '; /* filter out carriage returns */
  87.             buffer[i] = ch2;
  88.             i = i + 1;
  89.             ch2 = getc(data);
  90.           };
  91.        if (i == buffsize)
  92.           {
  93.             printf("line too long\n");
  94.             exit(4);
  95.           };
  96.        buffer[i] = '\n';
  97.        bufferend = i;
  98.        bufferptr = 0;
  99.        if (echo == 1)
  100.           for(i = 0; i <= bufferend; i++) putchar(buffer[i]);
  101.       }
  102.   ch2 = buffer[bufferptr];
  103.   bufferptr = bufferptr + 1;
  104.   return(ch2);
  105. }
  106.  
  107. void texterror() /* handles errors in text */
  108. {
  109.  printf("unexpected text:  ");
  110.  bufferptr = bufferptr - 1;
  111.  ch = readch();
  112.  while (ch != '\n')
  113.     {
  114.       putchar(ch);
  115.       ch = readch();
  116.     };
  117.  putchar('\n');
  118.  bufferptr = bufferptr - 1;
  119. }
  120.  
  121. int scanfordigit()    /* used to scan for the leading */
  122. {                     /* digit of a number and trap mistakes */
  123.  int sign;
  124.  
  125.  sign = 1;
  126. restart:
  127.  ch = readch();
  128.  while (ch == ' ' || ch == '\n') ch = readch();
  129.  if (ch >= '0' && ch <= '9')
  130.     {
  131.       bufferptr = bufferptr - 1; /* unget the character */
  132.       return(sign);
  133.     };
  134.  if (ch >= 'h' && ch <= 'k')
  135.     {
  136.       bufferptr = bufferptr - 1; /* unget the character */
  137.       return(0);
  138.     };
  139.           switch (ch) {
  140. case EOF: printf("unexpected EOF\n");
  141.           exit(2);
  142. case '*': while (ch != '\n') ch = readch();
  143.           goto restart;
  144. case '-': sign = -sign;
  145.           goto restart;
  146. case '?': bufferptr = bufferptr - 1; /* unget the character */
  147.           return(0);
  148. default:  readerror = 1;
  149.           return(0);
  150.           }; /* end switch */
  151. };
  152.  
  153. int readint(min,max,command)
  154. int min, max;   /* the minimum and maximum allowed values */
  155. char command;
  156. {
  157.   int sign, number;
  158.   readerror = 0;
  159.   sign = scanfordigit();
  160.   if (readerror == 1 || sign == 0)
  161.      {
  162.        readerror = 1;
  163.        texterror();
  164.        return(0);
  165.      };
  166.   number = 0;
  167.   ch = readch();
  168.   while (ch == ' ') ch = readch();
  169.   while (ch >= '0' && ch <= '9')
  170.      {
  171.        number = number * 10 + (ch - '0');
  172.        ch = readch();
  173.      };
  174.   bufferptr = bufferptr - 1; /* unget the character */
  175.   number = sign * number;
  176.   if (number < min || number > max)
  177.      {
  178.        printf("erroneous value: %d",number);
  179.        if (data == stdin) putchar('\n');
  180.        else printf(" in %c command\n",command);
  181.        readerror = 1;
  182.      };
  183.   return(number);
  184. }
  185.  
  186. double readreal(op,min,command)
  187. int op;
  188. double min;
  189. int command;
  190. {
  191.   double number;
  192.   double fractpart, divisor, intpart, sign;
  193.   readerror = 0;
  194.  
  195.   sign = (double) scanfordigit();
  196.   if (readerror == 1 || (sign == 0 && !readingpattern))
  197.      {
  198.        texterror();
  199.        return(0);
  200.      };
  201.   ch = readch();
  202.   if (ch == 'h' && readingpattern)
  203.      return(unscale(HCODE));
  204.   else if (ch == 'i' && readingpattern && nlayers >= 3)
  205.           return(unscale(ICODE));
  206.   else if (ch == 'j' && readingpattern && nlayers >= 4)
  207.           return(unscale(JCODE));
  208.   else if (ch == 'k' && readingpattern && nlayers >= 5)
  209.           return(unscale(KCODE));
  210.   else if (ch == '?' && readingpattern)
  211.           return(unscale(qmark));
  212.   intpart = 0.0;
  213.   while (ch >= '0' && ch <= '9')
  214.      {
  215.        intpart = 10.0 * intpart + (ch - '0');
  216.        ch = readch();
  217.      };
  218.   fractpart = 0.0;
  219.   divisor = 1.0;
  220.   if (ch == '.')
  221.      {
  222.        ch = readch();
  223.        while (ch >= '0' && ch <= '9')
  224.           {
  225.             fractpart = fractpart * 10.0 + (ch - '0');
  226.             divisor = divisor * 10.0;
  227.             ch = readch();
  228.           };
  229.      };
  230.   bufferptr = bufferptr - 1; /* unget the character */
  231.   number = sign * (((double) intpart) +
  232.                   ((double) fractpart) / ((double) divisor));
  233.   if (op == GT && number > min) return(number);
  234.   else if (op == GE && number >= min) return(number);
  235.   else
  236.      {
  237.        printf("erroneous value: %lf",number);
  238.        if (data == stdin) putchar('\n');
  239.        else printf(" in %c command\n",command);
  240.        readerror = 1;
  241.        return(0.0);
  242.      };
  243. }
  244.  
  245. WTTYPE rdr(op,min,command) /* reads double real numbers and converts */
  246. int op;                    /* them to 16-bit integers if necessary */
  247. double min;
  248. int command;
  249. {
  250.   double x;
  251.   WTTYPE ix;
  252.  
  253.   x = readreal(op,min,command);
  254.   if (readerror == 1) return(0);
  255.   ix = scale(x);
  256.   if (readerror == 1) return(0);
  257.   return(ix);
  258. }
  259.  
  260. double readchar()   /* reads data in compressed format */
  261. {
  262.   readerror = 0;
  263.   ch = readch();
  264.   do {
  265.              switch (ch) {
  266.   case '\n':
  267.   case ' ': ch = readch();
  268.             break;
  269.   case '1': return(1.0);
  270.   case '0': return(0.0);
  271.   case '?': return(unscale(qmark));
  272.   case '*': do {ch = readch();} while(ch != '\n');
  273.             break;
  274.   case 'h': return(unscale(HCODE));
  275.   case 'i': if (nlayers >= 3) return(unscale(ICODE));
  276.   case 'j': if (nlayers >= 4) return(unscale(JCODE));
  277.   case 'k': if (nlayers >= 5) return(unscale(KCODE));
  278.   default:  texterror();
  279.             readerror = 1;
  280.             return(0.0);
  281.           }; /* end switch */
  282.   } while (0 == 0);
  283. }
  284.  
  285. void printoutunits(layer,printerr)  /* prints values of units */
  286. LAYER *layer;
  287. int printerr;
  288. {
  289.  double error, e;
  290.  int counter, i;
  291.  UNIT *u;
  292.  WTTYPE upper, middle, diff;
  293.  PATNODE *target;
  294.  
  295.  upper = scale(1.0) - toler; /* compute whether needed or not */
  296.  middle = scale(0.5);
  297.  
  298.  u = (UNIT *) layer->units;
  299.  if (layer == last) target = (PATNODE *) last->currentpat->pats;
  300.  counter = 0;
  301.  i = 1;
  302.  if (printerr == 0) printf("    ");
  303.  while (u != NULL)
  304.     {
  305.       counter = counter + 1;
  306.       if (outformat == 'r')
  307.         {
  308.           printf("%5.2lf ",unscale(u->oj));
  309.           if (format[i] == counter)
  310.              {
  311.                printf("\n    ");
  312.                if (i < maxformat - 1) i = i + 1;
  313.              }
  314.          }
  315.       else if (outformat == 'a' && layer == last)
  316.          {
  317.            diff = target->val - u->oj;
  318.            if (diff < 0) diff = -diff;
  319.            if (diff < toler) putchar('c');
  320.            else if (u->oj > upper) putchar('1');
  321.            else if (u->oj < toler) putchar('0');
  322.            else if (u->oj > target->val) putchar('^');
  323.            else putchar('v');
  324.            if (format[i] == counter)
  325.               {
  326.                 putchar(' ');
  327.                 if (i < maxformat - 1) i = i + 1;
  328.               }
  329.          }
  330.       else 
  331.          {
  332.            if (u->oj > upper) putchar('1');
  333.            else if (u->oj > middle) putchar('^');
  334.            else if (u->oj < toler) putchar('0');
  335.            else putchar('v');
  336.            if (format[i] == counter)
  337.               {
  338.                 putchar(' ');
  339.                 if (i < maxformat - 1) i = i + 1;
  340.               }
  341.          }
  342.       u = u->next;
  343.       if (layer == last) target = target->next;
  344.     };
  345.  if (printerr == 1)
  346.     {
  347.       error = 0.0;
  348.       u = (UNIT *) layer->units;
  349.       target = (PATNODE *) last->currentpat->pats;
  350.       while (u != NULL)
  351.          {
  352.            e = unscale(target->val - u->oj);
  353.            error = error + e * e;
  354.            u = u->next;
  355.            target = target->next;
  356.          };
  357.        printf(" (%7.5lf)",error);
  358.     };
  359.  printf("\n");
  360. }
  361.  
  362. void wrb(wtfile,value,wtsize)
  363. FILE *wtfile;
  364. WTTYPE value;
  365. int wtsize;
  366. {
  367.   int i;
  368.   unsigned char *charptr, ch2;
  369.  
  370.   charptr = (unsigned char *) &value;
  371.   for (i=1;i<=wtsize;i++)
  372.      {
  373.        ch2 = *charptr;
  374.        putc(ch2,wtfile);
  375.        charptr++;
  376.      };
  377. }
  378.  
  379. void saveweights()    /* saves weights on the file weights */
  380. {
  381.   FILE *weights;
  382.   UNIT *u;
  383.   LAYER *layer;
  384.   WTNODE *w;
  385.   WTTYPE wvalue, evalue, dvalue;
  386.  
  387.   weights = fopen("weights","w");
  388.   fprintf(weights,"%d%c",totaliter,wtformat);
  389.   if (wtformat == 'b' || wtformat == 'B') fprintf(weights,"%1d",WTSIZE);
  390.   fprintf(weights,"   file = %s\n",datafilename);
  391.   layer = start->next;
  392.   while (layer != NULL)
  393.      {
  394.        u = (UNIT *) layer->units;
  395.        while (u != NULL)
  396.           {
  397.             w = (WTNODE *) u->wtlist;
  398.             while (w != NULL)
  399.                {
  400. #ifdef SYMMETRIC
  401.                  wvalue = *(w->weight);
  402.                  evalue = *(w->eta);
  403.                  dvalue = *(w->olddw);
  404. #else
  405.                  wvalue = w->weight;
  406.                  evalue = w->eta;
  407.                  dvalue = w->olddw;
  408. #endif
  409.                  if (wtformat == 'r' || wtformat == 'R')
  410.                     {
  411.                       fprintf(weights,"%16.10lf",unscale(wvalue));
  412.                       if (wtformat == 'R')
  413.                          {
  414.                            fprintf(weights," %16.10lf",unscale(evalue));
  415.                            fprintf(weights," %16.10lf",unscale(dvalue));
  416.                          };
  417.                       putc('\n',weights);
  418.                     }
  419.                  else  /* binary format; uses the least space */
  420.                     {
  421.                       wrb(weights,wvalue,WTSIZE);
  422.                       if (wtformat == 'B')
  423.                          {
  424.                            wrb(weights,evalue,WTSIZE);
  425.                            wrb(weights,dvalue,WTSIZE);
  426.                          };
  427.                     };
  428.                  w = w->next;
  429.                };
  430.             u = u->next;
  431.           };
  432.         layer = layer->next;
  433.       };
  434.   fflush(weights);
  435.   close(weights);
  436.   lastsave = totaliter;
  437. }
  438.  
  439. WTTYPE rdb(wtfile,wtsize) /* read binary and convert between sizes */
  440. FILE *wtfile;
  441. int wtsize;
  442. {
  443.   int i;
  444.   double value;
  445.   short ivalue;
  446.   unsigned char *charptr;
  447.  
  448.   if (wtsize == 2) charptr = (unsigned char *) &ivalue;
  449.   else charptr = (unsigned char *) &value;
  450.   for (i=1;i<=wtsize;i++)
  451.      {
  452.        *charptr = (unsigned char) getc(wtfile);
  453.        charptr++;
  454.      };
  455.   if (WTSIZE == 2 && wtsize == 2) return(ivalue);
  456.   else if (WTSIZE == 2 && wtsize == 8) return(scale(value));
  457.   else if (WTSIZE == 8 && wtsize == 8) return(value);
  458.   else if (WTSIZE == 8 && wtsize == 2) return(ivalue / 1024.0);
  459. }
  460.  
  461. void restoreweights()    /* restore weights from the file weights */
  462. {
  463.   FILE *weights;
  464.   UNIT *u;
  465.   LAYER *layer;
  466.   WTNODE *w;
  467.   int ch2, fileformat;
  468.   WTTYPE wvalue, evalue, dvalue;
  469.   double temp;
  470.   int wtsize;
  471.  
  472.   weights = fopen("weights","r");
  473.   if (weights == NULL)
  474.      {
  475.        printf("cannot open file weights\n");
  476.        return;
  477.      };
  478.   fscanf(weights,"%d",&totaliter);
  479.   fileformat = getc(weights);
  480.   if (fileformat != wtformat)
  481.      printf("caution: weight format mismatch\n");
  482.   if (fileformat == 'b' || fileformat == 'B')
  483.      {
  484.        wtsize = getc(weights) - '0';
  485.        if (WTSIZE != wtsize)
  486.           printf("caution: weight sizes mismatched\n");
  487.      }
  488.   else wtsize = WTSIZE;
  489.   ch2 = getc(weights);  /* skip over the file name */
  490.   while (ch2 != '\n') ch2 = getc(weights);
  491.   layer = start->next;
  492.   while (layer != NULL)
  493.      {
  494.        u = (UNIT *) layer->units;
  495.        while (u != NULL)
  496.           {
  497.             w = (WTNODE *) u->wtlist;
  498.             while (w != NULL)
  499.                {
  500.                  if (fileformat == 'r' || fileformat == 'R')
  501.                     {
  502.                       fscanf(weights,"%lf",&temp);
  503.                       wvalue = scale(temp);
  504.                       if (fileformat == 'R')
  505.                          {
  506.                            fscanf(weights,"%lf",&temp);
  507.                            evalue = scale(temp);
  508.                            fscanf(weights,"%lf",&temp);
  509.                            dvalue = scale(temp);
  510.                          };
  511.                      }
  512.                  else
  513.                     {
  514.                       wvalue = rdb(weights,wtsize);
  515.                       if (fileformat == 'B')
  516.                          {
  517.                            evalue = rdb(weights,wtsize);
  518.                            dvalue = rdb(weights,wtsize);
  519.                          };
  520.                     };
  521. #ifdef SYMMETRIC
  522.                  *(w->weight) = wvalue;
  523.                  if (fileformat == 'R' || fileformat == 'B')
  524.                     {
  525.                       *(w->olddw) = dvalue;
  526.                       *(w->eta) = evalue;
  527.                     }
  528.                  else *(w->olddw) = 0;
  529. #else
  530.                  w->weight = wvalue;
  531.                  if (fileformat == 'R' || fileformat == 'B')
  532.                     {
  533.                       w->olddw = dvalue;
  534.                       w->eta = evalue;
  535.                     }
  536.                  else w->olddw = 0;
  537. #endif
  538.                  w = w->next;
  539.                };
  540.             u = u->next;
  541.           };
  542.         layer = layer->next;
  543.       };
  544.    close(weights);
  545. }
  546.  
  547. void printweights(u)   /* print the weights leading into unit u */
  548. UNIT *u;
  549.  
  550. {WTNODE *w;
  551.  UNIT *bunit;
  552.  WTTYPE value;
  553. #ifdef INTEGER
  554.  int sum, input;
  555. #else
  556.  double sum, input;
  557. #endif
  558.  w = (WTNODE *) u->wtlist;
  559.  sum = 0;
  560.  printf("layer unit  unit value     weight         input from unit\n");
  561.  while (w != NULL)
  562.     {
  563.       bunit = (UNIT *) w->backunit;
  564. #ifdef SYMMETRIC
  565.       value = *(w->weight);
  566. #else
  567.       value = w->weight;
  568. #endif
  569.       input = value * bunit->oj;
  570. #ifdef INTEGER
  571.       input = input / 1024;
  572. #endif
  573.       sum = sum + input;
  574.       printf("%3d   ",bunit->layernumber);
  575.       if (bunit->unitnumber == 32767) printf("   t ");
  576.          else printf("%4d ",bunit->unitnumber);
  577.       printf("%10.5lf  %10.5lf  ",unscale(bunit->oj),unscaleint(value));
  578.       printf("%18.5lf\n",unscaleint(input));
  579.       w = w->next;
  580.     };
  581.  printf("                                      ");
  582.  printf("sum = %9.5lf\n\n",unscaleint(sum));
  583. }
  584.  
  585. void help()
  586. {
  587.   printf("\n");
  588.   ch = readch();
  589.   while (ch == ' ' && ch != '\n') ch = readch();
  590.           switch(ch) {
  591. default : printf("for help type h followed by letter of command\n");
  592.           break;
  593. case '?': printf("? prints program status and parameters.\n");
  594.           break;
  595. case '*': printf("* at the beginning of a line makes the line a");
  596.           printf(" comment.\n");
  597.           break;
  598. case '!': printf("Enter UNIX commands after the !.\n");
  599.           break;
  600. case 'A': printf("A is used to set the details of the algorithm. ");
  601.           printf("One or more\nof the following commands can go on ");
  602.           printf("the same line as the 'A':\n\n");
  603.           printf("a p sets the piecewise linear activation function\n");
  604.           printf("a s sets the smooth activation function (rbp only).");
  605.           printf("\n\nb + will backpropagate errors");
  606.           printf(" even when a unit is close to it's target.\n");
  607.           printf("b - will not backpropagate errors when a");
  608.           printf(" unit is close to it's target.\n\n");
  609.           printf("D <real> will set the sharpness of the sigmoid to");
  610.           printf(" <real>.\n\n");
  611.           printf("d d will use the derivative from the ");
  612.           printf("differential step size algorithm.\n");
  613.           printf("d f uses Fahlman's derivative.\n");
  614.           printf("d o uses the original derivative.\n\n");
  615.           printf("l <real> limits the weights to between +<real> ");
  616.           printf("and -<real>.  The default\n         is to not check");
  617.           printf(".  To reset to not check, use l 0.\n\n");
  618.           printf("s <int> will skip patterns that have been learned");
  619.           printf(" for <int> iterations.\n\n");
  620.           printf("u c will use the continuous update method.\n");
  621.           printf("u C will use the continuous update method with the");
  622.           printf(" differential step size etas.\n");
  623.           printf("u d will use the differential step size update.\nu ");
  624.           printf("j will use Jacob's delta-bar delta update method.\n");
  625.           printf("u o will use the original weight update method.\n");
  626.           break;
  627. case 'a': printf("a <real> sets the momentum parameter, alpha, to");
  628.           printf(" <real>.\n");
  629.           break;
  630. case 'b': printf("b <int1> <int2> ... <int10> puts a carriage return");
  631.           printf(" after each <inti>\nvalues when the output format");
  632.           printf(" is real and inserts a blank after each <inti>\n");
  633.           printf("value if the format is condensed.\n");
  634.           break;
  635. case 'C': printf("C clears the network and other relevant parameters");
  636.           printf(" so the problem can be re-run\nwith different");
  637.           printf(" initial weights.  Added hidden units are not");
  638.           printf(" removed.\n");
  639.           break;
  640.  
  641. #ifndef SYMMETRIC
  642. case 'c': printf("c <int1> <int2> <int3> <int4>\n");
  643.           printf("Adds a connection from layer <int1> unit <int2>\n");
  644.           printf("to layer <int3> unit <int4>.\n");
  645.           break;
  646. #endif
  647.  
  648. case 'E': printf("E1 echos input; E0 turns off echo of input.\n");
  649.           break;
  650. case 'e': printf("e <real1> <real2> sets eta, the learning rate, to");
  651.           printf(" <real1> and if\n");
  652.           printf("<real2> is present, eta2 of the differential");
  653.           printf(" step size algorithm\nis set to <real2>.  If ");
  654.           printf("<real2> is not present, eta2 = eta / 10.\n");
  655.           break;
  656. case 'f': printf("f is used to set the input and output formats for");
  657.           printf(" data.\nOne or more of the following commands can");
  658.           printf(" go on the line:\n\n");
  659.           printf("i c will read values in patterns as compressed.\n");
  660.           printf("i r will read values in patterns are reals.\n\n");
  661.           printf("o a will write node values as analog compressed.\n");
  662.           printf("o c will write node values as compressed.\n");
  663.           printf("o r will write node values as real.\n\n");
  664.           printf("s + will summarize learning status instead of");
  665.           printf(" listing each pattern.\n");
  666.           printf("s - will not summarize learning status and will");
  667.           printf(" list each pattern.\n\n");
  668.           printf("w b will write the weights to the file weights as");
  669.           printf(" binary values.\n");
  670.           printf("w B will write the weights and weight changes and");
  671.           printf(" etas as binary.\n");
  672.           printf("w r will write the weights to the file weights as");
  673.           printf(" real values.\n");
  674.           printf("w R will write the weights and weight changes and");
  675.           printf(" etas as real values.\n");
  676.           break;
  677.  
  678. #ifndef SYMMETRIC
  679. case 'H': printf("H <int> <real> adds a hidden unit to layer <int>\n");
  680.           printf("Weights are initialized to between -<real> and");
  681.           printf(" <real>.\n");
  682.           break;
  683. #endif
  684.  
  685. case 'h': printf("h <letter> gives help for command <letter>.\n");
  686.           break;
  687. case 'i': printf("i <filename> takes commands from <filename>.\n");
  688.           break;
  689. case 'j': printf("j is used to set parameters for Jacob's");
  690.           printf(" delta-bar-delta method.\nOne or more of the");
  691.           printf(" following commands can go on the line:\n\n");
  692.           printf("d <real> sets the decay factor to <real>.\n");
  693.           printf("e <real> sets the initial eta value to <real>.\n");
  694.           printf("k <real> sets kappa to <real>.\n");
  695.           printf("m <real> limits the maximum value of each eta to");
  696.           printf(" <real>.\nt <real> sets theta to <real>.\n");
  697.           break;
  698. case 'k': printf("k <real1> <real2> decreases all the weights in the ");
  699.           printf("network whose values\nare greater than <real1> by a");
  700.           printf(" random amount between 0 and <real2>.\nWeights ");
  701.           printf("less than -<real1> are increased by an amount ");
  702.           printf("between 0 and <real2>.\nIf <real1> = 0.0, and a ");
  703.           printf("weight = 0.0 then the weight is changed to\na ");
  704.           printf("value between -<real2> and +<real2>.\n");
  705.           break;
  706. case 'l': printf("l <int> prints values of nodes on layer <int>.\n");
  707.           break;
  708. case 'm': printf("m <int1> <int2> ... <intn> makes a network with\n");
  709.           printf("<int1> units in the first layer, <int2> units in\n");
  710.           printf("the second layer, ... , <intn> units in the nth");
  711.           printf(" layer\n");
  712.           break;
  713. case 'n': printf("n <int> <in1> <out1> ... <ini> <outi> ... <inN> ");
  714.           printf("<outN>\nreplaces all patterns with <int> new ones");
  715.           printf(".\n<ini> patterns go on the input units.\n");
  716.           printf("<outi> patterns go on the output units.\n");
  717.           break;
  718. case 'o': printf("o a outputs node values in analog compressed form.");
  719.           printf("\no c outputs node values in compressed form.\n");
  720.           printf("o r outputs node values as double.\n");
  721.           break;
  722. case 'P': printf("P lists the outputs for all patterns.\n");
  723.           printf("P <int> gives the output for pattern <int>.\n");
  724.           break;
  725. case 'p': printf("p <pat> submits the pattern, <pat>, to the input");
  726.           printf(" units.\n");
  727.           break;
  728. case 'Q': printf("Q <real> sets the value of ? in compressed input");
  729.           printf(" to be the value, <real>.\n");
  730.           break;
  731. case 'q': printf("q ends the program.\n");
  732.           break;
  733. case 'R': printf("R reloads weights from the file weights.\n");
  734.           break;
  735. case 'r': printf("r <int1> <int2> runs <int1> iterations thru the ");
  736.           printf("patterns.  If <int2> is\npresent, the patterns are ");
  737.           printf("printed (or summarized) every <int2> iterations.\n");
  738.           break;
  739. case 'S': printf("S <int> saves the weights on the file ");
  740.           printf("weights every <int> iterations.\nS saves the ");
  741.           printf("weights immediately.\n");
  742.           break;
  743. case 's': printf("s <int> sets the random number seed to <int>.\n");
  744.           break;
  745.  
  746. #ifdef SYMMETRIC
  747. case 'T': printf("T <real> freezes all threshold weights at <real>.\n");
  748.           break;
  749. #endif
  750.  
  751. case 't': printf("t <real> sets <real> as the tolerance used in ");
  752.           printf("printing compressed values\nand in checking for");
  753.           printf(" complete learning.\n");
  754.           break;
  755. #ifndef SYMMETRIC
  756. case 'W': printf("W <real> removes links whose weights are less than ");
  757.           printf("the absolute value\nof <real>, except links to ");
  758.           printf("threshold units are not removed.\n");
  759.           break;
  760. #endif
  761.  
  762. case 'w': printf("w <int1> <int2>  ");
  763.           printf("prints weights into unit <int2> in layer <int1>.\n");
  764.           break;
  765. case 'x': printf("x <int1> <in1> <out1> ... <ini> <outi> ... <inN>");
  766.           printf(" <outN>\nadds the extra <int1> patterns.\n");
  767.           printf("<in1> patterns go on the input units.\n");
  768.           printf("<out1> patterns go on the output units.\n");
  769.           break;
  770.        }; /* end switch */
  771.   putchar('\n');
  772. }
  773.