1 /*****************************************************************************
2   FILE           : $Source: /projects/higgs1/SNNS/CVS/SNNS/kernel/sources/kr_art.c,v $
3   SHORTNAME      :
4   SNNS VERSION   : 4.2
5 
6   PURPOSE        : SNNS Kernel Functions for ART networks
7   NOTES          :
8 
9   AUTHOR         : Kai-Uwe Herrmann
10   DATE           : 17.05.92
11 
12   CHANGED BY     : Sven Doering
13   RCS VERSION    : $Revision: 2.7 $
14   LAST CHANGE    : $Date: 1998/03/03 14:08:34 $
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 <config.h>
21 #include <stdlib.h>
22 
23 #ifndef NULL /* if NULL pointer is not defined include stdio.h */
24 #include <stdio.h>
25 #endif
26 
27 #include "krart_df.h"   /*  Definitions for ART networks */
28 
29 #include "kr_const.h"
30 #include "kr_mac.h"
31 #include "kr_def.h"
32 #include "kr_typ.h"
33 #include "kr_funcs.h"
34 #include "kernel.h"
35 #include "glob_typ.h"
36 #include "kr_art.ph"
37 
38 /* declaration of module functions
39 */
40 
41 /**************** functions, visible to other modules **************************/
42 
43 /*#################################################
44 
45 GROUP: ART kernel functions
46        by Kai-Uwe Herrmann
47 
48 #################################################*/
49 
50 
51 
52 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
53 /* initialization of activations of all input units according to their i_act
54    value. this initialization is necessary each time a new pattern is
55    presented to the network.
56 */
57 
krart_reset_activations(void)58 krui_err krart_reset_activations (void)
59 {
60    krui_err        ret_code = KRERR_NO_ERROR;
61 
62    struct Unit     *unit_ptr;
63 
64 
65    FOR_ALL_UNITS (unit_ptr) {
66 
67       if (! IS_INPUT_UNIT (unit_ptr)) {
68          unit_ptr->act = unit_ptr->i_act;
69       } /*if*/
70 
71       /* The output is set for input units, too
72       */
73       unit_ptr->Out.output = unit_ptr->act;
74 
75    } /*FOR_ALL_UNITS*/
76 
77    return (ret_code);
78 
79 } /* krart_reset_activations () */
80 /*___________________________________________________________________________*/
81 
82 
83 
84 
85 
86 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
87 /* synchronous propagation (1 cycle) i.e. each unit puts its output onto
88    its outgoing links and calculates its new activation.
89 */
90 
91 extern FlintType OUT_Custom_Python(FlintType act);
92 
krart_prop_synch(void)93 void  krart_prop_synch (void)
94 {
95   struct Unit    *unit_ptr;
96 
97   /* calculate new activations of non input units
98   */
99 
100   FOR_ALL_UNITS (unit_ptr) {
101 
102      if (!IS_INPUT_UNIT(unit_ptr)) {
103         unit_ptr->act = (*unit_ptr->act_func) (unit_ptr);
104      } /*if*/
105 
106   } /*FOR_ALL_UNITS*/
107 
108   /* set new output values
109   */
110 
111   FOR_ALL_UNITS (unit_ptr) {
112 
113      if (unit_ptr->out_func == OUT_IDENTITY) {
114         unit_ptr->Out.output = unit_ptr->act;
115      } else if(unit_ptr->out_func == OUT_Custom_Python) {
116      	unit_ptr->Out.output =
117 		kr_PythonOutFunction(unit_ptr->python_out_func,
118 				unit_ptr->act);
119      } else {
120         unit_ptr->Out.output = (*unit_ptr->out_func) (unit_ptr->act);
121      } /*if*/
122 
123   } /*FOR_ALL_UNITS*/
124 
125 } /* krart_prop_synch */
126 /*___________________________________________________________________________*/
127 
128 
129 
130 
131 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
132 /* get the winner of the last propagation cycle. returns a pointer to
133    the winning recognition unit.
134 */
krart_get_winner(TopoPtrArray wta_layer,FlintType winner_output)135 struct Unit  *krart_get_winner (TopoPtrArray wta_layer, FlintType winner_output)
136                             /* points to first pointer to recognition unit
137                             */
138                                 /* output value of the winning unit */
139 
140 {
141    TopoPtrArray   topo_ptr;
142 
143    struct Unit    *unit_ptr,
144                   *winner_ptr = NULL;  /* points to the unit with the maximal
145                                           activation
146                                        */
147 
148    FlintType      max_out  = 0.0;      /* contains the maximal activation
149                                        */
150 
151 
152    topo_ptr = wta_layer;
153 
154    while ((unit_ptr = *topo_ptr++) != NULL) {
155 
156       if (unit_ptr->Out.output > max_out) {
157          max_out    = unit_ptr->Out.output;
158          winner_ptr = unit_ptr;
159          continue;
160       } /*if*/
161 
162       /* The foollowing statements assure, that a winner is returned, if
163          no Reset signal is sent from Reset general unit. So we will
164          find a winner, even if the winner unit's activation is 0.0
165          This is neccessary to assure, that all recognition units are
166          tested for to get a 'not classifiable' signal when all and really
167          all local reset units are turned on.
168       */
169       if ((winner_ptr == NULL) && (unit_ptr->Out.output >= max_out)) {
170          max_out    = unit_ptr->Out.output;
171          winner_ptr = unit_ptr;
172       } /*if*/
173 
174    } /*while*/
175 
176 
177 
178    /* set activation and output of winner unit to 1.0, the one of the
179       other recognition units to 0.0
180    */
181 
182    topo_ptr = wta_layer;
183 
184    while ((unit_ptr = *topo_ptr++) != NULL) {
185 
186       if (unit_ptr != winner_ptr) {
187          unit_ptr->Out.output = 0.0;
188       } else {
189          unit_ptr->Out.output = winner_output;
190       } /*if*/
191 
192    } /*while*/
193 
194 
195    return (winner_ptr);
196 
197 } /* krart_get__winner () */
198 /*___________________________________________________________________________*/
199 
200 
201 
202 
203 
204 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
krart_deleteTouchFlags(void)205 void  krart_deleteTouchFlags (void)
206 {
207    register struct Unit *unit_ptr;
208 
209    FOR_ALL_UNITS (unit_ptr) {
210 
211       /* delete touch flags
212       */
213       unit_ptr->flags &= ~UFLAG_REFRESH;
214 
215    } /*FOR_ALL_UNITS*/
216 
217 } /* krart_deleteTouchFlags () */
218 /*___________________________________________________________________________*/
219 
220 
221 
222 
223 
224 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
krart_init_sorting(void)225 void  krart_init_sorting (void)
226 {
227    register struct Unit *unit_ptr;
228 
229 
230    krart_deleteTouchFlags ();
231 
232    FOR_ALL_UNITS (unit_ptr) {
233 
234       /* init lln and lun
235       */
236       unit_ptr->lln = unit_ptr->lun = 0;
237 
238    } /*FOR_ALL_UNITS*/
239 
240 } /* krart_init_sorting () */
241 /*___________________________________________________________________________*/
242 
243 
244 
245 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
krart_get_NoOfInputUnits(void)246 int  krart_get_NoOfInputUnits (void)
247 {
248    register struct Unit  *unit_ptr;
249    int                   count           = 0;
250 
251 
252    FOR_ALL_UNITS (unit_ptr) {
253 
254       if (IS_INPUT_UNIT(unit_ptr)) {
255          count++;
256       } /*if*/
257 
258    } /*FOR_ALL_UNITS*/
259 
260    return (count);
261 
262 
263 } /* krart_get_NoOfInputUnits () */
264 /*___________________________________________________________________________*/
265 
266 
267 
268 
269 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
krart_check_undeterminedUnits(void)270 bool   krart_check_undeterminedUnits (void)
271 {
272    register struct Unit   *unit_ptr;
273 
274    FOR_ALL_UNITS (unit_ptr) {
275 
276       if (unit_ptr->lln == 0) {
277          TOPO_MSG_UNDETERMINED_UNIT (unit_ptr);
278          return (TRUE);
279       } /*if*/
280 
281    } /*FOR_ALL_UNITS*/
282 
283    return (FALSE);
284 
285 } /* krart_check_undeterminedUnits () */
286 /*___________________________________________________________________________*/
287 
288 
289 
290 
291 
292 
293 
294 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
krart_save_inp_pat(TopoPtrArray topo_inp_ptr)295 void  krart_save_inp_pat (TopoPtrArray topo_inp_ptr)
296 {
297   TopoPtrArray   topo_ptr = topo_inp_ptr;
298 
299   while (*topo_ptr != NULL) {
300      if (IS_INPUT_UNIT (*topo_ptr)) {
301         (*topo_ptr)->value_a = (*topo_ptr)->act;
302      } /*if*/
303      topo_ptr++;
304   } /*while*/
305   return;
306 } /* krart_save_inp_pat () */
307 /*___________________________________________________________________________*/
308 
309 
310 
311 
312 
313 
314 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
krart_inp_pat_changed(TopoPtrArray topo_inp_ptr)315 bool  krart_inp_pat_changed (TopoPtrArray topo_inp_ptr)
316 {
317 
318    TopoPtrArray    topo_ptr = topo_inp_ptr;
319 
320    while (*topo_ptr != NULL) {
321       if ((IS_INPUT_UNIT(*topo_ptr)) && ((*topo_ptr)->value_a != (*topo_ptr)->act)) {
322          return (TRUE);
323       } /*if*/
324       topo_ptr++;
325    } /*FOR_ALL_UNITS*/
326 
327    return (FALSE);
328 } /* krart_inp_pat_changed () */
329 /*___________________________________________________________________________*/
330 
331 
332 
333 
334 
335 
336 
337 
338 
339 
340 
341 
342 
343