1 /***************************************************************************** 2 FILE : $Source: /projects/higgs1/SNNS/CVS/SNNS/kernel/sources/cc_mac.h,v $ 3 SHORTNAME : mac.h 4 SNNS VERSION : 4.2 5 6 PURPOSE : macros for cascade correlation and TACOMA 7 NOTES : 8 9 AUTHOR : Michael Schmalzl 10 DATE : 24.2.93 11 12 CHANGED BY : 13 RCS VERSION : $Revision: 2.12 $ 14 LAST CHANGE : $Date: 1998/02/25 15:25:59 $ 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 21 #ifndef _CC_MAC_DEFINED_ 22 #define _CC_MAC_DEFINED_ 23 24 /* constants for all algorithms */ 25 26 #define NO_INC_ALGORITHM 0 27 #define CC 1 28 #define TACOMA 3 29 30 #define OFF 0 31 #define ON 1 32 33 34 #define FIELD_EMPTY -1 35 36 #define NO_OF_ACT_FUNCS 7 37 38 #define ASYM_SIGMOID 0 39 #define SYM_SIGMOID 1 40 #define TANH 2 41 #define THRESHOLD 3 42 #define SINUS 4 43 #define EXPONENTIAL 5 44 #define RANDOM 6 /* RANDOM has to be last Act_function !!! */ 45 46 #define SIN_FAKTOR 0.1 47 #define THRESHOLD_DERIV 1 /* not used anymore */ 48 49 #define BACKPROP 0 50 #define BACKPROP_ONLINE 1 51 #define QUICKPROP 2 52 #define RPROP 3 53 54 #define SBC 0 55 #define AIC 1 56 #define CMSEP 2 57 58 #define CC_NO_MOD 0 59 #define CC_SDCC 1 60 #define CC_LFCC 2 61 #define CC_RLCC 3 62 #define CC_ECC 4 63 #define CC_GCC 5 64 #define CC_STAT 6 65 66 #define CONTINUE_LEARNING 1 67 #define STOP_LEARNING 0 68 69 #define CC_MAX_VALUE 0.1 70 #define FLOAT_MAX 1E+37 71 72 73 74 /* these are the standard parameter settings */ 75 76 /* output parameter definitions */ 77 #define OUT_PATIENCE 50 78 #define MAX_NO_OF_ERROR_UPDATE_CYCLES 200 79 #define MIN_ERROR_CHANGE 0.01 80 81 /* special parameter definitions */ 82 #define SPECIAL_PATIENCE 25 83 #define MAX_NO_OF_COVARIANCE_UPDATE_CYCLES 200 84 #define MIN_COVARIANCE_CHANGE 0.04 85 #define MAX_SPECIAL_UNIT_NO 8 86 #define SPECIAL_FUNC_TYPE SYM_SIGMOID 87 88 /* global parameter definitions */ 89 #define MAX_PIXEL_ERROR 0.2 90 #define LEARNING_FUNC QUICKPROP 91 #define MODIFICATION CC_NO_MOD 92 #define ON_OFF OFF 93 #define CACHING_ONOFF ON 94 95 96 /* Constants for the display-functions */ 97 98 #define X_MIN_POS 2 99 #define Y_MIN_POS 3 100 #define MAX_POS 1000000 101 #define MIN_HIDDEN_LAYER_HEIGHT 5 102 103 #define Y_MAX_MODE1 5 104 #define Y_MAX_MODE2 8 105 #define Y_MAX_MODE3 12 106 #define Y_MAX_MODE4 20 107 #define Y_MAX_MODE5 MAX_POS 108 #define X_MAX_DISPLAYABLE 30 109 #define DEFAULT_DISTANCE_BETWEEN_LAYERS 2 110 #define DISTANCE_TO_INOUT_LAYERS 3 111 112 /* Output-constants */ 113 114 #define LENGTH_HEADLINE 80 115 116 117 118 /* Size of one block of the layerlist */ 119 120 #define MINIMAL_LAYERLIST_SIZE 100 121 122 /* where the slopes are stored */ 123 124 #define LN_CURRENT_SLOPE(LinkPtr) LinkPtr->value_a 125 #define LN_PREVIOUS_SLOPE(LinkPtr) LinkPtr->value_b 126 #define LN_LAST_WEIGHT_CHANGE(LinkPtr) LinkPtr->value_c 127 128 #define BIAS_CURRENT_SLOPE(UnitPtr) UnitPtr->value_a 129 #define BIAS_PREVIOUS_SLOPE(UnitPtr) UnitPtr->value_b 130 #define BIAS_LAST_WEIGHT_CHANGE(UnitPtr) UnitPtr->value_c 131 132 133 /* Macros for all learn algorithms */ 134 135 #define NET_ERROR( param ) param[ 0 ] /* returns the net error */ 136 137 #define GET_UNIT_NO(UnitPtr) \ 138 ((int) ((UnitPtr) - unit_array)) 139 140 #define GET_UNIT_XPOS(UnitPtr) \ 141 (*UnitPtr).unit_pos.x 142 143 #define GET_UNIT_YPOS(UnitPtr) \ 144 (*UnitPtr).unit_pos.y 145 146 #define SET_UNIT_XPOS(UnitPtr,XPos) \ 147 (*UnitPtr).unit_pos.x = XPos 148 149 #define SET_UNIT_YPOS(UnitPtr,YPos) \ 150 (*UnitPtr).unit_pos.y = YPos 151 152 /* error-macros */ 153 154 #define ERROR_CHECK \ 155 if(KernelErrorCode!=KRERR_NO_ERROR) { \ 156 return(KernelErrorCode); \ 157 } 158 159 #define ERROR_CHECK_WITH_MEMORY_DEALLOCATION \ 160 if((TempErrorCode=KernelErrorCode)!=KRERR_NO_ERROR) { \ 161 cc_freeStorage(StartPattern,EndPattern,0); \ 162 return(TempErrorCode); \ 163 } 164 165 #define TAC_ERROR_CHECK_WITH_MEMORY_DEALLOCATION \ 166 if((TempErrorCode=KernelErrorCode)!=KRERR_NO_ERROR) { \ 167 tac_freeStorage(StartPattern,EndPattern); \ 168 return(TempErrorCode); \ 169 } 170 171 #define UPS_ERROR_CHECK_WITH_MEMORY_DEALLOCATION \ 172 if((TempErrorCode=KernelErrorCode)!=KRERR_NO_ERROR) { \ 173 ups_freeStorage(StartPattern,EndPattern); \ 174 return(TempErrorCode); \ 175 } 176 177 #define ERROR_CHECK_WRC \ 178 if(KernelErrorCode!=KRERR_NO_ERROR) { \ 179 return; \ 180 } 181 182 #define CC_ERROR(ErrorCode) \ 183 return(ErrorCode) 184 185 /* memory allocation macros */ 186 187 #define FREE_IF_USED(i) \ 188 if((i) != NULL){free(i); i=NULL; } 189 190 #define FREE_2DIMENSIONAL_ARRAY(Anker,NoOfRows,i) \ 191 if (Anker!=NULL){ \ 192 FREE_IF_USED(Anker[0]); \ 193 FREE_IF_USED(Anker); \ 194 Anker = NULL; \ 195 } 196 197 #define FREE_2DIMENSIONAL_ARRAY_WITH_PRINT(Anker,NoOfRows,i) \ 198 if (Anker!=NULL){ \ 199 FREE_IF_USED(Anker[0]); \ 200 Anker = NULL; \ 201 } 202 203 #define FREE_2ND_ARRAY(Anker,NoOfRows,UnderType,i) \ 204 if (Anker!=NULL){ \ 205 FREE_IF_USED(Anker[0].UnderType); \ 206 } 207 208 #define CALLOC_ERRORCHECK(Anker,Anzahl,Datentyp) \ 209 if( (Anker = (Datentyp *) calloc(Anzahl,sizeof(Datentyp))) == NULL){ \ 210 CC_ERROR(KernelErrorCode=KRERR_CC_ERROR3); \ 211 } 212 213 #define CALLOC_2DIMENSIONAL_ARRAY(Anker,NoOfRows,NoOfCols,DatenTyp,i) \ 214 { \ 215 CALLOC_ERRORCHECK(Anker,NoOfRows,DatenTyp*); \ 216 CALLOC_ERRORCHECK(Anker[0],(NoOfRows)*(NoOfCols),DatenTyp); \ 217 for(i=1;i<NoOfRows;i++) \ 218 { \ 219 Anker[i]=Anker[i-1]+NoOfCols; \ 220 } \ 221 } \ 222 223 #define CALLOC_2ND_ARRAY(Anker,NoOfRows,UnderType,NoOfCols,DataType,i) \ 224 { \ 225 CALLOC_ERRORCHECK(Anker[0].UnderType,(NoOfRows)*(NoOfCols),DataType); \ 226 for(i=1;i<(NoOfRows);i++) \ 227 { \ 228 Anker[i].UnderType=Anker[i-1].UnderType+(NoOfCols); \ 229 } \ 230 } 231 232 233 234 /* propagation macros */ 235 extern FlintType OUT_Custom_Python(FlintType act); 236 237 #define CALCULATE_ACTIVATION_AND_OUTPUT(UnitPtr,value,p) \ 238 { \ 239 UnitPtr->Out.output = ((UnitPtr->out_func == OUT_IDENTITY) ? \ 240 (UnitPtr->act = value) : \ 241 ((UnitPtr->out_func == OUT_Custom_Python) ? \ 242 kr_PythonOutFunction(UnitPtr->python_out_func, \ 243 UnitPtr->act = value) : \ 244 (*UnitPtr->out_func) (UnitPtr->act = value))); \ 245 } 246 247 #define CALCULATE_INPUTUNIT_ACTIVATION_AND_OUTPUT(UnitPtr,value) \ 248 UnitPtr->Out.output = ((UnitPtr->out_func == OUT_IDENTITY) ? \ 249 (UnitPtr->act = value) : \ 250 ((UnitPtr->out_func == OUT_Custom_Python) ? \ 251 kr_PythonOutFunction(UnitPtr->python_out_func, \ 252 UnitPtr->act = value) : \ 253 (*UnitPtr->out_func) (UnitPtr->act = value))); \ 254 255 #define PROPAGATE_THROUGH_INPUT_LAYER(inputUnitPtr,dummy,pattern) \ 256 FOR_ALL_INPUT_UNITS(inputUnitPtr,dummy){ \ 257 CALCULATE_INPUTUNIT_ACTIVATION_AND_OUTPUT(inputUnitPtr,*pattern++); \ 258 } 259 260 #define PROPAGATE_THROUGH_HIDDEN_LAYER(hiddenUnitPtr,dummy,pattern) \ 261 FOR_ALL_HIDDEN_UNITS(hiddenUnitPtr,dummy) { \ 262 CALCULATE_ACTIVATION_AND_OUTPUT(hiddenUnitPtr, \ 263 ((hiddenUnitPtr->act_func == ACT_Custom_Python) ? \ 264 kr_PythonActFunction(hiddenUnitPtr->python_act_func, \ 265 hiddenUnitPtr) : \ 266 (hiddenUnitPtr->act_func) (hiddenUnitPtr)) ,pattern); \ 267 } 268 269 #define PROPAGATE_THROUGH_OUTPUT_LAYER(outputUnitPtr,dummy,pattern) \ 270 FOR_ALL_OUTPUT_UNITS(outputUnitPtr,dummy) { \ 271 CALCULATE_ACTIVATION_AND_OUTPUT(outputUnitPtr, \ 272 ((outputUnitPtr->act_func == ACT_Custom_Python) ? \ 273 kr_PythonActFunction(outputUnitPtr->python_act_func, \ 274 outputUnitPtr) : \ 275 (outputUnitPtr->act_func) (outputUnitPtr)) ,pattern); \ 276 } 277 #define PROPAGATE_THROUGH_SPECIAL_LAYER(specialUnitPtr,dummy,pattern) \ 278 FOR_ALL_SPECIAL_UNITS(specialUnitPtr,dummy) { \ 279 CALCULATE_ACTIVATION_AND_OUTPUT(specialUnitPtr, \ 280 ((specialUnitPtr->act_func == ACT_Custom_Python) ? \ 281 kr_PythonActFunction(specialUnitPtr->python_act_func, \ 282 specialUnitPtr) : \ 283 (specialUnitPtr->act_func) (specialUnitPtr)) ,pattern); \ 284 } 285 286 /* modification macros */ 287 288 #define UNITS_IN_SAME_GROUP(spec,outpt) \ 289 ((cc_modification!=CC_GCC)|| \ 290 ((spec%CCS_NO_OF_GROUPS)==ccs_GroupList[outpt])) 291 292 #define NO_OF_GROUPS ((cc_modification!=CC_GCC) ? 1 : CCS_NO_OF_GROUPS) 293 294 295 /* misc macros */ 296 297 #define IF_PTR_IS_NOT_NULL(ptr) if(ptr!=NULL) 298 299 #define FOR_ALL_INPUT_UNITS(UnitPtr,i) \ 300 for(UnitPtr= *FirstInputUnitPtr,i=0;UnitPtr!=NULL;UnitPtr=FirstInputUnitPtr[++i]) 301 302 #define FOR_ALL_HIDDEN_UNITS(UnitPtr,h) \ 303 for(UnitPtr= *FirstHiddenUnitPtr,h=0;UnitPtr!=NULL;UnitPtr=FirstHiddenUnitPtr[++h]) 304 305 #define FOR_ALL_OUTPUT_UNITS(UnitPtr,o) \ 306 for(UnitPtr= *FirstOutputUnitPtr,o=0;UnitPtr!=NULL;UnitPtr=FirstOutputUnitPtr[++o]) 307 308 #define FOR_ALL_SPECIAL_UNITS(UnitPtr,s) \ 309 for(UnitPtr= *FirstSpecialUnitPtr,s=0;UnitPtr!=NULL;UnitPtr=FirstSpecialUnitPtr[++s]) 310 311 #define FOR_ALL_PATTERNS(StartPattern,EndPattern,p) \ 312 for(p=StartPattern;p<=EndPattern;p++) 313 314 #define SIGN(n) (((n) > 0) ? (1) : (-1)) 315 316 #define GET_RECURRENT_LINK(unit_ptr,link_ptr) \ 317 (link_ptr) = (struct Link *) (unit_ptr)->sites 318 319 #define FOR_ALL_NOT_RECURRENT_LINKS( unit_ptr, link_ptr ) \ 320 for ((link_ptr) = ((struct Link *) (unit_ptr)->sites)->next; (link_ptr) != NULL; \ 321 (link_ptr) = (link_ptr)->next) 322 323 #define MAX(a,b) (((a)>(b))?(a):(b)) 324 325 #define MIN(a,b) (((a)<(b))?(a):(b)) 326 327 #define NO_OF_NET_UNITS \ 328 (NoOfInputUnits+NoOfOutputUnits+NoOfHiddenUnits) 329 330 #define NO_OF_INOUT_UNITS \ 331 (NoOfInputUnits+NoOfOutputUnits) 332 333 #define REL_HIDDEN_NO(a) \ 334 ((a)-NoOfInputUnits-NoOfOutputUnits) 335 336 337 #define DISTANCE_BETWEEN_LAYERS(a) \ 338 (((a)==0)||((a)==NoOfLayers)) ? DISTANCE_TO_INOUT_LAYERS : cc_LayerDistance 339 340 341 #define CC_LAYER_NO(Ptr) ((Ptr->lln >= 0) ? Ptr->lln : ((-1) - Ptr->lln)) 342 343 #define CC_SET_LAYER_NO(Ptr,LayerNo) \ 344 if (Ptr->lln >= 0) \ 345 Ptr->lln = LayerNo; \ 346 else \ 347 Ptr->lln = (-1) - LayerNo; 348 349 #define FIRST_ROW_NEXT_LAYER(i) \ 350 ((i>0) ? \ 351 (ListOfLayers[i].xPosFirstRow + \ 352 (((ListOfLayers[i].NoOfUnitsInLayer)-1) / cc_display_mode) + \ 353 (DISTANCE_BETWEEN_LAYERS(i))) : \ 354 ListOfLayers[i].xPosFirstRow) 355 356 #define PRINTF if (cc_printOnOff) printf 357 358 #define SIGN_OF_THE_CORRELATION CorBetweenSpecialActAndOutError 359 360 #define OUTPUT_UNIT_SUM_ERROR MeanOutputUnitError 361 /* Aus Performance-Gruenden wird Variable 2-mal benutzt. 362 */ 363 /* */ 364 365 /* Parameters for Cascade-Correlation */ 366 367 368 #define PARAM1 ParameterInArray[0] 369 #define PARAM2 ParameterInArray[1] 370 #define PARAM3 ParameterInArray[2] 371 #define PARAM4 ParameterInArray[3] 372 #define PARAM5 ParameterInArray[4] 373 #define PARAM6 0.0001 374 #define MAX_PIXEL_ERR ParameterInArray[6] 375 #define LEARNING_FUNCTION (int)ParameterInArray[7] 376 #define CC_PRINT_ONOFF (int)ParameterInArray[8] 377 #define MIN_COVAR_CHANGE ParameterInArray[9] 378 #define SPEC_PATIENCE ParameterInArray[10] 379 #define MAX_NO_OF_COVAR_UPDATE_CYCLES ParameterInArray[11] 380 #define MAX_SPECIAL_UNIT_NUMBER ParameterInArray[12] 381 #define SPECIAL_FUNCTION_TYPE (int)ParameterInArray[13] 382 #define MINIMAL_ERROR_CHANGE ParameterInArray[14] 383 #define OUT_PATIEN ParameterInArray[15] 384 #define MAX_NO_ERROR_UPDATE_CYCLES ParameterInArray[16] 385 #define CC_PRUNE_ONOFF (int)ParameterInArray[17] 386 #define CC_BACKFITTING_ONOFF (int)ParameterInArray[18] 387 #define BACKFITT_PATIENCE ParameterInArray[19] 388 #define PRUNE_FUNC (int)ParameterInArray[20] 389 #define MODIFICATION_NO (int)ParameterInArray[21] 390 #define CC_PARAMETER1 ParameterInArray[22] 391 #define CC_PARAMETER2 ParameterInArray[23] 392 #define CC_PARAMETER3 ParameterInArray[24] 393 #define CC_PARAMETER4 ParameterInArray[25] 394 #define CC_PARAMETER5 ParameterInArray[26] 395 #define CC_FASTMODE ParameterInArray[27] 396 397 /* Parameters for the modifications of CC */ 398 399 400 #define CCM_HEIGHT cc_Parameter[0] 401 #define CCM_DIFF_HEIGHT cc_Parameter[1] 402 #define CCM_DAEMPFUNG cc_Parameter[2] 403 404 #define CCR_NO_OF_LINKS (int)cc_Parameter[0] 405 406 #define CCC_M cc_Parameter[0] 407 408 #define CCO_FAKTOR cc_Parameter[0] 409 410 #define CCS_NO_OF_GROUPS (int)cc_Parameter[0] 411 412 #define CCB_LAMBDA cc_Parameter[0] 413 414 #define SGN(x) (((x)==0.0)?0.0:(((x)<0.0)?-1.0:1.0)) 415 416 417 /* And now .... the TACOMA macros... */ 418 419 420 #define TAC_ALPHA(d,max) (0.1 * ((max-d)/(max))) 421 422 423 #define TAC_KOHONEN ((int)cc_Parameter[0]) 424 /* how much runs to determine the best special units ? */ 425 #define TAC_XI_RI_ETA (cc_Parameter[1]) 426 /* step-width learning of xi and ri */ 427 #define TAC_THRESHOLD cc_Parameter[2] 428 /* All special units with g over this threshold were built in */ 429 #define TAC_LAMBDA cc_Parameter[3] 430 /* A connection ist built in, iff the correlation is better than lambda */ 431 #define TAC_BETA cc_Parameter[4] 432 /* To determine the initial radius of a link.*/ 433 #define TAC_ETA 0.7 434 435 436 #define TAC_XIRI_ONLINE TRUE 437 438 439 #define TAC_EXP(x) \ 440 ( (x>88.72) ? MAXFLOAT : ((x<-88.0) ? 0.0 : exp(x)) ) 441 442 #define XI_OF_LINK(LinkPtr) \ 443 (LinkPtr->value_b) 444 445 #define RI_OF_LINK(LinkPtr) \ 446 (LinkPtr->value_a) 447 448 /* if you change XI_OF_LINK and/or RI_OF_LINK, then take a look at the loading 449 routines at krio_readConnectionDefs (kr_io.c) */ 450 451 452 #define SUMMED_DISTANCES Ri 453 454 #define TAC_MAX_VALUE 1.0 455 456 /* Macros for Upstart */ 457 458 459 #define UPS_MAX_VALUE 1.0 460 461 #define UPS_BEST_WEIGHT(LinkPtr) LinkPtr->value_c 462 463 #define UPS_MODIFIKATION_ON (cc_Parameter[0] > 0.0) 464 465 #define UPS_ETA (cc_Parameter[1]) 466 467 #define UPS_NEW_MODE (cc_Parameter[1]>0.0) 468 469 #define UPS_TEST (cc_Parameter[2]>0.0) 470 471 #define UPS_NOT_CALCULATED 0 472 473 #define UPS_GREAT_VALUE 10000 474 475 #define UPS_DAUGHTER_LINK(LinkPtr) LinkPtr->value_a 476 477 #endif 478