home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / sources / misc / 3880 < prev    next >
Encoding:
Text File  |  1992-09-02  |  41.0 KB  |  1,390 lines

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