[comp.sources.misc] v14i086: Fast Backpropagation Part 3 of 4

drt@chinet.chi.il.us (Donald Tveter) (09/16/90)

Posting-number: Volume 14, Issue 86
Submitted-by: Donald Tveter <drt@chinet.chi.il.us>
Archive-name: back-prop/part03

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 3 (of 4)."
# Contents:  io.c makefile rbp.h ibp.h
# Wrapped by drt@chinet on Fri Aug 31 08:18:13 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'io.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'io.c'\"
else
echo shar: Extracting \"'io.c'\" \(24037 characters\)
sed "s/^X//" >'io.c' <<'END_OF_FILE'
X/* ************************************************ */
X/* file io.c:  contains most input/output functions */
X/*                                                  */
X/* Copyright (c) 1990 by Donald R. Tveter           */
X/*                                                  */
X/* ************************************************ */
X
X#include <stdio.h>
X#ifdef INTEGER
X#include "ibp.h"
X#else
X#include "rbp.h"
X#endif
X
Xextern char buffer[buffsize];
Xextern int bufferend;
Xextern int bufferptr;
Xextern int ch;
Xextern FILE *data;
Xextern char datafilename[50];
Xextern int echo;
Xextern int format[maxformat];
Xextern LAYER *last;
Xextern int lastsave;
Xextern short nlayers;
Xextern char outformat;
Xextern WTTYPE qmark;
Xextern int readerror;
Xextern int readingpattern;
Xextern LAYER *start;
Xextern WTTYPE toler;
Xextern int totaliter;
Xextern char wtformat;
X
X#ifdef INTEGER
X
Xshort scale(x)     /* returns x as a scaled 16-bit value */
Xdouble x;
X{
X  short s;
X  if (x > 31.999 || x < -32.0)
X     {
X       printf("magnitude of %lf is too large for the integer",x);
X       printf(" representation\n",x);
X       readerror = 1;
X       return(0);
X     };
X  if (x > 0.0) s = x * 1024 + 0.5;
X  else s = x * 1024 - 0.5;
X  if (x != 0.0 && s == 0)
X     {
X       printf("warning:  magnitude of %lf is too small for",x);
X       printf(" the integer representation\n");
X       return(0);
X     };
X  return(s);
X}
X
Xdouble unscale(x)  /* returns the double value of short x */
Xshort x;
X{
X  double temp;
X  temp = (double) x / 1024.0; 
X  return(temp);
X}
X
Xdouble unscaleint(x)  /* returns the double value of int x */
Xint x;
X{
X  double temp;
X  temp = (double) x / 1024.0; 
X  return(temp);
X}
X
X#endif
X
Xint readch() /* returns the next character in the input buffer */
X{ 
X  int i, ch2;
X  if (bufferptr > bufferend) /* then read next line into buffer */
X     {
X       ch2 = getc(data);
X       if (ch2 == EOF) return(ch2);
X       i = 0;
X       while(ch2 != '\n' && i < buffsize)
X          {
X            if (ch2 == 015) ch2 = ' '; /* filter out carriage returns */
X            buffer[i] = ch2;
X            i = i + 1;
X            ch2 = getc(data);
X          };
X       if (i == buffsize)
X          {
X            printf("line too long\n");
X            exit(4);
X          };
X       buffer[i] = '\n';
X       bufferend = i;
X       bufferptr = 0;
X       if (echo == 1)
X          for(i = 0; i <= bufferend; i++) putchar(buffer[i]);
X      }
X  ch2 = buffer[bufferptr];
X  bufferptr = bufferptr + 1;
X  return(ch2);
X}
X
Xvoid texterror() /* handles errors in text */
X{
X printf("unexpected text:  ");
X bufferptr = bufferptr - 1;
X ch = readch();
X while (ch != '\n')
X    {
X      putchar(ch);
X      ch = readch();
X    };
X putchar('\n');
X bufferptr = bufferptr - 1;
X}
X
Xint scanfordigit()    /* used to scan for the leading */
X{                     /* digit of a number and trap mistakes */
X int sign;
X
X sign = 1;
Xrestart:
X ch = readch();
X while (ch == ' ' || ch == '\n') ch = readch();
X if (ch >= '0' && ch <= '9')
X    {
X      bufferptr = bufferptr - 1; /* unget the character */
X      return(sign);
X    };
X if (ch >= 'h' && ch <= 'k')
X    {
X      bufferptr = bufferptr - 1; /* unget the character */
X      return(0);
X    };
X          switch (ch) {
Xcase EOF: printf("unexpected EOF\n");
X          exit(2);
Xcase '*': while (ch != '\n') ch = readch();
X          goto restart;
Xcase '-': sign = -sign;
X          goto restart;
Xcase '?': bufferptr = bufferptr - 1; /* unget the character */
X          return(0);
Xdefault:  readerror = 1;
X          return(0);
X          }; /* end switch */
X};
X
Xint readint(min,max,command)
Xint min, max;   /* the minimum and maximum allowed values */
Xchar command;
X{
X  int sign, number;
X  readerror = 0;
X  sign = scanfordigit();
X  if (readerror == 1 || sign == 0)
X     {
X       readerror = 1;
X       texterror();
X       return(0);
X     };
X  number = 0;
X  ch = readch();
X  while (ch == ' ') ch = readch();
X  while (ch >= '0' && ch <= '9')
X     {
X       number = number * 10 + (ch - '0');
X       ch = readch();
X     };
X  bufferptr = bufferptr - 1; /* unget the character */
X  number = sign * number;
X  if (number < min || number > max)
X     {
X       printf("erroneous value: %d",number);
X       if (data == stdin) putchar('\n');
X       else printf(" in %c command\n",command);
X       readerror = 1;
X     };
X  return(number);
X}
X
Xdouble readreal(op,min,command)
Xint op;
Xdouble min;
Xint command;
X{
X  double number;
X  double fractpart, divisor, intpart, sign;
X  readerror = 0;
X
X  sign = (double) scanfordigit();
X  if (readerror == 1 || (sign == 0 && !readingpattern))
X     {
X       texterror();
X       return(0);
X     };
X  ch = readch();
X  if (ch == 'h' && readingpattern)
X     return(unscale(HCODE));
X  else if (ch == 'i' && readingpattern && nlayers >= 3)
X          return(unscale(ICODE));
X  else if (ch == 'j' && readingpattern && nlayers >= 4)
X          return(unscale(JCODE));
X  else if (ch == 'k' && readingpattern && nlayers >= 5)
X          return(unscale(KCODE));
X  else if (ch == '?' && readingpattern)
X          return(unscale(qmark));
X  intpart = 0.0;
X  while (ch >= '0' && ch <= '9')
X     {
X       intpart = 10.0 * intpart + (ch - '0');
X       ch = readch();
X     };
X  fractpart = 0.0;
X  divisor = 1.0;
X  if (ch == '.')
X     {
X       ch = readch();
X       while (ch >= '0' && ch <= '9')
X          {
X            fractpart = fractpart * 10.0 + (ch - '0');
X            divisor = divisor * 10.0;
X            ch = readch();
X          };
X     };
X  bufferptr = bufferptr - 1; /* unget the character */
X  number = sign * (((double) intpart) +
X                  ((double) fractpart) / ((double) divisor));
X  if (op == GT && number > min) return(number);
X  else if (op == GE && number >= min) return(number);
X  else
X     {
X       printf("erroneous value: %lf",number);
X       if (data == stdin) putchar('\n');
X       else printf(" in %c command\n",command);
X       readerror = 1;
X       return(0.0);
X     };
X}
X
XWTTYPE rdr(op,min,command) /* reads double real numbers and converts */
Xint op;                    /* them to 16-bit integers if necessary */
Xdouble min;
Xint command;
X{
X  double x;
X  WTTYPE ix;
X 
X  x = readreal(op,min,command);
X  if (readerror == 1) return(0);
X  ix = scale(x);
X  if (readerror == 1) return(0);
X  return(ix);
X}
X
Xdouble readchar()   /* reads data in compressed format */
X{
X  readerror = 0;
X  ch = readch();
X  do {
X             switch (ch) {
X  case '\n':
X  case ' ': ch = readch();
X            break;
X  case '1': return(1.0);
X  case '0': return(0.0);
X  case '?': return(unscale(qmark));
X  case '*': do {ch = readch();} while(ch != '\n');
X            break;
X  case 'h': return(unscale(HCODE));
X  case 'i': if (nlayers >= 3) return(unscale(ICODE));
X  case 'j': if (nlayers >= 4) return(unscale(JCODE));
X  case 'k': if (nlayers >= 5) return(unscale(KCODE));
X  default:  texterror();
X            readerror = 1;
X            return(0.0);
X          }; /* end switch */
X  } while (0 == 0);
X}
X
Xvoid printoutunits(layer,printerr)  /* prints values of units */
XLAYER *layer;
Xint printerr;
X{
X double error, e;
X int counter, i;
X UNIT *u;
X WTTYPE upper, middle, diff;
X PATNODE *target;
X
X upper = scale(1.0) - toler; /* compute whether needed or not */
X middle = scale(0.5);
X
X u = (UNIT *) layer->units;
X if (layer == last) target = (PATNODE *) last->currentpat->pats;
X counter = 0;
X i = 1;
X if (printerr == 0) printf("    ");
X while (u != NULL)
X    {
X      counter = counter + 1;
X      if (outformat == 'r')
X        {
X          printf("%5.2lf ",unscale(u->oj));
X          if (format[i] == counter)
X             {
X               printf("\n    ");
X               if (i < maxformat - 1) i = i + 1;
X             }
X         }
X      else if (outformat == 'a' && layer == last)
X         {
X           diff = target->val - u->oj;
X           if (diff < 0) diff = -diff;
X           if (diff < toler) putchar('c');
X           else if (u->oj > upper) putchar('1');
X           else if (u->oj < toler) putchar('0');
X           else if (u->oj > target->val) putchar('^');
X           else putchar('v');
X           if (format[i] == counter)
X              {
X                putchar(' ');
X                if (i < maxformat - 1) i = i + 1;
X              }
X         }
X      else 
X         {
X           if (u->oj > upper) putchar('1');
X           else if (u->oj > middle) putchar('^');
X           else if (u->oj < toler) putchar('0');
X           else putchar('v');
X           if (format[i] == counter)
X              {
X                putchar(' ');
X                if (i < maxformat - 1) i = i + 1;
X              }
X         }
X      u = u->next;
X      if (layer == last) target = target->next;
X    };
X if (printerr == 1)
X    {
X      error = 0.0;
X      u = (UNIT *) layer->units;
X      target = (PATNODE *) last->currentpat->pats;
X      while (u != NULL)
X         {
X           e = unscale(target->val - u->oj);
X           error = error + e * e;
X           u = u->next;
X           target = target->next;
X         };
X       printf(" (%7.5lf)",error);
X    };
X printf("\n");
X}
X
Xvoid wrb(wtfile,value,wtsize)
XFILE *wtfile;
XWTTYPE value;
Xint wtsize;
X{
X  int i;
X  unsigned char *charptr, ch2;
X
X  charptr = (unsigned char *) &value;
X  for (i=1;i<=wtsize;i++)
X     {
X       ch2 = *charptr;
X       putc(ch2,wtfile);
X       charptr++;
X     };
X}
X
Xvoid saveweights()    /* saves weights on the file weights */
X{
X  FILE *weights;
X  UNIT *u;
X  LAYER *layer;
X  WTNODE *w;
X  WTTYPE wvalue, evalue, dvalue;
X
X  weights = fopen("weights","w");
X  fprintf(weights,"%d%c",totaliter,wtformat);
X  if (wtformat == 'b' || wtformat == 'B') fprintf(weights,"%1d",WTSIZE);
X  fprintf(weights,"   file = %s\n",datafilename);
X  layer = start->next;
X  while (layer != NULL)
X     {
X       u = (UNIT *) layer->units;
X       while (u != NULL)
X          {
X            w = (WTNODE *) u->wtlist;
X            while (w != NULL)
X               {
X#ifdef SYMMETRIC
X                 wvalue = *(w->weight);
X                 evalue = *(w->eta);
X                 dvalue = *(w->olddw);
X#else
X                 wvalue = w->weight;
X                 evalue = w->eta;
X                 dvalue = w->olddw;
X#endif
X                 if (wtformat == 'r' || wtformat == 'R')
X                    {
X                      fprintf(weights,"%16.10lf",unscale(wvalue));
X                      if (wtformat == 'R')
X                         {
X                           fprintf(weights," %16.10lf",unscale(evalue));
X                           fprintf(weights," %16.10lf",unscale(dvalue));
X                         };
X                      putc('\n',weights);
X                    }
X                 else  /* binary format; uses the least space */
X                    {
X                      wrb(weights,wvalue,WTSIZE);
X                      if (wtformat == 'B')
X                         {
X                           wrb(weights,evalue,WTSIZE);
X                           wrb(weights,dvalue,WTSIZE);
X                         };
X                    };
X                 w = w->next;
X               };
X            u = u->next;
X          };
X        layer = layer->next;
X      };
X  fflush(weights);
X  close(weights);
X  lastsave = totaliter;
X}
X
XWTTYPE rdb(wtfile,wtsize) /* read binary and convert between sizes */
XFILE *wtfile;
Xint wtsize;
X{
X  int i;
X  double value;
X  short ivalue;
X  unsigned char *charptr;
X
X  if (wtsize == 2) charptr = (unsigned char *) &ivalue;
X  else charptr = (unsigned char *) &value;
X  for (i=1;i<=wtsize;i++)
X     {
X       *charptr = (unsigned char) getc(wtfile);
X       charptr++;
X     };
X  if (WTSIZE == 2 && wtsize == 2) return(ivalue);
X  else if (WTSIZE == 2 && wtsize == 8) return(scale(value));
X  else if (WTSIZE == 8 && wtsize == 8) return(value);
X  else if (WTSIZE == 8 && wtsize == 2) return(ivalue / 1024.0);
X}
X
Xvoid restoreweights()    /* restore weights from the file weights */
X{
X  FILE *weights;
X  UNIT *u;
X  LAYER *layer;
X  WTNODE *w;
X  int ch2, fileformat;
X  WTTYPE wvalue, evalue, dvalue;
X  double temp;
X  int wtsize;
X
X  weights = fopen("weights","r");
X  if (weights == NULL)
X     {
X       printf("cannot open file weights\n");
X       return;
X     };
X  fscanf(weights,"%d",&totaliter);
X  fileformat = getc(weights);
X  if (fileformat != wtformat)
X     printf("caution: weight format mismatch\n");
X  if (fileformat == 'b' || fileformat == 'B')
X     {
X       wtsize = getc(weights) - '0';
X       if (WTSIZE != wtsize)
X          printf("caution: weight sizes mismatched\n");
X     }
X  else wtsize = WTSIZE;
X  ch2 = getc(weights);  /* skip over the file name */
X  while (ch2 != '\n') ch2 = getc(weights);
X  layer = start->next;
X  while (layer != NULL)
X     {
X       u = (UNIT *) layer->units;
X       while (u != NULL)
X          {
X            w = (WTNODE *) u->wtlist;
X            while (w != NULL)
X               {
X                 if (fileformat == 'r' || fileformat == 'R')
X                    {
X                      fscanf(weights,"%lf",&temp);
X                      wvalue = scale(temp);
X                      if (fileformat == 'R')
X                         {
X                           fscanf(weights,"%lf",&temp);
X                           evalue = scale(temp);
X                           fscanf(weights,"%lf",&temp);
X                           dvalue = scale(temp);
X                         };
X                     }
X                 else
X                    {
X                      wvalue = rdb(weights,wtsize);
X                      if (fileformat == 'B')
X                         {
X                           evalue = rdb(weights,wtsize);
X                           dvalue = rdb(weights,wtsize);
X                         };
X                    };
X#ifdef SYMMETRIC
X                 *(w->weight) = wvalue;
X                 if (fileformat == 'R' || fileformat == 'B')
X                    {
X                      *(w->olddw) = dvalue;
X                      *(w->eta) = evalue;
X                    }
X                 else *(w->olddw) = 0;
X#else
X                 w->weight = wvalue;
X                 if (fileformat == 'R' || fileformat == 'B')
X                    {
X                      w->olddw = dvalue;
X                      w->eta = evalue;
X                    }
X                 else w->olddw = 0;
X#endif
X                 w = w->next;
X               };
X            u = u->next;
X          };
X        layer = layer->next;
X      };
X   close(weights);
X}
X
Xvoid printweights(u)   /* print the weights leading into unit u */
XUNIT *u;
X
X{WTNODE *w;
X UNIT *bunit;
X WTTYPE value;
X#ifdef INTEGER
X int sum, input;
X#else
X double sum, input;
X#endif
X w = (WTNODE *) u->wtlist;
X sum = 0;
X printf("layer unit  unit value     weight         input from unit\n");
X while (w != NULL)
X    {
X      bunit = (UNIT *) w->backunit;
X#ifdef SYMMETRIC
X      value = *(w->weight);
X#else
X      value = w->weight;
X#endif
X      input = value * bunit->oj;
X#ifdef INTEGER
X      input = input / 1024;
X#endif
X      sum = sum + input;
X      printf("%3d   ",bunit->layernumber);
X      if (bunit->unitnumber == 32767) printf("   t ");
X         else printf("%4d ",bunit->unitnumber);
X      printf("%10.5lf  %10.5lf  ",unscale(bunit->oj),unscaleint(value));
X      printf("%18.5lf\n",unscaleint(input));
X      w = w->next;
X    };
X printf("                                      ");
X printf("sum = %9.5lf\n\n",unscaleint(sum));
X}
X
Xvoid help()
X{
X  printf("\n");
X  ch = readch();
X  while (ch == ' ' && ch != '\n') ch = readch();
X          switch(ch) {
Xdefault : printf("for help type h followed by letter of command\n");
X          break;
Xcase '?': printf("? prints program status and parameters.\n");
X          break;
Xcase '*': printf("* at the beginning of a line makes the line a");
X          printf(" comment.\n");
X          break;
Xcase '!': printf("Enter UNIX commands after the !.\n");
X          break;
Xcase 'A': printf("A is used to set the details of the algorithm. ");
X          printf("One or more\nof the following commands can go on ");
X          printf("the same line as the 'A':\n\n");
X          printf("a p sets the piecewise linear activation function\n");
X          printf("a s sets the smooth activation function (rbp only).");
X          printf("\n\nb + will backpropagate errors");
X          printf(" even when a unit is close to it's target.\n");
X          printf("b - will not backpropagate errors when a");
X          printf(" unit is close to it's target.\n\n");
X          printf("D <real> will set the sharpness of the sigmoid to");
X          printf(" <real>.\n\n");
X          printf("d d will use the derivative from the ");
X          printf("differential step size algorithm.\n");
X          printf("d f uses Fahlman's derivative.\n");
X          printf("d o uses the original derivative.\n\n");
X          printf("l <real> limits the weights to between +<real> ");
X          printf("and -<real>.  The default\n         is to not check");
X          printf(".  To reset to not check, use l 0.\n\n");
X          printf("s <int> will skip patterns that have been learned");
X          printf(" for <int> iterations.\n\n");
X          printf("u c will use the continuous update method.\n");
X          printf("u C will use the continuous update method with the");
X          printf(" differential step size etas.\n");
X          printf("u d will use the differential step size update.\nu ");
X          printf("j will use Jacob's delta-bar delta update method.\n");
X          printf("u o will use the original weight update method.\n");
X          break;
Xcase 'a': printf("a <real> sets the momentum parameter, alpha, to");
X          printf(" <real>.\n");
X          break;
Xcase 'b': printf("b <int1> <int2> ... <int10> puts a carriage return");
X          printf(" after each <inti>\nvalues when the output format");
X          printf(" is real and inserts a blank after each <inti>\n");
X          printf("value if the format is condensed.\n");
X          break;
Xcase 'C': printf("C clears the network and other relevant parameters");
X          printf(" so the problem can be re-run\nwith different");
X          printf(" initial weights.  Added hidden units are not");
X          printf(" removed.\n");
X          break;
X
X#ifndef SYMMETRIC
Xcase 'c': printf("c <int1> <int2> <int3> <int4>\n");
X          printf("Adds a connection from layer <int1> unit <int2>\n");
X          printf("to layer <int3> unit <int4>.\n");
X          break;
X#endif
X
Xcase 'E': printf("E1 echos input; E0 turns off echo of input.\n");
X          break;
Xcase 'e': printf("e <real1> <real2> sets eta, the learning rate, to");
X          printf(" <real1> and if\n");
X          printf("<real2> is present, eta2 of the differential");
X          printf(" step size algorithm\nis set to <real2>.  If ");
X          printf("<real2> is not present, eta2 = eta / 10.\n");
X          break;
Xcase 'f': printf("f is used to set the input and output formats for");
X          printf(" data.\nOne or more of the following commands can");
X          printf(" go on the line:\n\n");
X          printf("i c will read values in patterns as compressed.\n");
X          printf("i r will read values in patterns are reals.\n\n");
X          printf("o a will write node values as analog compressed.\n");
X          printf("o c will write node values as compressed.\n");
X          printf("o r will write node values as real.\n\n");
X          printf("s + will summarize learning status instead of");
X          printf(" listing each pattern.\n");
X          printf("s - will not summarize learning status and will");
X          printf(" list each pattern.\n\n");
X          printf("w b will write the weights to the file weights as");
X          printf(" binary values.\n");
X          printf("w B will write the weights and weight changes and");
X          printf(" etas as binary.\n");
X          printf("w r will write the weights to the file weights as");
X          printf(" real values.\n");
X          printf("w R will write the weights and weight changes and");
X          printf(" etas as real values.\n");
X          break;
X
X#ifndef SYMMETRIC
Xcase 'H': printf("H <int> <real> adds a hidden unit to layer <int>\n");
X          printf("Weights are initialized to between -<real> and");
X          printf(" <real>.\n");
X          break;
X#endif
X
Xcase 'h': printf("h <letter> gives help for command <letter>.\n");
X          break;
Xcase 'i': printf("i <filename> takes commands from <filename>.\n");
X          break;
Xcase 'j': printf("j is used to set parameters for Jacob's");
X          printf(" delta-bar-delta method.\nOne or more of the");
X          printf(" following commands can go on the line:\n\n");
X          printf("d <real> sets the decay factor to <real>.\n");
X          printf("e <real> sets the initial eta value to <real>.\n");
X          printf("k <real> sets kappa to <real>.\n");
X          printf("m <real> limits the maximum value of each eta to");
X          printf(" <real>.\nt <real> sets theta to <real>.\n");
X          break;
Xcase 'k': printf("k <real1> <real2> decreases all the weights in the ");
X          printf("network whose values\nare greater than <real1> by a");
X          printf(" random amount between 0 and <real2>.\nWeights ");
X          printf("less than -<real1> are increased by an amount ");
X          printf("between 0 and <real2>.\nIf <real1> = 0.0, and a ");
X          printf("weight = 0.0 then the weight is changed to\na ");
X          printf("value between -<real2> and +<real2>.\n");
X          break;
Xcase 'l': printf("l <int> prints values of nodes on layer <int>.\n");
X          break;
Xcase 'm': printf("m <int1> <int2> ... <intn> makes a network with\n");
X          printf("<int1> units in the first layer, <int2> units in\n");
X          printf("the second layer, ... , <intn> units in the nth");
X          printf(" layer\n");
X          break;
Xcase 'n': printf("n <int> <in1> <out1> ... <ini> <outi> ... <inN> ");
X          printf("<outN>\nreplaces all patterns with <int> new ones");
X          printf(".\n<ini> patterns go on the input units.\n");
X          printf("<outi> patterns go on the output units.\n");
X          break;
Xcase 'o': printf("o a outputs node values in analog compressed form.");
X          printf("\no c outputs node values in compressed form.\n");
X          printf("o r outputs node values as double.\n");
X          break;
Xcase 'P': printf("P lists the outputs for all patterns.\n");
X          printf("P <int> gives the output for pattern <int>.\n");
X          break;
Xcase 'p': printf("p <pat> submits the pattern, <pat>, to the input");
X          printf(" units.\n");
X          break;
Xcase 'Q': printf("Q <real> sets the value of ? in compressed input");
X          printf(" to be the value, <real>.\n");
X          break;
Xcase 'q': printf("q ends the program.\n");
X          break;
Xcase 'R': printf("R reloads weights from the file weights.\n");
X          break;
Xcase 'r': printf("r <int1> <int2> runs <int1> iterations thru the ");
X          printf("patterns.  If <int2> is\npresent, the patterns are ");
X          printf("printed (or summarized) every <int2> iterations.\n");
X          break;
Xcase 'S': printf("S <int> saves the weights on the file ");
X          printf("weights every <int> iterations.\nS saves the ");
X          printf("weights immediately.\n");
X          break;
Xcase 's': printf("s <int> sets the random number seed to <int>.\n");
X          break;
X
X#ifdef SYMMETRIC
Xcase 'T': printf("T <real> freezes all threshold weights at <real>.\n");
X          break;
X#endif
X
Xcase 't': printf("t <real> sets <real> as the tolerance used in ");
X          printf("printing compressed values\nand in checking for");
X          printf(" complete learning.\n");
X          break;
X#ifndef SYMMETRIC
Xcase 'W': printf("W <real> removes links whose weights are less than ");
X          printf("the absolute value\nof <real>, except links to ");
X          printf("threshold units are not removed.\n");
X          break;
X#endif
X
Xcase 'w': printf("w <int1> <int2>  ");
X          printf("prints weights into unit <int2> in layer <int1>.\n");
X          break;
Xcase 'x': printf("x <int1> <in1> <out1> ... <ini> <outi> ... <inN>");
X          printf(" <outN>\nadds the extra <int1> patterns.\n");
X          printf("<in1> patterns go on the input units.\n");
X          printf("<out1> patterns go on the output units.\n");
X          break;
X       }; /* end switch */
X  putchar('\n');
X}
END_OF_FILE
if test 24037 -ne `wc -c <'io.c'`; then
    echo shar: \"'io.c'\" unpacked with wrong size!
