home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / APPS / ant.ytar / ant / ANT / ant_xor.c < prev    next >
Text File  |  1995-07-15  |  2KB  |  72 lines

  1.     
  2. /*************************************************************************
  3.  *   Program: ant_xor.c  this is an application program for the xor example 
  4.  *                       it shows how to include ant computation in any user
  5.  *                       program once the ant net is trained
  6.  *   To compile this program use the command:
  7.  *   
  8.  *     $cc -v=<ant_directory>/defs -l=<ant_directory>/lib/antlib.l ant_xor.c
  9.  * 
  10.  *  Version   Date       Author                         Comments & modif.
  11.  *  --------  ---------  ----------------------------   -------------------
  12.  *  V1.00     13-Jun-95  I. Labrador, R. Carrasco, LML  Very first version
  13.  */
  14.        
  15. #include <stdio.h>
  16. #include <math.h>
  17. #include <strings.h>
  18. #include "ant.h"        /* neural net header */
  19. #include "antlib.h"      /* functions prototypes */
  20. main ()
  21. {
  22.  
  23.   ant_neuron  **ant_neuronD;        /* declare net structures */
  24.   ant_net     ant_netD;
  25.   int l,n;                /* layer and neuron index */
  26.  
  27.   double  *input_vector,        /* user input and output vector */
  28.           *output_vector;
  29.  
  30.   strcpy( (ant_netD.init),"ant_init.xor");   /* get init file name  */
  31.  
  32.   ant_neuronD = ant_init(&ant_netD);    /* fill paramter of the net data structure, layers neurons , weights ...*/    
  33.  
  34.     
  35.   input_vector = ( double *) calloc( ant_netD.n[0] , sizeof(double));   /* allocate vector size = number of input of the net (layer 0)*/
  36.  
  37. /*     .      */
  38. /*     .      */
  39. /* user code  */    
  40. /*     .      */
  41. /*     .      */
  42.  
  43.   input_vector[0]=1.;        /* ant computation of an input vector */
  44.   input_vector[1]=1.;        
  45.  
  46.   output_vector=ant_process(input_vector,&ant_netD,ant_neuronD);  /* propagate and compute the net output*/
  47.                                      /* ant_process() return the pointer to the vector results*/    
  48.  
  49. /*                                           */
  50. /* user code where the ant result is applied */    
  51. /*                                           */
  52.  
  53. /* in this example we just print out the results */        
  54.   printf("INPUTS: ");
  55.   for(n = 1; n < ant_netD.n[0];n++)  /* per each input  */
  56.     printf("%12.4lf ",input_vector[n-1]);
  57.   printf("\n");
  58.   printf("OUTPUTS: ");
  59.   l=ant_netD.l - 1;          /* output layer */
  60.   for(n = 1; n < ant_netD.n[l];n++)   /* per each output */
  61.     printf("%12.4lf", output_vector[n-1]);
  62.   printf("\n");
  63.     
  64. }  
  65.     
  66.     
  67.     
  68.     
  69.     
  70.     
  71.     
  72.