home *** CD-ROM | disk | FTP | other *** search
-
- #include <stdio.h>
- #include <stdlib.h>
- #include "Neural_net.h"
-
- int main ()
- {
- int error;
- Neural_net *nn;
- double input [4] [2],output [4];
- int done,num_wrong,skip,actual_printed;
- int x,print_it,loops;
-
- nn = Neural_net_read_constr ("weights.xor",&error,0.1,0.05,0.1,0.8,0.2,0.025);
- /* 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 )
- {
- printf ("Epoch = %d ",loops);
- print_it = 2;
- }
- else
- print_it = 0;
-
- done = 1;
- for (x = 0; x < 4; ++x)
- {
- Neural_net_calc_forward (nn,input [x],&output [x],&num_wrong,&skip,
- print_it,&actual_printed);
- Neural_net_back_propagation (nn,input [x],&output [x],&done);
- }
- Neural_net_update_weights (nn);
- if ( print_it )
- printf ("\n");
- ++loops;
- }
-
- printf ("\nTotal # Epochs done = %d\n",loops);
- for (x = 0; x < 4; ++x)
- {
- Neural_net_calc_forward (nn,input [x],&output [x],&num_wrong,&skip,
- 2,&actual_printed);
- }
- printf ("\n");
-
- Neural_net_destr (nn);
- }