fi
# end of 'io.c'
fi
if test -f 'makefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'makefile'\"
else
echo shar: Extracting \"'makefile'\" \(632 characters\)
sed "s/^X//" >'makefile' <<'END_OF_FILE'
XCFLAGS= -s -O
X
Xbp: bp.o io.o misc.o int.o makefile ibp.h
X	cc $(CFLAGS) bp.o io.o misc.o int.o -o bp
X
Xsbp:
X	cc -DINTEGER -DSYMMETRIC int.c bp.c io.c misc.c $(CFLAGS) -o sbp
X	rm bp.o io.o int.o misc.o
X
Xrbp:
X	cc real.c bp.c io.c misc.c $(CFLAGS) -lm -o rbp
X	rm bp.o io.o real.o misc.o
X
Xsrbp:
X	cc -DSYMMETRIC real.c bp.c io.c misc.c $(CFLAGS) -lm -o srbp
X	rm bp.o io.o real.o misc.o
X
Xbp.o: bp.c ibp.h makefile
X	cc -DINTEGER $(CFLAGS) bp.c -c
X
Xio.o: io.c ibp.h makefile
X	cc -DINTEGER $(CFLAGS) io.c -c
X
Xmisc.o: misc.c ibp.h makefile
X	cc -DINTEGER $(CFLAGS) misc.c -c
X
Xint.o: int.c ibp.h makefile
X	cc -DINTEGER -DSMART $(CFLAGS) int.c -c
END_OF_FILE
if test 632 -ne `wc -c <'makefile'`; then
    echo shar: \"'makefile'\" unpacked with wrong size!
