home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / PROG / MISC / NASANETS.ZIP / WEIGHTS.H < prev    next >
Encoding:
Text File  |  1990-06-07  |  7.0 KB  |  122 lines

  1.  
  2. /*=============================*/
  3. /*           NETS              */
  4. /*                             */
  5. /* a product of the AI Section */
  6. /* NASA, Johnson Space Center  */
  7. /*                             */
  8. /* principal author:           */
  9. /*       Paul Baffes           */
  10. /*                             */
  11. /* contributing authors:       */
  12. /*      Bryan Dulock           */
  13. /*      Chris Ortiz            */
  14. /*=============================*/
  15.  
  16.  
  17. /*
  18. ----------------------------------------------------------------------
  19.   WEIGHTS MODULE  
  20. ----------------------------------------------------------------------
  21.  This module represents a weight matrix, which is defined to       
  22.   be the set of all weight connections between the nodes of        
  23.   one layer and another.  For simplicity sake, I assumed that      
  24.   these connections are only one way, (ie not symetric).           
  25.   A symetric connection could be made by using two weight          
  26.   matricies.                                 
  27.  Note, however, that all of the formulas used here adhere to       
  28.   the generalized delta theories described by Rumelhart. Such      
  29.   a net defines itself as not having symetric connections!         
  30.  Also, I assumed that any set of weights connecting a source       
  31.   layer to a target layer included ALL of the nodes in the two     
  32.   layers. Again, this was just a design choice to make the code    
  33.   easier, but note that this is not necessary in the Rumelhart     
  34.   scheme (actually, Rumelhart, Hinton, & Williams). This choice    
  35.   enabled me to NOT have to define a NODE module.  Instead, all    
  36.   nodes within a layer were treated the same.                      
  37.  Finally, note that the weights between two layers are defined     
  38.   here as a one-dimensional array of sufficient size.  This may    
  39.   seem strange, after all, wouldn't a 2-dimensional array be the   
  40.   way to go?  The answer is, yes, 2-d is probably the natural      
  41.   way to approach the weight matrix.  The reason for choosing a    
  42.   1-d representation is for SPEED.  We wanted to have an array     
  43.   representation which we controlled so that indexing through      
  44.   the weights could be made as fast a possible.  This is moti-     
  45.   vated by the fact that most of the computation time in this      
  46.   type of nerual net is spent working with the weights and nodes   
  47.   of two layers.  Having the means to quickly access this info     
  48.   is absolutely essential for the program to run quickly.          
  49. -------------------------------------------------------------------
  50.   4-5-88 I've decided to add another type of connection scheme to  
  51.   the network structure, and thus the weights representation has   
  52.   to change. There are two differences. First, I've added an int   
  53.   to specify the type as either PATTERNED or CONNECT_ALL (see the  
  54.   "common.h" file).  If the type is connect all, then all the      
  55.   source nodes are connected to all the target nodes, otherwise    
  56.   the connections occur in some sort of pattern (specified by the  
  57.   user). This pattern can be relatively complex, and thus to save  
  58.   time a "decoder" array, exactly as long as the "values" array,   
  59.   can be used. The decoding values need then only be calculated    
  60.   once, with the corresponding array indicies to the LARGER of the 
  61.   two layers stored in the "decoder" matrix. Thus, for the weight  
  62.   stored in values[5], there will be an index in decoder[5] which  
  63.   will indicate the node of the larger layer which is connected by 
  64.   this weight.                                                     
  65. -------------------------------------------------------------------
  66.   9-5-89 To make things go (hopefully) faster during the learning
  67.   process, I have decided to use function pointers to determine
  68.   how the weights should be propagated/updated. This amounts to 
  69.   writing three versions of the propagating/updating routines and
  70.   setting function pointers appropriately. What made most sense to 
  71.   me was to put those function pointers with each weight, since the
  72.   weights are dealt with as individuals. This should make the code
  73.   much cleaner and should speed up the learning process somewhat.
  74. -------------------------------------------------------------------
  75. */
  76. typedef struct weights_str {
  77.    int               type;           /* type of connection scheme    */
  78.    struct layer_str  *source_layer;  /* layer that weights come FROM */ 
  79.    struct layer_str  *target_layer;  /* layer that weights go TO     */
  80.    int               source_size;    /* # of nodes in source layer   */
  81.    int               target_size;    /* # of nodes in target layer   */
  82.    Sint              *values;        /* array of Sints, size equal   */
  83.                                      /* to source_size * target_size */
  84.                                      /* IFF the type is PATTERENED,  */
  85.                                      /* the number of values will be */
  86.                                      /* X_dim * Y_dim of the smaller */
  87.                                      /* layer, times the area of the */
  88.                                      /* mapping rectangle.           */
  89.    int16             *decoder;       /* array of indices for the     */
  90.                                      /* nodes of the LARGER of the   */
  91.                                      /* two layers IFF these weights */
  92.                                      /* are of type PATTERNED.       */
  93.                                      /* Otherwise, NULL.             */
  94.    int               map_area;       /* IFF patterned, this area is  */
  95.                                      /* needed for propagating input */
  96.                                      /* It indicates the size of the */
  97.                                      /* region created by a pattern  */
  98.                                      /* connection scheme, ie, P * Q */
  99.    Sint              *prev_deltaW;   /* previous weight change, ie,  */
  100.                                      /* from last back propigation.  */
  101.    D_Sint            (*f_prop) ();   /* The three function pointers  */
  102.    D_Sint            (*b_prop) ();   /* show which functs. are to be */
  103.    void              (*w_update) (); /* used for propagation and for */
  104. } Weights;                           /* weight updates (see prop.c). */
  105.  
  106.  
  107. /*
  108. -------------------------------------------------------------------
  109.  The need for the structure below arises within the Layer module.  
  110.   Each layer needs to keep two lists for both the forward and the  
  111.   backward propigation procedures described by Rumelhart.  These   
  112.   are lists of the weights which exist between the layer in ques-  
  113.   tion and other layers.  The structure below provides the means   
  114.   for building such a linked list.                                 
  115. -------------------------------------------------------------------
  116. */
  117.  
  118. typedef struct weights_lst_str {
  119.    Weights                 *value;   /* ptr to a weights structure   */
  120.    struct weights_lst_str  *next;    /* ptr to next set of weights   */
  121. } Weights_lst;
  122.