home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / NNUTL101.ZIP / NNWHAT / NNWHAT.C < prev   
Encoding:
C/C++ Source or Header  |  1993-07-30  |  4.0 KB  |  75 lines

  1. /*--------------------------------------------------------------------------*
  2.  * Gregory Stevens                                                   7/5/93 *
  3.  *                               NNWHAT.C                                   *
  4.  *               (Feed-Forward, Back-Propagation, Supervised)               *
  5.  *                                                                          *
  6.  *   This is a program to be used with the nn*.c series for implementing    *
  7.  * the "what" feature detector algorithm described in the paper called      *
  8.  * "Why are What and Where Processed By Separate Cortical Visual Systems?"  *
  9.  * by J.G. Rueckl and Kyle R. Cave.  The following constant settings must   *
  10.  * be made:                                                                 *
  11.  *      NNPARAMS.C : INPUT_LAYER_SIZE   25    (the retina: 5x5)             *
  12.  *                   OUTPUT_LAYER_SIZE  8     (8 possible patterns)         *
  13.  *                   NUM_HIDDEN_LAYERS  1                                   *
  14.  *                   HL_SIZE_1          8     (this can be changed)         *
  15.  *                                                                          *
  16.  *      NNINPUTS.C : NUM_PATTERNS  72         (8 patterns in 9 positions)++ *
  17.  *                                                                          *
  18.  *      NNSTRUCT.C : InitNet()  ...should set output nodes as logistic...   *
  19.  *                                                                          *
  20.  *      NNBKPROP.C : EPSILON 0.25  (recommended...this is what I used)      *
  21.  *                                                                          *
  22.  *  Everything else can be left unchanged.                                  *
  23.  *                                                                          *
  24.  * ++ NOTE: I would have used the full 9 patterns, 9 positions, but ran into*
  25.  *          inexplicable memory errors on the allocation of pattern 76.     *
  26.  *          I am using Borland C++ version 3.0 on an IBM compatable 486     *
  27.  *          machine with a math coprocessor and 4 megs RAM, and have no idea*
  28.  *          why there is a memory allocation error.  Even with only 72      *
  29.  *          input patterns I need the huge memory model.                    *
  30.  *--------------------------------------------------------------------------*/
  31. #include "nnbkprop.c"                /* to chain it to the nn*.c utilities  */
  32. #include <math.h>                    /* for the exp() for logistic units    */
  33.  
  34. #define NUM_ITS 2000                 /* iterations before it stops          */
  35.  
  36. /*  MAIN PROGRAM  */
  37. void main()
  38. {
  39.   int Pattern;                         /* for looping through patterns   */
  40.   int Layer;                           /* for looping through layers     */
  41.   int LCV;                             /* for looping training sets      */
  42.   NNETtype Net;
  43.   PATTERNtype InPatterns, OutPattern;
  44.  
  45.   Net = InitNet( NUMNODES );            /* initializes the network        */
  46.   InPatterns = InitInPatterns(0);       /* loads input patterns from file */
  47.   OutPattern = InitOutPatterns();       /* loads output patterns from file*/
  48.  
  49.   for (LCV=0; (LCV < NUM_ITS); ++LCV)   /* loop through a training set    */
  50.     {
  51.       for (Pattern=0; (Pattern<NUM_PATTERNS); ++Pattern)
  52.          {
  53.             /* FORWARD PROPAGATION */
  54.             Net = UpDateInputAct( InPatterns, Pattern, Net );
  55.             for (Layer=1; (Layer<NUMLAYERS); ++Layer)
  56.               {
  57.                  Net = UpDateLayerAct( Net, Layer );
  58.               }
  59.  
  60.             /* OUTPUT PRINTS */
  61.             printf( "Pat: %d  ", Pattern );
  62.             printf( "Itr: %d\n", LCV );
  63.             DisplayLayer( Net, 0, 5 );          /* display input layer  */
  64.             printf( "\n" );
  65.             DisplayLayer( Net, 2, 9 );          /* display output layer */
  66.             printf( "\n\n" );
  67.  
  68.             if (LCV>50) getc(stdin);
  69.  
  70.             /* BACKWARD PROPAGATION */
  71.             Net = UpDateWeightandThresh( Net, OutPattern, Pattern );
  72.          }
  73.     }
  74. }
  75.