home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume31 / backprop / part03 < prev    next >
Encoding:
Text File  |  1992-09-01  |  40.8 KB  |  1,384 lines

  1. Newsgroups: comp.sources.misc
  2. From: drt@chinet.chi.il.us (Donald Tveter)
  3. Subject:  v31i131:  backprop - Fast Backpropagation, Part03/04
  4. Message-ID: <1992Sep2.180724.28109@sparky.imd.sterling.com>
  5. X-Md4-Signature: ff438e5ac73adaf048e29ff6a68ec60f
  6. Date: Wed, 2 Sep 1992 18:07:24 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: drt@chinet.chi.il.us (Donald Tveter)
  10. Posting-number: Volume 31, Issue 131
  11. Archive-name: backprop/part03
  12. Supersedes: backprop: Volume 28, Issue 63-66
  13. Environment: UNIX, DOS
  14.  
  15. #! /bin/sh
  16. # This is a shell archive.  Remove anything before this line, then unpack
  17. # it by saving it into a file and typing "sh file".  To overwrite existing
  18. # files, type "sh file -c".  You can also feed this as standard input via
  19. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  20. # will see the following message at the end:
  21. #        "End of archive 3 (of 4)."
  22. # Contents:  io.c ibp.h rbp.h makefile makereal makefile.unx
  23. # Wrapped by drt@chinet on Sat Jun 13 14:57:16 1992
  24. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  25. if test -f 'io.c' -a "${1}" != "-c" ; then 
  26.   echo shar: Will not clobber existing file \"'io.c'\"
  27. else
  28. echo shar: Extracting \"'io.c'\" \(25359 characters\)
  29. sed "s/^X//" >'io.c' <<'END_OF_FILE'
  30. X/* ************************************************** */
  31. X/* file io.c:  contains most input/output functions   */
  32. X/*                                                    */
  33. X/* Copyright (c) 1990, 1991, 1992 by Donald R. Tveter */
  34. X/*                                                    */
  35. X/* ************************************************** */
  36. X
  37. X#include <stdio.h>
  38. X#ifdef INTEGER
  39. X#include "ibp.h"
  40. X#else
  41. X#include "rbp.h"
  42. X#endif
  43. X
  44. X#ifdef UNIX
  45. X#include <malloc.h>
  46. X#define WRITEBIN "w"
  47. X#define READBIN "r"
  48. X#else
  49. X#include <stdlib.h>
  50. X#define WRITEBIN "wb"
  51. X#define READBIN "rb"
  52. X#endif
  53. X
  54. Xextern char buffer[buffsize], copyflag, *datafilename, echo, outformat;
  55. Xextern char outstr[OUTSTRSIZE], *wtfile, wtformat;
  56. Xextern int bufferend, bufferptr, filestackptr, format[maxformat];
  57. Xextern FILE *data, *filestack[];
  58. Xextern LAYER *start;
  59. Xextern int lastsave, pagesize, readerror, readingpattern, totaliter;
  60. Xextern INT32 lineno;
  61. Xextern short nlayers;
  62. Xextern WTTYPE qmark, toler;
  63. Xextern FILE *copy;
  64. X
  65. XWTTYPE error;
  66. Xint bad;
  67. X
  68. X#ifdef INTEGER
  69. X
  70. Xshort scale(x)     /* returns x as a scaled 16-bit value */
  71. XREAL x;
  72. X{
  73. X short s;
  74. X
  75. Xif (x > 31.999 || x < -32.0)
  76. X {
  77. X  sprintf(outstr,"magnitude of %f is too large for the integer",x);
  78. X  pg(outstr);
  79. X  pg(" representation\n");
  80. X  readerror = 1;
  81. X  if (x > 31.999) return(MAXSHORT); else return(MINSHORT);
  82. X };
  83. Xif (x > 0.0) s = x * 1024 + 0.5;
  84. Xelse s = x * 1024 - 0.5;
  85. Xif (x != 0.0 && s == 0)
  86. X {
  87. X  sprintf(outstr,"warning:  magnitude of %f is too small for",x);
  88. X  pg(outstr);
  89. X  pg(" the integer representation\n");
  90. X  return(0);
  91. X };
  92. Xreturn(s);
  93. X}
  94. X
  95. XREAL unscale(x)  /* returns the REAL value of short x */
  96. Xshort x;
  97. X{ return((REAL) x / 1024.0); }
  98. X
  99. XREAL unscaleint(x)  /* returns the REAL value of INT32 x */
  100. XINT32 x;
  101. X{ return((REAL) x / 1024.0); }
  102. X
  103. X#endif
  104. X
  105. Xint pushfile(filename)
  106. Xchar *filename;
  107. X{
  108. XFILE *file;
  109. X
  110. Xbufferptr = 0;
  111. Xbufferend = 0;
  112. Xbuffer[0] = '\n';
  113. Xfile = fopen(filename,"r");
  114. Xif (file == NULL)
  115. X {
  116. X  sprintf(outstr,"cannot open:, %s\n",filename); pg(outstr);
  117. X  return(0);
  118. X };
  119. Xfilestackptr = filestackptr + 1;
  120. Xif (filestackptr > 3)
  121. X {
  122. X  pg("can't stack up any more files\n");
  123. X  filestackptr = filestackptr - 1;
  124. X  fclose(file);
  125. X  return(0);
  126. X };
  127. Xfilestack[filestackptr] = file;
  128. Xdata = file;
  129. Xreturn(1);
  130. X} 
  131. X
  132. Xvoid popfile()
  133. X{
  134. Xbufferptr = 0;
  135. Xbufferend = 0;
  136. Xbuffer[0] = '\n';
  137. Xif (filestackptr > 0)
  138. X {
  139. X  fclose(data);
  140. X  filestackptr = filestackptr - 1;
  141. X }
  142. Xelse pg("\nunexpected EOF:  to quit the program, type q\n");
  143. Xdata = filestack[filestackptr];
  144. X}
  145. X
  146. Xint readch() /* returns the next character in the input buffer */
  147. X{ 
  148. X int i, ch2;
  149. X char smallbuffer[2];
  150. X
  151. Xif (bufferptr > bufferend) /* then read next line into buffer */
  152. X {
  153. X  ch2 = getc(data);
  154. X  if (ch2 == EOF) return(ch2);
  155. X  i = 0;
  156. X  while(ch2 != '\n' && i < buffsize)
  157. X   {
  158. X#ifdef UNIX
  159. X    if (ch2 == 13) ch2 = ' '; /* turn a ctrl-M into a blank */
  160. X#endif
  161. X    buffer[i] = ch2;
  162. X    i = i + 1;
  163. X    ch2 = getc(data);
  164. X   };
  165. X  if (i == buffsize) pg("line too long\n");
  166. X  buffer[i] = '\n';
  167. X  bufferend = i;
  168. X  bufferptr = 0;
  169. X  if (echo == '+') for(i = 0; i <= bufferend; i++) putchar(buffer[i]);
  170. X  if (copy && ((data == stdin) || (echo == '+')))
  171. X   for (i=0;i<=bufferend;i++) putc(buffer[i],copy);
  172. X }
  173. Xch2 = buffer[bufferptr];
  174. Xbufferptr = bufferptr + 1;
  175. Xreturn(ch2);
  176. X}
  177. X
  178. Xvoid texterror()
  179. X{
  180. Xint ch2;
  181. Xpg("unexpected text:  ");
  182. Xpg(&buffer[bufferptr-1]);
  183. Xbufferptr = buffsize + 1;
  184. X}
  185. X
  186. Xchar *readstr()
  187. X{
  188. Xshort i,start,end;
  189. Xchar *addr, *addr2;
  190. Xi = bufferptr;
  191. Xwhile (buffer[i] == ' ') i = i + 1;
  192. Xstart = i;
  193. Xwhile (buffer[i] != ' ' && buffer[i] != '\n') i = i + 1;
  194. Xend = i-1;
  195. Xaddr = (char *) malloc((int) end-start+2);
  196. Xaddr2 = addr;
  197. Xfor (i=start;i<=end;i++) *addr++ = buffer[i];
  198. Xbufferptr = end + 1;
  199. X*addr = '\0';
  200. Xreturn(addr2);
  201. X}
  202. X
  203. Xint scanfordigit()
  204. X{
  205. Xint sign, ch2;
  206. X
  207. Xsign = 1;
  208. X
  209. Xrestart:
  210. Xdo ch2 = readch(); while (ch2 == ' ' || ch2 == '\n');
  211. Xif (ch2 >= '0' && ch2 <= '9')
  212. X {
  213. X  bufferptr = bufferptr - 1;
  214. X  return(sign);
  215. X };
  216. Xif (ch2 >= 'h' && ch2 <= 'k')
  217. X {
  218. X  bufferptr = bufferptr - 1;
  219. X  return(0);
  220. X };
  221. X          switch (ch2) {
  222. Xcase EOF: readerror = 2;
  223. X          return(0);
  224. Xcase '*': while (ch2 != '\n') ch2 = readch();
  225. X          goto restart;
  226. Xcase '-': sign = -sign;
  227. X          goto restart;
  228. Xcase '?': bufferptr = bufferptr - 1;
  229. X          return(0);
  230. Xdefault:  readerror = 1;
  231. X          return(0);
  232. X          };
  233. X}
  234. X
  235. Xint readint(min,max,command)
  236. Xint min, max;
  237. Xchar command;
  238. X{
  239. Xint sign, number, ch2;
  240. X
  241. Xreaderror = 0;
  242. Xsign = scanfordigit();
  243. Xif (readerror)
  244. X {
  245. X  if (readerror == 1) texterror();
  246. X  return(0);
  247. X };
  248. Xnumber = 0;
  249. Xdo ch2 = readch(); while (ch2 == ' ');
  250. Xwhile (ch2 >= '0' && ch2 <= '9')
  251. X {
  252. X  number = number * 10 + (ch2 - '0');
  253. X  ch2 = readch();
  254. X };
  255. Xbufferptr = bufferptr - 1;
  256. Xnumber = sign * number;
  257. Xif (number < min || number > max)
  258. X {
  259. X  sprintf(outstr,"out of range value: %d",number); pg(outstr);
  260. X  if (data == stdin) pg("\n");
  261. X  else {sprintf(outstr," in %c command\n",command); pg(outstr);};
  262. X  readerror = 1;
  263. X };
  264. Xreturn(number);
  265. X}
  266. X
  267. XREAL readreal(op,min,command)
  268. Xint op;
  269. XREAL min;
  270. Xint command;
  271. X{
  272. XREAL number, fractpart, divisor, intpart, sign;
  273. Xint ch2;
  274. X
  275. Xreaderror = 0;
  276. Xsign = (REAL) scanfordigit();
  277. Xif (readerror || (sign == 0 && !readingpattern))
  278. X {
  279. X  if (readerror == 1) texterror();
  280. X  return(0);
  281. X };
  282. Xch2 = readch();
  283. Xif (ch2 == 'h' && readingpattern) return(unscale(HCODE));
  284. Xelse if (ch2 == 'i' && readingpattern && nlayers >= 3)
  285. X  return(unscale(ICODE));
  286. Xelse if (ch2 == 'j' && readingpattern && nlayers >= 4)
  287. X  return(unscale(JCODE));
  288. Xelse if (ch2 == 'k' && readingpattern && nlayers >= 5)
  289. X  return(unscale(KCODE));
  290. Xelse if (ch2 == '?' && readingpattern)
  291. X  return(unscale(qmark));
  292. Xintpart = 0.0;
  293. Xwhile (ch2 >= '0' && ch2 <= '9')
  294. X {
  295. X  intpart = 10.0 * intpart + (ch2 - '0');
  296. X  ch2 = readch();
  297. X };
  298. Xfractpart = 0.0;
  299. Xdivisor = 1.0;
  300. Xif (ch2 == '.')
  301. X {
  302. X  ch2 = readch();
  303. X  while (ch2 >= '0' && ch2 <= '9')
  304. X   {
  305. X    fractpart = fractpart * 10.0 + (ch2 - '0');
  306. X    divisor = divisor * 10.0;
  307. X    ch2 = readch();
  308. X   };
  309. X };
  310. Xbufferptr = bufferptr - 1;
  311. Xnumber = sign * (((REAL) intpart) +
  312. X                ((REAL) fractpart) / ((REAL) divisor));
  313. Xif (op == GT && number > min) return(number);
  314. Xelse if (op == GE && number >= min) return(number);
  315. Xelse
  316. X {
  317. X  sprintf(outstr,"erroneous value: %f",number); pg(outstr);
  318. X  if (data == stdin) pg("\n");
  319. X  else {sprintf(outstr," in %c command\n",command); pg(outstr);};
  320. X  readerror = 1;
  321. X  return(0.0);
  322. X };
  323. X}
  324. X
  325. XWTTYPE rdr(op,min,command) /* reads REAL real numbers and converts */
  326. Xint op;                    /* them to 16-bit integers if necessary */
  327. XREAL min;
  328. Xint command;
  329. X{
  330. XREAL x;
  331. XWTTYPE ix;
  332. Xx = readreal(op,min,command);
  333. Xif (readerror) return(0);
  334. Xix = scale(x);
  335. Xif (readerror) return(0);
  336. Xreturn(ix);
  337. X}
  338. X
  339. XREAL readchar()   /* reads data in compressed format */
  340. X{
  341. Xint ch2;
  342. Xreaderror = 0;
  343. Xch2 = readch();
  344. Xdo {
  345. X          switch (ch2) {
  346. Xcase '\n':
  347. Xcase ' ': ch2 = readch();
  348. X          break;
  349. Xcase '1': return(1.0);
  350. Xcase '0': return(0.0);
  351. Xcase '?': return(unscale(qmark));
  352. Xcase '*': do ch2 = readch(); while(ch2 != '\n');
  353. X          break;
  354. Xcase 'h': return(unscale(HCODE));
  355. Xcase 'i': if (nlayers >= 3) return(unscale(ICODE));
  356. Xcase 'j': if (nlayers >= 4) return(unscale(JCODE));
  357. Xcase 'k': if (nlayers >= 5) return(unscale(KCODE));
  358. Xcase EOF: readerror = 2;
  359. X          return(0.0);
  360. Xdefault:  texterror();
  361. X          readerror = 1;
  362. X          return(0.0);};
  363. X} while (0 == 0);
  364. X}
  365. X
  366. Xint pg(str) /* paging and making a copy function */
  367. Xchar *str;
  368. X{
  369. Xchar *ch3,action,cr;
  370. Xint copying;
  371. X
  372. Xcopying = copyflag == '+';
  373. Xch3 = str;
  374. Xwhile (*ch3 != '\0')
  375. X   {
  376. X     if (*ch3 == '\n')
  377. X        {
  378. X          putchar('\n');
  379. X          if (copying) putc('\n',copy);
  380. X          lineno = lineno + 1;
  381. X          if (pagesize && lineno % pagesize == 0)
  382. X             {
  383. X               putchar(':');
  384. X               action = getchar();
  385. X               if (action == 'q')
  386. X                  {
  387. X                    cr = getchar();
  388. X                    return(action);
  389. X                  };
  390. X             }
  391. X        }
  392. X     else {putchar(*ch3); if (copying) putc(*ch3,copy); };
  393. X     ch3++;
  394. X   };
  395. Xreturn(0);
  396. X}
  397. X
  398. Xint printoutunits(printing,layer,printerr)  /* prints values of units */
  399. Xint printing;                               /* and computes errors */
  400. XLAYER *layer;
  401. Xint printerr;
  402. X{
  403. Xshort unitno, fmtbreaknum, maxval, maxunit;
  404. XUNIT *u;
  405. XWTTYPE upper, middle, diff;
  406. X
  407. Xif (printing)
  408. X {
  409. X  upper = scale(1.0) - toler;
  410. X  middle = scale(0.5);
  411. X  unitno = 0;
  412. X  fmtbreaknum = 1;
  413. X };
  414. Xbad = 0;
  415. Xmaxval = -scale(2.0);
  416. Xmaxunit = 0;
  417. Xerror = 0;
  418. Xu = (UNIT *) layer->units;
  419. Xwhile (u != NULL)
  420. X {
  421. X  diff = u->tj - u->oj;
  422. X  if (diff < 0) diff = -diff;
  423. X  if (diff >= toler) bad = 1;
  424. X  error = error +  diff;
  425. X  if (printing)
  426. X   {
  427. X    unitno = unitno + 1;
  428. X    if (outformat == 'r')
  429. X     {
  430. X      sprintf(outstr,"%6.3f ",unscale(u->oj)); pg(outstr);
  431. X      if (format[fmtbreaknum] == unitno)
  432. X       {
  433. X        if (pg("\n    ")) return(1);
  434. X        if (fmtbreaknum < maxformat - 1) fmtbreaknum = fmtbreaknum + 1;
  435. X       }
  436. X     }
  437. X    else if (outformat == 'a' && printerr)
  438. X     {
  439. X      if (diff < toler) pg("c");
  440. X      else if (u->oj > upper) pg("1");
  441. X      else if (u->oj < toler) pg("0");
  442. X      else if (u->oj > u->tj) pg("^");
  443. X      else pg("v");
  444. X      if (format[fmtbreaknum] == unitno)
  445. X       {
  446. X        pg(" ");
  447. X        if (fmtbreaknum < maxformat - 1) fmtbreaknum = fmtbreaknum + 1;
  448. X       }
  449. X     }
  450. X    else 
  451. X     {
  452. X      if (u->oj > upper) pg("1");
  453. X      else if (u->oj > middle) pg("^");
  454. X      else if (u->oj < toler) pg("0");
  455. X      else pg("v");
  456. X      if (format[fmtbreaknum] == unitno)
  457. X       {
  458. X        pg(" ");
  459. X        if (fmtbreaknum < maxformat - 1) fmtbreaknum = fmtbreaknum + 1;
  460. X       }
  461. X     }
  462. X   };
  463. X  u = u->next;
  464. X };
  465. Xif (!printing) return(0);
  466. Xif (printerr) {sprintf(outstr," (%5.3f)",unscale(error)); pg(outstr);};
  467. Xif (printerr && !bad) pg(" ok");
  468. Xif (pg("\n")) return(1); else return(0);
  469. X}
  470. X
  471. Xvoid saveweights()    /* saves weights on the file weights */
  472. X{
  473. XUNIT *u;
  474. XLAYER *layer;
  475. XWTNODE *w;
  476. XWTTYPE wvalue, evalue, dvalue, svalue;
  477. Xint wtsize;
  478. XFILE *weights;
  479. X
  480. Xwtsize = WTSIZE;
  481. Xweights = fopen(wtfile,WRITEBIN);
  482. Xif (weights == NULL)
  483. X {
  484. X  sprintf(outstr,"cannot open: %s\n",wtfile); pg(outstr);
  485. X  return;
  486. X };
  487. Xfprintf(weights,"%d%c",totaliter,wtformat);
  488. Xif (wtformat == 'b' || wtformat == 'B') fprintf(weights,"%1d",WTSIZE);
  489. Xfprintf(weights,"   file = %s\r\n",datafilename);
  490. Xlayer = start->next;
  491. Xwhile (layer != NULL)
  492. X {
  493. X  u = (UNIT *) layer->units;
  494. X  while (u != NULL)
  495. X   {
  496. X    w = (WTNODE *) u->wtlist;
  497. X    while (w != NULL)
  498. X     {
  499. X#ifdef SYMMETRIC
  500. X      wvalue = *(w->weight);
  501. X      evalue = *(w->eta);
  502. X      dvalue = *(w->olddw);
  503. X      svalue = 0; /* not worth having in the symmetric version */
  504. X#else
  505. X      wvalue = w->weight;
  506. X      evalue = w->eta;
  507. X      dvalue = w->olddw;
  508. X      svalue = w->slope;
  509. X#endif
  510. X      if (wtformat == 'r' || wtformat == 'R')
  511. X       {
  512. X        fprintf(weights,"%16.10f",unscale(wvalue));
  513. X        if (wtformat == 'R')
  514. X         {
  515. X          fprintf(weights," %16.10f",unscale(evalue));
  516. X          fprintf(weights," %16.10f",unscale(dvalue));
  517. X         };
  518. X        fprintf(weights,"\r\n");
  519. X       }
  520. X      else  /* binary format; uses the least space */
  521. X       {
  522. X        fwrite((char *) &wvalue,wtsize,1,weights);
  523. X        if (wtformat == 'B')
  524. X         {
  525. X          fwrite((char *) &evalue,wtsize,1,weights);
  526. X          fwrite((char *) &dvalue,wtsize,1,weights);
  527. X         };
  528. X       };
  529. X      w = w->next;
  530. X     };
  531. X    u = u->next;
  532. X   };
  533. X  layer = layer->next;
  534. X };
  535. Xfflush(weights);
  536. Xfclose(weights);
  537. Xlastsave = totaliter;
  538. X}
  539. X
  540. XWTTYPE rdb(wtfile,wtsize) /* read binary and convert between sizes */
  541. XFILE *wtfile;
  542. Xint wtsize;
  543. X{
  544. Xint i, ch2;
  545. Xdouble dvalue;
  546. Xfloat fvalue;
  547. Xshort ivalue;
  548. Xunsigned char *charptr;
  549. X
  550. Xif (wtsize == 2) charptr = (unsigned char *) &ivalue;
  551. Xelse if (wtsize == 4) charptr = (unsigned char *) &fvalue;
  552. Xelse if (wtsize == 8) charptr = (unsigned char *) &dvalue;
  553. Xelse pg("bad weight size\n");
  554. Xfor (i=1;i<=wtsize;i++)
  555. X {
  556. X  ch2 = fgetc(wtfile);
  557. X  *charptr = (unsigned char) ch2;
  558. X  charptr++;
  559. X };
  560. Xif (WTSIZE == 2 && wtsize == 2) return(ivalue);
  561. Xelse if (WTSIZE == 2 && wtsize == 4) return(scale(fvalue));
  562. Xelse if (WTSIZE == 2 && wtsize == 8) return(scale(dvalue));
  563. Xelse if (WTSIZE == 4 && wtsize == 2) return(ivalue / 1024.0);
  564. Xelse if (WTSIZE == 4 && wtsize == 4) return(fvalue);
  565. Xelse if (WTSIZE == 4 && wtsize == 8) return((float) dvalue);
  566. Xelse if (WTSIZE == 8 && wtsize == 2) return(ivalue / 1024.0);
  567. Xelse if (WTSIZE == 8 && wtsize == 4) return((double) fvalue);
  568. Xelse if (WTSIZE == 8 && wtsize == 8) return(dvalue);
  569. X}
  570. X
  571. Xvoid restoreweights()    /* restore weights from the file weights */
  572. X{
  573. XFILE *weights;
  574. XUNIT *u;
  575. XLAYER *layer;
  576. XWTNODE *w;
  577. Xint ch2, fileformat, wtsize;
  578. XWTTYPE wvalue, evalue, dvalue, svalue;
  579. Xdouble temp;
  580. X
  581. Xweights = fopen(wtfile,READBIN);
  582. Xif (weights == NULL)
  583. X {
  584. X  pg("cannot open file weights\n");
  585. X  return;
  586. X };
  587. Xfscanf(weights,"%d",&totaliter);
  588. Xfileformat = getc(weights);
  589. Xif (fileformat != wtformat) pg("note: weight format mismatch\n");
  590. Xif (fileformat == 'b' || fileformat == 'B')
  591. X {
  592. X  wtsize = getc(weights) - '0';
  593. X  if (WTSIZE != wtsize) pg("note: weight sizes mismatched\n");
  594. X }
  595. Xelse wtsize = WTSIZE;
  596. Xdo ch2 = getc(weights); while (ch2 != '\n'); /* skip rest of line */
  597. Xlayer = start->next;
  598. Xwhile (layer != NULL)
  599. X {
  600. X  u = (UNIT *) layer->units;
  601. X  while (u != NULL)
  602. X   {
  603. X    w = (WTNODE *) u->wtlist;
  604. X    while (w != NULL)
  605. X     {
  606. X      if (fileformat == 'r' || fileformat == 'R')
  607. X       {
  608. X        fscanf(weights,"%lf",&temp);
  609. X        wvalue = scale((REAL) temp);
  610. X        if (fileformat == 'R')
  611. X         {
  612. X          fscanf(weights,"%lf",&temp);
  613. X          evalue = scale((REAL) temp);
  614. X          fscanf(weights,"%lf",&temp);
  615. X          dvalue = scale((REAL) temp);
  616. X         };
  617. X       }
  618. X      else
  619. X       {
  620. X        wvalue = rdb(weights,wtsize);
  621. X        if (fileformat == 'B')
  622. X         {
  623. X          evalue = rdb(weights,wtsize);
  624. X          dvalue = rdb(weights,wtsize);
  625. X         };
  626. X       };
  627. X#ifdef SYMMETRIC
  628. X      *(w->weight) = wvalue;
  629. X      if (fileformat == 'R' || fileformat == 'B')
  630. X       {
  631. X        *(w->olddw) = dvalue;
  632. X        *(w->eta) = evalue;
  633. X       }
  634. X      else *(w->olddw) = 0;
  635. X#else
  636. X      w->weight = wvalue;
  637. X      if (fileformat == 'R' || fileformat == 'B')
  638. X       {
  639. X        w->olddw = dvalue;
  640. X        w->eta = evalue;
  641. X        w->slope = svalue;
  642. X       }
  643. X      else w->olddw = 0;
  644. X#endif
  645. X      w = w->next;
  646. X     };
  647. X    u = u->next;
  648. X   };
  649. X  layer = layer->next;
  650. X };
  651. Xfclose(weights);
  652. X}
  653. X
  654. Xvoid printweights(u)   /* print the weights leading into unit u */
  655. XUNIT *u;
  656. X
  657. X{
  658. XWTNODE *w;
  659. XUNIT *bunit;
  660. XWTTYPE value;
  661. X#ifdef INTEGER
  662. XINT32 sum, input;
  663. X#else
  664. XREAL sum, input;
  665. X#endif
  666. X
  667. Xw = (WTNODE *) u->wtlist;
  668. Xsum = 0;
  669. Xpg("layer unit  unit value     weight         input from unit\n");
  670. Xwhile (w != NULL)
  671. X {
  672. X  bunit = (UNIT *) w->backunit;
  673. X#ifdef SYMMETRIC
  674. X  value = *(w->weight);
  675. X#else
  676. X  value = w->weight;
  677. X#endif
  678. X
  679. X#ifdef INTEGER
  680. X  input = (INT32) value * bunit->oj;
  681. X  input = input / 1024;
  682. X#else
  683. X  input = value * bunit->oj;
  684. X#endif
  685. X  sum = sum + input;
  686. X  sprintf(outstr,"%3d   ",bunit->layernumber); pg(outstr);
  687. X  if (bunit->unitnumber == 32767) pg("   t ");
  688. X  else {sprintf(outstr,"%4d ",bunit->unitnumber); pg(outstr);};
  689. X  sprintf(outstr,"%10.5f  %10.5f  ",unscale(bunit->oj),unscale(value));
  690. X  pg(outstr);
  691. X  sprintf(outstr,"%18.5f\n",unscaleint(input));
  692. X  if (pg(outstr)) return;
  693. X  w = w->next;
  694. X };
  695. Xpg("                                      ");
  696. Xsprintf(outstr,"sum = %9.5f\n\n",unscaleint(sum)); pg(outstr);
  697. X}
  698. X
  699. Xvoid help()
  700. X{
  701. Xint ch2;
  702. Xpg("\n");
  703. Xdo ch2 = readch(); while (ch2 == ' ' && ch2 != '\n');
  704. X        switch(ch2) {
  705. X
  706. Xdefault:
  707. Xpg("for help type h followed by the letter of the command\n");
  708. Xif (ch2 == '\n') bufferptr = bufferptr - 1;
  709. Xbreak;
  710. X
  711. Xcase '?':
  712. Xpg("? prints program status and parameters.\n");
  713. Xbreak;
  714. X
  715. Xcase '*':
  716. Xpg("* at the beginning of a line makes the line a comment.\n");
  717. Xbreak;
  718. X
  719. Xcase '!':
  720. Xpg("Enter system commands after the !.\n");
  721. Xbreak;
  722. X
  723. Xcase 'A':
  724. Xpg("A is used to set details of the algorithm.  One or more of \n");
  725. Xpg("the following commands can go on the same line as the 'A':\n\n");
  726. Xpg("a l sets the linear activation function.\n");
  727. Xpg("a p sets the piecewise linear activation function.\n");
  728. Xpg("a t sets the piecewise near tanh activation function.\n");
  729. X#ifndef INTEGER
  730. Xpg("a s sets the smooth activation function.\n");
  731. Xpg("a T sets the smooth near tanh activation function.\n");
  732. X#endif
  733. Xpg("\n");
  734. Xpg("b + will backpropagate errors even when a unit is close to ");
  735. Xpg("its target.\n");
  736. Xpg("b - will not backpropagate errors when a unit is close to its");
  737. Xpg(" target.\n\n");
  738. Xpg("D <real> will set the sharpness of the sigmoid to <real>.\n\n");
  739. Xpg("d d will use the derivatives from the differential step size");
  740. Xpg(" algorithm.\n");
  741. Xpg("d F uses Fahlman's derivative in the output layer.\n");
  742. Xpg("d f uses Fahlman's derivative in all layers.\n");
  743. Xpg("d o uses the original derivative.\n\n");
  744. Xpg("g <int> updates weights after every group of <int> patterns if <int> != 0.\n\n");
  745. Xpg("s <int> will skip for <int> iterations patterns that have been ");
  746. Xpg("learned.\n\n");
  747. Xpg("t <int> will take pattern <int> out of the training process.\n");
  748. Xpg("   To bring it back in, use t 0.\n\n");
  749. Xpg("u c gives the continuous update method.\n");
  750. X#ifndef SYMMETRIC
  751. Xpg("u d gives the delta-bar-delta update method.\n");
  752. X#endif
  753. Xpg("u p gives the periodic update method.\n");
  754. Xbreak;
  755. X
  756. Xcase 'a':
  757. Xpg("a <real> sets the momentum parameter, alpha, to <real>.\n");
  758. Xbreak;
  759. X
  760. Xcase 'B':
  761. Xpg("B <options> sets the following benchmarking options:\n\n");
  762. Xpg("g <int> sets <int> to be the goal for the number of");
  763. Xpg(" networks to converge.\n\n");
  764. Xpg("k <real> sets the range of the initial random");
  765. Xpg(" weights for each network.\n\n");
  766. Xpg("m <int> sets the maximum number of networks to try.\n\n");
  767. Xpg("r <int1> <int2> sets <int1> to be the maximum ");
  768. Xpg("number of iterations to run.\n  <int2>, if present,");
  769. Xpg(" sets the rate at which to sample the network.\n  ");
  770. Xpg("Using r in a B command will initiate benchmarking.\n\n");
  771. Xpg("t <int> will benchmark with pattern <int> removed");
  772. Xpg(" from the training set\n  and test it at the");
  773. Xpg(" sample rate given in the r command.\n");
  774. Xpg("t f <testfile> will test patterns on <testfile> at ");
  775. Xpg("the interval given for\n   the sample rate.\n");
  776. Xpg("t 0 turns off either type of testing.\n");
  777. Xbreak;
  778. X
  779. Xcase 'b':
  780. Xpg("b <int1> <int2> ... <int20> puts a carriage break");
  781. Xpg(" after each <inti>\nvalues when the output format");
  782. Xpg(" is real and inserts a blank after each <inti>\n");
  783. Xpg("value if the format is condensed.\n");
  784. Xbreak;
  785. X
  786. Xcase 'C':
  787. Xpg("C clears the network and other relevant parameters");
  788. Xpg(" so the problem can be re-run\nwith different");
  789. Xpg(" initial weights.  Added hidden units are not removed.\n");
  790. Xbreak;
  791. X
  792. X#ifndef SYMMETRIC
  793. Xcase 'c':
  794. Xpg("c <int1> <int2> <int3> <int4>  ");
  795. Xpg("Adds a connection from layer <int1> unit <int2>\n");
  796. Xpg("   to layer <int3> unit <int4>.\n");
  797. Xbreak;
  798. X#endif
  799. X
  800. Xcase 'd':
  801. Xpg("d is used to set parameters for the delta-bar-delta method.\n");
  802. Xpg("One or more of the following commands can go on the line:\n\n");
  803. Xpg("d <real> sets the decay factor to <real>.\n");
  804. Xpg("e <real> sets the initial eta value to <real>.\n");
  805. Xpg("k <real> sets kappa to <real>.\n");
  806. Xpg("m <real> limits the maximum value of each eta to <real>.\n");
  807. X#ifdef INTEGER
  808. Xpg("n <real> sets some noise (integer versions only).");
  809. Xpg("   Try <real> around 0.005.\n");
  810. X#endif
  811. Xpg("t <real> sets the theta parameter to <real>.\n");
  812. Xbreak;
  813. X
  814. Xcase 'e':
  815. Xpg("e <real1> <real2> sets eta, the learning rate for the top layer");
  816. Xpg(" to <real1>\n   and eta2 for the lower layers to <real2>.  If ");
  817. Xpg("<real2> is not present,\n   eta2 is set to <real1>.\n");
  818. Xbreak;
  819. X
  820. Xcase 'f':
  821. Xpg("f is used to set the input and output formats for data.\nOne ");
  822. Xpg("or more of the following commands can go on the line:\n\n");
  823. Xpg("b + will ring the bell when learning is complete.\n");
  824. Xpg("b - will not ring the bell when learning is complete.\n\n");
  825. Xpg("c + will copy i/o to the file, copy.\n");
  826. Xpg("c - will stop writing to the file, copy.\n\n");
  827. Xpg("e + echos the input.\ne - does not echo.\n\n");
  828. Xpg("i c will read pattern values using compressed format.\n");
  829. Xpg("i r will read pattern values as reals.\n\n");
  830. Xpg("o a will write node values as analog compressed.\n");
  831. Xpg("o c will write node values as compressed.\n");
  832. Xpg("o r will write node values as real.\n\n");
  833. Xpg("P <int> sets the page size to <int>; 0 means no paging.\n\n");
  834. Xpg("p c will read patterns in the classification format and ");
  835. Xpg("summarize the results\n    when testing.\n");
  836. Xpg("p C will read patterns in the classification format and ");
  837. Xpg("print every result\n    when testing.\n");
  838. Xpg("p g will accept general patterns and summarize results when ");
  839. Xpg("testing.\n");
  840. Xpg("p G will accept general patterns and print every result when ");
  841. Xpg("testing.\n\n");
  842. Xpg("s + will summarize learning status.\n");
  843. Xpg("s - will not summarize learning status and will");
  844. Xpg(" list each pattern.\n\n");
  845. Xpg("u + will give up-to-date statistics on learning.\n");
  846. Xpg("u - will give statistics one iteration out of date.\n\n");
  847. Xpg("w b will write the weights as binary.\n");
  848. Xpg("w B will write the weights, weight changes and etas as binary.\n");
  849. Xpg("w r will write the weights as real values.\n");
  850. Xpg("w R will write the weights, weight changes and etas as real");
  851. Xpg(" values.\n");
  852. Xbreak;
  853. X
  854. X#ifndef SYMMETRIC
  855. Xcase 'H':
  856. Xpg("H <int> <real> adds a hidden unit to layer <int>\n");
  857. Xpg("Weights are initialized to between -<real> and +<real>.\n");
  858. Xbreak;
  859. X#endif
  860. X
  861. Xcase 'h':
  862. Xpg("h <letter> gives help for command <letter>.\n");
  863. Xbreak;
  864. X
  865. Xcase 'i':
  866. Xpg("i <inputfile> takes commands from the file.\n");
  867. Xpg("i takes commands from the current input file.\n");
  868. Xbreak;
  869. X
  870. Xcase 'k':
  871. Xpg("k <real1> <real2> decreases all the weights in the ");
  872. Xpg("network whose values\nare greater than <real1> by a");
  873. Xpg(" random amount between 0 and <real2>.\nWeights ");
  874. Xpg("less than -<real1> are increased by an amount ");
  875. Xpg("between 0 and <real2>.\nIf <real1> = 0.0, and a ");
  876. Xpg("weight = 0.0 then the weight is changed to\na ");
  877. Xpg("random value between -<real2> and +<real2>.\n");
  878. Xbreak;
  879. X
  880. Xcase 'l':
  881. Xpg("l <int> prints values of nodes on layer <int>.\n");
  882. Xbreak;
  883. X
  884. Xcase 'm':
  885. Xpg("m <int1> <int2> ... <intn> makes a network with\n");
  886. Xpg("<int1> units in the first layer, <int2> units in\n");
  887. Xpg("the second layer, ... , <intn> units in the nth layer.\n");
  888. Xbreak;
  889. X
  890. Xcase 'n':
  891. Xpg("n <int> <in1> <out1> ... <ini> <outi> ... <inN> <outN>");
  892. Xpg(" replaces all\n   training patterns with <int> new ones.\n");
  893. Xpg("n f <trainfile> reads however many patterns there are on");
  894. Xpg(" the file.\n");
  895. Xbreak;
  896. X
  897. Xcase 'O':
  898. Xpg("O <int> will give the output targets for pattern, <int>.\n");
  899. Xbreak;
  900. X
  901. Xcase 'o':
  902. Xpg("o a outputs node values in analog compressed form.");
  903. Xpg("\no c outputs node values in compressed form.\n");
  904. Xpg("o r outputs node values as real.\n");
  905. Xbreak;
  906. X
  907. Xcase 'P':
  908. Xpg("P lists the outputs for all patterns.\n");
  909. Xpg("P <int> gives the output for pattern <int>.\n");
  910. Xpg("P0 gives an up-to-date summary of learning.\n");
  911. Xbreak;
  912. X
  913. Xcase 'p':
  914. Xpg("p <pat> submits the pattern, <pat>, to the input units.\n");
  915. Xbreak;
  916. X
  917. Xcase 'Q':
  918. Xpg("Q <real> sets the value of ? in input patterns to <real>.\n");
  919. Xbreak;
  920. X
  921. Xcase 'q':
  922. Xpg("q followed immediately by a cr ends the program.\n\n");
  923. Xpg("qp is used to set parameters for the quickprop algorithm.\n");
  924. Xpg("One or more of the following commands can go on the line:\n\n");
  925. Xpg("d <real> sets the decay to <real> / 1000.\n");
  926. Xpg("e <real> sets the initial etas to <real>.\n");
  927. Xpg("m <real> sets mu, the accleration parameter to <real>.\n");
  928. Xpg("n <real> sets n, the noise (integer version only) to <real>.\n");
  929. Xpg("s+ adds the slope in to the weight changes (original algorithm).\n");
  930. Xpg("s- does not add the slope in.\n");
  931. Xbreak;
  932. X
  933. Xcase 'R':
  934. Xpg("R restores weights from the current weights file\n");
  935. Xbreak;
  936. X
  937. Xcase 'r':
  938. Xpg("r <int1> <int2> runs <int1> iterations thru the ");
  939. Xpg("patterns.  If <int2> is\npresent, the patterns are ");
  940. Xpg("printed (or summarized) every <int2> iterations.\n\n");
  941. Xpg("rw <filename> reads weights from the file, <filename> and sets ");
  942. Xpg("<filename>\n             to be the current weights file.\n");
  943. Xpg("rw reads weights from the current weights file.\n");
  944. Xbreak;
  945. X
  946. Xcase 'S':
  947. Xpg("S <int> saves the weights on the current weights file every <int>");
  948. Xpg(" iterations.\nS or S 0 saves the weights immediately.\n");
  949. Xbreak;
  950. X
  951. Xcase 's':
  952. Xpg("s <int1> <int2> ... <intn> sets the random number seeds.\n\n");
  953. Xpg("sw <filename> saves weights to the file, <filename> and sets ");
  954. Xpg("<filename>\n              to be the current weights file.\n");
  955. Xpg("sw saves weights to the current weights file.\n");
  956. Xbreak;
  957. X
  958. X#ifdef SYMMETRIC
  959. Xcase 'T':
  960. Xpg("T <real> freezes all threshold weights at <real>.\n");
  961. Xbreak;
  962. X#endif
  963. X
  964. Xcase 't':
  965. Xpg("t <real> sets <real> as the tolerance used in checking for");
  966. Xpg(" complete learning.\n");
  967. Xpg("t f <testfile> tests the patterns on the file.\n");
  968. Xpg("t f tests the patterns on the current test file.\n");
  969. Xpg("t tests the patterns on the current test file.\n");
  970. Xbreak;
  971. X
  972. X#ifndef SYMMETRIC
  973. Xcase 'W':
  974. Xpg("W <real> removes links whose weights are less than ");
  975. Xpg("the absolute value\nof <real>, except links to ");
  976. Xpg("threshold units are not removed.\n");
  977. Xbreak;
  978. X#endif
  979. X
  980. Xcase 'w':
  981. Xpg("w <int1> <int2>  ");
  982. Xpg("prints weights into unit <int2> in layer <int1>.\n");
  983. Xbreak;
  984. X
  985. Xcase 'x':
  986. Xpg("x <int1> <in1> <out1> ... <ini> <outi> ... <inN> <outN>  adds");
  987. Xpg(" the extra\n   <int1> patterns.\n");
  988. Xpg("x f <trainfile> adds the extra patterns found on the file.\n");
  989. Xbreak;
  990. X     }; /* end switch */
  991. Xpg("\n");
  992. X}
  993. END_OF_FILE
  994. if test 25359 -ne `wc -c <'io.c'`; then
  995.     echo shar: \"'io.c'\" unpacked with wrong size!
  996. fi
  997. # end of 'io.c'
  998. fi
  999. if test -f 'ibp.h' -a "${1}" != "-c" ; then 
  1000.   echo shar: Will not clobber existing file \"'ibp.h'\"
  1001. else
  1002. echo shar: Extracting \"'ibp.h'\" \(3468 characters\)
  1003. sed "s/^X//" >'ibp.h' <<'END_OF_FILE'
  1004. X/* ****************************************************** */
  1005. X/* file ibp.h: contains definitions for programs that use */
  1006. X/*             16-bit integer weights                     */
  1007. X/*                                                        */
  1008. X/* Copyright (c) 1990, 1991, 1992 by Donald R. Tveter     */
  1009. X/*                                                        */
  1010. X/* ****************************************************** */
  1011. X
  1012. X#ifdef DOS16
  1013. X#define INT32 long
  1014. X#define MAXINT 32767
  1015. X#else
  1016. X#define INT32 int
  1017. X#define MAXINT 2147483647
  1018. X#endif
  1019. X
  1020. X#define maxformat 21          /* maximum number of format breaks */
  1021. X#define buffsize 257          /* maximum size of an input line */
  1022. X#define WTTYPE short          /* a 16-bit integer */
  1023. X#define WTSIZE 2              /* shorts are two bytes */
  1024. X#define MAXSHORT 32767        /* largest short */
  1025. X#define MINSHORT -32768       /* smallest short */
  1026. X#define OUTSTRSIZE 257        /* max size of output string */
  1027. X#define HCODE -32768          /* code number for a layer h (2) unit */
  1028. X#define ICODE -32767          /* code number for a layer i (3) unit */
  1029. X#define JCODE -32766          /* code number for a layer j (4) unit */
  1030. X#define KCODE -32765          /* code number for a layer k (5) unit */
  1031. X#define GT 0                  /* a symbol meaning > */
  1032. X#define GE 1                  /* a symbol meaning >= */
  1033. X
  1034. X#ifdef FLOAT
  1035. X#define REAL float
  1036. X#else
  1037. X#define REAL double
  1038. X#endif
  1039. X
  1040. Xtypedef struct seednode
  1041. X   {
  1042. X     unsigned val;            /* a seed value */
  1043. X     struct seednode *next;   /* pointer to next node */
  1044. X   } SEEDNODE;
  1045. Xtypedef struct patlist
  1046. X   {
  1047. X     int bypass;              /* number of times to bypass pattern */
  1048. X     WTTYPE *pats;            /* the list of patterns */
  1049. X     struct patlist *next;    /* pointer to the next pattern */
  1050. X   } PATLIST;
  1051. Xtypedef struct unit
  1052. X   {
  1053. X     short layernumber;       /* layer number of the unit */
  1054. X     short unitnumber;        /* position within layer */
  1055. X     INT32 error;             /* to sum error factors */
  1056. X     WTTYPE oj;               /* state of activation of node */
  1057. X     WTTYPE tj;               /* output target of a node */
  1058. X     struct wtnode *wtlist;   /* the list of weights */
  1059. X     struct unit *next;       /* link to next unit in this layer */
  1060. X   } UNIT;
  1061. X
  1062. Xtypedef struct wtnode
  1063. X   {
  1064. X#ifdef SYMMETRIC
  1065. X     WTTYPE *weight;          /* ptr to weight */
  1066. X     WTTYPE *olddw;           /* ptr to delta wji */
  1067. X     WTTYPE *eta;             /* ptr to eta for the DBD method */
  1068. X     INT32 *total;            /* ptr to total of weight changes */
  1069. X     WTTYPE *slope;           /* previous slope */
  1070. X#else
  1071. X     WTTYPE weight;           /* weight from here to backunit */
  1072. X     WTTYPE olddw;            /* delta wji from previous iteration */
  1073. X     WTTYPE eta;              /* the eta for the DBD method */
  1074. X     INT32 total;             /* total weight changes for batch mode */
  1075. X     WTTYPE slope;            /* previous slope */
  1076. X#endif
  1077. X     struct wtnode *next;     /* link to next node */
  1078. X     UNIT *backunit;          /* ptr to unit the weight comes from */
  1079. X   } WTNODE;
  1080. X
  1081. Xtypedef struct layer
  1082. X   {
  1083. X     int unitcount;           /* number of units in this layer */
  1084. X     struct layer *backlayer; /* pointer to previous layer */
  1085. X     struct layer *next;      /* pointer to next layer */
  1086. X     UNIT *units;             /* start of list of units in this layer */
  1087. X     PATLIST *patstart;       /* to the list of patterns */
  1088. X     PATLIST *currentpat;     /* the current pattern */
  1089. X   } LAYER;
  1090. END_OF_FILE
  1091. if test 3468 -ne `wc -c <'ibp.h'`; then
  1092.     echo shar: \"'ibp.h'\" unpacked with wrong size!
  1093. fi
  1094. # end of 'ibp.h'
  1095. fi
  1096. if test -f 'rbp.h' -a "${1}" != "-c" ; then 
  1097.   echo shar: Will not clobber existing file \"'rbp.h'\"
  1098. else
  1099. echo shar: Extracting \"'rbp.h'\" \(3493 characters\)
  1100. sed "s/^X//" >'rbp.h' <<'END_OF_FILE'
  1101. X/* ***************************************************** */
  1102. X/* file rbp.h:  contains definitions for the rbp program */
  1103. X/*              that uses 64-bit floating point weights  */
  1104. X/*                                                       */
  1105. X/* Copyright (c) 1990, 1991, 1992 by Donald R. Tveter    */
  1106. X/*                                                       */
  1107. X/* *******************************************************/
  1108. X
  1109. X#define maxformat 21
  1110. X#define buffsize 257
  1111. X
  1112. X#ifdef FLOAT
  1113. X#define WTTYPE float
  1114. X#define WTSIZE 4
  1115. X#define REAL float
  1116. X#else
  1117. X#define WTTYPE double
  1118. X#define WTSIZE 8
  1119. X#define REAL double
  1120. X#endif
  1121. X
  1122. X#ifdef DOS16
  1123. X#define INT32 long
  1124. X#define MAXINT 32767
  1125. X#else
  1126. X#define INT32 int
  1127. X#define MAXINT 2147483647
  1128. X#endif
  1129. X
  1130. X#define HCODE -32768          /* code number for a layer h (2) unit */
  1131. X#define ICODE -32767          /* code number for a layer i (3) unit */
  1132. X#define JCODE -32766          /* code number for a layer j (4) unit */
  1133. X#define KCODE -32765          /* code number for a layer k (5) unit */
  1134. X#define GT 0                  /* a symbol meaning > */
  1135. X#define GE 1                  /* a symbol meaning >= */
  1136. X#define OUTSTRSIZE 257        /* max length of output string */
  1137. X#define scale(x) x            /* scale not used in real version */
  1138. X#define unscale(x) x          /* unscale not used in real version */
  1139. X#define unscaleint(x) x       /* unscaleint not used in real version */
  1140. X
  1141. Xtypedef struct seednode
  1142. X   {
  1143. X     unsigned val;            /* a seed value */
  1144. X     struct seednode *next;   /* pointer to next node */
  1145. X   } SEEDNODE;
  1146. Xtypedef struct patlist
  1147. X   {
  1148. X     int bypass;              /* number of times to bypass pattern */
  1149. X     WTTYPE *pats;            /* the list of patterns */
  1150. X     struct patlist *next;    /* pointer to the next pattern */
  1151. X   } PATLIST;
  1152. Xtypedef struct unit
  1153. X   {
  1154. X     short layernumber;       /* layer number of the unit */
  1155. X     short unitnumber;        /* position within layer */
  1156. X     REAL error;              /* to sum error factors */
  1157. X     WTTYPE oj;               /* state of activation of node */
  1158. X     WTTYPE tj;               /* output target for the node */
  1159. X     struct unit *wtlist;     /* to list of weights to prev layer */
  1160. X     struct unit *next;       /* link to next unit in this layer */
  1161. X   } UNIT;
  1162. X
  1163. Xtypedef struct wtnode
  1164. X   {
  1165. X#ifdef SYMMETRIC
  1166. X     WTTYPE *weight;          /* weight from here to backunit */
  1167. X     WTTYPE *olddw;           /* delta wji from previous iteration */
  1168. X     WTTYPE *total;           /* total of changes for batch updates */
  1169. X     WTTYPE *eta;             /* the eta of the DBD method */
  1170. X     WTTYPE *slope;           /* previous slope */
  1171. X#else
  1172. X     WTTYPE weight;           /* weight from here to backunit */
  1173. X     WTTYPE olddw;            /* delta wji from previous iterataion */
  1174. X     WTTYPE total;            /* total of changes for batch updates */
  1175. X     WTTYPE eta;              /* the eta of the DBD method */
  1176. X     WTTYPE slope;            /* previous slope */
  1177. X#endif
  1178. X     struct wtnode *next;     /* link to next node */
  1179. X     UNIT *backunit;          /* ptr to unit the weight comes from */
  1180. X   } WTNODE;
  1181. X
  1182. Xtypedef struct layer
  1183. X   {
  1184. X     int unitcount;           /* number of units in this layer */
  1185. X     struct layer *backlayer; /* pointer to previous layer */
  1186. X     struct layer *next;      /* pointer to next layer */
  1187. X     UNIT *units;             /* start of list of units in this layer */
  1188. X     PATLIST *patstart;       /* to the list of patterns */
  1189. X     PATLIST *currentpat;     /* the current pattern */
  1190. X   } LAYER;
  1191. END_OF_FILE
  1192. if test 3493 -ne `wc -c <'rbp.h'`; then
  1193.     echo shar: \"'rbp.h'\" unpacked with wrong size!
  1194. fi
  1195. # end of 'rbp.h'
  1196. fi
  1197. if test -f 'makefile' -a "${1}" != "-c" ; then 
  1198.   echo shar: Will not clobber existing file \"'makefile'\"
  1199. else
  1200. echo shar: Extracting \"'makefile'\" \(2257 characters\)
  1201. sed "s/^X//" >'makefile' <<'END_OF_FILE'
  1202. X#
  1203. X# This makefile can be used to make all 4 programs but note that
  1204. X# it is designed to make compiling the integer version bp easy
  1205. X# by keeping its object files around.  The other 3 programs erase
  1206. X# their object files.
  1207. X#
  1208. X# Below, where I say 32-bit floating point or 64-bit floating point,
  1209. X# note that the program uses some floating point instructions even the
  1210. X# integer versions, bp and sbp.  In standard UNIX C all floating point
  1211. X# arithmetic is done as double so using double values actually is faster
  1212. X# than using float values (because all the covnersions take time).
  1213. X# To use float rather than double define FLOAT like so:  -DFLOAT
  1214. X#
  1215. X# To get the compiler to use 32-bit DOS settings include: -DDOS32
  1216. X# To get the compiler to use 16-bit DOS settings include: -DDOS16
  1217. X#
  1218. X# Below are the settings I've been using for Zortech 3.0.
  1219. X# The -f flag in the ZORTECH CFLAGS forces hardware floating point
  1220. X# instructions to be generated.  The -o is for optimize, -m is used
  1221. X# to give the memory model.  NOTE that in the following makefile I don't
  1222. X# use the Zortech optimization flag -o in the CFLAGS, instead it is used
  1223. X# in the definitions for bp.obj, misc.obj and int.obj because for
  1224. X# some reason the compiler bombs when it optimizes io.obj.  As its
  1225. X# set up, sbp, srbp and rbp will not be optimized.
  1226. X#
  1227. X# use the following line for DOS/ZORTECH (486)
  1228. X#CFLAGS= -mx -4 -f -DFLOAT -DDOS32
  1229. X# use the following line for DOS/ZORTECH (386)
  1230. X#CFLAGS= -mx -3 -DFLOAT -DDOS32
  1231. X# use the following line for DOS/ZORTECH (286)
  1232. X#CFLAGS= -mz -2 -f -DFLOAT -DDOS16
  1233. X# use the following line for DOS/ZORTECH (8088) large memory model
  1234. XCFLAGS= -ml -f -DFLOAT -DDOS16
  1235. X
  1236. Xbp: bp.obj io.obj misc.obj int.obj makefile ibp.h
  1237. X    ztc $(CFLAGS) bp.obj io.obj misc.obj int.obj -obp.exe
  1238. X
  1239. Xsbp:
  1240. X    ztc -DINTEGER -DSYMMETRIC int.c bp.c io.c misc.c $(CFLAGS) -osbp.exe
  1241. X    erase *.obj
  1242. X
  1243. Xrbp:
  1244. X    ztc real.c bp.c io.c misc.c $(CFLAGS) -orbp.exe
  1245. X    erase *.obj
  1246. X
  1247. Xsrbp:
  1248. X    ztc -DSYMMETRIC real.c bp.c io.c misc.c $(CFLAGS) -osrbp.exe
  1249. X    erase *.obj
  1250. X
  1251. Xbp.obj: bp.c ibp.h makefile
  1252. X    ztc -DINTEGER $(CFLAGS) bp.c -c -o
  1253. X
  1254. Xio.obj: io.c ibp.h makefile
  1255. X    ztc -DINTEGER $(CFLAGS) io.c -c
  1256. X
  1257. Xmisc.obj: misc.c ibp.h makefile
  1258. X    ztc -DINTEGER $(CFLAGS) misc.c -c -o
  1259. X
  1260. Xint.obj: int.c ibp.h makefile
  1261. X    ztc -DINTEGER -DSMART $(CFLAGS) int.c -c -o
  1262. END_OF_FILE
  1263. if test 2257 -ne `wc -c <'makefile'`; then
  1264.     echo shar: \"'makefile'\" unpacked with wrong size!
  1265. fi
  1266. # end of 'makefile'
  1267. fi
  1268. if test -f 'makereal' -a "${1}" != "-c" ; then 
  1269.   echo shar: Will not clobber existing file \"'makereal'\"
  1270. else
  1271. echo shar: Extracting \"'makereal'\" \(1677 characters\)
  1272. sed "s/^X//" >'makereal' <<'END_OF_FILE'
  1273. X#
  1274. X# This makefile is designed to make only the rbp program AND TO KEEP
  1275. X# all the .obj files, so you can apply changes to one file without
  1276. X# recompiling all the others.
  1277. X#
  1278. X# Below, where I say 32-bit floating point or 64-bit floating point,
  1279. X# note that all the programs use some floating point instructions even
  1280. X# the integer versions, bp and sbp.  In standard UNIX C all floating
  1281. X# point arithmetic is done as double so using double values actually is
  1282. X# faster than using float values (because all the covnersions take
  1283. X# time).  To use float rather than double define FLOAT like so:  -DFLOAT
  1284. X#
  1285. X# To get the compiler to use 32-bit DOS settings include: -DDOS32
  1286. X# To get the compiler to use 16-bit DOS settings include: -DDOS16
  1287. X#
  1288. X# Below are the settings I've been using for Zortech C 3.0.
  1289. X# The -f flag in the ZORTECH CFLAGS forces hardware floating point
  1290. X# instructions to be generated.  The -o is for optimize, -m is used
  1291. X# to give the memory model, -4 for a 486, -3 for a 386, -2 for a 286.
  1292. X#
  1293. X# use the following line for DOS/ZORTECH (486)
  1294. XCFLAGS= -mx -4 -f -o -DFLOAT -DDOS32
  1295. X# use the following line for DOS/ZORTECH (386)
  1296. X#CFLAGS= -mx -3 -o -DFLOAT -DDOS32
  1297. X# use the following line for DOS/ZORTECH (286)
  1298. X#CFLAGS= -mz -2 -f -o -DFLOAT -DDOS16
  1299. X# use the following line for DOS/ZORTECH (8088) large memory model
  1300. X#CFLAGS= -ml -f -o -DFLOAT -DDOS16
  1301. X
  1302. Xrbp: bp.obj io.obj misc.obj real.obj makereal rbp.h
  1303. X    ztc $(CFLAGS) bp.obj io.obj misc.obj real.obj -orbp.exe
  1304. X
  1305. Xbp.obj: bp.c rbp.h makereal
  1306. X    ztc $(CFLAGS) bp.c -c
  1307. X
  1308. Xio.obj: io.c rbp.h makereal
  1309. X    ztc $(CFLAGS) io.c -c
  1310. X
  1311. Xmisc.obj: misc.c rbp.h makereal
  1312. X    ztc $(CFLAGS) misc.c -c
  1313. X
  1314. Xreal.obj: real.c rbp.h makereal
  1315. X    ztc $(CFLAGS) real.c -c
  1316. END_OF_FILE
  1317. if test 1677 -ne `wc -c <'makereal'`; then
  1318.     echo shar: \"'makereal'\" unpacked with wrong size!
  1319. fi
  1320. # end of 'makereal'
  1321. fi
  1322. if test -f 'makefile.unx' -a "${1}" != "-c" ; then 
  1323.   echo shar: Will not clobber existing file \"'makefile.unx'\"
  1324. else
  1325. echo shar: Extracting \"'makefile.unx'\" \(774 characters\)
  1326. sed "s/^X//" >'makefile.unx' <<'END_OF_FILE'
  1327. X# for 32-bit floating point use the following line:
  1328. X#CFLAGS= -s -O -DFLOAT -DUNIX
  1329. X# for 64-bit floating point use the following line:
  1330. XCFLAGS= -s -O -DUNIX
  1331. X
  1332. Xbp: bp.o io.o misc.o int.o makefile ibp.h
  1333. X    cc $(CFLAGS) bp.o io.o misc.o int.o -o bp
  1334. X
  1335. Xsbp:
  1336. X    cc -DINTEGER -DSYMMETRIC int.c bp.c io.c misc.c $(CFLAGS) -o sbp
  1337. X    rm bp.o io.o int.o misc.o
  1338. X
  1339. Xrbp:
  1340. X    cc real.c bp.c io.c misc.c $(CFLAGS) -lm -o rbp
  1341. X    rm bp.o io.o real.o misc.o
  1342. X
  1343. Xsrbp:
  1344. X    ztc -DSYMMETRIC real.c bp.c io.c misc.c $(CFLAGS) -lm -o srbp
  1345. X    rm bp.o io.o real.o misc.o
  1346. X
  1347. Xbp.o: bp.c ibp.h makefile
  1348. X    cc -DINTEGER $(CFLAGS) bp.c -c
  1349. X
  1350. Xio.o: io.c ibp.h makefile
  1351. X    cc -DINTEGER $(CFLAGS) io.c -c
  1352. X
  1353. Xmisc.o: misc.c ibp.h makefile
  1354. X    cc -DINTEGER $(CFLAGS) misc.c -c
  1355. X
  1356. Xint.o: int.c ibp.h makefile
  1357. X    cc -DINTEGER -DSMART $(CFLAGS) int.c -c
  1358. END_OF_FILE
  1359. if test 774 -ne `wc -c <'makefile.unx'`; then
  1360.     echo shar: \"'makefile.unx'\" unpacked with wrong size!
  1361. fi
  1362. # end of 'makefile.unx'
  1363. fi
  1364. echo shar: End of archive 3 \(of 4\).
  1365. cp /dev/null ark3isdone
  1366. MISSING=""
  1367. for I in 1 2 3 4 ; do
  1368.     if test ! -f ark${I}isdone ; then
  1369.     MISSING="${MISSING} ${I}"
  1370.     fi
  1371. done
  1372. if test "${MISSING}" = "" ; then
  1373.     echo You have unpacked all 4 archives.
  1374.     rm -f ark[1-9]isdone
  1375. else
  1376.     echo You still need to unpack the following archives:
  1377.     echo "        " ${MISSING}
  1378. fi
  1379. ##  End of shell archive.
  1380. exit 0
  1381.  
  1382. exit 0 # Just in case...
  1383.