fi
# end of 'makefile'
fi
if test -f 'rbp.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'rbp.h'\"
else
echo shar: Extracting \"'rbp.h'\" \(3137 characters\)
sed "s/^X//" >'rbp.h' <<'END_OF_FILE'
X/* ***************************************************** */
X/* file rbp.h:  contains definitions for the rbp program */
X/*              that uses 64-bit floating point weights  */
X/*                                                       */
X/* Copyright (c) 1990 by Donald R. Tveter                */
X/*                                                       */
X/* *******************************************************/
X
X#define maxformat 21
X#define buffsize 257
X
X#define WTTYPE double         /* 64-bit floating point */
X#define WTSIZE 8              /* reals uses 8 bytes */
X#define HCODE -32768          /* code number for a layer h (2) unit */
X#define ICODE -32767          /* code number for a layer i (3) unit */
X#define JCODE -32766          /* code number for a layer j (4) unit */
X#define KCODE -32765          /* code number for a layer k (5) unit */
X#define GT 0                  /* a symbol meaning > */
X#define GE 1                  /* a symbol meaning >= */
X#define scale(x) x            /* scale not used in real version */
X#define unscale(x) x          /* unscale not used in real version */
X#define unscaleint(x) x       /* unscaleint not used in real version */
X
Xtypedef struct patnode
X   {
X     WTTYPE val;              /* input or output pattern */
X     struct patnode *next;    /* pointer to next node */
X   } PATNODE;
Xtypedef struct patlist
X   {
X     int bypass;              /* number of times to bypass pattern */
X     PATNODE *pats;           /* the list of patterns */
X     struct patlist *next;    /* the next pattern */
X   } PATLIST;
Xtypedef struct unit
X   {
X     short layernumber;       /* layer number of the unit */
X     short unitnumber;        /* position within layer */
X     double error;            /* to sum error factors */
X     WTTYPE oj;               /* state of activation of node */
X     WTTYPE tj;
X     struct unit *wtlist;     /* to list of weights to prev layer */
X     struct unit *next;       /* link to next unit in this layer */
X   } UNIT;
X
Xtypedef struct wtnode
X   {
X#ifdef SYMMETRIC
X     WTTYPE *weight;          /* weight from here to backunit */
X     WTTYPE *olddw;           /* delta wji from previous iteration */
X     WTTYPE *total;           /* total of changes for batch updates */
X     WTTYPE *eta;             /* the eta of the DBD method */
X#else
X     WTTYPE weight;           /* weight from here to backunit */
X     WTTYPE olddw;            /* delta wji from previous iterataion */
X     WTTYPE total;            /* total of changes for batch updates */
X     WTTYPE eta;              /* the eta of the DBD method */
X#endif
X     struct wtnode *next;     /* link to next node */
X     struct UNIT *backunit;   /* ptr to unit the weight comes from */
X   } WTNODE;
X
Xtypedef struct layer
X   {
X     int unitcount;           /* number of units in this layer */
X     struct layer *backlayer; /* pointer to previous layer */
X     struct layer *next;      /* pointer to next layer */
X     struct UNIT *units;      /* start of list of units in this layer */
X     PATLIST *patstart;       /* to the list of patterns */
X     PATLIST *currentpat;     /* the current pattern */
X   } LAYER;
END_OF_FILE
if test 3137 -ne `wc -c <'rbp.h'`; then
    echo shar: \"'rbp.h'\" unpacked with wrong size!
