📄 neural.c
字号:
return 1 ; if ((key == 'n') || (key == 'N')) return 0 ; printf ( " Y or N:" ) ; }}//static int get_layer_init ( char *rest ){ if (! strcmp ( rest , "NOINIT" )) return 0 ; else if (! strcmp ( rest , "ANNEAL NOREGRESS" )) return 1 ; else if (! strcmp ( rest , "ANNEAL" )) return 2 ; else if (! strcmp ( rest , "GENETIC" )) return 3 ; else if (! strcmp ( rest , "REGRESS" )) return 4 ; else return -1 ;}//static int get_koh_init ( char *rest ){ if (! strcmp ( rest , "NOINIT" )) return 0 ; else if (! strcmp ( rest , "RANDOM" )) return 1 ; else return -1 ;}//static int check_anneal ( char *command , char *rest , struct AnnealParams *anneal_params ){ int m, n ; double p ; char msg[80] ; if (! strcmp ( command , "ANNEAL INIT TEMPS" )) { m = sscanf ( rest , "%d" , &n ) ; if ((m <= 0) || (n <= 0)) { sprintf ( msg , "Illegal ANNEAL TEMPS: %s", rest ) ; error_message ( msg ) ; } else anneal_params->temps0 = n ; return 1 ; } if (! strcmp ( command , "ANNEAL TEMPS" )) { m = sscanf ( rest , "%d" , &n ) ; if ((m <= 0) || (n <= 0)) { sprintf ( msg , "Illegal ANNEAL INIT TEMPS: %s", rest ) ; error_message ( msg ) ; } else anneal_params->temps = n ; return 1 ; } if (! strcmp ( command , "ANNEAL INIT ITERS" )) { m = sscanf ( rest , "%d" , &n ) ; if ((m <= 0) || (n <= 0)) { sprintf ( msg , "Illegal ANNEAL INIT ITERS: %s", rest ) ; error_message ( msg ) ; } else anneal_params->iters0 = n ; return 1 ; } if (! strcmp ( command , "ANNEAL ITERS" )) { m = sscanf ( rest , "%d" , &n ) ; if ((m <= 0) || (n <= 0)) { sprintf ( msg , "Illegal ANNEAL ITERS: %s", rest ) ; error_message ( msg ) ; } else anneal_params->iters = n ; return 1 ; } if (! strcmp ( command , "ANNEAL INIT SETBACK" )) { m = sscanf ( rest , "%d" , &n ) ; if ((m <= 0) || (n < 0)) { sprintf ( msg , "Illegal ANNEAL INIT SETBACK: %s", rest ) ; error_message ( msg ) ; } else anneal_params->setback0 = n ; return 1 ; } if (! strcmp ( command , "ANNEAL SETBACK" )) { m = sscanf ( rest , "%d" , &n ) ; if ((m <= 0) || (n < 0)) { sprintf ( msg , "Illegal ANNEAL SETBACK: %s", rest ) ; error_message ( msg ) ; } else anneal_params->setback = n ; return 1 ; } if (! strcmp ( command , "ANNEAL INIT START" )) { p = atof ( rest ) ; if (p <= 0.0) { sprintf ( msg , "Illegal ANNEAL INIT START: %s", rest ) ; error_message ( msg ) ; } else anneal_params->start0 = p ; return 1 ; } if (! strcmp ( command , "ANNEAL START" )) { p = atof ( rest ) ; if (p <= 0.0) { sprintf ( msg , "Illegal ANNEAL START: %s", rest ) ; error_message ( msg ) ; } else anneal_params->start = p ; return 1 ; } if (! strcmp ( command , "ANNEAL INIT STOP" )) { p = atof ( rest ) ; if (p <= 0.0) { sprintf ( msg , "Illegal ANNEAL INIT STOP: %s", rest ) ; error_message ( msg ) ; } else anneal_params->stop0 = p ; return 1 ; } if (! strcmp ( command , "ANNEAL STOP" )) { p = atof ( rest ) ; if (p <= 0.0) { sprintf ( msg , "Illegal ANNEAL STOP: %s", rest ) ; error_message ( msg ) ; } else anneal_params->stop = p ; return 1 ; } return 0 ;}//static int check_genetic ( char *command , char *rest , struct GenInitParams *geninit_params ){ int m, n ; double p ; char msg[80] ; if (! strcmp ( command , "GENETIC INIT POOL" )) { m = sscanf ( rest , "%d" , &n ) ; if ((m <= 0) || (n <= 0)) { sprintf ( msg , "Illegal GENETIC INIT POOL: %s", rest ) ; error_message ( msg ) ; } else geninit_params->pool = n ; return 1 ; } if (! strcmp ( command , "GENETIC INIT GENS" )) { m = sscanf ( rest , "%d" , &n ) ; if ((m <= 0) || (n <= 0)) { sprintf ( msg , "Illegal GENETIC INIT GENS: %s", rest ) ; error_message ( msg ) ; } else geninit_params->gens = n ; return 1 ; } if (! strcmp ( command , "GENETIC INIT CLIMB" )) { geninit_params->climb = 1 ; return 1 ; } if (! strcmp ( command , "GENETIC INIT NOCLIMB" )) { geninit_params->climb = 0 ; return 1 ; } if (! strcmp ( command , "GENETIC INIT CROSS" )) { p = atof ( rest ) ; if ((p < 0.0) || (p > 1.0)) { sprintf ( msg , "Illegal GENETIC INIT CROSS: %s", rest ) ; error_message ( msg ) ; } else geninit_params->pcross = p ; return 1 ; } if (! strcmp ( command , "GENETIC INIT MUTATE" )) { p = atof ( rest ) ; if ((p < 0.0) || (p > 1.0)) { sprintf ( msg , "Illegal GENETIC INIT MUTATE: %s", rest ) ; error_message ( msg ) ; } else geninit_params->pmutate = p ; return 1 ; } if (! strcmp ( command , "GENETIC INIT OVERINIT" )) { p = atof ( rest ) ; if (p < 1.0) { sprintf ( msg , "Illegal GENETIC INIT OVERINIT: %s", rest ) ; error_message ( msg ) ; } else geninit_params->overinit = p ; return 1 ; } return 0 ;}//static int check_kohonen ( char *command , char *rest , struct KohParams *koh_params , Network **net ){ int m, n ; double p ; char msg[80] ; if (! strcmp ( command , "KOHONEN NORMALIZATION MULTIPLICATIVE" )) { if (koh_params->normalization == 0) return 1 ; if (ok_to_clear_weights( net )) koh_params->normalization = 0 ; return 1 ; } if (! strcmp ( command , "KOHONEN NORMALIZATION Z" )) { if (koh_params->normalization == 1) return 1 ; if (ok_to_clear_weights( net )) koh_params->normalization = 1 ; return 1 ; } if (! strcmp ( command , "KOHONEN LEARN ADDITIVE" )) { koh_params->learn_method = 0 ; return 1 ; } if (! strcmp ( command , "KOHONEN LEARN SUBTRACTIVE" )) { koh_params->learn_method = 1 ; return 1 ; } if (! strcmp ( command , "KOHONEN LEARNING RATE" )) { p = atof ( rest ) ; if ((p < 0.0) || (p > 1.0)) { sprintf ( msg , "Illegal KOHONEN LEARNING RATE: %s", rest ) ; error_message ( msg ) ; } else koh_params->rate = p ; return 1 ; } if (! strcmp ( command , "KOHONEN LEARNING REDUCTION" )) { p = atof ( rest ) ; if ((p < 0.0) || (p > 1.0)) { sprintf ( msg , "Illegal KOHONEN LEARNING REDUCTION: %s", rest ) ; error_message ( msg ) ; } else koh_params->reduction = p ; return 1 ; } return 0 ;}//static int check_learn_params ( char *command , char *rest , struct LearnParams *learn_params , int netmod ){ int m, n ; double p ; char msg[80] ; if (! strcmp ( command , "QUIT ERROR" )) { p = atof ( rest ) / 100.0 ; // User expresses it as percent if ((p < 0.0) || (p > 1.0)) { sprintf ( msg , "Illegal QUIT ERROR: %s", rest ) ; error_message ( msg ) ; } else learn_params->quit_err = p ; return 1 ; } if (! strcmp ( command , "QUIT RETRIES" )) { m = sscanf ( rest , "%d" , &n ) ; if ((m <= 0) || (n < 0)) { sprintf ( msg , "Illegal QUIT RETRIES: %s", rest ) ; error_message ( msg ) ; } else learn_params->retries = n ; return 1 ; } if (! strcmp ( command , "LAYER INIT" )) { if (netmod != NETMOD_LAYER) { error_message ( "LAYER INIT makes no sense for this model." ) ; return 1 ; } if ((n = get_layer_init ( rest )) < 0) { error_message ( "Illegal LAYER INIT method." ) ; return 1 ; } learn_params->init = n ; return 1 ; } if (! strcmp ( command , "KOHONEN INIT" )) { if (netmod != NETMOD_KOH) { error_message ( "KOHONEN INIT makes no sense for this model." ) ; return 1 ; } if ((n = get_koh_init ( rest )) < 0) { error_message ( "Illegal KOHONEN INIT method." ) ; return 1 ; } learn_params->init = n ; return 1 ; } return 0 ;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -