home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / aijournl / 1988_11 / outstar < prev    next >
Text File  |  1988-05-03  |  24KB  |  780 lines

  1.  /***********************************************************
  2. OUTSTAR Simulator
  3.  
  4. )Maureen Caudill
  5. Adaptics
  6. 16776 Bernardo Center Drive
  7. Suite 110 B
  8. San Diego, CA  92128
  9. (617) 451-3752
  10.  July, 1988
  11. Written in Lightspeed C (v. 2.15) on Macintosh
  12. Version 1.0
  13.  
  14. This outstar learns to reproduce a specified pattern
  15. on a grid of border neurodes.  The pattern to be learned
  16. is read from an external text file called "pattern"
  17.  
  18. --------------------------------------------------------------------------------
  19. OPERATION OF THIS SIMULATOR
  20.  
  21. Read AI Expert Article, November, 1988 for discussion of Grossberg
  22. Learning, Activation Equations and Instar/Outstar.
  23.  
  24. This simulator models a biological system.  The outstar neurode stimulates
  25. each of a 7x10 grid of neurodes at the same time as an external pattern
  26. stimulates the grid.  The initial weight connections between the outstar
  27. and the grid neurodes are randomly set between -0.5 and +0.5.  The initial
  28. activity in the grid is also randomly set to activity between 0.0 and 0.5.
  29.  
  30. To run the simulator, you need to have a pattern file which contains the
  31. pattern you want the grid to learn to reproduce when stimulated by the outstar.
  32. The program begins by initializing the weights, activations, reading the data
  33. file and so on.  Then the values of the Grossberg learning/activation constants
  34. are checked, with default values assumed initially. I suggest that you leave 
  35. these values as they are until you are sure you understand the learning laws.
  36.  
  37. The menu gives you four choices.
  38. 1.  Train the network for some specified number of time units.
  39. 2.  Allow the activation in the grid to decay for some number of time units
  40. 3.  Test the network by having the outstar stimulate the grid for some number
  41. of time units.
  42.    -1.  Reset the network (and possibly change the network constants) to either
  43.        quit or start over.
  44.  When asked to enter the number of time units (for 1 or 2 or 3), remember that
  45.  a negative number will only display the grid activation after that number of time
  46.  units has passed, while a positive number displays the grid activation after each
  47.  time unit.
  48.  
  49.  The proper operation of the simulator is as follows:
  50.  train the network for some number of time periods.  Remember that the
  51.  transmission constant t0 determines how many time units must pass before
  52.  the grid even sees the outstar's stimulus (the external pattern is applied
  53.  immediately).  Thus, if the t0 constant is 3, you should do NOTHING in less 
  54.  than 4 time units (3 to travel, and 1 to have an effect on the grid).
  55.  allow the grid activation levels to decay to zero.  No weight changes occur
  56.  during this time (why?), so you are effectively just "clearing the slate".
  57.  test the network (again for t0+1 time units).  If the performance is inadequate,
  58.  train again for additional time periods, then allow decay, then test.
  59. Have fun!
  60. -----------------------------------------------------------------------------------------
  61.  
  62. --------------------------------------------------------------------------------
  63. STRUCTURE OF THIS FILE
  64.  
  65. include files
  66. constant definitions
  67. general global storage
  68. Grossberg activation/learning constant storage (global)
  69.  
  70. QQ Major functions QQ
  71. initialize();; initialize network operations
  72. train();; train the grid for a specified time
  73. decay();; allow grid activation to decay a specified time
  74. test();; test the grid for a specified time
  75. QQ Utility functions QQ
  76. compute_activation();; compute current activation for a grid neurode
  77. change_weight();; modify weight of a grid neurode
  78. read_pattern() ;; read pattern from data file
  79. parseline()  ;; parse one line of data from file 
  80. randomize_wts();; randomize weights on grid neurodes
  81. randomize_activity();; randomize activity of grid neurodes
  82. set_constants();; set Grossberg equation constants
  83.   show_constants();; show current values of learning/activity constants
  84. show_wts();; print current weights on grid neurodes
  85. displaygrid();; print the current grid activation
  86. print_menu();; print menu of operator choices (train, test, decay, quit)
  87. QQ Main control function QQ
  88. main();; main control function
  89. -----------------------------------------------------------------------------------
  90. ****************************************************************************************/
  91.  
  92. include <math.h>
  93. include <stdio.h>
  94. #defineROWSIZE7
  95. defineCOLSIZE10
  96. defineSTRINGSIZE80
  97. defineQUIT-1
  98. defineSTIMMASK1
  99. defineACTIVATION  1
  100. defineLEARNING2
  101. defineDISPLAYON1
  102. defineDISPLAYOFF2
  103. defineSTIM1
  104. defineNOSTIM0
  105. /************* General Global Storage ***************************************************/
  106. oublegridwts[ROWSIZE][COLSIZE]; /* this stores only the weights from the
  107.    single outstar neurode to the grid of rim
  108.    neurodes. */
  109. ntpattern[ROWSIZE][COLSIZE];  /*this contains the pattern to be impressed
  110. on the grid of rim neurodes */
  111. oubleactivity[ROWSIZE][COLSIZE]; /*this contains the current activation levels
  112. of each grid neurode */   
  113. ntcurtime;/* current time (in integral units)  */
  114. oubleoutstar;/*  activation level of outstar */
  115. har*inpath = "pattern";/*  file containing pattern to be learned */
  116. nsigned intoutstar_save;/*saves history of outstar's output */
  117. /*****************************************************************************************/
  118. /************* Grossberg Activation Constants (set by user or default values) ************/
  119. oubleA  =  0.9;/* activation decay constant */
  120. oubleT  =  0.0;/* threshold */
  121. ntt0 =    1;/* transmission time between neurodes */
  122. oubleF  =  0.01;/* forgetting constant for long term memory */
  123. oubleG  =  0.2;/* learning constant for Hebbian learning term */
  124. /*************************************************************
  125. initialize()
  126. initializes the system by:
  127. 1.  reading in the pattern file
  128. 2.randomizing the weights
  129. 3.setting the current time to 0
  130. 4.establishing the activation/learning constants
  131. *************************************************************/
  132. nitialize()
  133.  
  134. read_pattern();/* read in training pattern from file */
  135. randomize_wts();/* randomize weights to grid neurodes from outstar */
  136. randomize_activity();/* randomize activity of grid neurodes */
  137. show_wts();/* display resulting grid neurode weights */
  138. curtime = 0;/* reset current time to 0 */
  139. displaygrid(curtime);/* display the initial activity of the grid */
  140. set_constants();/* set the constants to user specified values */
  141. return;
  142.  
  143. *************************************************************
  144. train(duration)
  145. trains the outstar and grid for "duration" timeunits. 
  146. weights are modified during this training period
  147. After each synchronous update of the grid, the
  148. activations are displayed.
  149.  
  150. If training time is negative, only the grid status after
  151. all "duration" time units will be displayed.
  152.  
  153. *************************************************************/
  154. rain()
  155.  
  156. intduration, displayflag;
  157. intstoptime;
  158. inti,j;
  159. intstim_grid, stim_outstar;
  160. /* ask how many time units to train */
  161. printf("\n How many time units do you want the network to train?  ");
  162. printf("\n (Integer value < 32767, negative suppresses all but final display)  ");
  163. scanf("%d", &duration);
  164. displayflag = DISPLAYON;
  165. if (duration<0)
  166. {
  167. duration = -duration;
  168. displayflag = DISPLAYOFF;
  169. }
  170. stoptime = curtime+duration;
  171. for ( ; curtime<stoptime; curtime++)
  172. {
  173. stim_grid = STIM;
  174. stim_outstar = STIM;
  175. printf("\n Current time = %d",curtime);
  176. save_outstim(stim_outstar);
  177. for (i=0; i<ROWSIZE; i++)
  178. {
  179. for (j=0; j<COLSIZE; j++)
  180. {
  181. compute_activation(i,j,stim_grid, stim_outstar);
  182. change_weight(i,j,stim_outstar);
  183. }
  184. }
  185. if(displayflag == DISPLAYON)
  186. displaygrid();
  187. }
  188. curtime--;  /* decrement to avoid using an extra time unit */
  189. /* when complete, if have not been updating display, do a final display of status */
  190. if (displayflag == DISPLAYOFF)
  191. displaygrid();
  192.  
  193. return;
  194.  
  195. /*************************************************************
  196. decay(duration)
  197. allows grid activation to decay for "duration" timeunits. 
  198. no weights are modified during this period, since
  199. stimulations from the outstar are 0.0
  200. After each synchronous update of the grid, the
  201. activations are displayed.
  202.  
  203. If decay time is negative, only the grid status after
  204. all "duration" time units will be displayed.
  205.  
  206. *************************************************************/
  207. ecay()
  208.  
  209. intduration;
  210. intdisplayflag;
  211. intstoptime;
  212. inti,j;
  213. intstim_grid, stim_outstar;
  214. /* ask how many time units to decay */
  215. printf("\n How many time units do you want the network to decay?  ");
  216. printf("\n (Integer value < 32767, negative suppresses all but final display)  ");
  217. scanf("%d", &duration);
  218.  
  219. displayflag = DISPLAYON;
  220. if (duration<0)
  221. {
  222. duration = -duration;
  223. displayflag = DISPLAYOFF;
  224. }
  225. stim_grid = NOSTIM;/* during decay, no external stimulation of grid */
  226. stim_outstar = NOSTIM;/* during decay, the outstar does not stimulate grid */
  227. stoptime = curtime+duration;
  228. for ( ; curtime<stoptime; curtime++)
  229. {
  230. printf("\n Current time = %d",curtime);
  231. save_outstim(stim_outstar);
  232. for (i=0; i<ROWSIZE; i++)
  233. {
  234. for (j=0; j<COLSIZE; j++)
  235. {
  236. compute_activation(i,j,stim_grid, stim_outstar);
  237. }
  238. }
  239. if(displayflag == DISPLAYON)
  240. displaygrid();
  241. }
  242. curtime--;
  243. /* when complete, if have not been updating display, do a final display of status */
  244. if (displayflag == DISPLAYOFF)
  245. displaygrid();
  246.  
  247. return;
  248.  
  249. /*************************************************************
  250. test(duration)
  251. tests the outstar and grid for "duration" timeunits. 
  252. weights are not modified during this training period
  253. After each synchronous update of the grid, the
  254. activations are displayed.
  255.  
  256. If testing time is negative, only the grid status after
  257. all "duration" time units will be displayed.
  258.  
  259. *************************************************************/
  260. est()
  261.  
  262. intduration, displayflag;
  263. intstoptime;
  264. inti,j;
  265. intstim_grid, stim_outstar;
  266.  
  267. /* ask how many time units to test */
  268. printf("\n How many time units do you want the network to test?  ");
  269. printf("\n (Integer value < 32767, negative suppresses all but final display)  ");
  270. scanf("%d", &duration);
  271. displayflag = DISPLAYON;
  272. if (duration<0)
  273. {
  274. duration = -duration;
  275. displayflag = DISPLAYOFF;
  276. }
  277.  
  278. stim_grid = NOSTIM;/* no external stimulation of grid during testing */
  279. stim_outstar = STIM;/* outstar does stimulate grid during testing */
  280. stoptime = curtime+duration;
  281. for ( ; curtime<stoptime; curtime++)
  282. {
  283. printf("\n Current time = %d",curtime);
  284. save_outstim(stim_outstar);
  285. for (i=0; i<ROWSIZE; i++)
  286. {
  287. for (j=0; j<COLSIZE; j++)
  288. {
  289. compute_activation(i,j,stim_grid, stim_outstar);
  290. }
  291. }
  292. if(displayflag == DISPLAYON)
  293. displaygrid();
  294. }
  295. curtime-- ; /* decrement to avoid using an extra time unit */
  296. /* when complete, if have not been updating display, do a final display of status */
  297. if (displayflag == DISPLAYOFF)
  298. displaygrid();
  299.  
  300. return;
  301.  
  302. ****************************************************************************
  303. save_outstim(stimout)
  304. Parameter stimout either has the value STIM (1) or NOSTIM (0).
  305. save_outstim keeps a 16-time-unit historical record of
  306. the outputs of the outstar by modifying the global unsigned
  307. integer "outstar_save".
  308. Each time unit the outstar is stimulating the grid is represented
  309. by a "1" in outstar_save; if there is no stimulus, outstar_save has
  310. a "0".  The 0th bit has the most recent record, the 15th bit has
  311. the oldest record.
  312. ****************************************************************************/
  313. ave_outstim(stimout)
  314. ntstimout;
  315.  
  316. outstar_save = outstar_save << 1;/* left shift one bit.  A zero fills
  317.    the lowest order bit, and the oldest
  318.    (highest order bit) is lost         */
  319. outstar_save += stimout;/* add current stimulus value 
  320. (0 if no stim, 1 if stim)   */
  321. return;
  322.  
  323.  
  324. **************************************************************
  325. compute_activation(row,col,grid_on,out_on)
  326. compute the current activation for the specified
  327. grid neurode
  328. Parameter "grid_on" is a flag to tell whether or not
  329. the external stimulus is impressing the pattern on
  330. the grid.  
  331. Parameter "out_on" is a flag indicating whether the
  332. outstar is currently stimulating the grid.
  333.  
  334. Note that differential equation is calculated as an
  335. incremental difference equation.
  336. **************************************************************/
  337. ompute_activation(row,col,grid_on,out_on)
  338. ntrow,col,grid_on,out_on;
  339.  
  340. doublechange;
  341. unsigned intstatus;
  342. intoutstim;/* effective outstar stimulation at current time */
  343.  
  344. change = -A*activity[row][col] ; /* no matter what, activity will tend to try to decay */
  345. if (grid_on == STIM) /* if there is external stimulus, it will counter decay */
  346. change += pattern[row][col];
  347. if (out_on == STIM) /* if there is outstar stimulus... */
  348. {
  349. status = outstar_save;/* Be sure not to change the global version */
  350. status = status >> t0;/* right shift by t0 time units to allow for
  351.    transmission time from outstar           */
  352. outstim = status & STIMMASK;
  353. change += gridwts[row][col]*outstim - T;
  354. }
  355. activity[row][col] += change;/* new activity = old plus incremental change */
  356. return;
  357.  
  358. /**************************************************************************************
  359. change_weight(row,col,out_on)
  360. modify the weight of the specified grid neurode synapse
  361. Parameter "out_on" is a flag indicating whether or not
  362. the outstar is currently stimulating the grid.
  363. Note that differential equation is calculated as an
  364. incremental difference equation.
  365. ***************************************************************************************/
  366. hange_weight(row,col,out_on)
  367. ntrow,col, out_on;
  368.  
  369. doublechange;/* the incremental change to this weight */
  370. unsigned intstatus;/* local copy of global outstar output history */
  371. intoutstim;/* effective stimulus from outstar at this time */
  372.  
  373. change = -F * activity[row][col];
  374. if (out_on == STIM)
  375. {
  376. status = outstar_save;/* Be sure not to change the global version */
  377. status = status >> t0;/* right shift by t0 time units to allow for
  378.    transmission time from outstar           */
  379. outstim = status & STIMMASK;
  380. change += G * activity[row][col] * (outstim - T);
  381. }
  382. gridwts[row][col] += change;
  383. return;
  384.  
  385. /*******************************************************************
  386. read_pattern()
  387. Read in the input data file and store the patterns in
  388. in_pats and out_pats.
  389.  
  390. The format for the data file is as follows:
  391. line#   data expected
  392. -----   -----------------------------
  393. 1In-X-size,in-y-size
  394. 21st X row of 1st pattern
  395. 3..following rows of 1st pattern
  396. etc.
  397.  
  398. Each row of data is separated by commas or spaces.
  399. The data is expected to be ascii text corresponding to
  400. either a +1 or a 0.  
  401.  
  402. Sample input for a pattern file (The comments to the
  403. right may NOT be in the file unless more sophisticated
  404. parsing of the input is done.):
  405.  
  406. 5,7                        input is 5x7 grid
  407. 0,1,1,1,0                  beginning of pattern for "O"
  408. 1,0,0,0,1
  409. 1,0,0,0,1
  410. 1,0,0,0,1
  411. 1,0,0,0,1
  412. 1,0,0,0,0
  413. 0,1,1,1,0
  414.  
  415. Clearly, this simple scheme can be expanded or enhanced
  416. any way you like.
  417.  
  418. Returns -1 if any file error occurred, otherwise 0.
  419. *******************************************************************/
  420. ead_pattern()
  421.  
  422. FILE*infile;
  423.  
  424. intxinsize,yinsize;
  425. intrownum, numcols,x;
  426. intvalue, vals_read, status;
  427. charinstring[STRINGSIZE];
  428.  
  429. printf("\n Opening and retrieving data from file.");
  430.  
  431. infile = fopen(inpath, "r");
  432. if (infile == NULL)
  433. {
  434. printf("\n error in opening file!");
  435. return -1 ;
  436. }
  437. vals_read =fscanf(infile,"%d,%d",&xinsize,&yinsize);
  438. if (vals_read != 2)
  439. {
  440. printf("\n Should read 2 items in line one; did read %d",vals_read);
  441. return -1;
  442. }
  443. if ((xinsize != ROWSIZE) || (yinsize != COLSIZE))
  444. {
  445. printf("\n\n ERROR:  Pattern file is invalid!");
  446. printf("\n Pattern is a %d by %d grid instead of %d by %d",
  447. xinsize, yinsize, ROWSIZE, COLSIZE);
  448. return -1;
  449. }
  450. numcols = ROWSIZE;
  451. for (rownum = 0; rownum<COLSIZE; rownum++)
  452. {
  453. status = fscanf(infile,"%s",&instring);
  454. if (status == -1)
  455. {
  456. printf("\n  ERROR:  Insufficient data in file!");
  457. return -1;
  458. }
  459. value = parseline(instring,numcols,rownum);
  460. if (value == -1)
  461. return -1;
  462. }
  463. printf("\n Closing the input file now. ");
  464. fclose(infile);
  465. return 0;
  466.  
  467. /*******************************************************************
  468. parseline(string,numele,row)
  469. parse line of text to derive elements from pattern string.
  470. Parameters
  471.  "string" is a pointer to string to be parsed.
  472.  "numele" specifies number of elements contained in "string"
  473.  "row" is pointer to correct row of "pattern" for elements.
  474. Elements in the string must be either "0", "1", <space>, ","
  475.  0,1 puts appropriate values in pattern array
  476.  "<space>", or "," is ignored
  477.  
  478.  Notice that this is an extremely primitive parsing routine.
  479.  This can (and should) be improved or modified as desired.
  480.  
  481. Return:
  482.  -1 if error, 0 else.
  483. *******************************************************************/
  484. arseline(string,numele,ygrid)
  485. harstring[];
  486. ntnumele,ygrid;
  487.  
  488. intvalue;
  489. intcharnum, ele;
  490. charch;
  491.  
  492. charnum = 0;
  493. value = 0;
  494. ele = 0;
  495. while ((ele < numele) && (value == 0))
  496. {
  497. if (charnum == STRINGSIZE) /* made it to the end without filling all element entries */
  498. value = -1;
  499. else
  500. {/*This routine does not care if digits are separated or not.
  501.   each instance of a 0 or 1 will be taken as an element entry in
  502.   the pattern.  */
  503.   
  504. ch = string[charnum];
  505. switch (ch)
  506. {
  507. case '0' :  /* each "0" will be treated as a grid entry */
  508. pattern[ele][ygrid] = 0;
  509. ele++;
  510. break;
  511. case '1' :  /* each "1" will be treated as a grid entry */
  512. pattern[ele][ygrid] = 1;
  513. ele++;
  514. break;
  515. default :  /* all other characters are ignored. */
  516. break;
  517. }
  518. charnum++;
  519. }
  520. }
  521. return value;
  522.  
  523. /*******************************************************************
  524. randomize_wts()
  525. Intialize the weights in the grid neurodes to
  526. random values between -0.25..+0.25
  527. *******************************************************************/
  528. andomize_wts()
  529.  
  530. inti,j;
  531. doublevalue;
  532.  
  533. printf("\n Please enter a random number seed (1..32767):  ");
  534. scanf("%d", &i);
  535. srand(i);  
  536. for(i=0; i<ROWSIZE; i++)
  537. {
  538. for (j = 0; j<COLSIZE; j++)
  539. {
  540. value = (rand() / 32767.0 ) - 0.5;
  541. gridwts[i][j] = value/2;
  542. }
  543. }
  544. return;
  545.  
  546. *******************************************************************
  547. randomize_activity()
  548. Intialize the activity in the grid neurodes to
  549. random values between 0.0..0.5
  550. *******************************************************************/
  551. andomize_activity()
  552.  
  553. inti,j;
  554. doublevalue;
  555.  
  556. for(i=0; i<ROWSIZE; i++)
  557. {
  558. for (j = 0; j<COLSIZE; j++)
  559. {
  560. value = ( rand() / 32767.0 );
  561. activity[i][j] = value/2.0;
  562. }
  563. }
  564. return;
  565.  
  566. /*******************************************************************
  567. set_constants()
  568. displays current (default) values for learning/activation
  569. constants and requests user changes.  
  570. *******************************************************************/
  571. et_constants()
  572.  
  573. intans;
  574. floatvalue;
  575.  
  576. show_constants(ACTIVATION);
  577. scanf("%d",&ans);
  578. while (ans != 0)
  579. {
  580. printf("\n    New value for A?  ");
  581. scanf("%f",&value);
  582. A = (double) value;
  583. printf("\n    New value for T?  ");
  584. scanf("%f",&value);
  585. T = (double) value;
  586. printf("\n    New value for t0?  ");
  587. scanf("%d",&t0);
  588. show_constants(ACTIVATION);
  589. scanf("%d",&ans);
  590. }
  591. show_constants(LEARNING);
  592. scanf("%d",&ans);
  593. while (ans != 0)
  594. {
  595. printf("\n    New value for F?  ");
  596. scanf("%f",&value);
  597. F = (double) value;
  598. printf("\n    New value for G?  ");
  599. scanf("%f",&value);
  600. G = (double) value;
  601. show_constants(LEARNING);
  602. scanf("%d",&ans);
  603. }
  604. return;
  605.  
  606. *********************************************************************
  607. show_constants (which)
  608. displays either activation or learning constants for
  609. user approval or modification
  610. Paramter "which" determines which set will be displayed
  611. *********************************************************************/
  612. how_constants(which)
  613. ntwhich;
  614.  
  615. if (which == ACTIVATION) 
  616. {
  617. printf("\n The current values for the Grossberg activation constants are:");
  618. printf("\n   Activation Decay Time constant (A):  %6.3f",A);
  619. printf("\n   Activity Threshold (T):              %6.3f",T);
  620. printf("\n   Transmission time to grid (t0):      %d",t0);
  621. }
  622. if (which == LEARNING)
  623. {
  624. printf("\n The current values for the Grossberg learning constants are:");
  625. printf("\n   Learning Decay 'Forgetting' constant (F):  %6.3f",F);
  626. printf("\n   Learning Gain constant (G):                %6.3f",G);
  627. }
  628. printf("\n\n Do you wish to change any of these constants? (0 = no) ");
  629. return;
  630.  
  631. /*******************************************************************
  632. show_wts()
  633. print out the weights for the grid neurodes on the screen
  634. *******************************************************************/
  635. how_wts()
  636.  
  637. introw,col;
  638.  
  639. printf("\n  The current weights for the grid neurodes are:\n");
  640. for (col = 0; col < COLSIZE; col++)
  641. {
  642. printf ("\n");
  643. for (row = 0; row < ROWSIZE; row++)
  644. {
  645. printf(" %6.3f ",gridwts[row][col]);
  646. }
  647. }
  648. printf("\n\n");
  649. return;
  650.  
  651. /**************************************************************
  652. displaygrid()
  653. prints (text-only for portability) the current activity
  654. of the grid neurodes.  Also displays the current time,
  655. and the desired pattern.
  656. **************************************************************/
  657. isplaygrid()
  658.  
  659. inti,j;
  660. doublevalue;
  661.  
  662. printf("\n  Current pattern and activity at time %d:",curtime);
  663. printf("\n Scale (0.0 to 1.0):  '  .  _  o  O  %' \n");
  664. printf("\n Grid activity is:");
  665. printf("                   ");
  666. printf("  Desired pattern is:");
  667. for (j=0; j<COLSIZE; j++)
  668. {
  669. printf("\n     ");
  670. for (i=0; i<ROWSIZE; i++)
  671. {
  672. value = activity[i][j];
  673. if (value < 0.17)
  674. printf("   ");
  675. if ((value >= 0.17) && (value < 0.35))
  676. printf(" . ");
  677. if ((value >= 0.35) && (value < 0.50))
  678. printf(" _ ");
  679. if ((value >= 0.50) && (value < 0.67))
  680. printf(" o ");
  681. if ((value >= 0.67) && (value < 0.83))
  682. printf(" O ");
  683. if (value >= 0.83)
  684. printf(" % ");
  685. }
  686. printf("                   ");
  687. for (i=0; i<ROWSIZE; i++)
  688. {
  689. switch(pattern[i][j])
  690. {
  691. case 0:printf("   ");
  692. break;
  693. case 1:printf(" % ");
  694. break;
  695. default:break;
  696. }
  697. }
  698. }
  699. printf("\n");
  700. return;
  701.  
  702. /***************************************************************
  703. print_menu()
  704. prints out menu of operations for user choice
  705. ***************************************************************/
  706. rint_menu()
  707.  
  708. printf("\n\n\n     Please select an operation:");
  709. printf("\n\n          1.  Train the network for a period of time.");
  710. printf("\n              (Both external and outstar stimulate grid)");
  711. printf("\n\n          2.  Allow the network to decay for a period of time.");
  712. printf("\n              (Neither external or outstar stimulates grid)");
  713. printf("\n\n          3.  Test the network for a period of time.");
  714. printf("\n              (Only outstar stimulates grid)");
  715. printf("\n\n         -1.  Train the network for a period of time.");
  716. return;
  717.  
  718. /***************************************************************
  719. main()
  720. main program
  721. ***************************************************************/
  722. ain()
  723.  
  724. intyesno;
  725. intdone, donetraining;
  726. inttraintime;
  727. intchoice;
  728.  
  729. done = 0; donetraining = 0;
  730. while (done == 0)
  731. {
  732. initialize();
  733. choice = 0;
  734. /* display the desired grid pattern on the screen */
  735. print_menu();
  736. printf("\n\n  Please enter your choice:  ");
  737. scanf("%d",&choice);
  738. printf("\n Your selection was %d",choice);
  739. while (choice != QUIT)
  740. {
  741. switch (choice)
  742. {
  743. case 1:
  744. train();
  745. break;
  746. case 2:
  747. decay();
  748. break;
  749. case 3:
  750. test();
  751. break;
  752. default:
  753. {
  754. choice = QUIT;
  755. break;
  756. }
  757. }
  758. print_menu();
  759. printf("\n\n  Please enter your choice:  ");
  760. scanf("%d",&choice);
  761. printf("\n Your selection was %d",choice);
  762. }
  763. printf("\n\n Training session terminated at user request...");
  764.  
  765. /* want to start over (allows modification of constants)? */
  766. printf("\n\n Would you like to reset the network and begin again (no = 0)?  ");
  767. scanf("%d",&yesno);
  768. if (yesno < 1)
  769. done = 2;
  770. }
  771. printf("\n\n Program complete.");
  772. /* stop */
  773. return;
  774. ain (no = 0)?  ");
  775. scanf("%d",&yesno);
  776. if (yesno < 1)
  777. done = 2;
  778. }
  779. printf("\n\n Program complete.");
  780. /* stop