fi
# end of 'rbp.h'
fi
if test -f 'ibp.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'ibp.h'\"
else
echo shar: Extracting \"'ibp.h'\" \(2964 characters\)
sed "s/^X//" >'ibp.h' <<'END_OF_FILE'
X/* ****************************************************** */
X/* file ibp.h: contains definitions for programs that use */
X/*             16-bit integer weights                     */
X/*                                                        */
X/* Copyright (c) 1990 by Donald R. Tveter                 */
X/*                                                        */
X/* ****************************************************** */
X
X#define maxformat 21          /* maximum number of format breaks */
X#define buffsize 257          /* maximum size of an input line */
X#define WTTYPE short          /* a 16-bit integer */
X#define WTSIZE 2              /* shorts are two bytes */
X#define HCODE -32768          /* code number for a layer h (2) unit */
X#define ICODE -32767          /* code number for a layer i (3) unit */
X#define JCODE -32766          /* code number for a layer j (4) unit */
X#define KCODE -32765          /* code number for a layer k (5) unit */
X#define GT 0                  /* a symbol meaning > */
X#define GE 1                  /* a symbol meaning >= */
X
Xtypedef struct patnode
X   {
X     WTTYPE val;              /* input or output pattern */
X     struct patnode *next;    /* pointer to next node */
X   } PATNODE;
Xtypedef struct patlist
X   {
X     int bypass;              /* number of times to bypass pattern */
X     PATNODE *pats;           /* the list of patterns */
X     struct patlist *next;    /* the next pattern */
X   } PATLIST;
Xtypedef struct unit
X   {
X     short layernumber;       /* layer number of the unit */
X     short unitnumber;        /* position within layer */
X     int error;               /* to sum error factors */
X     WTTYPE oj;               /* state of activation of node */
X     struct wtnode *wtlist;   /* the list of weights */
X     struct unit *next;       /* link to next unit in this layer */
X   } UNIT;
X
Xtypedef struct wtnode
X   {
X#ifdef SYMMETRIC
X     WTTYPE *weight;          /* ptr to weight */
X     WTTYPE *olddw;           /* ptr to delta wji */
X     WTTYPE *eta;             /* ptr to eta for the DBD method */
X     int *total;              /* ptr to total of weight changes */
X#else
X     WTTYPE weight;           /* weight from here to backunit */
X     WTTYPE olddw;            /* delta wji from previous iteration */
X     WTTYPE eta;              /* the eta for the DBD method */
X     int total;               /* total weight changes for batch mode */
X#endif
X     struct wtnode *next;     /* link to next node */
X     struct UNIT *backunit;   /* ptr to unit the weight comes from */
X   } WTNODE;
X
Xtypedef struct layer
X   {
X     int unitcount;           /* number of units in this layer */
X     struct layer *backlayer; /* pointer to previous layer */
X     struct layer *next;      /* pointer to next layer */
X     struct UNIT *units;      /* start of list of units in this layer */
X     PATLIST *patstart;       /* to the list of patterns */
X     PATLIST *currentpat;     /* the current pattern */
X   } LAYER;
END_OF_FILE
if test 2964 -ne `wc -c <'ibp.h'`; then
    echo shar: \"'ibp.h'\" unpacked with wrong size!
fi
# end of 'ibp.h'
fi
echo shar: End of archive 3 \(of 4\).
cp /dev/null ark3isdone
MISSING=""
for I in 1 2 3 4 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 4 archives.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0