home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 618a.lha / NeuralNetwork / xor_dbd.cc < prev   
C/C++ Source or Header  |  1992-03-05  |  1KB  |  65 lines

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