home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume29 / persim / part02 < prev    next >
Text File  |  1992-04-06  |  55KB  |  1,835 lines

  1. Newsgroups: comp.sources.misc
  2. From: stein.wbst129@xerox.com (Adam Stein)
  3. Subject:  v29i055:  persim - Single-Layer Perceptron Simulator, Part02/03
  4. Message-ID: <1992Apr5.025036.28360@sparky.imd.sterling.com>
  5. X-Md4-Signature: fc709629782e70bd08fd2d6d91564d31
  6. Date: Sun, 5 Apr 1992 02:50:36 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: stein.wbst129@xerox.com (Adam Stein)
  10. Posting-number: Volume 29, Issue 55
  11. Archive-name: persim/part02
  12. Environment: BSD
  13.  
  14. #! /bin/sh
  15. # into a shell via "sh file" or similar.  To overwrite existing files,
  16. # type "sh file -c".
  17. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  18. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  19. # Contents:  MANIFEST Makefile TODO alloc.c commands.h error.c
  20. #   example1/README example1/output2 example1/output3 example1/output5
  21. #   example1/runit example2/README example2/output1 example2/output2
  22. #   example2/output3 example2/output4 example2/output5 example2/runit
  23. #   funcs.h grammar.y help.c lexical.l load.c math.c persim.c range.c
  24. #   resize.c save.c startup.c toggle.c
  25. # Wrapped by kent@sparky on Sat Apr  4 20:29:30 1992
  26. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  27. echo If this archive is complete, you will see the following message:
  28. echo '          "shar: End of archive 2 (of 3)."'
  29. if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  30.   echo shar: Will not clobber existing file \"'MANIFEST'\"
  31. else
  32.   echo shar: Extracting \"'MANIFEST'\" \(1310 characters\)
  33.   sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
  34. X   File Name            Shar #           Description
  35. X-----------------------------------------------------------
  36. XMANIFEST           1          This list of files
  37. XMakefile           1          Makefile for persim
  38. XREADME               1              Details about program
  39. XTODO               1          List of possible future enhancements
  40. Xalloc.c               1          Memory allocation routines
  41. Xcommands.h           1          Available commands arrays
  42. Xerror.c               1          Error printing routine
  43. Xexample1.tar           1          10 Random points example
  44. Xexample2.tar           1          Another 10 Random points example
  45. Xfuncs.h               1          Which function for which command
  46. Xgrammar.y           1          Persim grammar syntax
  47. Xhelp.c               1          'Help' command
  48. Xis.c               1          Which command was typed in
  49. Xlexical.l           1          Lexical input
  50. Xload.c               1          'Load' command
  51. Xmath.c               1          Output node math routines
  52. Xpersim.1           1          Man page
  53. Xpersim.c           1          The persim program
  54. Xpersim.h           1          Common definitions
  55. Xrange.c               1          'Range' command
  56. Xread.c               1          Read input files routines
  57. Xresize.c           1          Resize memory allocations routines
  58. Xrun.c               1          'Run' command
  59. Xsave.c               1          'Save' command
  60. Xset.c               1          Routines to set values to variables
  61. Xshow.c               1          'Show' command
  62. Xstartup.c           1          Starup lex & yacc processing
  63. Xtoggle.c           1          Routines for toggle commands
  64. Xwrite.c               1          Write output files routines
  65. X
  66. END_OF_FILE
  67.   if test 1310 -ne `wc -c <'MANIFEST'`; then
  68.     echo shar: \"'MANIFEST'\" unpacked with wrong size!
  69.   fi
  70.   # end of 'MANIFEST'
  71. fi
  72. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  73.   echo shar: Will not clobber existing file \"'Makefile'\"
  74. else
  75.   echo shar: Extracting \"'Makefile'\" \(889 characters\)
  76.   sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  77. X.KEEP_STATE:
  78. X
  79. XBINDIR=/usr/local/bin
  80. XMANDIR=/usr/local/man/man1
  81. X
  82. X.y.o:
  83. X    ${YACC} ${YFLAGS} $<
  84. X    sh -c 'cmp -s y.tab.h $< || cp y.tab.h $*.h'
  85. X    rm -f y.tab.h
  86. X    ${CC} -c ${CFLAGS} y.tab.c
  87. X    mv y.tab.o $*.o
  88. X    rm y.tab.c
  89. X
  90. XOBJS        = alloc.o error.o help.o grammar.o is.o lexical.o load.o math.o\
  91. X          persim.o range.o read.o resize.o run.o save.o set.o show.o\
  92. X          startup.o toggle.o write.o
  93. XCFLAGS        =
  94. XYFLAGS        = -d
  95. XTARGET        = persim
  96. X
  97. X${TARGET}: date.h ${OBJS}
  98. X    ${CC} -o ${TARGET} ${OBJS} -lm
  99. X    @rm date.h
  100. X
  101. Xinstall: ${TARGET}
  102. X    @strip ${TARGET}
  103. X    mv ${TARGET} ${BINDIR}
  104. X    cp ${TARGET}.1 ${MANDIR}
  105. X
  106. Xclean:
  107. X    rm -f core makelog ${TARGET} ${OBJS} grammar.h lexical.c
  108. X
  109. Xdate.h:
  110. X    @echo "#define DATE \"`date +%D`\"" > date.h
  111. X    @echo "#define TIME \"`date +%r`\"" >> date.h
  112. X
  113. Xshar:
  114. X    (cd .. ; shar -n ${TARGET} -a -s stein.wbst129@xerox.com -c -o ${TARGET} -L 50 -p -T persim/[A-Z]* persim/*.[hcly1] -B persim/example*)
  115. X
  116. END_OF_FILE
  117.   if test 889 -ne `wc -c <'Makefile'`; then
  118.     echo shar: \"'Makefile'\" unpacked with wrong size!
  119.   fi
  120.   # end of 'Makefile'
  121. fi
  122. if test -f 'TODO' -a "${1}" != "-c" ; then 
  123.   echo shar: Will not clobber existing file \"'TODO'\"
  124. else
  125.   echo shar: Extracting \"'TODO'\" \(529 characters\)
  126.   sed "s/^X//" >'TODO' <<'END_OF_FILE'
  127. XPossible Future Enhancements:
  128. X
  129. X1.  Adjust input, output, desired, wts., node_attr when changing inodes,
  130. X    onodes, load state
  131. X
  132. X2.  Have routine read rest of line to print out for batch mode errors
  133. X
  134. X3.  Multilayer support
  135. X
  136. X4.  Various types of learning algorithms besides Rosenblatt's
  137. X
  138. X5.  More output node functions
  139. X
  140. X6.  Graphical front-end
  141. X
  142. X7.  History list (remember what commands user ran), be able to save/load the
  143. X    history list
  144. X
  145. X8.  Ability to read/write image/graphic formats (for pattern & image perceptron
  146. X    work)
  147. X
  148. END_OF_FILE
  149.   if test 529 -ne `wc -c <'TODO'`; then
  150.     echo shar: \"'TODO'\" unpacked with wrong size!
  151.   fi
  152.   # end of 'TODO'
  153. fi
  154. if test -f 'alloc.c' -a "${1}" != "-c" ; then 
  155.   echo shar: Will not clobber existing file \"'alloc.c'\"
  156. else
  157.   echo shar: Extracting \"'alloc.c'\" \(2495 characters\)
  158.   sed "s/^X//" >'alloc.c' <<'END_OF_FILE'
  159. X/*Copyright  (c)   1992  Adam  Stein.   All  Rights Reserved.
  160. X
  161. X  Permission to use,  copy,  modify  and  distribute  without
  162. X  charge this software, documentation, images, etc. is grant-
  163. X  ed, provided that this copyright and the author's  name  is
  164. X  retained.
  165. X
  166. X  A fee may be charged for this program ONLY to recover costs
  167. X  for distribution (i.e. media costs).  No profit can be made
  168. X  on this program.
  169. X
  170. X  The author assumes no responsibility for disasters (natural
  171. X  or otherwise) as a consequence of use of this software.
  172. X
  173. X  Adam Stein (stein.wbst129@xerox.com)
  174. X*/
  175. X
  176. X#include <stdio.h>
  177. X#include "persim.h"
  178. X
  179. Xchar *calloc();
  180. X
  181. X/*This routine allocates data for 1D arrays of double numbers.
  182. X
  183. X  Inputs:  array    - pointer to array allocate (and deallocate if necessary)
  184. X       numnodes - number of elements to allocate for
  185. X  Outputs: array    - pointer to new array
  186. X  Locals:  none
  187. X  Globals: NULL     - 0
  188. X*/
  189. Xalloc_data(numnodes,array)
  190. Xregister int numnodes;
  191. Xregister double **array;
  192. X{
  193. X    /*Deallocate previous array if there is one*/
  194. X    if(*array) free((char *) *array);
  195. X
  196. X    /*Allocate space for new array*/
  197. X    if((*array = (double *) calloc(numnodes,sizeof(double))) == NULL)
  198. X      error();
  199. X}
  200. X
  201. X/*This routine allocates data for 2D arrays of double numbers (i.e. the
  202. X  weights).
  203. X
  204. X  Inputs:  array    - pointer to array allocate (and deallocate if necessary)
  205. X       inodes   - number of input nodes
  206. X       onodes   - number of output nodes
  207. X  Outputs: none
  208. X  Locals:  loop     - number of input nodes (1st deminsion of 2D array)
  209. X  Globals: none
  210. X*/
  211. Xalloc_wts(array,inodes,onodes)
  212. Xregister int inodes,onodes;
  213. Xregister double ***array;
  214. X{
  215. X    register int loop;
  216. X
  217. X    /*Deallocate array if there is one*/
  218. X    if(*array) {
  219. X      for(loop = 0;loop < inodes;++loop)
  220. X        free((char *) (*array)[loop]);
  221. X
  222. X      free((char *) *array);
  223. X    }
  224. X
  225. X    /*Allocate new array*/
  226. X    if((*array = (double **) calloc(inodes,sizeof(double *)))== NULL)
  227. X      error();
  228. X    for(loop = 0;loop < inodes;++loop)
  229. X      if(((*array)[loop] = (double *) calloc(onodes,sizeof(double))) == NULL)
  230. X        error();
  231. X}
  232. X
  233. X/*This routine will deallocate the space taken up by the perceptron weights
  234. X  arrays.
  235. X
  236. X  Inputs:  none
  237. X  Outputs: none
  238. X  Locals:  loop    - loop through weights array
  239. X  Globals: state   - system variables
  240. X       weights - percetron weights
  241. X       NULL    - 0
  242. X*/
  243. Xdeallocwts()
  244. X{
  245. X    register int loop;
  246. X    extern double **weights;
  247. X    extern STATE state;
  248. X
  249. X    for(loop = 0;loop < state.inodes;++loop)
  250. X      free((char *) weights[loop]);
  251. X
  252. X    free((char *) weights);
  253. X
  254. X    weights = (double **) NULL;
  255. X}
  256. X
  257. END_OF_FILE
  258.   if test 2495 -ne `wc -c <'alloc.c'`; then
  259.     echo shar: \"'alloc.c'\" unpacked with wrong size!
  260.   fi
  261.   # end of 'alloc.c'
  262. fi
  263. if test -f 'commands.h' -a "${1}" != "-c" ; then 
  264.   echo shar: Will not clobber existing file \"'commands.h'\"
  265. else
  266.   echo shar: Extracting \"'commands.h'\" \(2111 characters\)
  267.   sed "s/^X//" >'commands.h' <<'END_OF_FILE'
  268. X/*Copyright  (c)   1992  Adam  Stein.   All  Rights Reserved. 
  269. X
  270. X  Permission to use,  copy,  modify  and  distribute  without
  271. X  charge this software, documentation, images, etc. is grant-
  272. X  ed, provided that this copyright and the author's  name  is
  273. X  retained. 
  274. X  A fee may be charged for this program ONLY to recover costs 
  275. X  for distribution (i.e. media costs).  No profit can be made    
  276. X  on this program. 
  277. X  The author assumes no responsibility for disasters (natural 
  278. X  or otherwise) as a consequence of use of this software.  
  279. X  Adam Stein (stein.wbst129@xerox.com)   
  280. X*/
  281. X
  282. X/*Command names and the number of arguments to issue the command.  A -1
  283. X  indicates that the value isn't used for that command.*/
  284. XCMD cmd[NUM_CMDS] = {
  285. X              {2,"alpha"},
  286. X              {-1,"exit"},
  287. X              {-1,"help"},
  288. X              {2,"inodes"},
  289. X              {3,"load"},
  290. X              {3,"node"},
  291. X              {2,"onodes"},
  292. X              {4,"range"},
  293. X              {-1,"run"},
  294. X              {3,"save"},
  295. X              {-1,"show"},
  296. X              {1,"training"},
  297. X              {0,"version"}
  298. X            };
  299. X
  300. X/*Qualifiers*/
  301. Xchar *qual[NUM_QUALIFIERS] = {
  302. X                   "ascii","binary","desired","function","input",
  303. X                   "output","random", "stdin","state","threshold",
  304. X                   "verbose", "weights"
  305. X                 };
  306. X
  307. X/*Description of each command for the help function*/
  308. Xchar *desc[NUM_CMDS] = {
  309. X"set alpha\n\
  310. X\n\
  311. Xsyntax: alpha = #",
  312. X
  313. X"exit program\n\
  314. X\n\
  315. Xsyntax: exit",
  316. X
  317. X"print local help information\n\
  318. X\n\
  319. Xsyntax: help <command>",
  320. X
  321. X"set the number of input nodes\n\
  322. X\n\
  323. Xsyntax: inodes = #",
  324. X
  325. X"load variables from a file or stdin\n\
  326. X\n\
  327. Xsyntax: load <var> \"filename\"[, type]  (file)\n\
  328. X    load <var> stdin               (keyboard)",
  329. X
  330. X"set output node information\n\
  331. X\n\
  332. Xsyntax: node[#] attr value",
  333. X
  334. X"set the number of output nodes\n\
  335. X\n\
  336. Xsyntax: onodes = #",
  337. X
  338. X"set a range\n\
  339. X\n\
  340. Xsyntax: range <obj> min max",
  341. X
  342. X"run the simulator\n\
  343. X\n\
  344. Xsyntax: run [verbose]",
  345. X
  346. X"save variables to a file\n\
  347. X\n\
  348. Xsyntax: save <var> \"filename\"[, type]",
  349. X
  350. X"show the value of a variable\n\
  351. X\n\
  352. Xsyntax: show <var>",
  353. X
  354. X"toggle training mode\n\
  355. X\n\
  356. Xsyntax: training",
  357. X
  358. X"print current version\n\
  359. X\n\
  360. Xsyntax: version"
  361. X};
  362. X
  363. END_OF_FILE
  364.   if test 2111 -ne `wc -c <'commands.h'`; then
  365.     echo shar: \"'commands.h'\" unpacked with wrong size!
  366.   fi
  367.   # end of 'commands.h'
  368. fi
  369. if test -f 'error.c' -a "${1}" != "-c" ; then 
  370.   echo shar: Will not clobber existing file \"'error.c'\"
  371. else
  372.   echo shar: Extracting \"'error.c'\" \(1057 characters\)
  373.   sed "s/^X//" >'error.c' <<'END_OF_FILE'
  374. X/*Copyright  (c)   1992  Adam  Stein.   All  Rights Reserved.  
  375. X
  376. X  Permission to use,  copy,  modify  and  distribute  without
  377. X  charge this software, documentation, images, etc. is grant-
  378. X  ed, provided that this copyright and the author's  name  is 
  379. X  retained.  
  380. X  A fee may be charged for this program ONLY to recover costs  
  381. X  for distribution (i.e. media costs).  No profit can be made        
  382. X  on this program.  
  383. X  
  384. X  The author assumes no responsibility for disasters (natural  
  385. X  or otherwise) as a consequence of use of this software.    
  386. X  
  387. X  Adam Stein (stein.wbst129@xerox.com)      
  388. X*/ 
  389. X#include <stdio.h>
  390. X
  391. Xextern int errno;
  392. Xextern char *program;
  393. X
  394. X/*This routines uses the standard UNIX error routine, perror(), to report any
  395. X  system errors.  This routine then exits with the an error code equal to the
  396. X  last error encountered.
  397. X
  398. X  Inputs:  none
  399. X  Outputs: none
  400. X  Locals:  none
  401. X  Globals: errno   - number of last system error encountered
  402. X       program - name of currently executing program
  403. X*/
  404. Xerror()
  405. X{
  406. X    perror(program);
  407. X    exit(errno);
  408. X}
  409. X
  410. END_OF_FILE
  411.   if test 1057 -ne `wc -c <'error.c'`; then
  412.     echo shar: \"'error.c'\" unpacked with wrong size!
  413.   fi
  414.   # end of 'error.c'
  415. fi
  416. if test -f 'example1/README' -a "${1}" != "-c" ; then 
  417.   echo shar: Will not clobber existing file \"'example1/README'\"
  418. else
  419.   echo shar: Extracting \"'example1/README'\" \(1121 characters\)
  420.   sed "s/^X//" >'example1/README' <<'END_OF_FILE'
  421. XThis is an example of perceptron learning and testing.  The idea is to have
  422. XPersim be able to tell which side of a line a particular point is.
  423. X
  424. XThe only difference between example1 (this directory) and example2 is the
  425. Xrandom X & Y coordinates for the ten points (and the alpha used).
  426. X
  427. XThe boundary line used is:
  428. X
  429. X    y = -1/2X + 1
  430. X
  431. XTen random points were generated (input1.asc - input10.asc).  An extra input
  432. Xnode of value 1 was added to each input set instead of having an output
  433. Xnode threshold.
  434. X
  435. XDesired1.asc - desired10.asc is the expected answer for each corresponding
  436. Xinput set (input1.asc with expected output desired1.asc).
  437. X
  438. XWeights.asc is the file containing the weights.  This file get updated during
  439. Xtraining and used during testing.  This file is initially created by the
  440. Xfirst training session with Persim.
  441. X
  442. XOutput1 - output10 is the output for each session with Persim.
  443. X
  444. XRunit is a shell script to automate the training and testing of Persim.  It
  445. Xconsists of 2 FOR loops.  The first FOR loop creates batch files and runs
  446. XPersim to train and the second FOR loop creates batch files and runs Persim
  447. Xfor testing.
  448. X
  449. END_OF_FILE
  450.   if test 1121 -ne `wc -c <'example1/README'`; then
  451.     echo shar: \"'example1/README'\" unpacked with wrong size!
  452.   fi
  453.   # end of 'example1/README'
  454. fi
  455. if test -f 'example1/output2' -a "${1}" != "-c" ; then 
  456.   echo shar: Will not clobber existing file \"'example1/output2'\"
  457. else
  458.   echo shar: Extracting \"'example1/output2'\" \(440 characters\)
  459.   sed "s/^X//" >'example1/output2' <<'END_OF_FILE'
  460. Xpersim> inodes=3
  461. Xpersim> onodes=1
  462. Xpersim> alpha=0.01
  463. Xpersim> node function step
  464. Xpersim> load input "input2.asc",asc
  465. Xpersim> load desired "desired2.asc",asc
  466. Xpersim> load weights "weights.asc",asc
  467. Xpersim> run verbose
  468. XEpoch #1:
  469. X  Actual Output Node #1 = 1.000000
  470. X
  471. X  [New] From #1, To #1, Weight = 0.396465
  472. X  [New] From #2, To #1, Weight = 0.840485
  473. X  [New] From #3, To #1, Weight = 0.353336
  474. X
  475. Xpersim> save weights "weights.asc",asc
  476. Xpersim> exit
  477. END_OF_FILE
  478.   if test 440 -ne `wc -c <'example1/output2'`; then
  479.     echo shar: \"'example1/output2'\" unpacked with wrong size!
  480.   fi
  481.   # end of 'example1/output2'
  482. fi
  483. if test -f 'example1/output3' -a "${1}" != "-c" ; then 
  484.   echo shar: Will not clobber existing file \"'example1/output3'\"
  485. else
  486.   echo shar: Extracting \"'example1/output3'\" \(440 characters\)
  487.   sed "s/^X//" >'example1/output3' <<'END_OF_FILE'
  488. Xpersim> inodes=3
  489. Xpersim> onodes=1
  490. Xpersim> alpha=0.01
  491. Xpersim> node function step
  492. Xpersim> load input "input3.asc",asc
  493. Xpersim> load desired "desired3.asc",asc
  494. Xpersim> load weights "weights.asc",asc
  495. Xpersim> run verbose
  496. XEpoch #1:
  497. X  Actual Output Node #1 = 1.000000
  498. X
  499. X  [New] From #1, To #1, Weight = 0.396465
  500. X  [New] From #2, To #1, Weight = 0.840485
  501. X  [New] From #3, To #1, Weight = 0.353336
  502. X
  503. Xpersim> save weights "weights.asc",asc
  504. Xpersim> exit
  505. END_OF_FILE
  506.   if test 440 -ne `wc -c <'example1/output3'`; then
  507.     echo shar: \"'example1/output3'\" unpacked with wrong size!
  508.   fi
  509.   # end of 'example1/output3'
  510. fi
  511. if test -f 'example1/output5' -a "${1}" != "-c" ; then 
  512.   echo shar: Will not clobber existing file \"'example1/output5'\"
  513. else
  514.   echo shar: Extracting \"'example1/output5'\" \(441 characters\)
  515.   sed "s/^X//" >'example1/output5' <<'END_OF_FILE'
  516. Xpersim> inodes=3
  517. Xpersim> onodes=1
  518. Xpersim> alpha=0.01
  519. Xpersim> node function step
  520. Xpersim> load input "input5.asc",asc
  521. Xpersim> load desired "desired5.asc",asc
  522. Xpersim> load weights "weights.asc",asc
  523. Xpersim> run verbose
  524. XEpoch #1:
  525. X  Actual Output Node #1 = 1.000000
  526. X
  527. X  [New] From #1, To #1, Weight = -0.143535
  528. X  [New] From #2, To #1, Weight = 0.079450
  529. X  [New] From #3, To #1, Weight = 0.339017
  530. X
  531. Xpersim> save weights "weights.asc",asc
  532. Xpersim> exit
  533. END_OF_FILE
  534.   if test 441 -ne `wc -c <'example1/output5'`; then
  535.     echo shar: \"'example1/output5'\" unpacked with wrong size!
  536.   fi
  537.   # end of 'example1/output5'
  538. fi
  539. if test -f 'example1/runit' -a "${1}" != "-c" ; then 
  540.   echo shar: Will not clobber existing file \"'example1/runit'\"
  541. else
  542.   echo shar: Extracting \"'example1/runit'\" \(1326 characters\)
  543.   sed "s/^X//" >'example1/runit' <<'END_OF_FILE'
  544. X#!/bin/sh
  545. X
  546. Xfor loop in 1 2 3 4 5
  547. Xdo
  548. X  echo "inodes=3" > /tmp/persim.$$
  549. X  echo "onodes=1" >> /tmp/persim.$$
  550. X  echo "alpha=0.01" >> /tmp/persim.$$
  551. X  echo "node function step" >> /tmp/persim.$$
  552. X  echo "load input \"input$loop.asc\",asc" >> /tmp/persim.$$
  553. X  echo "load desired \"desired$loop.asc\",asc" >> /tmp/persim.$$
  554. X  if [ $loop -eq 1 ]
  555. X  then
  556. X    echo "load weights random" >> /tmp/persim.$$
  557. X  else
  558. X    echo "load weights \"weights.asc\",asc" >> /tmp/persim.$$
  559. X  fi
  560. X  echo "run verbose" >> /tmp/persim.$$
  561. X  echo "save weights \"weights.asc\",asc" >> /tmp/persim.$$
  562. X  echo "exit" >> /tmp/persim.$$
  563. X
  564. X  echo -n "Training with input file #$loop ... "
  565. X  persim /tmp/persim.$$ > output$loop
  566. X  echo "done"
  567. Xdone
  568. X
  569. Xecho ""
  570. X
  571. Xfor loop in 6 7 8 9 10
  572. Xdo
  573. X  echo "training" > /tmp/persim.$$
  574. X  echo "inodes=3" >> /tmp/persim.$$
  575. X  echo "onodes=1" >> /tmp/persim.$$
  576. X  echo "node function step" >> /tmp/persim.$$
  577. X  echo "load input \"input$loop.asc\",asc" >> /tmp/persim.$$
  578. X  echo "load weights \"weights.asc\",asc" >> /tmp/persim.$$
  579. X  echo "run" >> /tmp/persim.$$
  580. X  echo "# Expecting `cat desired$loop.asc` for output value" >> /tmp/persim.$$
  581. X  echo "show output" >> /tmp/persim.$$
  582. X  echo "exit" >> /tmp/persim.$$
  583. X
  584. X  echo -n "Testing with input file #$loop ... "
  585. X  persim /tmp/persim.$$ > output$loop
  586. X  echo "done"
  587. Xdone
  588. X
  589. Xrm -f /tmp/persim.$$
  590. X
  591. END_OF_FILE
  592.   if test 1326 -ne `wc -c <'example1/runit'`; then
  593.     echo shar: \"'example1/runit'\" unpacked with wrong size!
  594.   fi
  595.   chmod +x 'example1/runit'
  596.   # end of 'example1/runit'
  597. fi
  598. if test -f 'example2/README' -a "${1}" != "-c" ; then 
  599.   echo shar: Will not clobber existing file \"'example2/README'\"
  600. else
  601.   echo shar: Extracting \"'example2/README'\" \(1121 characters\)
  602.   sed "s/^X//" >'example2/README' <<'END_OF_FILE'
  603. XThis is an example of perceptron learning and testing.  The idea is to have
  604. XPersim be able to tell which side of a line a particular point is.
  605. X
  606. XThe only difference between example2 (this directory) and example1 is the
  607. Xrandom X & Y coordinates for the ten points (and the alpha used).
  608. X
  609. XThe boundary line used is:
  610. X
  611. X    y = -1/2X + 1
  612. X
  613. XTen random points were generated (input1.asc - input10.asc).  An extra input
  614. Xnode of value 1 was added to each input set instead of having an output
  615. Xnode threshold.
  616. X
  617. XDesired1.asc - desired10.asc is the expected answer for each corresponding
  618. Xinput set (input1.asc with expected output desired1.asc).
  619. X
  620. XWeights.asc is the file containing the weights.  This file get updated during
  621. Xtraining and used during testing.  This file is initially created by the
  622. Xfirst training session with Persim.
  623. X
  624. XOutput1 - output10 is the output for each session with Persim.
  625. X
  626. XRunit is a shell script to automate the training and testing of Persim.  It
  627. Xconsists of 2 FOR loops.  The first FOR loop creates batch files and runs
  628. XPersim to train and the second FOR loop creates batch files and runs Persim
  629. Xfor testing.
  630. X
  631. END_OF_FILE
  632.   if test 1121 -ne `wc -c <'example2/README'`; then
  633.     echo shar: \"'example2/README'\" unpacked with wrong size!
  634.   fi
  635.   # end of 'example2/README'
  636. fi
  637. if test -f 'example2/output1' -a "${1}" != "-c" ; then 
  638.   echo shar: Will not clobber existing file \"'example2/output1'\"
  639. else
  640.   echo shar: Extracting \"'example2/output1'\" \(429 characters\)
  641.   sed "s/^X//" >'example2/output1' <<'END_OF_FILE'
  642. Xpersim> inodes=3
  643. Xpersim> onodes=1
  644. Xpersim> alpha=0.08
  645. Xpersim> node function step
  646. Xpersim> load input "input1.asc",asc
  647. Xpersim> load desired "desired1.asc",asc
  648. Xpersim> load weights random
  649. Xpersim> run verbose
  650. XEpoch #1:
  651. X  Actual Output Node #1 = 1.000000
  652. X
  653. X  [New] From #1, To #1, Weight = 0.396465
  654. X  [New] From #2, To #1, Weight = 0.840485
  655. X  [New] From #3, To #1, Weight = 0.353336
  656. X
  657. Xpersim> save weights "weights.asc",asc
  658. Xpersim> exit
  659. END_OF_FILE
  660.   if test 429 -ne `wc -c <'example2/output1'`; then
  661.     echo shar: \"'example2/output1'\" unpacked with wrong size!
  662.   fi
  663.   # end of 'example2/output1'
  664. fi
  665. if test -f 'example2/output2' -a "${1}" != "-c" ; then 
  666.   echo shar: Will not clobber existing file \"'example2/output2'\"
  667. else
  668.   echo shar: Extracting \"'example2/output2'\" \(1312 characters\)
  669.   sed "s/^X//" >'example2/output2' <<'END_OF_FILE'
  670. Xpersim> inodes=3
  671. Xpersim> onodes=1
  672. Xpersim> alpha=0.08
  673. Xpersim> node function step
  674. Xpersim> load input "input2.asc",asc
  675. Xpersim> load desired "desired2.asc",asc
  676. Xpersim> load weights "weights.asc",asc
  677. Xpersim> run verbose
  678. XEpoch #1:
  679. X  Actual Output Node #1 = 1.000000
  680. X
  681. X  [New] From #1, To #1, Weight = 0.236465
  682. X  [New] From #2, To #1, Weight = 0.707865
  683. X  [New] From #3, To #1, Weight = 0.272974
  684. X
  685. XEpoch #2:
  686. X  Actual Output Node #1 = 1.000000
  687. X
  688. X  [New] From #1, To #1, Weight = 0.076465
  689. X  [New] From #2, To #1, Weight = 0.575245
  690. X  [New] From #3, To #1, Weight = 0.192612
  691. X
  692. XEpoch #3:
  693. X  Actual Output Node #1 = 1.000000
  694. X
  695. X  [New] From #1, To #1, Weight = -0.083535
  696. X  [New] From #2, To #1, Weight = 0.442625
  697. X  [New] From #3, To #1, Weight = 0.112250
  698. X
  699. XEpoch #4:
  700. X  Actual Output Node #1 = 1.000000
  701. X
  702. X  [New] From #1, To #1, Weight = -0.243535
  703. X  [New] From #2, To #1, Weight = 0.310004
  704. X  [New] From #3, To #1, Weight = 0.031888
  705. X
  706. XEpoch #5:
  707. X  Actual Output Node #1 = 1.000000
  708. X
  709. X  [New] From #1, To #1, Weight = -0.403535
  710. X  [New] From #2, To #1, Weight = 0.177384
  711. X  [New] From #3, To #1, Weight = -0.048474
  712. X
  713. XEpoch #6:
  714. X  Actual Output Node #1 = -1.000000
  715. X
  716. X  [New] From #1, To #1, Weight = -0.403535
  717. X  [New] From #2, To #1, Weight = 0.177384
  718. X  [New] From #3, To #1, Weight = -0.048474
  719. X
  720. Xpersim> save weights "weights.asc",asc
  721. Xpersim> exit
  722. END_OF_FILE
  723.   if test 1312 -ne `wc -c <'example2/output2'`; then
  724.     echo shar: \"'example2/output2'\" unpacked with wrong size!
  725.   fi
  726.   # end of 'example2/output2'
  727. fi
  728. if test -f 'example2/output3' -a "${1}" != "-c" ; then 
  729.   echo shar: Will not clobber existing file \"'example2/output3'\"
  730. else
  731.   echo shar: Extracting \"'example2/output3'\" \(616 characters\)
  732.   sed "s/^X//" >'example2/output3' <<'END_OF_FILE'
  733. Xpersim> inodes=3
  734. Xpersim> onodes=1
  735. Xpersim> alpha=0.08
  736. Xpersim> node function step
  737. Xpersim> load input "input3.asc",asc
  738. Xpersim> load desired "desired3.asc",asc
  739. Xpersim> load weights "weights.asc",asc
  740. Xpersim> run verbose
  741. XEpoch #1:
  742. X  Actual Output Node #1 = -1.000000
  743. X
  744. X  [New] From #1, To #1, Weight = -0.243535
  745. X  [New] From #2, To #1, Weight = 0.207843
  746. X  [New] From #3, To #1, Weight = 0.188877
  747. X
  748. XEpoch #2:
  749. X  Actual Output Node #1 = 1.000000
  750. X
  751. X  [New] From #1, To #1, Weight = -0.243535
  752. X  [New] From #2, To #1, Weight = 0.207843
  753. X  [New] From #3, To #1, Weight = 0.188877
  754. X
  755. Xpersim> save weights "weights.asc",asc
  756. Xpersim> exit
  757. END_OF_FILE
  758.   if test 616 -ne `wc -c <'example2/output3'`; then
  759.     echo shar: \"'example2/output3'\" unpacked with wrong size!
  760.   fi
  761.   # end of 'example2/output3'
  762. fi
  763. if test -f 'example2/output4' -a "${1}" != "-c" ; then 
  764.   echo shar: Will not clobber existing file \"'example2/output4'\"
  765. else
  766.   echo shar: Extracting \"'example2/output4'\" \(441 characters\)
  767.   sed "s/^X//" >'example2/output4' <<'END_OF_FILE'
  768. Xpersim> inodes=3
  769. Xpersim> onodes=1
  770. Xpersim> alpha=0.08
  771. Xpersim> node function step
  772. Xpersim> load input "input4.asc",asc
  773. Xpersim> load desired "desired4.asc",asc
  774. Xpersim> load weights "weights.asc",asc
  775. Xpersim> run verbose
  776. XEpoch #1:
  777. X  Actual Output Node #1 = 1.000000
  778. X
  779. X  [New] From #1, To #1, Weight = -0.243535
  780. X  [New] From #2, To #1, Weight = 0.207843
  781. X  [New] From #3, To #1, Weight = 0.188877
  782. X
  783. Xpersim> save weights "weights.asc",asc
  784. Xpersim> exit
  785. END_OF_FILE
  786.   if test 441 -ne `wc -c <'example2/output4'`; then
  787.     echo shar: \"'example2/output4'\" unpacked with wrong size!
  788.   fi
  789.   # end of 'example2/output4'
  790. fi
  791. if test -f 'example2/output5' -a "${1}" != "-c" ; then 
  792.   echo shar: Will not clobber existing file \"'example2/output5'\"
  793. else
  794.   echo shar: Extracting \"'example2/output5'\" \(442 characters\)
  795.   sed "s/^X//" >'example2/output5' <<'END_OF_FILE'
  796. Xpersim> inodes=3
  797. Xpersim> onodes=1
  798. Xpersim> alpha=0.08
  799. Xpersim> node function step
  800. Xpersim> load input "input5.asc",asc
  801. Xpersim> load desired "desired5.asc",asc
  802. Xpersim> load weights "weights.asc",asc
  803. Xpersim> run verbose
  804. XEpoch #1:
  805. X  Actual Output Node #1 = -1.000000
  806. X
  807. X  [New] From #1, To #1, Weight = -0.243535
  808. X  [New] From #2, To #1, Weight = 0.207843
  809. X  [New] From #3, To #1, Weight = 0.188877
  810. X
  811. Xpersim> save weights "weights.asc",asc
  812. Xpersim> exit
  813. END_OF_FILE
  814.   if test 442 -ne `wc -c <'example2/output5'`; then
  815.     echo shar: \"'example2/output5'\" unpacked with wrong size!
  816.   fi
  817.   # end of 'example2/output5'
  818. fi
  819. if test -f 'example2/runit' -a "${1}" != "-c" ; then 
  820.   echo shar: Will not clobber existing file \"'example2/runit'\"
  821. else
  822.   echo shar: Extracting \"'example2/runit'\" \(1326 characters\)
  823.   sed "s/^X//" >'example2/runit' <<'END_OF_FILE'
  824. X#!/bin/sh
  825. X
  826. Xfor loop in 1 2 3 4 5
  827. Xdo
  828. X  echo "inodes=3" > /tmp/persim.$$
  829. X  echo "onodes=1" >> /tmp/persim.$$
  830. X  echo "alpha=0.08" >> /tmp/persim.$$
  831. X  echo "node function step" >> /tmp/persim.$$
  832. X  echo "load input \"input$loop.asc\",asc" >> /tmp/persim.$$
  833. X  echo "load desired \"desired$loop.asc\",asc" >> /tmp/persim.$$
  834. X  if [ $loop -eq 1 ]
  835. X  then
  836. X    echo "load weights random" >> /tmp/persim.$$
  837. X  else
  838. X    echo "load weights \"weights.asc\",asc" >> /tmp/persim.$$
  839. X  fi
  840. X  echo "run verbose" >> /tmp/persim.$$
  841. X  echo "save weights \"weights.asc\",asc" >> /tmp/persim.$$
  842. X  echo "exit" >> /tmp/persim.$$
  843. X
  844. X  echo -n "Training with input file #$loop ... "
  845. X  persim /tmp/persim.$$ > output$loop
  846. X  echo "done"
  847. Xdone
  848. X
  849. Xecho ""
  850. X
  851. Xfor loop in 6 7 8 9 10
  852. Xdo
  853. X  echo "training" > /tmp/persim.$$
  854. X  echo "inodes=3" >> /tmp/persim.$$
  855. X  echo "onodes=1" >> /tmp/persim.$$
  856. X  echo "node function step" >> /tmp/persim.$$
  857. X  echo "load input \"input$loop.asc\",asc" >> /tmp/persim.$$
  858. X  echo "load weights \"weights.asc\",asc" >> /tmp/persim.$$
  859. X  echo "run" >> /tmp/persim.$$
  860. X  echo "# Expecting `cat desired$loop.asc` for output value" >> /tmp/persim.$$
  861. X  echo "show output" >> /tmp/persim.$$
  862. X  echo "exit" >> /tmp/persim.$$
  863. X
  864. X  echo -n "Testing with input file #$loop ... "
  865. X  persim /tmp/persim.$$ > output$loop
  866. X  echo "done"
  867. Xdone
  868. X
  869. Xrm -f /tmp/persim.$$
  870. X
  871. END_OF_FILE
  872.   if test 1326 -ne `wc -c <'example2/runit'`; then
  873.     echo shar: \"'example2/runit'\" unpacked with wrong size!
  874.   fi
  875.   chmod +x 'example2/runit'
  876.   # end of 'example2/runit'
  877. fi
  878. if test -f 'funcs.h' -a "${1}" != "-c" ; then 
  879.   echo shar: Will not clobber existing file \"'funcs.h'\"
  880. else
  881.   echo shar: Extracting \"'funcs.h'\" \(963 characters\)
  882.   sed "s/^X//" >'funcs.h' <<'END_OF_FILE'
  883. X/*Copyright  (c)   1992  Adam  Stein.   All  Rights Reserved.   
  884. X
  885. X  Permission to use,  copy,  modify  and  distribute  without
  886. X  charge this software, documentation, images, etc. is grant-
  887. X  ed, provided that this copyright and the author's  name  is  
  888. X  retained.   
  889. X  
  890. X  A fee may be charged for this program ONLY to recover costs   
  891. X  for distribution (i.e. media costs).  No profit can be made            
  892. X  on this program.   
  893. X   
  894. X  The author assumes no responsibility for disasters (natural   
  895. X  or otherwise) as a consequence of use of this software.      
  896. X   
  897. X  Adam Stein (stein.wbst129@xerox.com)         
  898. X*/ 
  899. X
  900. Xvoid fpset(),help(),iset(),load(),range(),run(),save(),show(),toggle();
  901. Xvoid version();
  902. X
  903. X/*Array of functions to execute for keywords.  Index into the array is
  904. X  determined by which keyword was found.*/
  905. Xvoid (*execute[NUM_CMDS])() = {
  906. X                 fpset, NULL, help, iset, load, NULL, iset,
  907. X                range, run, save, show, toggle, version
  908. X                  };
  909. X
  910. END_OF_FILE
  911.   if test 963 -ne `wc -c <'funcs.h'`; then
  912.     echo shar: \"'funcs.h'\" unpacked with wrong size!
  913.   fi
  914.   # end of 'funcs.h'
  915. fi
  916. if test -f 'grammar.y' -a "${1}" != "-c" ; then 
  917.   echo shar: Will not clobber existing file \"'grammar.y'\"
  918. else
  919.   echo shar: Extracting \"'grammar.y'\" \(3578 characters\)
  920.   sed "s/^X//" >'grammar.y' <<'END_OF_FILE'
  921. X%{
  922. X#include <stdio.h>
  923. X#include "persim.h"
  924. X#include "funcs.h"
  925. X
  926. Xextern int linenum,inhelp,inamb,print_line;
  927. Xextern char *program,*yacc_filename;
  928. X%}
  929. X
  930. X%union
  931. X{
  932. X    int inum;
  933. X    double dnum;
  934. X    char *string;
  935. X}
  936. X
  937. X%token AMBIGUOUS_KEYWORD EXIT_CMD HELP_CMD SHOW_CMD
  938. X%token FUNC_ATTR THRESHOLD_ATTR RUN_CMD VERBOSE_ATTR
  939. X%token <inum> DATA FILETYPE INT KEYWORD0 KEYWORD1 KEYWORD2 KEYWORD3
  940. X%token <inum> NODE_CMD KEYWORD4 NOTFILE
  941. X%token <dnum> FP
  942. X%token <string> STRING
  943. X
  944. X%type <inum> help run show
  945. X
  946. X%%
  947. Xline:
  948. X        | line '\n'            { wrapup_line(1); }
  949. X        | line command            { wrapup_line(0); }
  950. X        ;
  951. Xcommand:      error '\n'             { yyerrok; }
  952. X        | EXIT_CMD '\n'            { YYACCEPT; }
  953. X        | ambiguous '\n'        { yyerror(); }
  954. X        | help '\n'            { help($1); }
  955. X        | KEYWORD0 '\n'            { execute[$1](); }
  956. X        | KEYWORD1 '\n'            { execute[$1](); }
  957. X        | KEYWORD2 '=' INT '\n'        { execute[$1]($1,$3); }
  958. X        | KEYWORD2 '=' FP '\n'        { execute[$1]($1,$3); }
  959. X        | KEYWORD3 DATA '"' STRING '"' '\n'
  960. X                        { execute[$1]($2,$4,UNKNOWN); }
  961. X        | KEYWORD3 DATA '"' STRING '"' ',' FILETYPE '\n'
  962. X                        { execute[$1]($2,$4,$7); }
  963. X        | KEYWORD3 DATA NOTFILE '\n'     { execute[$1]($2,NULL,$3); }
  964. X        | KEYWORD4 STRING FP FP '\n'    { execute[$1]($2,$3,$4); }
  965. X        | NODE_CMD FUNC_ATTR STRING '\n'
  966. X                        { set_func($1,$3); }
  967. X        | NODE_CMD THRESHOLD_ATTR INT '\n'
  968. X                        { set_threshold($1,(double) $3); }
  969. X        | NODE_CMD THRESHOLD_ATTR FP '\n'
  970. X                        { set_threshold($1,$3); }
  971. X        | SHOW_CMD NODE_CMD '\n'    { show(NODE,$2); }
  972. X        | run '\n'            { run($1); }
  973. X        | show '\n'            { show($1,0); }
  974. X        ;
  975. Xambiguous:      AMBIGUOUS_KEYWORD        { }
  976. X        | AMBIGUOUS_KEYWORD '"' STRING '"'
  977. X                        { }
  978. X        | AMBIGUOUS_KEYWORD '=' INT     { }
  979. X        | AMBIGUOUS_KEYWORD '=' '"' STRING '"'
  980. X                        { }
  981. X        | AMBIGUOUS_KEYWORD '=' '"' STRING '"' ',' FILETYPE
  982. X                        { }
  983. X        | AMBIGUOUS_KEYWORD '=' NOTFILE
  984. X                        { }
  985. X        | AMBIGUOUS_KEYWORD FUNC_ATTR STRING
  986. X                        { }
  987. X        | AMBIGUOUS_KEYWORD THRESHOLD_ATTR INT
  988. X                        { }
  989. X        | AMBIGUOUS_KEYWORD THRESHOLD_ATTR FP
  990. X                        { }
  991. X        | AMBIGUOUS_KEYWORD VERBOSE_ATTR
  992. X                        { }
  993. X        | AMBIGUOUS_KEYWORD STRING FP FP
  994. X                        { }
  995. X        ;
  996. Xhelp:          HELP_CMD             { $$ = -1; }
  997. X        | HELP_CMD EXIT_CMD        { $$ = EXIT; }
  998. X        | HELP_CMD HELP_CMD        { $$ = HELP; }
  999. X        | HELP_CMD KEYWORD0        { $$ = $2; }
  1000. X        | HELP_CMD KEYWORD1        { $$ = $2; }
  1001. X        | HELP_CMD KEYWORD2        { $$ = $2; }
  1002. X        | HELP_CMD KEYWORD3        { $$ = $2; }
  1003. X        | HELP_CMD KEYWORD4        { $$ = $2; }
  1004. X        | HELP_CMD NODE_CMD        { $$ = NODE; }
  1005. X        | HELP_CMD RUN_CMD        { $$ = RUN; }
  1006. X        | HELP_CMD SHOW_CMD        { $$ = SHOW; }
  1007. X        | HELP_CMD AMBIGUOUS_KEYWORD    { $$ = AMBIGUOUS; }
  1008. X        ;
  1009. Xrun:          RUN_CMD            { $$ = 0; }
  1010. X        | RUN_CMD VERBOSE_ATTR        { $$ = 1; }
  1011. X        ;
  1012. Xshow:          SHOW_CMD DATA            { $$ = $2; }
  1013. X        | SHOW_CMD KEYWORD1        { $$ = $2; }
  1014. X        | SHOW_CMD KEYWORD2        { $$ = $2; }
  1015. X        | SHOW_CMD KEYWORD3        { $$ = $2; }
  1016. X        | SHOW_CMD KEYWORD4        { $$ = $2; }
  1017. X        | SHOW_CMD AMBIGUOUS_KEYWORD    { $$ = AMBIGUOUS; }
  1018. X        ;
  1019. X%%  
  1020. X
  1021. X/*This function is called when yacc has an error in parsing.
  1022. X
  1023. X  Inputs:  none
  1024. X  Outputs: none
  1025. X  Locals:  none
  1026. X  Globals: linenum       - current line number in file that yacc is reading
  1027. X       print_line    -
  1028. X       program       - name of program
  1029. X       stderr     - standard error
  1030. X       NULL         - 0
  1031. X*/
  1032. Xyyerror()
  1033. X{
  1034. X    if(print_line)
  1035. X      if(inhelp) printf("\ninvalid command to ask for help");
  1036. X      else if(inamb)
  1037. X         printf("%s: ambiguous command on line %d\n",program,linenum);
  1038. X           else printf("\n%s: syntax error on line %d",program,linenum);
  1039. X    else 
  1040. X      if(inhelp) puts("invalid command to ask for help");
  1041. X      else if(inamb) fputs("*** ambiguous command ***\n",stderr);
  1042. X           else fputs("*** syntax error ***\n",stderr);
  1043. X}
  1044. X
  1045. Xwrapup_line(blank)
  1046. Xregister int blank;
  1047. X{
  1048. X    ++linenum;
  1049. X    inhelp = 0;
  1050. X    inamb = 0;
  1051. X
  1052. X    prompt();
  1053. X}
  1054. X
  1055. END_OF_FILE
  1056.   if test 3578 -ne `wc -c <'grammar.y'`; then
  1057.     echo shar: \"'grammar.y'\" unpacked with wrong size!
  1058.   fi
  1059.   # end of 'grammar.y'
  1060. fi
  1061. if test -f 'help.c' -a "${1}" != "-c" ; then 
  1062.   echo shar: Will not clobber existing file \"'help.c'\"
  1063. else
  1064.   echo shar: Extracting \"'help.c'\" \(1462 characters\)
  1065.   sed "s/^X//" >'help.c' <<'END_OF_FILE'
  1066. X/*Copyright  (c)   1992  Adam  Stein.   All  Rights Reserved.   
  1067. X
  1068. X  Permission to use,  copy,  modify  and  distribute  without
  1069. X  charge this software, documentation, images, etc. is grant-
  1070. X  ed, provided that this copyright and the author's  name  is  
  1071. X  retained.   
  1072. X  
  1073. X  A fee may be charged for this program ONLY to recover costs   
  1074. X  for distribution (i.e. media costs).  No profit can be made            
  1075. X  on this program.   
  1076. X   
  1077. X  The author assumes no responsibility for disasters (natural   
  1078. X  or otherwise) as a consequence of use of this software.      
  1079. X   
  1080. X  Adam Stein (stein.wbst129@xerox.com)         
  1081. X*/ 
  1082. X
  1083. X#include "persim.h"
  1084. X
  1085. X/*This routine prints information and the syntax for a specified command or
  1086. X  a list of all commands if no special commands is specified.
  1087. X
  1088. X  Inputs:  subject - subject to provide help on
  1089. X  Outputs: none
  1090. X  Locals:  none
  1091. X  Globals: cmd     - name of command to print information about
  1092. X       desc    - help description to print
  1093. X*/
  1094. Xvoid help(subject)
  1095. Xregister int subject;
  1096. X{
  1097. X    extern char *desc[];
  1098. X    extern CMD cmd[];
  1099. X
  1100. X    if(subject == UNKNOWN) {
  1101. X      puts("Commands may be abbreviated.  The following commands are available:");
  1102. X      puts("");
  1103. X      puts("alpha\t\tinodes\t\tonodes\t\tsave\t\ttraining");
  1104. X      puts("exit\t\tload\t\trange\t\tshow\t\tversion");
  1105. X      puts("help\t\tnode\t\trun");
  1106. X    } else if(subject == AMBIGUOUS)
  1107. X         puts("*** ambiguous help subject ***");
  1108. X           else printf("%s - %s\n",cmd[subject].name,desc[subject]);
  1109. X}
  1110. X
  1111. END_OF_FILE
  1112.   if test 1462 -ne `wc -c <'help.c'`; then
  1113.     echo shar: \"'help.c'\" unpacked with wrong size!
  1114.   fi
  1115.   # end of 'help.c'
  1116. fi
  1117. if test -f 'lexical.l' -a "${1}" != "-c" ; then 
  1118.   echo shar: Will not clobber existing file \"'lexical.l'\"
  1119. else
  1120.   echo shar: Extracting \"'lexical.l'\" \(2174 characters\)
  1121.   sed "s/^X//" >'lexical.l' <<'END_OF_FILE'
  1122. X%{
  1123. X#include "grammar.h"
  1124. X#include "persim.h"
  1125. X
  1126. Xint linenum = 1,inhelp = 0,inamb = 0,quotes = 0;
  1127. Xextern int print_line;
  1128. Xdouble atof();
  1129. Xchar *strdup();
  1130. X%}
  1131. XCOMMENT        (#.*\n)
  1132. XMATCH_STRING    ([a-zA-Z/][a-zA-Z0-9_\./]*)
  1133. XNODE        (node[0-9]+)
  1134. XNUMBER        ([-+]?[0-9]+\.?[0-9]*)
  1135. X%%
  1136. X{COMMENT}    { ++linenum; if(print_line) ECHO; prompt(); }
  1137. X{NODE}        { ECHO; yylval.inum = atoi(yytext+4); return(NODE_CMD); }
  1138. X{MATCH_STRING}    {
  1139. X          int info;
  1140. X
  1141. X          if(print_line) ECHO;
  1142. X
  1143. X          if(quotes)
  1144. X            if((yylval.string = strdup(yytext)) == NULL) {
  1145. X              error();
  1146. X              exit(1);
  1147. X            } else return(STRING);
  1148. X
  1149. X          switch(yylval.inum = iskeyword(yytext,&info)) {
  1150. X            case EXIT:
  1151. X            return(EXIT_CMD);
  1152. X            case HELP:
  1153. X            inhelp = 1;
  1154. X            return(HELP_CMD);
  1155. X            case NODE:
  1156. X            yylval.inum = -1;
  1157. X            return(NODE_CMD);
  1158. X            case RUN:
  1159. X            return(RUN_CMD);
  1160. X            case SHOW:
  1161. X            return(SHOW_CMD);
  1162. X            case UNKNOWN:
  1163. X            if((yylval.inum = isqualifier(yytext,&info)) == UNKNOWN)
  1164. X              if((yylval.string = strdup(yytext)) == NULL) {
  1165. X                error();
  1166. X                exit(1);
  1167. X              } else return(STRING);
  1168. X            else if(yylval.inum == AMBIGUOUS)
  1169. X                   return(AMBIGUOUS_KEYWORD);
  1170. X                 else return(info);
  1171. X            case AMBIGUOUS:
  1172. X            inamb = 1;
  1173. X            return(AMBIGUOUS_KEYWORD);
  1174. X            default:
  1175. X            switch(info) {
  1176. X              case 0:    return(KEYWORD0);
  1177. X              case 1:    return(KEYWORD1);
  1178. X              case 2:    return(KEYWORD2);
  1179. X              case 3:    return(KEYWORD3);
  1180. X              case 4:    return(KEYWORD4);
  1181. X            }
  1182. X          }
  1183. X        }
  1184. X{NUMBER}    {
  1185. X          if(print_line) ECHO;
  1186. X
  1187. X          if(index(yytext,'.')) {
  1188. X            yylval.dnum = atof(yytext);
  1189. X            return(FP);
  1190. X          } else {
  1191. X                   yylval.inum = atoi(yytext);
  1192. X                   return(INT);
  1193. X             }
  1194. X        }
  1195. X\?        { if(print_line) putchar('?'); yylval.inum = HELP;
  1196. X          inhelp = 1; return(HELP_CMD); }
  1197. X\"        { if(print_line) ECHO; quotes ^= 1; return('\"'); }
  1198. X\n        { if(print_line) ECHO; return('\n'); }
  1199. X[^ \t]        { if(print_line) putchar(yytext[0]); return(yytext[0]); }
  1200. X[= \t]          { if(print_line) putchar(yytext[0]); }
  1201. X%%
  1202. X
  1203. X/*This function is called when lex reaches EOF.  A value of 1 is returned
  1204. X  to tell lex to finish up normally.
  1205. X
  1206. X  Inputs:  none
  1207. X  Outputs: 1 - tells lex to finish normally
  1208. X  Locals:  none
  1209. X  Globals: none
  1210. X*/
  1211. Xint yywrap()
  1212. X{
  1213. X    return(1);
  1214. X}
  1215. X
  1216. END_OF_FILE
  1217.   if test 2174 -ne `wc -c <'lexical.l'`; then
  1218.     echo shar: \"'lexical.l'\" unpacked with wrong size!
  1219.   fi
  1220.   # end of 'lexical.l'
  1221. fi
  1222. if test -f 'load.c' -a "${1}" != "-c" ; then 
  1223.   echo shar: Will not clobber existing file \"'load.c'\"
  1224. else
  1225.   echo shar: Extracting \"'load.c'\" \(3399 characters\)
  1226.   sed "s/^X//" >'load.c' <<'END_OF_FILE'
  1227. X/*Copyright  (c)   1992  Adam  Stein.   All  Rights Reserved.   
  1228. X
  1229. X  Permission to use,  copy,  modify  and  distribute  without
  1230. X  charge this software, documentation, images, etc. is grant-
  1231. X  ed, provided that this copyright and the author's  name  is  
  1232. X  retained.   
  1233. X  
  1234. X  A fee may be charged for this program ONLY to recover costs   
  1235. X  for distribution (i.e. media costs).  No profit can be made            
  1236. X  on this program.   
  1237. X   
  1238. X  The author assumes no responsibility for disasters (natural   
  1239. X  or otherwise) as a consequence of use of this software.      
  1240. X   
  1241. X  Adam Stein (stein.wbst129@xerox.com)         
  1242. X*/ 
  1243. X
  1244. X#include <stdio.h>
  1245. X#include "persim.h"
  1246. X
  1247. X/*This routine will load values into the different variables.
  1248. X
  1249. X  Inputs:  filename - name of the file containing the values
  1250. X       filetype - what type this file it is
  1251. X       var      - what variable to load
  1252. X  Outputs: none
  1253. X  Locals:  none
  1254. X  Globals: desired  - desired output value array
  1255. X       input    - input value array
  1256. X       output   - output value array
  1257. X       state    - system variables
  1258. X       weights  - perceptron weights
  1259. X       DESIRED  - load desired output values
  1260. X       INPUT    - load input values
  1261. X       NULL     - 0
  1262. X       OUTPUT   - load output values
  1263. X       RANDOM   - load variable with random numbers
  1264. X       SYS_VARS - load system variables
  1265. X       UNKNOWN  - variable isn't set
  1266. X       WEIGHTS  - load perceptron weights
  1267. X*/
  1268. Xvoid load(var,filename,filetype)
  1269. Xregister int var,filetype;
  1270. Xregister char *filename;
  1271. X{
  1272. X    char *calloc();
  1273. X    extern double *input,*output,*desired,**weights;
  1274. X    extern STATE state;
  1275. X
  1276. X    switch(var) {
  1277. X      case DESIRED:
  1278. X        if(filetype == RANDOM)
  1279. X          puts("can't assign random values to desired output");
  1280. X        else if(state.onodes == UNKNOWN)
  1281. X               puts("the number of output nodes has not been set");
  1282. X             else {
  1283. X                /*Allocate space*/
  1284. X                    alloc_data(state.onodes,&desired);
  1285. X
  1286. X                /*Read in values from file or keyboard*/
  1287. X                    if(!readdata(desired,state.onodes,filename,
  1288. X                     filetype)) {
  1289. X                  /*If the read failed, deallocate unused space*/
  1290. X                  free((char *) desired);
  1291. X                  desired = (double *) NULL;
  1292. X                    }
  1293. X                  }
  1294. X        break;
  1295. X      case INPUT:
  1296. X        if(filetype == RANDOM)
  1297. X          puts("can't assign random values for input");
  1298. X        else if(state.inodes == UNKNOWN)
  1299. X               puts("the number of input nodes has not been set");
  1300. X             else {
  1301. X                /*Allocate space*/
  1302. X                alloc_data(state.inodes,&input);
  1303. X
  1304. X                /*Read in values from file or keyboard*/
  1305. X                    if(!readdata(input,state.inodes,filename,
  1306. X                     filetype)) {
  1307. X                  /*If read failed, deallocate unused space*/
  1308. X                  free((char *) input);
  1309. X                  input = (double *) NULL;
  1310. X                    }
  1311. X                  }
  1312. X        break;
  1313. X      case OUTPUT:
  1314. X        puts("can't load output values (must be generated)");
  1315. X        break;
  1316. X      case SYS_VARS:
  1317. X        readstate(filename);
  1318. X        break;
  1319. X      case WEIGHTS:
  1320. X        if(state.inodes == UNKNOWN)
  1321. X          puts("the number of input nodes has not been set");
  1322. X        else if(state.onodes == UNKNOWN)
  1323. X               puts("the number of output nodes has not been set");
  1324. X             else {
  1325. X                if(filetype != RANDOM) {
  1326. X                  /*Allocate space*/
  1327. X                  alloc_wts(&weights,state.inodes,state.onodes);
  1328. X
  1329. X                  /*Read in values from file or keyboard*/
  1330. X                      if(!readwts(weights,state.inodes,state.onodes,
  1331. X                      filename,filetype))
  1332. X                /*If read failed, deallocate unused space*/
  1333. X                deallocwts();
  1334. X                } else randomize();
  1335. X              }
  1336. X        break;
  1337. X    }
  1338. X}
  1339. X
  1340. END_OF_FILE
  1341.   if test 3399 -ne `wc -c <'load.c'`; then
  1342.     echo shar: \"'load.c'\" unpacked with wrong size!
  1343.   fi
  1344.   # end of 'load.c'
  1345. fi
  1346. if test -f 'math.c' -a "${1}" != "-c" ; then 
  1347.   echo shar: Will not clobber existing file \"'math.c'\"
  1348. else
  1349.   echo shar: Extracting \"'math.c'\" \(1047 characters\)
  1350.   sed "s/^X//" >'math.c' <<'END_OF_FILE'
  1351. X/*Copyright  (c)   1992  Adam  Stein.   All  Rights Reserved.   
  1352. X
  1353. X  Permission to use,  copy,  modify  and  distribute  without
  1354. X  charge this software, documentation, images, etc. is grant-
  1355. X  ed, provided that this copyright and the author's  name  is  
  1356. X  retained.   
  1357. X  
  1358. X  A fee may be charged for this program ONLY to recover costs   
  1359. X  for distribution (i.e. media costs).  No profit can be made            
  1360. X  on this program.   
  1361. X   
  1362. X  The author assumes no responsibility for disasters (natural   
  1363. X  or otherwise) as a consequence of use of this software.      
  1364. X   
  1365. X  Adam Stein (stein.wbst129@xerox.com)         
  1366. X*/ 
  1367. X
  1368. Xextern double ranges[1][2];
  1369. X
  1370. X/*This routine is a step (i.e. sgn) function.  Any value greater than or equal
  1371. X  to 0 outputs 1 value, less than 0 outputs another value.
  1372. X
  1373. X  Inputs:  value  - value to act upon
  1374. X  Outputs: max range if value >=0, min range if < 0
  1375. X  Locals:  none
  1376. X  Globals: ranges - max and min values to return
  1377. X*/
  1378. Xdouble step(value)
  1379. Xregister double value;
  1380. X{
  1381. X    return((value >= 0.0)?ranges[0][1]:ranges[0][0]);
  1382. X}
  1383. X
  1384. END_OF_FILE
  1385.   if test 1047 -ne `wc -c <'math.c'`; then
  1386.     echo shar: \"'math.c'\" unpacked with wrong size!
  1387.   fi
  1388.   # end of 'math.c'
  1389. fi
  1390. if test -f 'persim.c' -a "${1}" != "-c" ; then 
  1391.   echo shar: Will not clobber existing file \"'persim.c'\"
  1392. else
  1393.   echo shar: Extracting \"'persim.c'\" \(2510 characters\)
  1394.   sed "s/^X//" >'persim.c' <<'END_OF_FILE'
  1395. X/*Copyright  (c)   1992  Adam  Stein.   All  Rights Reserved.   
  1396. X
  1397. X  Permission to use,  copy,  modify  and  distribute  without
  1398. X  charge this software, documentation, images, etc. is grant-
  1399. X  ed, provided that this copyright and the author's  name  is  
  1400. X  retained.   
  1401. X  
  1402. X  A fee may be charged for this program ONLY to recover costs   
  1403. X  for distribution (i.e. media costs).  No profit can be made            
  1404. X  on this program.   
  1405. X   
  1406. X  The author assumes no responsibility for disasters (natural   
  1407. X  or otherwise) as a consequence of use of this software.      
  1408. X   
  1409. X  Adam Stein (stein.wbst129@xerox.com)         
  1410. X*/ 
  1411. X
  1412. X#include <stdio.h>
  1413. X#include "persim.h"
  1414. X#include "date.h"
  1415. X
  1416. Xchar *program;
  1417. Xdouble *input,*output,*desired,**weights,ranges[1][2];
  1418. XNODE_ATTR *node_attr;
  1419. XSTATE state;
  1420. X
  1421. X/*This program simulates a single layer perceptron.
  1422. X
  1423. X  Inputs:  argc      - number of command line arguments
  1424. X       argv      - command line arguments
  1425. X  Outputs: 0 (no error status)
  1426. X  Locals:  none
  1427. X  Globals: desired   - array of desired output values
  1428. X       input     - array of input values
  1429. X       node_attr - node attributes (function, threshold)
  1430. X       output    - array of output values
  1431. X       program   - name of currently executing program
  1432. X       ranges    - max and min values (only for step function right now)
  1433. X       state     - system variables
  1434. X       weights   - perceptron weights
  1435. X       NULL         - 0
  1436. X*/
  1437. Xmain(argc,argv)
  1438. Xregister int argc;
  1439. Xregister char *argv[];
  1440. X{
  1441. X    /*Initialize*/
  1442. X    program = argv[0];
  1443. X
  1444. X    state.alpha = 0.1;
  1445. X    state.inodes = UNKNOWN;
  1446. X    state.onodes = UNKNOWN;
  1447. X    state.training = 1;
  1448. X
  1449. X    ranges[0][0] = -1.0;
  1450. X    ranges[0][1] = 1.0;
  1451. X
  1452. X    input = output = desired = (double *) NULL;
  1453. X    weights = (double **) NULL;
  1454. X    node_attr = (NODE_ATTR *) NULL;
  1455. X
  1456. X    /*Start up the parser*/
  1457. X    if(argc > 1) startup(argv[1]);
  1458. X    else startup(NULL);
  1459. X
  1460. X    if(input != (double *) NULL) free(input);
  1461. X    if(output != (double *) NULL) free(output);
  1462. X    if(desired != (double *) NULL) free(desired);
  1463. X    if(weights != (double **) NULL) deallocwts();
  1464. X
  1465. X    exit(0);
  1466. X}
  1467. X
  1468. X/*This routine prints out the interactive prompt.
  1469. X
  1470. X  Inputs:  none
  1471. X  Outputs: none
  1472. X  Locals:  none
  1473. X  Globals: program - name of currently executing program
  1474. X*/
  1475. Xprompt()
  1476. X{
  1477. X    printf("%s> ",program);
  1478. X}
  1479. X
  1480. X/*This routine prints the current version of this program.
  1481. X
  1482. X  Inputs:  none
  1483. X  Outputs: none
  1484. X  Locals:  none
  1485. X  Globals: DATE        - compilation date
  1486. X       TIME        - compilation time
  1487. X       VERSION_STR - current version and author
  1488. X*/
  1489. Xvoid version()
  1490. X{
  1491. X    printf("%s  (Last Compiled: %s @ %s)\n",VERSION_STR,DATE,TIME);
  1492. X}
  1493. X
  1494. END_OF_FILE
  1495.   if test 2510 -ne `wc -c <'persim.c'`; then
  1496.     echo shar: \"'persim.c'\" unpacked with wrong size!
  1497.   fi
  1498.   # end of 'persim.c'
  1499. fi
  1500. if test -f 'range.c' -a "${1}" != "-c" ; then 
  1501.   echo shar: Will not clobber existing file \"'range.c'\"
  1502. else
  1503.   echo shar: Extracting \"'range.c'\" \(1172 characters\)
  1504.   sed "s/^X//" >'range.c' <<'END_OF_FILE'
  1505. X/*Copyright  (c)   1992  Adam  Stein.   All  Rights Reserved.   
  1506. X
  1507. X  Permission to use,  copy,  modify  and  distribute  without
  1508. X  charge this software, documentation, images, etc. is grant-
  1509. X  ed, provided that this copyright and the author's  name  is  
  1510. X  retained.   
  1511. X  
  1512. X  A fee may be charged for this program ONLY to recover costs   
  1513. X  for distribution (i.e. media costs).  No profit can be made            
  1514. X  on this program.   
  1515. X   
  1516. X  The author assumes no responsibility for disasters (natural   
  1517. X  or otherwise) as a consequence of use of this software.      
  1518. X   
  1519. X  Adam Stein (stein.wbst129@xerox.com)         
  1520. X*/ 
  1521. X
  1522. X/*This function assigned max and min values for an object (right now, only
  1523. X  the range of the step function can be set).
  1524. X
  1525. X  Inputs:  max    - maximum value to set
  1526. X       min    - minimum value to set
  1527. X       string - object to set range for
  1528. X  Outputs: none
  1529. X  Locals:  none
  1530. X  Globals: ranges - max and min values of objects
  1531. X*/
  1532. Xvoid range(string,min,max)
  1533. Xregister double min,max;
  1534. Xregister char *string;
  1535. X{
  1536. X    extern double ranges[1][2];
  1537. X
  1538. X    if(!strcmp(string,"step")) {
  1539. X      ranges[0][0] = min;
  1540. X      ranges[0][1] = max;
  1541. X    } else puts("illegal object for a range");
  1542. X}
  1543. X
  1544. END_OF_FILE
  1545.   if test 1172 -ne `wc -c <'range.c'`; then
  1546.     echo shar: \"'range.c'\" unpacked with wrong size!
  1547.   fi
  1548.   # end of 'range.c'
  1549. fi
  1550. if test -f 'resize.c' -a "${1}" != "-c" ; then 
  1551.   echo shar: Will not clobber existing file \"'resize.c'\"
  1552. else
  1553.   echo shar: Extracting \"'resize.c'\" \(1350 characters\)
  1554.   sed "s/^X//" >'resize.c' <<'END_OF_FILE'
  1555. X/*Copyright  (c)   1992  Adam  Stein.   All  Rights Reserved.   
  1556. X
  1557. X  Permission to use,  copy,  modify  and  distribute  without
  1558. X  charge this software, documentation, images, etc. is grant-
  1559. X  ed, provided that this copyright and the author's  name  is  
  1560. X  retained.   
  1561. X  
  1562. X  A fee may be charged for this program ONLY to recover costs   
  1563. X  for distribution (i.e. media costs).  No profit can be made            
  1564. X  on this program.   
  1565. X   
  1566. X  The author assumes no responsibility for disasters (natural   
  1567. X  or otherwise) as a consequence of use of this software.      
  1568. X   
  1569. X  Adam Stein (stein.wbst129@xerox.com)         
  1570. X*/ 
  1571. X
  1572. X#include <stdio.h>
  1573. X#include "persim.h"
  1574. X
  1575. Xchar *realloc();
  1576. X
  1577. X/*This routine will resize the 1D arrays.
  1578. X
  1579. X  Inputs:  array - array to resize
  1580. X       size  - number of nodes to resize to
  1581. X  Outputs: none
  1582. X  Locals:  none
  1583. X  Globals: NULL  - 0
  1584. X*/
  1585. Xresize_io(array,size)
  1586. Xregister int size;
  1587. Xdouble **array;
  1588. X{
  1589. X    if((*array = (double *) realloc(*array,size*sizeof(double))) == NULL)
  1590. X      error();
  1591. X}
  1592. X
  1593. X/*This routine will resize an array of node attributes.
  1594. X
  1595. X  Inputs:  array - array to resize
  1596. X       size  - number of nodes to resize to
  1597. X  Outputs: none
  1598. X  Locals:  none
  1599. X  Globals: NULL  - 0
  1600. X*/
  1601. Xresize_attr(array,size)
  1602. Xregister int size;
  1603. XNODE_ATTR **array;
  1604. X{
  1605. X    if((*array = (NODE_ATTR *) realloc(*array,size*sizeof(NODE_ATTR)))
  1606. X       == NULL)
  1607. X      error();
  1608. X}
  1609. X
  1610. END_OF_FILE
  1611.   if test 1350 -ne `wc -c <'resize.c'`; then
  1612.     echo shar: \"'resize.c'\" unpacked with wrong size!
  1613.   fi
  1614.   # end of 'resize.c'
  1615. fi
  1616. if test -f 'save.c' -a "${1}" != "-c" ; then 
  1617.   echo shar: Will not clobber existing file \"'save.c'\"
  1618. else
  1619.   echo shar: Extracting \"'save.c'\" \(2244 characters\)
  1620.   sed "s/^X//" >'save.c' <<'END_OF_FILE'
  1621. X/*Copyright  (c)   1992  Adam  Stein.   All  Rights Reserved.   
  1622. X
  1623. X  Permission to use,  copy,  modify  and  distribute  without
  1624. X  charge this software, documentation, images, etc. is grant-
  1625. X  ed, provided that this copyright and the author's  name  is  
  1626. X  retained.   
  1627. X  
  1628. X  A fee may be charged for this program ONLY to recover costs   
  1629. X  for distribution (i.e. media costs).  No profit can be made            
  1630. X  on this program.   
  1631. X   
  1632. X  The author assumes no responsibility for disasters (natural   
  1633. X  or otherwise) as a consequence of use of this software.      
  1634. X   
  1635. X  Adam Stein (stein.wbst129@xerox.com)         
  1636. X*/ 
  1637. X
  1638. X#include <stdio.h>
  1639. X#include "persim.h"
  1640. X
  1641. X/*This function will save values from the different variables.
  1642. X
  1643. X  Inputs:  filename - name of the file to save values to
  1644. X       filetype - what type this file it is
  1645. X       var      - what variable to save
  1646. X  Outputs: none
  1647. X  Locals:  none
  1648. X  Globals: desired  - desired output value array
  1649. X       input    - input value array
  1650. X       output   - output value array
  1651. X       state    - system variables
  1652. X       weights  - perceptron weights
  1653. X       DESIRED  - save desired output values
  1654. X       INPUT    - save input values
  1655. X       NULL     - 0
  1656. X       OUTPUT   - save output values
  1657. X       SYS_VARS - save system variables
  1658. X       WEIGHTS  - save perceptron weights
  1659. X*/
  1660. Xsave(var,filename,filetype)
  1661. Xregister int var,filetype;
  1662. Xregister char *filename;
  1663. X{
  1664. X    extern double *input,*output,*desired,**weights;
  1665. X    extern STATE state;
  1666. X
  1667. X    if(!filename) {
  1668. X      puts("no filename given");
  1669. X      return;
  1670. X    }
  1671. X
  1672. X    switch(var) {
  1673. X      case DESIRED:
  1674. X        if(desired == (double *) NULL)
  1675. X          puts("there are no desired output values to save");
  1676. X        else writedata(desired,state.onodes,filename,filetype);
  1677. X        break;
  1678. X      case INPUT:
  1679. X        if(input == (double *) NULL)
  1680. X          puts("there are no input values to save");
  1681. X        else writedata(input,state.inodes,filename,filetype);
  1682. X        break;
  1683. X      case OUTPUT:
  1684. X        if(output == (double *) NULL)
  1685. X          puts("there are no output values to save");
  1686. X        else writedata(output,state.onodes,filename,filetype);
  1687. X        break;
  1688. X      case SYS_VARS:
  1689. X        writestate(filename);
  1690. X        break;
  1691. X      case WEIGHTS:
  1692. X        if(weights == (double **) NULL)
  1693. X          puts("there are no weights to save");
  1694. X        else writewts(weights,state.inodes,state.onodes,filename,
  1695. X                  filetype);
  1696. X        break;
  1697. X    }
  1698. X}
  1699. X
  1700. END_OF_FILE
  1701.   if test 2244 -ne `wc -c <'save.c'`; then
  1702.     echo shar: \"'save.c'\" unpacked with wrong size!
  1703.   fi
  1704.   # end of 'save.c'
  1705. fi
  1706. if test -f 'startup.c' -a "${1}" != "-c" ; then 
  1707.   echo shar: Will not clobber existing file \"'startup.c'\"
  1708. else
  1709.   echo shar: Extracting \"'startup.c'\" \(1423 characters\)
  1710.   sed "s/^X//" >'startup.c' <<'END_OF_FILE'
  1711. X/*Copyright  (c)   1992  Adam  Stein.   All  Rights Reserved.   
  1712. X
  1713. X  Permission to use,  copy,  modify  and  distribute  without
  1714. X  charge this software, documentation, images, etc. is grant-
  1715. X  ed, provided that this copyright and the author's  name  is  
  1716. X  retained.   
  1717. X  
  1718. X  A fee may be charged for this program ONLY to recover costs   
  1719. X  for distribution (i.e. media costs).  No profit can be made            
  1720. X  on this program.   
  1721. X   
  1722. X  The author assumes no responsibility for disasters (natural   
  1723. X  or otherwise) as a consequence of use of this software.      
  1724. X   
  1725. X  Adam Stein (stein.wbst129@xerox.com)         
  1726. X*/ 
  1727. X
  1728. X#include <stdio.h>
  1729. X
  1730. Xint print_line;
  1731. X
  1732. Xextern FILE *yyin;
  1733. X
  1734. X/*This routine will open the file containing commands to execute
  1735. X  (for batch processing).  If no filename is passed in, commands are
  1736. X  assumed to come from stdin.  Finally the function to startup yacc
  1737. X  is called.
  1738. X
  1739. X  Inputs:  filename      - name of file containing PERSIM commands
  1740. X  Outputs: none
  1741. X  Locals:  none
  1742. X  Globals: errno     - number of last error
  1743. X       print_line    - flag indicating if commands are from a batch file
  1744. X       stdin     - standard input
  1745. X       yyin          - file pointer used by lex
  1746. X       NULL          - 0
  1747. X*/
  1748. Xstartup(filename)
  1749. Xregister char *filename;
  1750. X{
  1751. X    if(filename == NULL) {
  1752. X      yyin = stdin;
  1753. X      print_line = 0;
  1754. X    } else if((yyin = fopen(filename,"r")) == NULL) error();
  1755. X           else print_line = 1;
  1756. X
  1757. X    prompt();
  1758. X    yyparse();
  1759. X}
  1760. X
  1761. END_OF_FILE
  1762.   if test 1423 -ne `wc -c <'startup.c'`; then
  1763.     echo shar: \"'startup.c'\" unpacked with wrong size!
  1764.   fi
  1765.   # end of 'startup.c'
  1766. fi
  1767. if test -f 'toggle.c' -a "${1}" != "-c" ; then 
  1768.   echo shar: Will not clobber existing file \"'toggle.c'\"
  1769. else
  1770.   echo shar: Extracting \"'toggle.c'\" \(956 characters\)
  1771.   sed "s/^X//" >'toggle.c' <<'END_OF_FILE'
  1772. X/*Copyright  (c)   1992  Adam  Stein.   All  Rights Reserved.   
  1773. X
  1774. X  Permission to use,  copy,  modify  and  distribute  without
  1775. X  charge this software, documentation, images, etc. is grant-
  1776. X  ed, provided that this copyright and the author's  name  is  
  1777. X  retained.   
  1778. X  
  1779. X  A fee may be charged for this program ONLY to recover costs   
  1780. X  for distribution (i.e. media costs).  No profit can be made            
  1781. X  on this program.   
  1782. X   
  1783. X  The author assumes no responsibility for disasters (natural   
  1784. X  or otherwise) as a consequence of use of this software.      
  1785. X   
  1786. X  Adam Stein (stein.wbst129@xerox.com)         
  1787. X*/ 
  1788. X
  1789. X#include "persim.h"
  1790. X
  1791. X/*This routine will toggle the value of a variable.
  1792. X
  1793. X  Inputs:  none
  1794. X  Outputs: none
  1795. X  Locals:  none
  1796. X  Globals: state - system variables
  1797. X*/
  1798. Xvoid toggle()
  1799. X{
  1800. X    extern STATE state;
  1801. X
  1802. X    state.training ^= 1;
  1803. X    if(state.training) puts("training mode is now turned on");
  1804. X    else puts("training mode has been turned off");
  1805. X}
  1806. X
  1807. END_OF_FILE
  1808.   if test 956 -ne `wc -c <'toggle.c'`; then
  1809.     echo shar: \"'toggle.c'\" unpacked with wrong size!
  1810.   fi
  1811.   # end of 'toggle.c'
  1812. fi
  1813. echo shar: End of archive 2 \(of 3\).
  1814. cp /dev/null ark2isdone
  1815. MISSING=""
  1816. for I in 1 2 3 ; do
  1817.     if test ! -f ark${I}isdone ; then
  1818.     MISSING="${MISSING} ${I}"
  1819.     fi
  1820. done
  1821. if test "${MISSING}" = "" ; then
  1822.     echo You have unpacked all 3 archives.
  1823.     rm -f ark[1-9]isdone
  1824. else
  1825.     echo You still must unpack the following archives:
  1826.     echo "        " ${MISSING}
  1827. fi
  1828. exit 0
  1829. exit 0 # Just in case...
  1830.