home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / Source / GPCHAP23 / NETWARE.ZIP / nnlist1.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-19  |  1.7 KB  |  75 lines

  1. // MCULLOCCH PITTS SIMULATOR /////////////////////////////////////////////////////
  2.  
  3. // INCLUDES //////////////////////////////////////////////////////////////////////
  4.  
  5. #include <conio.h>
  6. #include <stdlib.h>
  7. #include <malloc.h>
  8. #include <memory.h>
  9. #include <string.h>
  10. #include <stdarg.h>
  11. #include <stdio.h>
  12. #include <math.h>
  13. #include <io.h>
  14. #include <fcntl.h>
  15.  
  16. // MAIN //////////////////////////////////////////////////////////////////////////
  17.  
  18. void main(void)
  19. {
  20. float    threshold,    // this is the theta term used to threshold the summation 
  21.         w1,w2,        // these hold the weights
  22.         x1,x2,        // inputs to the neurode        
  23.         y_in,        // summed input activation
  24.         y_out;        // final output of neurode
  25.         
  26. printf("\nMcCulloch-Pitts Single Neurode Simulator.\n");
  27. printf("\nPlease Enter Threshold?");
  28. scanf("%f",&threshold);
  29.  
  30. printf("\nEnter value for weight w1?");
  31. scanf("%f",&w1);
  32.  
  33. printf("\nEnter value for weight w2?");
  34. scanf("%f",&w2);
  35.  
  36. printf("\n\nBegining Simulation:");
  37.  
  38. // enter main event loop
  39.  
  40. while(1)
  41.     {
  42.     printf("\n\nSimulation Parms: threshold=%f, W=(%f,%f)\n",threshold,w1,w2);
  43.  
  44.     // request inputs from user
  45.     printf("\nEnter input for X1?");
  46.     scanf("%f",&x1);
  47.  
  48.     printf("\nEnter input for X2?");
  49.     scanf("%f",&x2);
  50.  
  51.     // compute activation
  52.     y_in = x1*w1 + x2*w2;
  53.  
  54.     // input result to activation function (simple binary step)
  55.     if (y_in>=threshold)
  56.         y_out = (float)1.0;
  57.     else
  58.         y_out = (float)0.0;
  59.  
  60.     // print out result
  61.     printf("\nNeurode Output is %f\n",y_out);
  62.  
  63.     // try again
  64.     printf("\nDo you wish to continue Y or N?");
  65.     char ans[8];
  66.     scanf("%s",ans);
  67.     if (toupper(ans[0])!='Y')
  68.         break;
  69.         
  70.     } // end while
  71.  
  72. printf("\n\nSimulation Complete.\n");
  73.  
  74. } // end main
  75.