home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 618a.lha / NeuralNetwork / xor_c_bp.c < prev    next >
C/C++ Source or Header  |  1992-03-08  |  2KB  |  67 lines

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