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

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