home *** CD-ROM | disk | FTP | other *** search
/ Robotics & Artificial Int…3 (Professional Edition) / Robotics & Artificial Intelligence Tools 2003 (Professional Edition).iso / neural network tool and application / nsinstall.exe / data1.cab / Demos_Files / Code_Generation / xorFileTesting.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2002-03-08  |  2.4 KB  |  85 lines

  1. // xorFileTesting.cpp
  2. // Automatically generated from breadboard by NeuroSolutions.
  3.  
  4. #include "NSLib.h"
  5.  
  6. BOOL networkStopped=FALSE;
  7. unsigned short int weightFileVersion=225;
  8.  
  9. // Component Construction
  10. Axon inputAxon;
  11. File inputFile;
  12. FullSynapse hidden1Synapse;
  13. TanhAxon hidden1Axon;
  14. FullSynapse outputSynapse;
  15. TanhAxon outputAxon;
  16. File activeOutputProbe;
  17.  
  18. int main() {
  19.     srand((unsigned)time(NULL));
  20.  
  21.     // Component Initialization
  22.     inputAxon.setRows(2);
  23.     inputFile.setFilePath("inputFile.asc");
  24.     inputFile.setMode(READ,ASCII);
  25.     inputFile.setSpatialDimension(2,1);
  26.     hidden1Axon.setRows(2);
  27.     outputAxon.setRows(1);
  28.     activeOutputProbe.setMode(WRITE,STANDARD);
  29.     activeOutputProbe.setSpatialDimension(1,1);
  30.     FILE *loadStream = fopen("xorWeights.nsw","r");
  31.     if (!loadStream) {
  32.         fprintf(stderr, "Could not open weight file xorWeights.nsw");
  33.         exit(1);
  34.     }
  35.     weightFileVersion = getWeightFileVersion(loadStream);
  36.  
  37.     // Load Normalization Coefficients of Files
  38.     inputFile.loadWeights(seekComponent(loadStream, "File", "inputFile"),weightFileVersion);
  39.  
  40.     // Component Interconnection
  41.     inputAxon.setPreActivityAccess(&inputFile);
  42.     outputAxon.setActivityAccess(&activeOutputProbe);
  43.     inputAxon.setNext(&hidden1Synapse);
  44.     hidden1Synapse.setLast(&inputAxon);
  45.     hidden1Synapse.setNext(&hidden1Axon);
  46.     hidden1Axon.setLast(&hidden1Synapse);
  47.     hidden1Axon.setNext(&outputSynapse);
  48.     outputSynapse.setLast(&hidden1Axon);
  49.     outputSynapse.setNext(&outputAxon);
  50.     outputAxon.setLast(&outputSynapse);
  51.  
  52.     // Load Axon Weights
  53.     inputAxon.loadWeights(seekComponent(loadStream, "Axon", "inputAxon"),weightFileVersion);
  54.     hidden1Axon.loadWeights(seekComponent(loadStream, "TanhAxon", "hidden1Axon"),weightFileVersion);
  55.     outputAxon.loadWeights(seekComponent(loadStream, "TanhAxon", "outputAxon"),weightFileVersion);
  56.  
  57.     // Load Synapse Weights
  58.     hidden1Synapse.loadWeights(seekComponent(loadStream, "FullSynapse", "hidden1Synapse"),weightFileVersion);
  59.     outputSynapse.loadWeights(seekComponent(loadStream, "FullSynapse", "outputSynapse"),weightFileVersion);
  60.     fclose(loadStream);
  61.  
  62.     // Get Ready to Run Network
  63.  
  64.     // Run Network
  65.     int epochs = 1;
  66.     int exemplars = 4;
  67.     int epochsPerCV = 0;
  68.     for (int epoch=0; epoch<epochs; epoch++) {
  69.         for (int exemplar=0; exemplar<exemplars; exemplar++) {
  70.             inputAxon.fire();
  71.             if (networkStopped) {
  72.                 goto ConcludeFiring;
  73.             }
  74.         }
  75.         if (networkStopped)
  76.             goto ConcludeFiring;
  77.     }
  78.  
  79.     ConcludeFiring:
  80.  
  81.  
  82.     return 0;
  83. }
  84.  
  85.