[comp.ai.neural-nets] More bugs and fixes for my backprop source

drt@chinet.chi.il.us (Donald Tveter) (11/25/90)

Here are some bugs and oversights for my fast back-propagation
source that was posted a few months ago:

First, someone found that on some machines that doing a second 'n'
command to erase old patterns and replace them with new ones causes
a core dump.  This doesn't happen everywhere and not on SysV, I guess,
although it ought to happen everywhere!  The problem was that a pointer
becomes NULL.  The following procedure, nullpatterns now has the bug
fixed so you can just replace the old nullpatterns (file misc.c) with
this new one:


void nullpatterns()  /* dispose of any patterns before reading more */
{
  PATLIST *pl, *nextpl;
  PATNODE *pn, *nextpn;
  if (start->patstart != NULL)
     {
       pl = start->patstart;
       while (pl != NULL)
          {
            nextpl = pl->next;
            pn = pl->pats;
            while (pn != NULL)
               {
                 nextpn = pn->next;
                 free(pn);
                 pn = nextpn;
               };
            free(pl);
            pl = nextpl;
          };
       pl = last->patstart;
       while (pl != NULL)
          {
            nextpl = pl->next;
            pn = pl->pats;
            while (pn != NULL)
               {
                 nextpn = pn->next;
                 free(pn);
                 pn = nextpn;
               };
            free(pl);
            pl = nextpl;
          };
     };
  start->patstart = NULL;
  last->patstart = NULL;
  npats = 0;
  prevnpats = 0;
}


-------------------

Second, someone found that when you set the output format to be
the summary format you can't set it back to the non-summary format.
The problem is due to the following line in the file bp.c, in the
procedure cmdloop under case 'f':

              if (ch == '+' || summary == '-') summary = ch;

This should be changed to:

              if (ch == '+' || ch == '-') summary = ch;

-------------------

Third, there are commands where you can get a core dump if
there is no network or no patterns.  My philosophy has been that
anyone that does something like this deserves a core dump :-)
but I suppose I should become sensitive to users, so I wrote two
little functions to detect these conditions and give a helpful
message.  These two functions can be placed before the procedure
cmdloop in the file bp.c:

int nonetwork()
{
  if (start != NULL) return(0);
  printf("there is no network\n");
  return(1);
}

int nopatterns()
{
  if (npats != 0) return(0);
  printf("there are no patterns\n");
  return(1);
}

Then for the commands C,c,H,k,l,n,p,R,T,W,w and x (not all of these
will core dump but I guess a warning is appropriate) I added a line
at the beginning of the command like this one for C:

case 'C': if (nonetwork()) break;


Furthermore, for the P and r commands I added this:

          if (nonetwork() || nopatterns()) break;


Then for the S command I changed the code to the following:

          if (itemp == 0)
             if(nonetwork()) break; else saveweights();
          else saverate = itemp;

-------------------

Don Tveter
5228 N. Nashville Ave.
Chicago, Illinois   60656
drt@chinet.chi.il.us