1 /*****************************************************************************
2   FILE           : $Source: /projects/higgs1/SNNS/CVS/SNNS/kernel/sources/kr_typ.h,v $
3   SHORTNAME      :
4   SNNS VERSION   : 4.2
5 
6   PURPOSE        : SNNS-Kernel: Datatypes and Constants for Internal Useage
7   NOTES          : 12.02.90
8 
9   AUTHOR         : Niels Mache
10   DATE           :
11 
12   CHANGED BY     : Sven Doering, Michael Vogt
13   RCS VERSION    : $Revision: 2.11 $
14   LAST CHANGE    : $Date: 1998/04/08 09:26:39 $
15 
16     Copyright (c) 1990-1995  SNNS Group, IPVR, Univ. Stuttgart, FRG
17     Copyright (c) 1996-1998  SNNS Group, WSI, Univ. Tuebingen, FRG
18 
19 ******************************************************************************/
20 #include "glob_typ.h"	 /*  Global datatypes and constants  */
21 #include "ext_typ.h"     /*  Types and constants for extern kernel */
22 
23 #ifndef KR_TYPES
24 #define KR_TYPES
25 
26 
27 /*#################################################
28 
29 GROUP: Type Definitions
30 
31 #################################################*/
32 
33 #ifdef __BORLANDC__
34 
35 #ifndef strdup
36 #define  strdup  bsd_strdup
37 #endif
38 
39 /*
40 #define  int long
41 */
42 
43 #endif
44 
45 /*  type definition of input/output pattern array
46 */
47 typedef  FlintType     *Patterns;
48 
49 /*  type definition of integer array for shuffeling input/output patterns
50 */
51 typedef  int    *PatternNumbers;
52 
53 struct Unit ; /* Dummy declaration */
54 struct Site ; /* Dummy declaration */
55 typedef  FlintType   (* SiteFuncPtr) (struct Site *);
56 typedef  FlintType   (* ActFuncPtr)  (struct Unit *);
57 typedef  FlintType   (* ActDerivFuncPtr) (struct Unit *);
58 
59 
60 typedef  FlintType   (* OutFuncPtr)  (FlintType);
61 typedef  krui_err    (* LearnFuncPtr) (int, int, float *, int, float * *, int *);
62 typedef  krui_err    (* UpdateFuncPtr) (float *, int);
63 typedef  krui_err    (* InitFuncPtr) (float *, int);
64 
65 typedef  krui_err    (* RemapFuncPtr) (float *pat_data, int pat_size,
66 				       float *remap_params, int no_of_remap_params);
67 
68 /*#################################################
69 
70 GROUP: Type Definition of Name Table
71 
72 #################################################*/
73 
74 /*  Name table structure
75 */
76 struct   NameTable  {
77   union  {
78     char               *symbol;             /*  stores symbol name  */
79     struct  NameTable  *next;               /*  stores name-table block ptr
80                                                 and free name-table entry   */
81   }  Entry;
82 
83   unsigned short       sym_type,            /*  stores type of entry   */
84                        ref_count;           /*  stores no. of references to
85                                                 this symbol (If more then MAXSHORT
86                                                 references are detected the symbol will
87                                                 released only by krm_releaseMem()
88                                             */
89 };
90 
91 
92 
93 /*#################################################
94 
95 GROUP: Type Definition of Site-Table
96 
97 #################################################*/
98 
99 /*  Site table structure
100 */
101 struct   SiteTable  {
102   union  {
103     struct NameTable	*site_name;  /*  stores the site symbol (it's not a direkt
104 					 pointer to the symbol, but a pointer to the
105 					 name-table entry */
106     struct SiteTable	*next;	     /*  stores next site-table block ptr
107 					 and free site-table entries */
108   }  Entry;
109 
110   SiteFuncPtr   site_func;      /*  stores site function    */
111 };
112 
113 #ifndef Py_PYTHON_H
114 /* dummy declaration */
115 
116 typedef struct PyObject PyObject;
117 
118 #endif
119 
120 
121 
122 /*#################################################
123 
124 GROUP: Type definition of unit functionality table
125 
126 #################################################*/
127 
128 /*  Unit prototype structure
129 */
130 struct   FtypeUnitStruct  {
131   struct  NameTable     *Ftype_symbol;
132 
133   OutFuncPtr      out_func;
134   ActFuncPtr      act_func;
135   ActDerivFuncPtr  act_deriv_func;
136   ActDerivFuncPtr  act_2_deriv_func;
137   PyObject *      python_out_func;
138   PyObject *      python_act_func;
139   PyObject *      python_act_deriv_func;
140   PyObject *      python_act_2_deriv_func;
141 
142 
143   struct Site              *sites;
144 
145   struct FtypeUnitStruct   *next;
146   struct FtypeUnitStruct   *prev;
147 };
148 
149 
150 
151 /*#################################################
152 
153 GROUP: Unit/Site/Link type definitions
154 
155 #################################################*/
156 
157 /*m.r.*/
158 /* BPTT: maximum number additional unit activity copies back in time,
159  (= number of non-input layers for backpropagation)
160 */
161 #define MAX_BPTT_BACKSTEP 10
162 
163 /*  Link structure
164 */
165 struct   Link  {
166   struct Unit   *to;      /*  points to the source unit  */
167   FlintType     weight;   /*  link weight  */
168 
169   FlintType     value_a,  /*  general purpose elements for the  */
170                 value_b,  /*  learning functions  */
171                 value_c;
172 
173   struct Link   *next;    /*  next link  */
174 };
175 
176 
177 /*  Site structure
178 */
179 struct   Site  {
180   struct Link   *links;   /*  input links of the site  */
181   struct SiteTable      *site_table;  /*  : site name and function  */
182   struct Site   *next;    /*  next site  */
183 };
184 
185 /*  Type of unit flags
186 */
187 typedef  unsigned short  FlagWord;
188 
189 /*  Unit structure
190 */
191 
192 struct   Unit  {
193   /*  output MUST be the first element in unit structure !
194       (access is faster if functions can assume that <output>
195       is the FIRST element of the unit structure)
196   */
197   union  {
198     FlintType     output;       /*  unit's output  */
199     int           nextFreeUnit; /*  used by the unit memory manager  */
200   } Out;
201 
202   FlagWord        flags;        /*  unit flags  */
203 
204   int             lun;          /*  logical unit number  */
205   int             lln;          /*  logical layer number  */
206 
207   struct  FtypeUnitStruct   *Ftype_entry;  /*  pointer to the unit's prototype  */
208 
209   union  {
210     FlintType     flint_no;     /*  used by backpropagation: holds errors from successors   */
211     int           int_no;       /*  used by layer sorting: holds the layer no of the unit   */
212     char         *ptr;          /*  used for garbage collection  */
213   }  Aux;   /*  general purpose use  */
214 
215   struct
216     {
217     struct Unit   **my_topo_ptr;   /* pointer to coresponding entry in */
218                                    /* topo_ptr_array */
219     int           target_offset;   /* offset to prototype target unit via */
220                                    /* topo_ptr_array */
221     int           source_offset;   /* offset to logioal source unit via */
222                                    /* prototype target and topo_ptr_array */
223     int           td_connect_typ;  /* recept. field or not */
224     }  TD;  /* TimeDelay net datas */
225 
226   FlintType	  act,		/*  current activation	*/
227 		  i_act,	/*  initial activation	*/
228 		  bias; 	/*  bias  */
229 
230   FlintType       value_a,      /*  general purpose elements for the  */
231                   value_b,      /*  learning functions  */
232                   value_c;
233 
234   unsigned long int usr_flags;  /* long flag word for general purpose usage
235                                    within learning functions */
236 
237 /*m.r.*/
238   FlintType       olddelta,     /* BPTT-section: delta value at time t */
239                   newdelta;     /* delta value at time t-1
240 				   (deltas are propagated back in time )*/
241   FlintType       actbuf[MAX_BPTT_BACKSTEP]; /*outacts at previous time steps*/
242 /*m.r.*/
243 
244   OutFuncPtr	  out_func;	    /*	output function  */
245   ActFuncPtr	  act_func;	    /*	activation function */
246   ActDerivFuncPtr  act_deriv_func;  /*	derivation act. function */
247   ActDerivFuncPtr act_2_deriv_func; /*  second derivation act. function */
248 
249   PyObject       *python_out_func; /* Same as above, only if Python */
250   PyObject       *python_act_func; /* functions should be used */
251   PyObject       *python_act_deriv_func;
252   PyObject       *python_act_2_deriv_func;
253 
254   char           *unit_name;    /*  unit name */
255   short           subnet_no;    /*  subnet no.  */
256   unsigned short  layer_no;     /*  display layer (bitfield)  */
257 
258   struct PosType  unit_pos;     /*  unit position  */
259 
260 
261   /*  unit's center position  */
262   struct PositionVector unit_center_pos[ NO_OF_UNIT_CENTER_POS ];
263 
264 
265   struct Site     *sites;           /*  points to unit's input links or sites  */
266 };
267 
268 
269 
270 /*#################################################
271 
272 GROUP: Var types used by kernel functions
273 
274 #################################################*/
275 
276 /*  stucture for storing the error codes and messages of the topologic sorting
277     and network checking functions
278 */
279 struct TopologicMessages  {
280   int  error_code,         /*  stores the internal error code  */
281        no_of_cycles,       /*  no. of detected cycles in the network  */
282        no_of_dead_units,   /*  no. of dead units in the network  */
283        no_of_layers,       /*  no. of layers of the network */
284        dest_error_unit,    /*  first error unit (destination unit)  */
285        src_error_unit;     /*  first error unit (source unit)  */
286   char name[20];           /*  a chararcter string that can be passed */
287 };
288 
289 
290 /*#################################################
291 
292 GROUP: Link/Site/Unit and Unit Ptrs Array Type Definitions
293 
294 #################################################*/
295 
296 /*  definition of link array
297 */
298 typedef  struct Link    *LinkArray;
299 
300 /*  definition of site array
301 */
302 typedef  struct Site    *SiteArray;
303 
304 /*  definition of pointer array for topological sorting
305 */
306 typedef  struct Unit *  *TopoPtrArray;
307 
308 /*  definition of unit array
309 */
310 typedef  struct Unit    *UnitArray;
311 
312 /*  Definition of Name Table Array
313 */
314 typedef  struct NameTable  *NTableArray;
315 
316 /*  Definition of Site Name Table Array
317 */
318 typedef  struct SiteTable  *STableArray;
319 
320 
321 
322 
323 struct   TransTable  {
324   short  z,
325          x,
326 	 y;
327 };
328 
329 
330 
331 /*#################################################
332 
333 GROUP: Structure Size Constants
334 
335 #################################################*/
336 
337 #define   UNIT_SIZE             sizeof (struct Unit)
338 #define   SITE_SIZE             sizeof (struct Site)
339 #define   LINK_SIZE             sizeof (struct Link)
340 
341 #define   PATTERN_SIZE          sizeof (FlintType)
342 #define   PATTERN_NO_SIZE       sizeof (int)
343 
344 #define   TOPO_PTR_SIZE         sizeof (struct Unit *)
345 
346 #define   NTABLE_SIZE           sizeof (struct NameTable)
347 
348 #define   STABLE_SIZE           sizeof (struct SiteTable)
349 
350 #define   FTYPE_UNIT_SIZE       sizeof (struct FtypeUnitStruct)
351 
352 
353 #endif
354