1 /*****************************************************************************
2 FILE : $Source: /projects/higgs1/SNNS/CVS/SNNS/kernel/sources/trans_f.c,v $
3 SHORTNAME :
4 SNNS VERSION : 4.2
5
6 PURPOSE : SNNS-Kernel transfer functions
7 NOTES :
8
9 AUTHOR : Niels Mache
10 DATE : 25.06.90
11
12 CHANGED BY : Sven Doering, Ralf Huebner, Marc Seemann (Uni Tuebingen)
13 RCS VERSION : $Revision: 2.15 $
14 LAST CHANGE : $Date: 1998/03/13 16:24:05 $
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 <stdio.h>
22 #include <math.h>
23 #ifdef HAVE_VALUES_H
24 #include <values.h>
25 #endif
26 #include <string.h>
27
28 #include "kr_typ.h" /* Kernel types and constants */
29 #include "kr_const.h" /* Constant Declarators for SNNS-Kernel */
30 #include "func_mac.h" /* Transfer function macros */
31 #include "glob_typ.h"
32 #include "kr_mac.h"
33 #include "cc_mac.h"
34
35 #include "trans_f.ph"
36
37 #ifdef __BORLANDC__
38 #pragma option -w-
39 #endif
40
41 /*#################################################
42
43 GROUP: Aritmetic Functions
44
45 #################################################*/
46
47 /* exp function that prevents from over- and underflow, that means
48 exp_s ist a "save" exp function.
49 */
exp_s(float arg)50 static float exp_s( float arg )
51 {
52 if (arg > 88.72) return( MAXFLOAT );
53 else if (arg < -88.0) return( 0.0 );
54 return( exp( arg ) );
55 }
56
57
58 /*#################################################
59
60 GROUP: Unit Output Functions
61
62 #################################################*/
63
64 /* Linear Output Function
65 This function isn't used now, because the identity output function is
66 the NULL pointer.
67 */
OUTP_Identity(register FlintType activation)68 FlintType OUTP_Identity(register FlintType activation)
69 {
70 return( activation );
71 }
72
73
74 /* Clipping [0,1] function
75 */
OUT_Clip_01(register FlintType activation)76 FlintType OUT_Clip_01(register FlintType activation)
77 {
78 if (activation < 0.0) return( (FlintType) 0.0 );
79 if (activation > 1.0) return( (FlintType) 1.0 );
80 return( activation );
81 }
82
83
84 /* Clipping [-1,1] function
85 */
OUT_Clip_11(register FlintType activation)86 FlintType OUT_Clip_11(register FlintType activation)
87 {
88 if (activation < -1.0) return( (FlintType) -1.0 );
89 if (activation > 1.0) return( (FlintType) 1.0 );
90 return( activation );
91 }
92
93 /* Threshold 0.5 Output Function
94 */
OUT_Threshold05(register FlintType activation)95 FlintType OUT_Threshold05(register FlintType activation)
96 {
97 if (activation < 0.5) return( (FlintType) 0.0 );
98 return( (FlintType) 1.0 );
99 }
100
OUT_Custom_Python(register FlintType activation)101 FlintType OUT_Custom_Python(register FlintType activation)
102 {
103 fputs("Dummy for custom python output functions - should never be called\n",stderr);
104 return 0;
105 }
106
107 /*#################################################
108
109 GROUP: Unit Activation Functions
110
111 #################################################*/
112
113
114 /* Linear Activation Function
115 */
ACT_Linear(struct Unit * unit_ptr)116 FlintType ACT_Linear(struct Unit *unit_ptr)
117 {
118 ACT_FUNC_DEFS
119 register FlintType sum;
120
121
122 sum = 0.0;
123 if (GET_FIRST_UNIT_LINK( unit_ptr ))
124 do
125 sum += GET_WEIGHTED_OUTPUT;
126 while (GET_NEXT_LINK);
127 else
128 if (GET_FIRST_SITE( unit_ptr ))
129 do
130 sum += GET_SITE_VALUE;
131 while (GET_NEXT_SITE);
132
133 return( sum );
134 }
135
136 /* Brain-State-in-a-Box Function
137 */
ACT_BSBFunction(struct Unit * unit_ptr)138 FlintType ACT_BSBFunction(struct Unit *unit_ptr)
139 {
140 ACT_FUNC_DEFS
141 register FlintType sum;
142
143
144 sum = 0.0;
145 if (GET_FIRST_UNIT_LINK( unit_ptr ))
146 do
147 sum += GET_WEIGHTED_OUTPUT;
148 while (GET_NEXT_LINK);
149 else
150 if (GET_FIRST_SITE( unit_ptr ))
151 do
152 sum += GET_SITE_VALUE;
153 while (GET_NEXT_SITE);
154
155 return( sum * GET_UNIT_BIAS( unit_ptr ));
156 }
157
158 /* Minimum Function (Unit's output and weight)
159 */
ACT_MinOutPlusWeight(struct Unit * unit_ptr)160 FlintType ACT_MinOutPlusWeight(struct Unit *unit_ptr)
161 {
162 ACT_FUNC_DEFS
163 register FlintType min1, min2;
164
165
166 min1 = 0.0;
167
168 if (GET_FIRST_UNIT_LINK( unit_ptr )) {
169 min1 = GET_OUTPUT + GET_WEIGHT;
170 while (GET_NEXT_LINK)
171 if ((min2 = GET_OUTPUT + GET_WEIGHT) < min1)
172 min1 = min2;
173 }
174 else
175 if (GET_FIRST_SITE( unit_ptr )) {
176 min1 = GET_SITE_VALUE;
177 while (GET_NEXT_SITE)
178 if ((min2 = GET_SITE_VALUE) < min1)
179 min1 = min2;
180 }
181
182 return( min1 );
183 }
184
185
186 /* Hyperbolic Tangent Function with Bias
187 */
ACT_TanHFunction(struct Unit * unit_ptr)188 FlintType ACT_TanHFunction(struct Unit *unit_ptr)
189 {
190 ACT_FUNC_DEFS
191 register FlintType sum;
192
193
194 sum = 0.0;
195 if (GET_FIRST_UNIT_LINK( unit_ptr ))
196 do
197 sum += GET_WEIGHTED_OUTPUT;
198 while (GET_NEXT_LINK);
199 else
200 if (GET_FIRST_SITE( unit_ptr ))
201 do
202 sum += GET_SITE_VALUE;
203 while (GET_NEXT_SITE);
204
205 return( tanh( sum + GET_UNIT_BIAS( unit_ptr )));
206 }
207
208
209 /* Hyperbolic Tangent Function of (unit_ptr/2)
210 */
ACT_TanHFunction_Xdiv2(unit_ptr)211 FlintType ACT_TanHFunction_Xdiv2( unit_ptr )
212 UNIT_PTR unit_ptr;
213 {
214 ACT_FUNC_DEFS
215 register FlintType sum;
216 float expon;
217 float wert;
218
219 sum = 0.0;
220 if (GET_FIRST_UNIT_LINK( unit_ptr ))
221 do
222 sum += GET_WEIGHTED_OUTPUT;
223 while (GET_NEXT_LINK);
224 else
225 if (GET_FIRST_SITE( unit_ptr ))
226 do
227 sum += GET_SITE_VALUE;
228 while (GET_NEXT_SITE);
229
230 wert = sum + GET_UNIT_BIAS( unit_ptr );
231 if( wert > 9 ) wert = 9;
232 if( wert < -9 ) wert = -9;
233
234 expon = exp_s(wert);
235 return( (expon - 1) / (expon + 1));
236
237 }
238
239
240
241
242 /* Sigmoid Function
243 */
ACT_Logistic(struct Unit * unit_ptr)244 FlintType ACT_Logistic(struct Unit *unit_ptr)
245 {
246 ACT_FUNC_DEFS
247 register FlintType sum;
248
249
250 sum = 0.0;
251 if (GET_FIRST_UNIT_LINK( unit_ptr ))
252 do
253 sum += GET_WEIGHTED_OUTPUT;
254 while (GET_NEXT_LINK);
255 else
256 if (GET_FIRST_SITE( unit_ptr ))
257 do
258 sum += GET_SITE_VALUE;
259 while (GET_NEXT_SITE);
260
261 return( (FlintType) (1.0 / (1.0 + exp_s( -sum - GET_UNIT_BIAS( unit_ptr )))) );
262 }
263
264
265 /* Elliott Function
266 */
ACT_Elliott(struct Unit * unit_ptr)267 FlintType ACT_Elliott(struct Unit *unit_ptr)
268 {
269 ACT_FUNC_DEFS
270 register FlintType sum;
271
272
273 sum = 0.0;
274 if (GET_FIRST_UNIT_LINK( unit_ptr ))
275 do
276 sum += GET_WEIGHTED_OUTPUT;
277 while (GET_NEXT_LINK);
278 else
279 if (GET_FIRST_SITE( unit_ptr ))
280 do
281 sum += GET_SITE_VALUE;
282 while (GET_NEXT_SITE);
283
284 sum += GET_UNIT_BIAS(unit_ptr);
285 if (sum <= 0.0)
286 return (FlintType) sum/(1.0 - sum);
287 else
288 return (FlintType) sum/(1.0 + sum);
289 }
290
291
292 /* Perceptron Function
293 */
ACT_Perceptron(struct Unit * unit_ptr)294 FlintType ACT_Perceptron(struct Unit *unit_ptr)
295 {
296 ACT_FUNC_DEFS
297 register FlintType sum;
298
299
300 sum = 0.0;
301 if (GET_FIRST_UNIT_LINK( unit_ptr ))
302 do
303 sum += GET_WEIGHTED_OUTPUT;
304 while (GET_NEXT_LINK);
305 else
306 if (GET_FIRST_SITE( unit_ptr ))
307 do
308 sum += GET_SITE_VALUE;
309 while (GET_NEXT_SITE);
310
311 if (sum >= GET_UNIT_BIAS(unit_ptr))
312 return( (FlintType) 1.0 );
313
314 return( (FlintType) 0.0 );
315 }
316
317 /* Signum Function
318 */
ACT_Signum(struct Unit * unit_ptr)319 FlintType ACT_Signum(struct Unit *unit_ptr)
320 {
321 ACT_FUNC_DEFS
322 register FlintType sum;
323
324
325 sum = 0.0;
326 if (GET_FIRST_UNIT_LINK( unit_ptr ))
327 do
328 sum += GET_WEIGHTED_OUTPUT;
329 while (GET_NEXT_LINK);
330 else
331 if (GET_FIRST_SITE( unit_ptr ))
332 do
333 sum += GET_SITE_VALUE;
334 while (GET_NEXT_SITE);
335
336 if (sum > 0.0)
337 return( (FlintType) 1.0 );
338
339 return( (FlintType) -1.0 );
340 }
341
342 /* Softmax Function
343 */
ACT_Softmax(struct Unit * unit_ptr)344 FlintType ACT_Softmax(struct Unit *unit_ptr)
345 {
346 ACT_FUNC_DEFS
347 register FlintType sum;
348
349
350 sum = 0.0;
351 if (GET_FIRST_UNIT_LINK( unit_ptr ))
352 do
353 sum += GET_WEIGHTED_OUTPUT;
354 while (GET_NEXT_LINK);
355 else
356 if (GET_FIRST_SITE( unit_ptr ))
357 do
358 sum += GET_SITE_VALUE;
359 while (GET_NEXT_SITE);
360
361 return( exp_s( -sum - GET_UNIT_BIAS( unit_ptr )) );
362 }
363
ACT_EXPONENT(struct Unit * unit_ptr)364 FlintType ACT_EXPONENT(struct Unit *unit_ptr)
365 {
366 ACT_FUNC_DEFS
367 register FlintType sum;
368
369 sum = GET_UNIT_BIAS(unit_ptr);
370 if (GET_FIRST_UNIT_LINK( unit_ptr ))
371 do
372 sum += GET_WEIGHTED_OUTPUT;
373 while (GET_NEXT_LINK);
374 else
375 if (GET_FIRST_SITE( unit_ptr ))
376 do
377 sum += GET_SITE_VALUE;
378 while (GET_NEXT_SITE);
379 return exp_s(-0.5*sum*sum);
380 }
381
ACT_DERIV_EXPONENT(struct Unit * unit_ptr)382 FlintType ACT_DERIV_EXPONENT(struct Unit *unit_ptr)
383 {
384 ACT_FUNC_DEFS
385 register FlintType sum;
386
387
388 sum = GET_UNIT_BIAS(unit_ptr);
389 if (GET_FIRST_UNIT_LINK( unit_ptr ))
390 do
391 sum += GET_WEIGHTED_OUTPUT;
392 while (GET_NEXT_LINK);
393 else
394 if (GET_FIRST_SITE( unit_ptr ))
395 do
396 sum += GET_SITE_VALUE;
397 while (GET_NEXT_SITE);
398 return (-sum*exp_s(-0.5*sum*sum));
399 }
400
ACT_SIN(struct Unit * unit_ptr)401 FlintType ACT_SIN(struct Unit *unit_ptr)
402 {
403 ACT_FUNC_DEFS
404 register FlintType sum;
405
406
407 sum = GET_UNIT_BIAS(unit_ptr);
408 if (GET_FIRST_UNIT_LINK( unit_ptr ))
409 do
410 sum += GET_WEIGHTED_OUTPUT;
411 while (GET_NEXT_LINK);
412 else
413 if (GET_FIRST_SITE( unit_ptr ))
414 do
415 sum += GET_SITE_VALUE;
416 while (GET_NEXT_SITE);
417
418 return(sin(SIN_FAKTOR*sum));
419 }
420
ACT_DERIV_SIN(struct Unit * unit_ptr)421 FlintType ACT_DERIV_SIN(struct Unit *unit_ptr)
422 {
423 ACT_FUNC_DEFS
424 register FlintType sum;
425
426
427 sum = GET_UNIT_BIAS(unit_ptr);
428 if (GET_FIRST_UNIT_LINK( unit_ptr ))
429 do
430 sum += GET_WEIGHTED_OUTPUT;
431 while (GET_NEXT_LINK);
432 else
433 if (GET_FIRST_SITE( unit_ptr ))
434 do
435 sum += GET_SITE_VALUE;
436 while (GET_NEXT_SITE);
437 return SIN_FAKTOR*cos(SIN_FAKTOR*sum);
438 }
439
440
ACT_CC_Threshold(struct Unit * unit_ptr)441 FlintType ACT_CC_Threshold(struct Unit *unit_ptr)
442 /* only used, because I need a pseudo-derivation */
443 {
444 ACT_FUNC_DEFS
445 register FlintType sum;
446
447
448 sum = 0.0;
449 if (GET_FIRST_UNIT_LINK( unit_ptr ))
450 do
451 sum += GET_WEIGHTED_OUTPUT;
452 while (GET_NEXT_LINK);
453 else
454 if (GET_FIRST_SITE( unit_ptr ))
455 do
456 sum += GET_SITE_VALUE;
457 while (GET_NEXT_SITE);
458
459 if (sum >= - GET_UNIT_BIAS(unit_ptr)) /* remember it's negative */
460 return( (FlintType) 1.0 );
461
462 return( (FlintType) 0.0 );
463 }
464
ACT_DERIV_CC_Threshold(struct Unit * unit_ptr)465 FlintType ACT_DERIV_CC_Threshold(struct Unit *unit_ptr)
466 {
467 /* return ACT_DERIV_Logistic(unit_ptr);*/
468 return (THRESHOLD_DERIV);
469 }
470
471 /* Signum0 Function
472 */
ACT_Signum0(struct Unit * unit_ptr)473 FlintType ACT_Signum0(struct Unit *unit_ptr)
474 {
475 ACT_FUNC_DEFS
476 register FlintType sum;
477
478
479 sum = 0.0;
480 if (GET_FIRST_UNIT_LINK( unit_ptr ))
481 do
482 sum += GET_WEIGHTED_OUTPUT;
483 while (GET_NEXT_LINK);
484 else
485 if (GET_FIRST_SITE( unit_ptr ))
486 do
487 sum += GET_SITE_VALUE;
488 while (GET_NEXT_SITE);
489
490 if (sum > 0.0) return( (FlintType) 1.0 );
491 if (sum < 0.0) return( (FlintType) -1.0 );
492 return( (FlintType) 0.0 );
493 }
494
495
496 /* Step Function
497 */
ACT_StepFunction(struct Unit * unit_ptr)498 FlintType ACT_StepFunction(struct Unit *unit_ptr)
499 {
500 ACT_FUNC_DEFS
501 register FlintType sum;
502
503
504 sum = 0.0;
505 if (GET_FIRST_UNIT_LINK( unit_ptr ))
506 do
507 sum += GET_WEIGHTED_OUTPUT;
508 while (GET_NEXT_LINK);
509 else
510 if (GET_FIRST_SITE( unit_ptr ))
511 do
512 sum += GET_SITE_VALUE;
513 while (GET_NEXT_SITE);
514
515 if (sum > 0.0) return( (FlintType) 1.0 );
516 return( (FlintType) 0.0 );
517 }
518
519
520 /* Hysteresis Step Function
521 */
ACT_HystStepFunction(struct Unit * unit_ptr)522 FlintType ACT_HystStepFunction(struct Unit *unit_ptr)
523 {
524 ACT_FUNC_DEFS
525 register FlintType sum;
526 FlintType Schwellwert = 0.1;
527
528 sum = 0.0;
529 if (GET_FIRST_UNIT_LINK( unit_ptr ))
530 do
531 sum += GET_WEIGHTED_OUTPUT;
532 while (GET_NEXT_LINK);
533 else
534 if (GET_FIRST_SITE( unit_ptr ))
535 do
536 sum += GET_SITE_VALUE;
537 while (GET_NEXT_SITE);
538
539 if (sum - (unit_ptr->bias) > Schwellwert) return( (FlintType) 1.0 );
540 if (sum - (unit_ptr->bias) < -Schwellwert) return( (FlintType) 0.0 );
541
542 return( unit_ptr->act );
543 }
544
545 /* Bi-Directional Associative Memory
546 */
ACT_BAMFunction(struct Unit * unit_ptr)547 FlintType ACT_BAMFunction(struct Unit *unit_ptr)
548 {
549 ACT_FUNC_DEFS
550 register FlintType sum;
551
552
553 sum = 0.0;
554 if (GET_FIRST_UNIT_LINK( unit_ptr ))
555 do
556 sum += GET_WEIGHTED_OUTPUT;
557 while (GET_NEXT_LINK);
558 else
559 if (GET_FIRST_SITE( unit_ptr ))
560 do
561 sum += GET_SITE_VALUE;
562 while (GET_NEXT_SITE);
563
564 if (sum > 0.0) return( (FlintType) 1.0 );
565 if (sum < 0.0) return( (FlintType) -1.0 );
566 return( unit_ptr->Out.output );
567 }
568
569 /* Rummelhart-McClelland's activation function for the delta rule
570 */
ACT_RM(struct Unit * unit_ptr)571 FlintType ACT_RM (struct Unit *unit_ptr)
572 {
573 ACT_FUNC_DEFS
574 register FlintType RM_act, sum;
575 FlintType Eparam=.15, Dparam=.15;
576
577 sum = 0.0;
578
579 if (GET_FIRST_UNIT_LINK (unit_ptr))
580 do
581 sum += GET_WEIGHTED_OUTPUT;
582 while (GET_NEXT_LINK);
583 else
584 if (GET_FIRST_SITE (unit_ptr))
585 do
586 sum += GET_SITE_VALUE;
587 while (GET_NEXT_SITE);
588
589 if (sum > 0)
590 RM_act = (unit_ptr->act + (Eparam * sum * (1 - unit_ptr->act))
591 - (Dparam * unit_ptr->act));
592 else
593 RM_act = (unit_ptr->act + (Eparam * sum * (unit_ptr->act + 1))
594 - (Dparam * unit_ptr->act));
595
596 return (RM_act);
597 }
598
599 /* Tacoma-Activation-Function.
600 This Function needs additional parameters. They are stored
601 in value_a (radius) and value_b (coord.) */
602
603
604
ACT_TACOMA(struct Unit * unit_ptr)605 FlintType ACT_TACOMA(struct Unit *unit_ptr)
606 {
607 ACT_FUNC_DEFS
608 register FlintType sum, coordAct,WeightSum;
609
610 sum = 0.0;
611 WeightSum = GET_UNIT_BIAS( unit_ptr );
612
613 if (GET_FIRST_UNIT_LINK(unit_ptr))
614 do{
615 if ((GET_TACOMA_RADIUS > 0.0)&&(GET_TACOMA_RADIUS>0)){
616 coordAct = ((GET_OUTPUT-GET_TACOMA_COORD) / GET_TACOMA_RADIUS);
617 sum += coordAct*coordAct;
618 }
619 WeightSum += GET_WEIGHTED_OUTPUT;
620 }while (GET_NEXT_LINK);
621 /* {
622 printf("Summe ist %.3f, exp ist : %.3f, normal was %.4f Erg ist %.3f\n",
623 sum,exp_s(-sum),(1/(1+exp_s(-WeightSum))-0.5),
624 (exp_s(-sum) * (1/(1+exp_s(-WeightSum))-0.5)));
625 }*/
626 return(exp_s(-sum) * (1/(1+exp_s(-WeightSum))-0.5));
627 }
628
629
630
631
632 /* demonstation function: this function act like the Logistic function,
633 but the site with the name "Inhibit" will be skipped.
634 */
ACT_LogisticI(struct Unit * unit_ptr)635 FlintType ACT_LogisticI(struct Unit *unit_ptr)
636 {
637 ACT_FUNC_DEFS
638 register FlintType sum;
639
640
641 sum = 0.0;
642 if (GET_FIRST_SITE( unit_ptr ))
643 /* Do not calculate the 'Inhibit' site */
644 do
645 if (strcmp( "Inhibit", GET_SITE_NAME ))
646 sum += GET_SITE_VALUE;
647 while (GET_NEXT_SITE);
648 else
649 if (GET_FIRST_UNIT_LINK( unit_ptr ))
650 do
651 sum += GET_WEIGHTED_OUTPUT;
652 while (GET_NEXT_LINK);
653
654 return( (FlintType) (1.0 / (1.0 + exp_s( -sum - GET_UNIT_BIAS( unit_ptr )))) );
655 }
656
657 /* help function for all Radial Basis Activation, Derivation and Learn
658 * functions. Computes the square of the L2-Norm of (T - X), where T is the
659 * vector of all weights from links leading to <unit_ptr> and X is the
660 * vector of output units the links are connected from.
661 * Store calculated value into value_a field of the current unit.
662 * ALL FUTURE RBF ACTIVATION FUNCTIONS HAVE TO CALL THIS FUNCTION !!!!!!!!!!
663 */
664
RbfUnitGetNormsqr(struct Unit * unit_ptr)665 FlintType RbfUnitGetNormsqr(struct Unit *unit_ptr)
666 {
667 ACT_FUNC_DEFS
668 register FlintType norm_2 = 0.0; /* |X - T|^2 */
669 register FlintType diff; /* difference */
670
671
672 if (!GET_FIRST_UNIT_LINK(unit_ptr))
673 {
674 fprintf(stderr,"No input links!\n");
675 return norm_2;
676 }
677
678 do
679 {
680 diff = GET_OUTPUT - GET_WEIGHT;
681 norm_2 += diff * diff;
682 }
683 while (GET_NEXT_LINK);
684
685 return unit_ptr -> value_a = norm_2;
686 }
687
688 /*
689 * Gaussian RBF Activation function: h(L2, s) = exp(-s*L2^2)
690 * where L2 is the L2 Norm (see RbfUnitGetNormsqr), and s is the bias
691 * of <unit_ptr>.
692 */
693
ACT_RBF_Gaussian(struct Unit * unit_ptr)694 FlintType ACT_RBF_Gaussian(struct Unit *unit_ptr)
695 {
696 register FlintType norm_2;
697
698 norm_2 = RbfUnitGetNormsqr(unit_ptr);
699 return (FlintType) exp_s(- GET_UNIT_BIAS(unit_ptr)*norm_2);
700 }
701
702 /*
703 * Multiquadratic Activation function: h(L2, s) = sqrt(s^2 + L2^2)
704 */
705
ACT_RBF_Multiquadratic(struct Unit * unit_ptr)706 FlintType ACT_RBF_Multiquadratic(struct Unit *unit_ptr)
707 {
708 register FlintType norm_2;
709
710 norm_2 = RbfUnitGetNormsqr(unit_ptr);
711 return (FlintType) sqrt(norm_2 + GET_UNIT_BIAS(unit_ptr));
712 }
713
714 /*
715 * Thin plate splines Activation function: h(L2, s) = (L2*s)^2*ln(L2*s)
716 */
717
ACT_RBF_Thinplatespline(struct Unit * unit_ptr)718 FlintType ACT_RBF_Thinplatespline(struct Unit *unit_ptr)
719 {
720 register FlintType norm_2;
721 register FlintType bias;
722
723 norm_2 = RbfUnitGetNormsqr(unit_ptr);
724 bias = GET_UNIT_BIAS(unit_ptr);
725
726 if (norm_2 == (FlintType) 0.0)
727 return (FlintType) 0.0;
728 else
729 return (FlintType) bias*bias*norm_2*(0.5*log(norm_2) + log(bias));
730 }
731
732 /* Linear Activation Function + BIAS
733 */
ACT_Linear_bias(struct Unit * unit_ptr)734 FlintType ACT_Linear_bias(struct Unit *unit_ptr)
735 {
736 ACT_FUNC_DEFS
737 register FlintType sum;
738
739
740 sum = 0.0;
741 if (GET_FIRST_UNIT_LINK( unit_ptr ))
742 do
743 sum += GET_WEIGHTED_OUTPUT;
744 while (GET_NEXT_LINK);
745 else
746 if (GET_FIRST_SITE( unit_ptr ))
747 do
748 sum += GET_SITE_VALUE;
749 while (GET_NEXT_SITE);
750
751 return( sum + GET_UNIT_BIAS(unit_ptr));
752 }
753
754
755
756 /* NOTE: This function is nothing but a threshold function,
757 which checks, whether the netinput is greater or equal 2, and if so
758 returns 1.0, else 0.0 .
759 */
ACT_at_least_2(struct Unit * unit_ptr)760 FlintType ACT_at_least_2 (struct Unit *unit_ptr)
761 {
762 ACT_FUNC_DEFS
763 register FlintType sum = 0.0;
764
765 if (GET_FIRST_UNIT_LINK (unit_ptr)) {
766 do {
767 sum += GET_WEIGHTED_OUTPUT;
768 } while (GET_NEXT_LINK);
769 } else {
770 if (GET_FIRST_SITE (unit_ptr)) {
771 do {
772 sum += GET_SITE_VALUE;
773 } while (GET_NEXT_SITE);
774 } /*if*/
775 } /*if*/
776
777
778 if (sum >= 2.0) {
779 return ( (FlintType) 1.0);
780 } else {
781 return ( (FlintType) 0.0);
782 } /*if*/
783 } /* ACT_at_least_2 */
784
785
786
ACT_less_than_0(struct Unit * unit_ptr)787 FlintType ACT_less_than_0 (struct Unit *unit_ptr)
788 {
789 ACT_FUNC_DEFS
790 register FlintType sum = 0.0;
791
792
793 if (GET_FIRST_UNIT_LINK (unit_ptr)) {
794 do {
795 sum += GET_WEIGHTED_OUTPUT;
796 } while (GET_NEXT_LINK);
797 } else {
798 if (GET_FIRST_SITE (unit_ptr)) {
799 do {
800 sum += GET_SITE_VALUE;
801 } while (GET_NEXT_SITE);
802 } /*if*/
803 } /*if*/
804
805 if (sum >= 0.0) {
806 return ( (FlintType) 0.0);
807 } else {
808 return ( (FlintType) 1.0);
809 } /*if*/
810
811 } /* ACT_less_than_0 */
812
813
814
815
816
ACT_at_least_1(struct Unit * unit_ptr)817 FlintType ACT_at_least_1 (struct Unit *unit_ptr)
818 {
819 ACT_FUNC_DEFS
820 register FlintType sum = 0.0;
821
822
823 if (GET_FIRST_SITE (unit_ptr)) {
824 do {
825 sum += GET_SITE_VALUE;
826 } while (GET_NEXT_SITE);
827 } else {
828 if (GET_FIRST_UNIT_LINK (unit_ptr)) {
829 do {
830 sum += GET_WEIGHTED_OUTPUT;
831 } while (GET_NEXT_LINK);
832 } /*if*/
833 } /*if*/
834
835
836 if (sum >= 1.0) {
837 return ( (FlintType) 1.0);
838 } else {
839 return ( (FlintType) 0.0);
840 } /*if*/
841
842 } /* ACT_at_least_1 */
843
844
845
ACT_at_most_0(struct Unit * unit_ptr)846 FlintType ACT_at_most_0 (struct Unit *unit_ptr)
847 {
848 ACT_FUNC_DEFS
849 register FlintType sum = 0.0;
850
851
852 if (GET_FIRST_UNIT_LINK (unit_ptr)) {
853 do {
854 sum += GET_WEIGHTED_OUTPUT;
855 } while (GET_NEXT_LINK);
856 } else {
857 if (GET_FIRST_SITE (unit_ptr)) {
858 do {
859 sum += GET_SITE_VALUE;
860 } while (GET_NEXT_SITE);
861 } /*if*/
862 } /*if*/
863
864 if (sum > 0.0) {
865 return ( (FlintType) 0.0);
866 } else {
867 return ( (FlintType) 1.0);
868 } /*if*/
869
870 } /* ACT_at_most_0 */
871
872
873
ACT_Product(struct Unit * unit_ptr)874 FlintType ACT_Product (struct Unit *unit_ptr)
875 {
876 ACT_FUNC_DEFS
877 register FlintType prod = 1.0;
878
879
880 if (GET_FIRST_UNIT_LINK (unit_ptr)) {
881 do {
882 prod *= GET_WEIGHTED_OUTPUT;
883 if (prod == 0.0) {
884 break;
885 } /*if*/
886 } while (GET_NEXT_LINK);
887 } else {
888 if (GET_FIRST_SITE (unit_ptr)) {
889 do {
890 prod *= GET_SITE_VALUE;
891 if (prod == 0.0) {
892 break;
893 } /*if*/
894 } while (GET_NEXT_SITE);
895 } /*if*/
896 } /*if*/
897
898 return (prod);
899
900 } /* ACT_Product () */
901
902
ACT_exactly_1(struct Unit * unit_ptr)903 FlintType ACT_exactly_1 (struct Unit *unit_ptr)
904 {
905 ACT_FUNC_DEFS
906 register FlintType sum = 0.0;
907
908
909 if (GET_FIRST_UNIT_LINK (unit_ptr)) {
910 do {
911 sum += GET_WEIGHTED_OUTPUT;
912 } while (GET_NEXT_LINK);
913 } else {
914 if (GET_FIRST_SITE (unit_ptr)) {
915 do {
916 sum += GET_SITE_VALUE;
917 } while (GET_NEXT_SITE);
918 } /*if*/
919 } /*if*/
920
921 if ((sum > 0.8) && (sum < 1.2)) {
922 return (1.0);
923 } else {
924 return (0.0);
925 } /*if*/
926
927 } /* ACT_exactly_1 */
928
929 /*****************************************************************************
930 FUNCTION : ACT_TD_Logistic
931
932 PURPOSE : logistic activation function for use in time delay networks
933 RETURNS : activation
934 NOTES : the TD section of the unit must be initialized correct
935 the units must be sorted TOPOLOGIC_LOGICAL
936
937 UPDATE : 19.2.93 M. Vogt
938 ******************************************************************************/
939
ACT_TD_Logistic(struct Unit * unit_ptr)940 FlintType ACT_TD_Logistic(struct Unit *unit_ptr)
941 {
942 /* the common macros are not used */
943
944 register FlintType sum;
945 register UNIT_PTR ref_unit;
946 register int source_offset;
947 register struct Link *link;
948
949 if (unit_ptr -> TD.td_connect_typ == 0)
950 return ACT_Logistic(unit_ptr);
951
952 ref_unit = *(unit_ptr -> TD.my_topo_ptr + unit_ptr -> TD.target_offset);
953 source_offset = unit_ptr -> TD.source_offset;
954 sum = 0.0;
955 if ((ref_unit -> flags) & UFLAG_DLINKS)
956 {
957 link = (struct Link *) ref_unit->sites;
958 while (link != (struct Link *) NULL)
959 {
960 sum += (*(link->to->TD.my_topo_ptr + source_offset))->Out.output
961 * link->weight;
962 link = link->next;
963 }
964 }
965 else
966 {
967 fprintf(stderr,
968 "Warning: Illegal link structure used in time delay layer\n");
969 }
970 return( (FlintType) (1.0 / (1.0 + exp_s( -sum - ref_unit->bias))) );
971 }
972
973 /*****************************************************************************
974 FUNCTION : ACT_TD_Elliott
975
976 PURPOSE : elliott activation function for use in time delay networks
977 RETURNS : activation
978 NOTES : the TD section of the unit must be initialized correct
979 the units must be sorted TOPOLOGIC_LOGICAL
980
981 UPDATE : 5.3.93 M. Vogt
982 ******************************************************************************/
983
ACT_TD_Elliott(struct Unit * unit_ptr)984 FlintType ACT_TD_Elliott(struct Unit *unit_ptr)
985 {
986 /* the common macros are not used */
987
988 register FlintType sum;
989 register UNIT_PTR ref_unit;
990 register int source_offset;
991 register struct Link *link;
992
993 if (unit_ptr -> TD.td_connect_typ == 0)
994 return ACT_Elliott(unit_ptr);
995
996 ref_unit = *(unit_ptr -> TD.my_topo_ptr + unit_ptr -> TD.target_offset);
997 source_offset = unit_ptr -> TD.source_offset;
998 sum = 0.0;
999 if ((ref_unit -> flags) & UFLAG_DLINKS)
1000 {
1001 link = (struct Link *) ref_unit->sites;
1002 while (link != (struct Link *) NULL)
1003 {
1004 sum += (*(link->to->TD.my_topo_ptr + source_offset))->Out.output
1005 * link->weight;
1006 link = link->next;
1007 }
1008 }
1009 else
1010 {
1011 fprintf(stderr,
1012 "Warning: Illegal link structure used in time delay layer\n");
1013 }
1014
1015 sum += ref_unit->bias;
1016 if (sum <= 0.0)
1017 return (FlintType) sum/(1.0 - sum);
1018 else
1019 return (FlintType) sum/(1.0 + sum);
1020 }
1021
1022
1023
1024 /* This function is called by a xgui function for kohonen networks */
kohonen_SetExtraParameter(int x)1025 void kohonen_SetExtraParameter(int x)
1026 /* no. of layer chosen in remote panel */
1027 {
1028 ExtraParameter=x;
1029 }
1030
1031
1032 /* Activate specific layer of the net chosen in the remote panel, to set
1033 the layer call: kohonen_SetExtraParameter( Layer )
1034 */
ACT_Component(UNIT_PTR unit_ptr)1035 FlintType ACT_Component( UNIT_PTR unit_ptr )
1036
1037 {
1038 ACT_FUNC_DEFS
1039 register FlintType sum;
1040 int i=1,n;
1041
1042 n = ExtraParameter;
1043
1044 sum = 0.0;
1045 if (GET_FIRST_SITE( unit_ptr ))
1046 sum = GET_SITE_VALUE;
1047 else
1048 if (GET_FIRST_UNIT_LINK( unit_ptr ))
1049 do
1050 sum=GET_WEIGHT;
1051 while((i++<n)&&GET_NEXT_LINK);
1052
1053 return( sum );
1054 }
1055
1056 /* Calculate the simple euclidic distance
1057 between in-vector and weight-vector for kohonen networks
1058 */
ACT_Euclid(UNIT_PTR unit_ptr)1059 FlintType ACT_Euclid( UNIT_PTR unit_ptr )
1060
1061 {
1062 ACT_FUNC_DEFS
1063 register FlintType dist;
1064
1065 dist= 0.0;
1066 if (GET_FIRST_SITE( unit_ptr ))
1067 do
1068 dist += GET_SITE_VALUE;
1069 while (GET_NEXT_SITE);
1070 else
1071 if (GET_FIRST_UNIT_LINK( unit_ptr ))
1072 do
1073 dist += GET_EUCLID_COMP;
1074 while (GET_NEXT_LINK);
1075
1076 return(sqrt(dist));
1077 }
1078
ACT_Custom_Python(struct Unit * unit_ptr)1079 FlintType ACT_Custom_Python(struct Unit *unit_ptr)
1080 {
1081 fputs("Dummy for custom python activation functions - should never be called\n",stderr);
1082 return 0;
1083 }
1084
1085
1086
1087 /*######################################################################
1088
1089 GROUP: First and Second Derivation Functions of the Activation Functions
1090
1091 Second Derivation Funtions are not available for TD and RBF activation
1092 functions.
1093
1094 ######################################################################*/
1095
ACT_DERIV_Custom_Python(struct Unit * unit_ptr)1096 FlintType ACT_DERIV_Custom_Python(struct Unit *unit_ptr)
1097 {
1098 fputs("Dummy for custom python activation functions - should never be called\n",stderr);
1099 return 0;
1100 }
1101
ACT_2_DERIV_Custom_Python(struct Unit * unit_ptr)1102 FlintType ACT_2_DERIV_Custom_Python(struct Unit *unit_ptr)
1103 {
1104 fputs("Dummy for custom python activation functions - should never be called\n",stderr);
1105 return 0;
1106 }
1107
1108 /* Sigmoid Derivation Function
1109 */
ACT_DERIV_Logistic(struct Unit * unit_ptr)1110 FlintType ACT_DERIV_Logistic(struct Unit *unit_ptr)
1111 {
1112 return( GET_UNIT_ACT( unit_ptr ) * (1.0 - GET_UNIT_ACT( unit_ptr )) );
1113 }
1114
1115
ACT_2_DERIV_Logistic(struct Unit * unit_ptr)1116 FlintType ACT_2_DERIV_Logistic (struct Unit *unit_ptr)
1117 {
1118
1119 return (GET_UNIT_ACT (unit_ptr) * (1.0 - GET_UNIT_ACT (unit_ptr))
1120 * (2 * GET_UNIT_ACT (unit_ptr) - 1.0));
1121
1122 }
1123
1124
1125 /* Elliott Derivation Function
1126 */
ACT_DERIV_Elliott(struct Unit * unit_ptr)1127 FlintType ACT_DERIV_Elliott(struct Unit *unit_ptr)
1128 {
1129 register FlintType act;
1130 if ((act = GET_UNIT_ACT(unit_ptr)) <= 0.0)
1131 act = 1.0 + act;
1132 else
1133 act = 1.0 - act;
1134
1135 return (act*act);
1136 }
1137
1138
ACT_2_DERIV_Elliott(struct Unit * unit_ptr)1139 FlintType ACT_2_DERIV_Elliott (struct Unit *unit_ptr)
1140 {
1141
1142 register FlintType act;
1143
1144 if ((act = GET_UNIT_ACT(unit_ptr)) <= 0.0)
1145 act = 1.0 + act;
1146 else
1147 act = 1.0 - act;
1148
1149 if (act <= 0.0)
1150 return (2 * act * act);
1151 else
1152 return (-2 * act * act);
1153
1154 }
1155
1156
1157 /* Sigmoid Derivation Function for TD Networks
1158 */
1159
ACT_DERIV_TD_Logistic(struct Unit * unit_ptr)1160 FlintType ACT_DERIV_TD_Logistic(struct Unit *unit_ptr)
1161 {
1162 return( GET_UNIT_ACT( unit_ptr ) * (1.0 - GET_UNIT_ACT( unit_ptr )) );
1163 }
1164
1165
1166 /* Elliott Derivation Function for TD Networks
1167 */
1168
ACT_DERIV_TD_Elliott(struct Unit * unit_ptr)1169 FlintType ACT_DERIV_TD_Elliott(struct Unit *unit_ptr)
1170 {
1171 register FlintType act;
1172 if ((act = GET_UNIT_ACT(unit_ptr)) <= 0.0)
1173 act = 1.0 + act;
1174 else
1175 act = 1.0 - act;
1176
1177 return (act*act);
1178 }
1179
1180
1181 /* Identity Derivation Function
1182 */
ACT_DERIV_Identity(struct Unit * unit_ptr)1183 FlintType ACT_DERIV_Identity(struct Unit *unit_ptr)
1184 {
1185 return( (FlintType) 1.0 );
1186 }
1187
1188
ACT_2_DERIV_Identity(struct Unit * unit_ptr)1189 FlintType ACT_2_DERIV_Identity (struct Unit *unit_ptr)
1190 {
1191
1192 return ((FlintType) 0.0);
1193
1194 }
1195
1196 /* Brain-State-in-a-Box Derivation Function
1197 */
ACT_DERIV_BSBFunction(struct Unit * unit_ptr)1198 FlintType ACT_DERIV_BSBFunction(struct Unit *unit_ptr)
1199 {
1200 return( GET_UNIT_BIAS( unit_ptr ));
1201 }
1202
1203
ACT_2_DERIV_BSBFunction(struct Unit * unit_ptr)1204 FlintType ACT_2_DERIV_BSBFunction (struct Unit *unit_ptr)
1205 {
1206
1207 return ((FlintType) 0.0);
1208
1209 }
1210
1211
1212 /* TanH Derivation Function
1213 */
ACT_DERIV_TanHFunction(struct Unit * unit_ptr)1214 FlintType ACT_DERIV_TanHFunction(struct Unit *unit_ptr)
1215 {
1216 return(1.0-GET_UNIT_ACT( unit_ptr ) * (GET_UNIT_ACT( unit_ptr )) );
1217 }
1218
1219
ACT_2_DERIV_TanHFunction(struct Unit * unit_ptr)1220 FlintType ACT_2_DERIV_TanHFunction (struct Unit *unit_ptr)
1221 {
1222
1223 return (2 * GET_UNIT_ACT (unit_ptr) *
1224 (1.0 - GET_UNIT_ACT (unit_ptr) *
1225 GET_UNIT_ACT (unit_ptr)));
1226
1227 }
1228
1229
1230 /* TanH Derivation Function
1231 */
ACT_DERIV_TanHFunction_Xdiv2(struct Unit * unit_ptr)1232 FlintType ACT_DERIV_TanHFunction_Xdiv2(struct Unit *unit_ptr)
1233 {
1234 return(1.0-(GET_UNIT_ACT( unit_ptr ) * (GET_UNIT_ACT( unit_ptr )))/2 );
1235 }
1236
1237
ACT_2_DERIV_TanHFunction_Xdiv2(struct Unit * unit_ptr)1238 FlintType ACT_2_DERIV_TanHFunction_Xdiv2 (struct Unit *unit_ptr)
1239 {
1240
1241 return (ACT_2_DERIV_TanHFunction (unit_ptr) / 2);
1242
1243 }
1244
1245
1246 /* Dummy function for the derivation functions. Returns always the value 1.0.
1247 This function is used for activation functions that can't have a derivation
1248 function.
1249
1250 NOTE: All activation functions have to provide a derivation function.
1251 */
ACT_DERIV_Dummy(struct Unit * unit_ptr)1252 FlintType ACT_DERIV_Dummy(struct Unit *unit_ptr)
1253 {
1254 return( (FlintType) 1.0 );
1255 }
1256
1257
1258 /* Dummy function for second derivation, always returns 0.0. */
1259
ACT_2_DERIV_Dummy(struct Unit * unit_ptr)1260 FlintType ACT_2_DERIV_Dummy (struct Unit *unit_ptr)
1261 {
1262
1263 return ((FlintType) 0.0);
1264
1265 }
1266
1267
1268 /* Gaussian Radial Basis Derivation functionS
1269 * depending on Aux: 0 derivated to T
1270 * 1 derivated to s (BIAS)
1271 * 2 derivated to T if value_a holds norm ^ 2;
1272 * 3 derivated to s if value_a holds norm ^ 2;
1273 * others: const 1;
1274 */
1275
ACT_DERIV_RBF_Gaussian(struct Unit * unit_ptr)1276 FlintType ACT_DERIV_RBF_Gaussian(struct Unit *unit_ptr)
1277 {
1278 register FlintType rc; /* return value */
1279 register FlintType norm_2; /* norm ^ 2 */
1280
1281 switch (unit_ptr -> Aux.int_no)
1282 {
1283 case 0:
1284 /* derivated to norm_2: */
1285 norm_2 = RbfUnitGetNormsqr(unit_ptr);
1286 rc = (FlintType) -GET_UNIT_BIAS(unit_ptr)
1287 * exp_s(- GET_UNIT_BIAS(unit_ptr)*norm_2);
1288 break;
1289 case 1:
1290 /* derivated to BIAS: */
1291 norm_2 = RbfUnitGetNormsqr(unit_ptr);
1292 rc = (FlintType) -norm_2
1293 * exp_s(- GET_UNIT_BIAS(unit_ptr)*norm_2);
1294 break;
1295 case 2:
1296 /* derivated to norm_2: (norm ^ 2 = value_a) */
1297 rc = (FlintType) -GET_UNIT_BIAS(unit_ptr)
1298 * exp_s(- GET_UNIT_BIAS(unit_ptr)*unit_ptr -> value_a);
1299 break;
1300 case 3:
1301 /* derivated to BIAS: (norm ^ 2 = value_a) */
1302 rc = (FlintType) -unit_ptr -> value_a
1303 * exp_s(- GET_UNIT_BIAS(unit_ptr)*unit_ptr -> value_a);
1304 break;
1305 default:
1306 rc = (FlintType) 1.0;
1307 }
1308
1309 return rc;
1310 }
1311
1312 /* Multiquadratic Radial Basis Derivation functionS
1313 * depending on Aux: 0 derivated to T
1314 * 1 derivated to s (BIAS)
1315 * 2 derivated to T if value_a holds norm ^ 2;
1316 * 3 derivated to s if value_a holds norm ^ 2;
1317 * others: const 1;
1318 */
1319
ACT_DERIV_RBF_Multiquadratic(struct Unit * unit_ptr)1320 FlintType ACT_DERIV_RBF_Multiquadratic(struct Unit *unit_ptr)
1321 {
1322 register FlintType rc; /* return value */
1323 register FlintType norm_2; /* norm ^ 2 */
1324 register FlintType bias; /* s */
1325
1326 bias = (FlintType) GET_UNIT_BIAS(unit_ptr);
1327 switch (unit_ptr -> Aux.int_no)
1328 {
1329 case 0:
1330 case 1:
1331 /* derivated to BIAS: */
1332 /* derivated to norm_2: */
1333 norm_2 = RbfUnitGetNormsqr(unit_ptr);
1334 rc = (FlintType) 1.0/(2.0 * sqrt(bias + norm_2));
1335 break;
1336 case 2:
1337 case 3:
1338 /* derivated to BIAS: (norm ^ 2 = value_a) */
1339 /* derivated to norm_2: (norm ^ 2 = value_a) */
1340 rc = (FlintType) 1.0/(2.0 * sqrt(bias + unit_ptr -> value_a));
1341 break;
1342 default:
1343 rc = (FlintType) 1.0;
1344 }
1345
1346 return rc;
1347 }
1348
1349 /* Thin Plate Spline Radial Basis Derivation functionS
1350 * depending on Aux: 0 derivated to T
1351 * 1 derivated to s (BIAS)
1352 * 2 derivated to T if value_a holds norm ^ 2;
1353 * 3 derivated to s if value_a holds norm ^ 2;
1354 * others: const 1;
1355 */
1356
ACT_DERIV_RBF_Thinplatespline(struct Unit * unit_ptr)1357 FlintType ACT_DERIV_RBF_Thinplatespline(struct Unit *unit_ptr)
1358 {
1359 register FlintType rc; /* return value */
1360 register FlintType norm_2; /* norm ^ 2 */
1361 register FlintType bias; /* s */
1362
1363 bias = (FlintType) GET_UNIT_BIAS(unit_ptr);
1364 switch (unit_ptr -> Aux.int_no)
1365 {
1366 case 0:
1367 /* derivated to norm_2: */
1368 norm_2 = RbfUnitGetNormsqr(unit_ptr);
1369 if (norm_2 == (FlintType) 0.0)
1370 rc = (FlintType) 0.0;
1371 else
1372 rc = (FlintType) bias * bias *
1373 (log(norm_2) + 2.0*log(bias) + 1.0) / 2.0;
1374 break;
1375 case 1:
1376 /* derivated to BIAS: */
1377 norm_2 = RbfUnitGetNormsqr(unit_ptr);
1378 if (norm_2 == (FlintType) 0.0)
1379 rc = (FlintType) 0.0;
1380 else
1381 rc = (FlintType) bias * norm_2 *
1382 (log(norm_2) + 2.0*log(bias) + 1.0);
1383 break;
1384 case 2:
1385 /* derivated to norm_2: (norm ^ 2 = value_a) */
1386 if (unit_ptr -> value_a == (FlintType) 0.0)
1387 rc = (FlintType) 0.0;
1388 else
1389 rc = (FlintType) bias * bias *
1390 (log(unit_ptr -> value_a) + 2.0*log(bias) + 1.0) / 2.0;
1391 break;
1392 case 3:
1393 /* derivated to BIAS: (norm ^ 2 = value_a) */
1394 if (unit_ptr -> value_a == (FlintType) 0.0)
1395 rc = (FlintType) 0.0;
1396 else
1397 rc = (FlintType) bias * unit_ptr -> value_a *
1398 (log(unit_ptr -> value_a) + 2.0*log(bias) + 1.0);
1399 break;
1400 default:
1401 rc = (FlintType) 1.0;
1402 }
1403
1404 return rc;
1405 }
1406
1407
1408
1409
1410 /* Tacoma-Deriv-Activation-Function.
1411 This Function needs additional parameters. They are stored
1412 in value_a (radius) and value_b (coord.) */
1413
ACT_DERIV_TACOMA(struct Unit * unit_ptr)1414 FlintType ACT_DERIV_TACOMA(struct Unit *unit_ptr)
1415 {
1416
1417 /* returns ( ( 1 1 ) 2 1 ) _
1418 ( ( ------------- - --- ) - --- ) h(x)
1419 ( ( 1+e^(-Net) 2 ) 4 )
1420
1421 or in latex-code :
1422 ((\frac{1}{1+e^{-Net}}-\frac{1}{2})^2 - frac{1}{4} )*h(\vec{x}) */
1423
1424
1425 ACT_FUNC_DEFS
1426 float sum,coordAct,WeightSum;
1427 float bruch;
1428
1429 sum = 0.0;
1430
1431 WeightSum=GET_UNIT_BIAS(unit_ptr);
1432
1433 if (GET_FIRST_UNIT_LINK(unit_ptr))
1434 do{
1435 if (GET_TACOMA_RADIUS > 0.0){
1436 coordAct = ((GET_OUTPUT-GET_TACOMA_COORD) / GET_TACOMA_RADIUS);
1437 sum += coordAct*coordAct;
1438 }
1439 WeightSum+=GET_WEIGHTED_OUTPUT;
1440 }while (GET_NEXT_LINK);
1441 bruch=1/(1+exp_s(-WeightSum))-0.5;
1442 return (bruch*bruch-0.25)*(exp_s(-sum));
1443 }
1444
1445
1446
1447
1448
1449 /*#################################################
1450
1451 GROUP: Site functions
1452
1453 #################################################*/
1454
1455 /* Linear Site Function
1456 */
SITE_WeightedSum(struct Site * site_ptr)1457 FlintType SITE_WeightedSum(struct Site *site_ptr)
1458 {
1459 SITE_FUNC_DEFS
1460 register FlintType sum;
1461
1462
1463 sum = 0.0;
1464 if (GET_FIRST_SITE_LINK( site_ptr ))
1465 do
1466 sum += GET_WEIGHTED_OUTPUT;
1467 while (GET_NEXT_LINK);
1468
1469 return( sum );
1470 }
1471
1472
1473 /* Product of all predecessor outputs and input link weights
1474 */
SITE_Product(struct Site * site_ptr)1475 FlintType SITE_Product(struct Site *site_ptr)
1476 {
1477 SITE_FUNC_DEFS
1478 register FlintType prod;
1479
1480
1481 if (GET_FIRST_SITE_LINK( site_ptr )) {
1482 prod = 1.0;
1483 do
1484 prod *= GET_WEIGHTED_OUTPUT;
1485 while (GET_NEXT_LINK);
1486
1487 return( prod );
1488 }
1489 else
1490 return( (FlintType) 0.0 );
1491 }
1492
1493
1494 /* Like SITE_Product() but no weighting of the unit's output
1495 */
SITE_ProductA(struct Site * site_ptr)1496 FlintType SITE_ProductA(struct Site *site_ptr)
1497 {
1498 SITE_FUNC_DEFS
1499 register FlintType prod;
1500
1501
1502 if (GET_FIRST_SITE_LINK( site_ptr )) {
1503 prod = 1.0;
1504 do
1505 prod *= GET_OUTPUT;
1506 while (GET_NEXT_LINK);
1507
1508 /* Future Application (in SNNS-Kernel V2.1 the sites don't have weights).
1509 So the return value is only the product.
1510 */
1511 return( GET_SITE_WEIGHT * prod );
1512 }
1513 else
1514 return( (FlintType) 0.0 );
1515 }
1516
1517
1518
1519 /* Get the highest weighted output
1520 */
SITE_Max(struct Site * site_ptr)1521 FlintType SITE_Max(struct Site *site_ptr)
1522 {
1523 SITE_FUNC_DEFS
1524 register FlintType max, out;
1525
1526
1527 if (GET_FIRST_SITE_LINK( site_ptr )) {
1528 max = GET_WEIGHTED_OUTPUT;
1529
1530 while (GET_NEXT_LINK) {
1531 out = GET_WEIGHTED_OUTPUT;
1532 if (max < out) max = out;
1533 }
1534
1535 return( max );
1536 }
1537 else
1538 return( (FlintType) 0.0 );
1539 }
1540
1541
1542 /* Get the lowest weighted output
1543 */
SITE_Min(struct Site * site_ptr)1544 FlintType SITE_Min(struct Site *site_ptr)
1545 {
1546 SITE_FUNC_DEFS
1547 register FlintType min, out;
1548
1549
1550 if (GET_FIRST_SITE_LINK( site_ptr )) {
1551 min = GET_WEIGHTED_OUTPUT;
1552
1553 while (GET_NEXT_LINK) {
1554 out = GET_WEIGHTED_OUTPUT;
1555 if (min > out) min = out;
1556 }
1557
1558 return( min );
1559 }
1560 else
1561 return( (FlintType) 0.0 );
1562
1563 }
1564
1565
SITE_at_least_2(struct Site * site_ptr)1566 FlintType SITE_at_least_2 (struct Site *site_ptr)
1567 {
1568 SITE_FUNC_DEFS
1569 register FlintType sum = 0.0;
1570
1571
1572 sum = 0.0;
1573 if (GET_FIRST_SITE_LINK (site_ptr))
1574 do
1575 sum += GET_WEIGHTED_OUTPUT;
1576 while (GET_NEXT_LINK);
1577
1578 if (sum >= 2.0) {
1579 return ( (FlintType) 1.0);
1580 } else {
1581 return ( (FlintType) 0.0);
1582 } /*if*/
1583
1584 } /* SITE_at_least_2 */
1585
1586
SITE_at_least_1(struct Site * site_ptr)1587 FlintType SITE_at_least_1 (struct Site *site_ptr)
1588 {
1589 SITE_FUNC_DEFS
1590 register FlintType sum = 0.0;
1591
1592
1593 sum = 0.0;
1594 if (GET_FIRST_SITE_LINK (site_ptr))
1595 do
1596 sum += GET_WEIGHTED_OUTPUT;
1597 while (GET_NEXT_LINK);
1598
1599 if (sum >= 1.0) {
1600 return ( (FlintType) 1.0);
1601 } else {
1602 return ( (FlintType) 0.0);
1603 } /*if*/
1604
1605 } /* SITE_at_least_1 */
1606
1607
SITE_at_most_0(struct Site * site_ptr)1608 FlintType SITE_at_most_0 (struct Site *site_ptr)
1609 {
1610 SITE_FUNC_DEFS
1611 register FlintType sum = 0.0;
1612
1613
1614 sum = 0.0;
1615 if (GET_FIRST_SITE_LINK (site_ptr))
1616 do
1617 sum += GET_WEIGHTED_OUTPUT;
1618 while (GET_NEXT_LINK);
1619
1620 if (sum <= 0.0) {
1621 return ( (FlintType) 1.0);
1622 } else {
1623 return ( (FlintType) 0.0);
1624 } /*if*/
1625
1626 } /* SITE_at_most_0 */
1627
1628
1629
1630 /* IMPORTANT:
1631 This function doesn't check for overflows. So make sure
1632 that sum is greater than 0.0 when using this Site function.
1633 */
SITE_Reciprocal_WeightedSum(struct Site * site_ptr)1634 FlintType SITE_Reciprocal_WeightedSum (struct Site *site_ptr)
1635 {
1636 SITE_FUNC_DEFS
1637 register FlintType sum = 0.0;
1638
1639
1640 sum = 0.0;
1641 if (GET_FIRST_SITE_LINK( site_ptr ))
1642 do
1643 sum += GET_WEIGHTED_OUTPUT;
1644 while (GET_NEXT_LINK);
1645
1646 if (sum == 0.0) {
1647 return (0.0);
1648 } else {
1649 return((FlintType) (1/sum));
1650 } /*if*/
1651 } /* SITE_Reciprocal_WeightedSum */
1652
1653
1654
ACT_LogisticSym(struct Unit * unit_ptr)1655 FlintType ACT_LogisticSym(struct Unit *unit_ptr)
1656 {
1657 ACT_FUNC_DEFS
1658 register FlintType sum;
1659
1660
1661 sum = 0.0;
1662 if (GET_FIRST_UNIT_LINK( unit_ptr ))
1663 do
1664 sum += GET_WEIGHTED_OUTPUT;
1665 while (GET_NEXT_LINK);
1666 else
1667 if (GET_FIRST_SITE( unit_ptr ))
1668 do
1669 sum += GET_SITE_VALUE;
1670 while (GET_NEXT_SITE);
1671 return( (FlintType) (1.0 / (1.0 + exp_s( -sum - GET_UNIT_BIAS( unit_ptr ))))-0.5);
1672 }
1673
ACT_DERIV_LogisticSym(struct Unit * unit_ptr)1674 FlintType ACT_DERIV_LogisticSym(struct Unit *unit_ptr)
1675 {
1676 return( 0.25 - GET_UNIT_ACT( unit_ptr ) * GET_UNIT_ACT( unit_ptr ));
1677 }
1678
ACT_DERIV_tanh(struct Unit * unit_ptr)1679 FlintType ACT_DERIV_tanh(struct Unit *unit_ptr)
1680 {
1681 return( 2 * (1.0 - GET_UNIT_ACT( unit_ptr )) * GET_UNIT_ACT( unit_ptr ));
1682 }
1683
1684
ACT_2_DERIV_tanh(struct Unit * unit_ptr)1685 FlintType ACT_2_DERIV_tanh (struct Unit *unit_ptr)
1686 {
1687
1688 return (2 * ACT_2_DERIV_Logistic (unit_ptr));
1689
1690 }
1691
1692
1693 #ifdef __BORLANDC__
1694 #pragma option -w+.
1695 #endif
1696