
#include <iostream.h>
#include <stdlib.h>
#include "Neural_network.h"

int main ()
{
  int             error;
  Neural_network  nn ("weights.xor",error,0.1,0.05,0.1,0.8,0.2,0.025);
  double          input [4] [2],output [4];
  int             done,num_wrong,skip,actual_printed;
  int             x,print_it,loops;

  // Create inputs and desired outputs.  Use XOR test.
  input [0] [0] = 0.0;
  input [0] [1] = 0.0;
  output [0] = 0.0;

  input [1] [0] = 1.0;
  input [1] [1] = 0.0;
  output [1] = 1.0;

  input [2] [0] = 0.0;
  input [2] [1] = 1.0;
  output [2] = 1.0;

  input [3] [0] = 1.0;
  input [3] [1] = 1.0;
  output [3] = 0.0;

  done = 0;
  print_it = 0;
  loops = 0;
  while ( !done )
    {
      if ( (loops % 50) == 0 )
        {
          cout << "Epoch = " << loops << "  ";
          print_it = 2;
        }
      else
          print_it = 0;

      done = 1;
      for (x = 0; x < 4; ++x)
        {
          nn.calc_forward (input [x],&output [x],num_wrong,skip,
                           print_it,actual_printed);
          nn.back_propagation (input [x],&output [x],done);
        }
      nn.update_weights ();
      if ( print_it )
          cout << "\n";
      ++loops;
    }

  cout << "\nTotal # Epochs done = " << loops << "\n";
  for (x = 0; x < 4; ++x)
    {
      nn.calc_forward (input [x],&output [x],num_wrong,skip,
                       2,actual_printed);
    }
  cout << "\n";
}