home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 624a.lha / Neural_Network_v2.0 / xor_bp.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-29  |  1.3 KB  |  64 lines

  1.  
  2. #include <iostream.h>
  3. #include "Neural_network.h"
  4.  
  5. int main ()
  6. {
  7.   int             error;
  8.   Neural_network  nn ("weights.xor",error);
  9.   double          input [4] [2],output [4];
  10.   int             done,num_wrong,skip,actual_printed;
  11.   int             x,print_it,loops;
  12.  
  13.   // Create inputs and desired outputs.  Use XOR test.
  14.   input [0] [0] = 0.0;
  15.   input [0] [1] = 0.0;
  16.   output [0] = 0.0;
  17.  
  18.   input [1] [0] = 1.0;
  19.   input [1] [1] = 0.0;
  20.   output [1] = 1.0;
  21.  
  22.   input [2] [0] = 0.0;
  23.   input [2] [1] = 1.0;
  24.   output [2] = 1.0;
  25.  
  26.   input [3] [0] = 1.0;
  27.   input [3] [1] = 1.0;
  28.   output [3] = 0.0;
  29.  
  30.   done = 0;
  31.   print_it = 0;
  32.   loops = 0;
  33.   while ( !done )
  34.     {
  35.       if ( (loops % 50) == 0 )
  36.         {
  37.           cout << "Epoch = " << loops << "  ";
  38.           print_it = 2;
  39.         }
  40.       else
  41.           print_it = 0;
  42.  
  43.       done = 1;
  44.       for (x = 0; x < 4; ++x)
  45.         {
  46.           nn.calc_forward (input [x],&output [x],num_wrong,skip,
  47.                            print_it,actual_printed);
  48.           nn.back_propagation (input [x],&output [x],done);
  49.         }
  50.       nn.update_weights ();
  51.       if ( print_it )
  52.           cout << "\n";
  53.       ++loops;
  54.     }
  55.  
  56.   cout << "\nTotal # Epochs done = " << loops << "\n";
  57.   for (x = 0; x < 4; ++x)
  58.     {
  59.       nn.calc_forward (input [x],&output [x],num_wrong,skip,
  60.                        2,actual_printed);
  61.     }
  62.   cout << "\n";
  63.  
  64. }