#include #include model_data::model_data(void) { nyrs.allocate("nyrs"); Data.allocate(1,nyrs,1,87,"Data"); Year.allocate(1,nyrs); obs_bio_GB_HAD.allocate(1,nyrs); obs_bio_GB_YTL.allocate(1,nyrs); obs_bio_GB_WFL.allocate(1,nyrs); obs_bio_GB_LSK.allocate(1,nyrs); obs_bio_GB_COD.allocate(1,nyrs); obs_bio_GB_SFL.allocate(1,nyrs); obs_bio_GB_SHK.allocate(1,nyrs); obs_bio_GB_SPD.allocate(1,nyrs); obs_bio_GB_WSK.allocate(1,nyrs); obs_bio_GB_GOS.allocate(1,nyrs); obs_bio_GB_POL.allocate(1,nyrs); obs_bio_GB_WHK.allocate(1,nyrs); obs_bio_GB_HER.allocate(1,nyrs); obs_bio_GB_MCK.allocate(1,nyrs); obs_bio_GB_SQD.allocate(1,nyrs); obs_cat_GB_HAD.allocate(1,nyrs); obs_cat_GB_YTL.allocate(1,nyrs); obs_cat_GB_WFL.allocate(1,nyrs); obs_cat_GB_LSK.allocate(1,nyrs); obs_cat_GB_COD.allocate(1,nyrs); obs_cat_GB_SFL.allocate(1,nyrs); obs_cat_GB_SHK.allocate(1,nyrs); obs_cat_GB_SPD.allocate(1,nyrs); obs_cat_GB_WSK.allocate(1,nyrs); obs_cat_GB_GOS.allocate(1,nyrs); obs_cat_GB_POL.allocate(1,nyrs); obs_cat_GB_WHK.allocate(1,nyrs); obs_cat_GB_HER.allocate(1,nyrs); obs_cat_GB_MCK.allocate(1,nyrs); obs_cat_GB_SQD.allocate(1,nyrs); obs_bio_GOM_HAD.allocate(1,nyrs); obs_bio_GOM_YTL.allocate(1,nyrs); obs_bio_GOM_WFL.allocate(1,nyrs); obs_bio_GOM_LSK.allocate(1,nyrs); obs_bio_GOM_COD.allocate(1,nyrs); obs_bio_GOM_SFL.allocate(1,nyrs); obs_bio_GOM_SHK.allocate(1,nyrs); obs_bio_GOM_SPD.allocate(1,nyrs); obs_bio_GOM_WSK.allocate(1,nyrs); obs_bio_GOM_GOS.allocate(1,nyrs); obs_bio_GOM_POL.allocate(1,nyrs); obs_bio_GOM_WHK.allocate(1,nyrs); obs_bio_GOM_HER.allocate(1,nyrs); obs_bio_GOM_MCK.allocate(1,nyrs); obs_bio_GOM_SQD.allocate(1,nyrs); obs_cat_GOM_HAD.allocate(1,nyrs); obs_cat_GOM_YTL.allocate(1,nyrs); obs_cat_GOM_WFL.allocate(1,nyrs); obs_cat_GOM_LSK.allocate(1,nyrs); obs_cat_GOM_COD.allocate(1,nyrs); obs_cat_GOM_SFL.allocate(1,nyrs); obs_cat_GOM_SHK.allocate(1,nyrs); obs_cat_GOM_SPD.allocate(1,nyrs); obs_cat_GOM_WSK.allocate(1,nyrs); obs_cat_GOM_GOS.allocate(1,nyrs); obs_cat_GOM_POL.allocate(1,nyrs); obs_cat_GOM_WHK.allocate(1,nyrs); obs_cat_GOM_HER.allocate(1,nyrs); obs_cat_GOM_MCK.allocate(1,nyrs); obs_cat_GOM_SQD.allocate(1,nyrs); obs_bio_SNE_YTL.allocate(1,nyrs); obs_bio_SNE_WFL.allocate(1,nyrs); obs_bio_SNE_LSK.allocate(1,nyrs); obs_bio_SNE_SFL.allocate(1,nyrs); obs_bio_SNE_SHK.allocate(1,nyrs); obs_bio_SNE_SPD.allocate(1,nyrs); obs_bio_SNE_WSK.allocate(1,nyrs); obs_bio_SNE_GOS.allocate(1,nyrs); obs_bio_SNE_POL.allocate(1,nyrs); obs_bio_SNE_WHK.allocate(1,nyrs); obs_bio_SNE_HER.allocate(1,nyrs); obs_bio_SNE_MCK.allocate(1,nyrs); obs_bio_SNE_SQD.allocate(1,nyrs); obs_cat_SNE_YTL.allocate(1,nyrs); obs_cat_SNE_WFL.allocate(1,nyrs); obs_cat_SNE_LSK.allocate(1,nyrs); obs_cat_SNE_SFL.allocate(1,nyrs); obs_cat_SNE_SHK.allocate(1,nyrs); obs_cat_SNE_SPD.allocate(1,nyrs); obs_cat_SNE_WSK.allocate(1,nyrs); obs_cat_SNE_GOS.allocate(1,nyrs); obs_cat_SNE_POL.allocate(1,nyrs); obs_cat_SNE_WHK.allocate(1,nyrs); obs_cat_SNE_HER.allocate(1,nyrs); obs_cat_SNE_MCK.allocate(1,nyrs); obs_cat_SNE_SQD.allocate(1,nyrs); obs_bio_B_GB.allocate(1,nyrs); obs_cat_B_GB.allocate(1,nyrs); obs_bio_S_GB.allocate(1,nyrs); obs_cat_S_GB.allocate(1,nyrs); obs_bio_F_GB.allocate(1,nyrs); obs_cat_F_GB.allocate(1,nyrs); obs_bio_P_GB.allocate(1,nyrs); obs_cat_P_GB.allocate(1,nyrs); obs_bio_B_GOM.allocate(1,nyrs); obs_cat_B_GOM.allocate(1,nyrs); obs_bio_S_GOM.allocate(1,nyrs); obs_cat_S_GOM.allocate(1,nyrs); obs_bio_F_GOM.allocate(1,nyrs); obs_cat_F_GOM.allocate(1,nyrs); obs_bio_P_GOM.allocate(1,nyrs); obs_cat_P_GOM.allocate(1,nyrs); obs_bio_B_SNE.allocate(1,nyrs); obs_cat_B_SNE.allocate(1,nyrs); obs_bio_S_SNE.allocate(1,nyrs); obs_cat_S_SNE.allocate(1,nyrs); obs_bio_F_SNE.allocate(1,nyrs); obs_cat_F_SNE.allocate(1,nyrs); obs_bio_P_SNE.allocate(1,nyrs); obs_cat_P_SNE.allocate(1,nyrs); obs_bio_F_tot.allocate(1,nyrs); obs_cat_F_tot.allocate(1,nyrs); obs_bio_P_tot.allocate(1,nyrs); obs_cat_P_tot.allocate(1,nyrs); Year=column(Data,1); // Georges Bank //F = Migrating Piscivores = Silver hake, spiny dogfish, Winter skate, Goosefish, Pollock, White hake obs_bio_F_tot = column(Data,8) + column(Data,9) + column(Data,10) + column(Data,11) +column(Data,12) + column(Data,13) + column(Data,38) + column(Data,39) + column(Data,40)+ column(Data,41)+ column(Data,42)+ column(Data,43) + column(Data,66) + column(Data,67) + column(Data,68)+ column(Data,69)+ column(Data,70)+ column(Data,71); obs_cat_F_tot = column(Data,23) + column(Data,24) + column(Data,25) + column(Data,26) + column(Data,27) + column(Data,28) + column(Data,53) + column(Data,54) + column(Data,55)+ column(Data,56)+ column(Data,57)+ column(Data,58) + column(Data,79) + column(Data,80) + column(Data,81)+ column(Data,82)+ column(Data,83)+ column(Data,84); //P = Migrating Planktivores = Atlantic herring, Mackerel, Longfin squid obs_bio_P_tot = column(Data,14)+column(Data,15)+column(Data,16)+column(Data,44)+column(Data,45)+column(Data,46)+column(Data,72)+column(Data,73)+column(Data,74); obs_cat_P_tot = column(Data,59)+column(Data,60)+column(Data,61)+column(Data,29)+column(Data,30)+column(Data,31)+column(Data,85)+column(Data,86)+column(Data,87); obs_bio_P_GB = column(Data,14)+column(Data,15)+column(Data,16); obs_cat_P_GB = column(Data,29)+column(Data,30)+column(Data,31) ; obs_bio_P_GOM = column(Data,44)+column(Data,45)+column(Data,46); obs_cat_P_GOM = column(Data,59)+column(Data,60)+column(Data,61) ; obs_bio_P_SNE = column(Data,72)+column(Data,73)+column(Data,74); obs_cat_P_SNE = column(Data,85)+column(Data,86)+column(Data,87) ; obs_bio_F_GB = column(Data,8) + column(Data,9) + column(Data,10) + column(Data,11) +column(Data,12) + column(Data,13); obs_cat_F_GB = column(Data,23) + column(Data,24) + column(Data,25) + column(Data,26) + column(Data,27) + column(Data,28); obs_bio_F_GOM = column(Data,38) + column(Data,39) + column(Data,40)+ column(Data,41)+ column(Data,42)+ column(Data,43); obs_cat_F_GOM = column(Data,53) + column(Data,54) + column(Data,55)+ column(Data,56)+ column(Data,57)+ column(Data,58); obs_bio_F_SNE = column(Data,66) + column(Data,67) + column(Data,68)+ column(Data,69)+ column(Data,70)+ column(Data,71); obs_cat_F_SNE = column(Data,79) + column(Data,80) + column(Data,81)+ column(Data,82)+ column(Data,83)+ column(Data,84); obs_bio_B_GB = column(Data,2) + column(Data,3) + column(Data,4) + column(Data,5); obs_cat_B_GB = column(Data,17) + column(Data,18) + column(Data,19) + column(Data,20); obs_bio_B_GOM = column(Data,32) + column(Data,33) + column(Data,34) + column(Data,35); obs_cat_B_GOM = column(Data,47) + column(Data,48) + column(Data,49) + column(Data,50); obs_bio_B_SNE = column(Data,62) + column(Data,63) + column(Data,64); obs_cat_B_SNE = column(Data,75) + column(Data,76) + column(Data,77); //S =Non-migrating Piscivores = Atlantic cod, Summer flounder obs_bio_S_GB = column(Data,6) + column(Data,7); obs_cat_S_GB = column(Data,21)+ column(Data,22); obs_bio_S_GOM = column(Data,36) + column(Data,37); obs_cat_S_GOM = column(Data,51) + column(Data,52); obs_bio_S_SNE = column(Data,65); obs_cat_S_SNE = column(Data,78); k_pseudo_B_GB=max(obs_bio_B_GB)*3; k_pseudo_B_GOM=max(obs_bio_B_GOM)*2; k_pseudo_B_SNE=max(obs_bio_B_SNE)*2; k_pseudo_F_tot=max(obs_bio_F_tot)*1.5; k_pseudo_P_tot=max(obs_bio_P_tot)*1.5; } model_parameters::model_parameters(int sz,int argc,char * argv[]) : ad_comm(argc,argv), model_data() , function_minimizer(sz) { initializationfunction(); log_r_P_tot.allocate(-4.6,-0.11,"log_r_P_tot"); r_P_tot.allocate("r_P_tot"); #ifndef NO_AD_INITIALIZE r_P_tot.initialize(); #endif log_k_P_tot.allocate(1.0,10.0,"log_k_P_tot"); k_P_tot.allocate("k_P_tot"); #ifndef NO_AD_INITIALIZE k_P_tot.initialize(); #endif log_B0_P_tot.allocate(1.0,10.0,"log_B0_P_tot"); B0_P_tot.allocate("B0_P_tot"); #ifndef NO_AD_INITIALIZE B0_P_tot.initialize(); #endif log_r_F_tot.allocate(-4.6,-0.11,"log_r_F_tot"); r_F_tot.allocate("r_F_tot"); #ifndef NO_AD_INITIALIZE r_F_tot.initialize(); #endif log_k_F_tot.allocate(1.0,10.0,"log_k_F_tot"); k_F_tot.allocate("k_F_tot"); #ifndef NO_AD_INITIALIZE k_F_tot.initialize(); #endif log_B0_F_tot.allocate(1.0,10.0,"log_B0_F_tot"); B0_F_tot.allocate("B0_F_tot"); #ifndef NO_AD_INITIALIZE B0_F_tot.initialize(); #endif log_r_B_GB.allocate(-4.6,-0.11,"log_r_B_GB"); r_B_GB.allocate("r_B_GB"); #ifndef NO_AD_INITIALIZE r_B_GB.initialize(); #endif log_k_B_GB.allocate(1.0,10.0,"log_k_B_GB"); k_B_GB.allocate("k_B_GB"); #ifndef NO_AD_INITIALIZE k_B_GB.initialize(); #endif log_B0_B_GB.allocate(1.0,10.0,"log_B0_B_GB"); B0_B_GB.allocate("B0_B_GB"); #ifndef NO_AD_INITIALIZE B0_B_GB.initialize(); #endif log_r_B_GOM.allocate(-4.6,-0.11,"log_r_B_GOM"); r_B_GOM.allocate("r_B_GOM"); #ifndef NO_AD_INITIALIZE r_B_GOM.initialize(); #endif log_k_B_GOM.allocate(1.0,10.0,"log_k_B_GOM"); k_B_GOM.allocate("k_B_GOM"); #ifndef NO_AD_INITIALIZE k_B_GOM.initialize(); #endif log_B0_B_GOM.allocate(1.0,10.0,"log_B0_B_GOM"); B0_B_GOM.allocate("B0_B_GOM"); #ifndef NO_AD_INITIALIZE B0_B_GOM.initialize(); #endif log_r_B_SNE.allocate(-4.6,-0.11,"log_r_B_SNE"); r_B_SNE.allocate("r_B_SNE"); #ifndef NO_AD_INITIALIZE r_B_SNE.initialize(); #endif log_k_B_SNE.allocate(1.0,10.0,"log_k_B_SNE"); k_B_SNE.allocate("k_B_SNE"); #ifndef NO_AD_INITIALIZE k_B_SNE.initialize(); #endif log_B0_B_SNE.allocate(1.0,10.0,"log_B0_B_SNE"); B0_B_SNE.allocate("B0_B_SNE"); #ifndef NO_AD_INITIALIZE B0_B_SNE.initialize(); #endif log_r_S_GB.allocate(-4.6,-0.11,"log_r_S_GB"); r_S_GB.allocate("r_S_GB"); #ifndef NO_AD_INITIALIZE r_S_GB.initialize(); #endif k_S_GB.allocate(-1,"k_S_GB"); log_B0_S_GB.allocate("log_B0_S_GB"); B0_S_GB.allocate("B0_S_GB"); #ifndef NO_AD_INITIALIZE B0_S_GB.initialize(); #endif log_r_S_GOM.allocate(-4.6,-0.11,"log_r_S_GOM"); r_S_GOM.allocate("r_S_GOM"); #ifndef NO_AD_INITIALIZE r_S_GOM.initialize(); #endif k_S_GOM.allocate(-1,"k_S_GOM"); log_B0_S_GOM.allocate("log_B0_S_GOM"); B0_S_GOM.allocate("B0_S_GOM"); #ifndef NO_AD_INITIALIZE B0_S_GOM.initialize(); #endif log_r_S_SNE.allocate(-4.6,-0.11,"log_r_S_SNE"); r_S_SNE.allocate("r_S_SNE"); #ifndef NO_AD_INITIALIZE r_S_SNE.initialize(); #endif k_S_SNE.allocate(-1,"k_S_SNE"); log_B0_S_SNE.allocate("log_B0_S_SNE"); B0_S_SNE.allocate("B0_S_SNE"); #ifndef NO_AD_INITIALIZE B0_S_SNE.initialize(); #endif log_n_PB_GB.allocate(-16.0,-2.3,2,"log_n_PB_GB"); n_PB_GB.allocate("n_PB_GB"); #ifndef NO_AD_INITIALIZE n_PB_GB.initialize(); #endif log_n_BP_SNE.allocate(-16.0,-2.3,2,"log_n_BP_SNE"); n_BP_SNE.allocate("n_BP_SNE"); #ifndef NO_AD_INITIALIZE n_BP_SNE.initialize(); #endif log_c_fb_GB.allocate(-16.0,-2.3,3,"log_c_fb_GB"); c_fb_GB.allocate("c_fb_GB"); #ifndef NO_AD_INITIALIZE c_fb_GB.initialize(); #endif log_d_fb_GB.allocate(-16.0,-2.3,3,"log_d_fb_GB"); d_fb_GB.allocate("d_fb_GB"); #ifndef NO_AD_INITIALIZE d_fb_GB.initialize(); #endif log_alpha_fb_GB.allocate(-16.0,-2.3,3,"log_alpha_fb_GB"); alpha_fb_GB.allocate("alpha_fb_GB"); #ifndef NO_AD_INITIALIZE alpha_fb_GB.initialize(); #endif log_alpha_fp_GB.allocate(-16.0,-2.3,3,"log_alpha_fp_GB"); alpha_fp_GB.allocate("alpha_fp_GB"); #ifndef NO_AD_INITIALIZE alpha_fp_GB.initialize(); #endif log_c_fb_GOM.allocate(-16.0,-2.3,3,"log_c_fb_GOM"); c_fb_GOM.allocate("c_fb_GOM"); #ifndef NO_AD_INITIALIZE c_fb_GOM.initialize(); #endif log_alpha_fb_GOM.allocate(-16.0,-2.3,3,"log_alpha_fb_GOM"); alpha_fb_GOM.allocate("alpha_fb_GOM"); #ifndef NO_AD_INITIALIZE alpha_fb_GOM.initialize(); #endif log_alpha_fp_GOM.allocate(-16.0,-2.3,3,"log_alpha_fp_GOM"); alpha_fp_GOM.allocate("alpha_fp_GOM"); #ifndef NO_AD_INITIALIZE alpha_fp_GOM.initialize(); #endif pred_bio_P_tot.allocate(1,nyrs,"pred_bio_P_tot"); #ifndef NO_AD_INITIALIZE pred_bio_P_tot.initialize(); #endif pred_bio_F_tot.allocate(1,nyrs,"pred_bio_F_tot"); #ifndef NO_AD_INITIALIZE pred_bio_F_tot.initialize(); #endif prop_GB_P.allocate(1,nyrs,"prop_GB_P"); #ifndef NO_AD_INITIALIZE prop_GB_P.initialize(); #endif prop_GOM_P.allocate(1,nyrs,"prop_GOM_P"); #ifndef NO_AD_INITIALIZE prop_GOM_P.initialize(); #endif prop_SNE_P.allocate(1,nyrs,"prop_SNE_P"); #ifndef NO_AD_INITIALIZE prop_SNE_P.initialize(); #endif pred_bio_P_GB.allocate(1,nyrs,"pred_bio_P_GB"); #ifndef NO_AD_INITIALIZE pred_bio_P_GB.initialize(); #endif pred_bio_P_GOM.allocate(1,nyrs,"pred_bio_P_GOM"); #ifndef NO_AD_INITIALIZE pred_bio_P_GOM.initialize(); #endif pred_bio_P_SNE.allocate(1,nyrs,"pred_bio_P_SNE"); #ifndef NO_AD_INITIALIZE pred_bio_P_SNE.initialize(); #endif prop_GB_F.allocate(1,nyrs,"prop_GB_F"); #ifndef NO_AD_INITIALIZE prop_GB_F.initialize(); #endif prop_GOM_F.allocate(1,nyrs,"prop_GOM_F"); #ifndef NO_AD_INITIALIZE prop_GOM_F.initialize(); #endif prop_SNE_F.allocate(1,nyrs,"prop_SNE_F"); #ifndef NO_AD_INITIALIZE prop_SNE_F.initialize(); #endif pred_bio_F_GB.allocate(1,nyrs,"pred_bio_F_GB"); #ifndef NO_AD_INITIALIZE pred_bio_F_GB.initialize(); #endif pred_bio_F_GOM.allocate(1,nyrs,"pred_bio_F_GOM"); #ifndef NO_AD_INITIALIZE pred_bio_F_GOM.initialize(); #endif pred_bio_F_SNE.allocate(1,nyrs,"pred_bio_F_SNE"); #ifndef NO_AD_INITIALIZE pred_bio_F_SNE.initialize(); #endif pred_bio_B_GB.allocate(1,nyrs,"pred_bio_B_GB"); #ifndef NO_AD_INITIALIZE pred_bio_B_GB.initialize(); #endif pred_bio_B_GOM.allocate(1,nyrs,"pred_bio_B_GOM"); #ifndef NO_AD_INITIALIZE pred_bio_B_GOM.initialize(); #endif pred_bio_B_SNE.allocate(1,nyrs,"pred_bio_B_SNE"); #ifndef NO_AD_INITIALIZE pred_bio_B_SNE.initialize(); #endif pred_bio_B_tot.allocate(1,nyrs,"pred_bio_B_tot"); #ifndef NO_AD_INITIALIZE pred_bio_B_tot.initialize(); #endif pred_bio_S_SNE.allocate(1,nyrs,"pred_bio_S_SNE"); #ifndef NO_AD_INITIALIZE pred_bio_S_SNE.initialize(); #endif pred_bio_S_GOM.allocate(1,nyrs,"pred_bio_S_GOM"); #ifndef NO_AD_INITIALIZE pred_bio_S_GOM.initialize(); #endif pred_bio_S_GB.allocate(1,nyrs,"pred_bio_S_GB"); #ifndef NO_AD_INITIALIZE pred_bio_S_GB.initialize(); #endif fpenP_tot.allocate("fpenP_tot"); #ifndef NO_AD_INITIALIZE fpenP_tot.initialize(); #endif fpenF_tot.allocate("fpenF_tot"); #ifndef NO_AD_INITIALIZE fpenF_tot.initialize(); #endif fpenB_GB.allocate("fpenB_GB"); #ifndef NO_AD_INITIALIZE fpenB_GB.initialize(); #endif fpenB_GOM.allocate("fpenB_GOM"); #ifndef NO_AD_INITIALIZE fpenB_GOM.initialize(); #endif fpenB_SNE.allocate("fpenB_SNE"); #ifndef NO_AD_INITIALIZE fpenB_SNE.initialize(); #endif fpenS_SNE.allocate("fpenS_SNE"); #ifndef NO_AD_INITIALIZE fpenS_SNE.initialize(); #endif fpenS_GOM.allocate("fpenS_GOM"); #ifndef NO_AD_INITIALIZE fpenS_GOM.initialize(); #endif fpenS_GB.allocate("fpenS_GB"); #ifndef NO_AD_INITIALIZE fpenS_GB.initialize(); #endif p.allocate("p"); #ifndef NO_AD_INITIALIZE p.initialize(); #endif y.allocate("y"); #ifndef NO_AD_INITIALIZE y.initialize(); #endif AIC.allocate("AIC"); #ifndef NO_AD_INITIALIZE AIC.initialize(); #endif p = 30; //number of parameters y = nyrs*8; //number of guilds: 4 sd_r_P_tot.allocate("sd_r_P_tot"); sd_k_P_tot.allocate("sd_k_P_tot"); sd_B0_P_tot.allocate("sd_B0_P_tot"); sd_r_F_tot.allocate("sd_r_F_tot"); sd_k_F_tot.allocate("sd_k_F_tot"); sd_B0_F_tot.allocate("sd_B0_F_tot"); sd_r_B_GB.allocate("sd_r_B_GB"); sd_k_B_GB.allocate("sd_k_B_GB"); sd_B0_B_GB.allocate("sd_B0_B_GB"); sd_r_B_GOM.allocate("sd_r_B_GOM"); sd_k_B_GOM.allocate("sd_k_B_GOM"); sd_B0_B_GOM.allocate("sd_B0_B_GOM"); sd_r_B_SNE.allocate("sd_r_B_SNE"); sd_k_B_SNE.allocate("sd_k_B_SNE"); sd_B0_B_SNE.allocate("sd_B0_B_SNE"); sd_r_S_GB.allocate("sd_r_S_GB"); sd_B0_S_GB.allocate("sd_B0_S_GB"); sd_r_S_GOM.allocate("sd_r_S_GOM"); sd_B0_S_GOM.allocate("sd_B0_S_GOM"); sd_r_S_SNE.allocate("sd_r_S_SNE"); sd_B0_S_SNE.allocate("sd_B0_S_SNE"); sd_n_PB_GB.allocate("sd_n_PB_GB"); sd_n_BP_SNE.allocate("sd_n_BP_SNE"); sd_c_fb_GB.allocate("sd_c_fb_GB"); sd_d_fb_GB.allocate("sd_d_fb_GB"); sd_alpha_fb_GB.allocate("sd_alpha_fb_GB"); sd_alpha_fp_GB.allocate("sd_alpha_fp_GB"); sd_c_fb_GOM.allocate("sd_c_fb_GOM"); sd_alpha_fb_GOM.allocate("sd_alpha_fb_GOM"); sd_alpha_fp_GOM.allocate("sd_alpha_fp_GOM"); f.allocate("f"); } void model_parameters::initializationfunction(void) { log_r_P_tot.set_initial_value(-1.33); log_k_P_tot.set_initial_value(8.44); log_B0_P_tot.set_initial_value(6.88); log_r_F_tot.set_initial_value(-1.98); log_k_F_tot.set_initial_value(8.29); log_B0_F_tot.set_initial_value(7.6); log_r_B_GB.set_initial_value(-1.34); log_k_B_GB.set_initial_value(6.05); log_B0_B_GB.set_initial_value(5.3); log_r_B_GOM.set_initial_value(-0.95); log_k_B_GOM.set_initial_value(4.39); log_B0_B_GOM.set_initial_value(3.95); log_r_B_SNE.set_initial_value(-0.62); log_k_B_SNE.set_initial_value(5.4); log_B0_B_SNE.set_initial_value(4.84); log_r_S_GB.set_initial_value(-0.49); log_B0_S_GB.set_initial_value(4.87); k_S_GB.set_initial_value(300); log_r_S_GOM.set_initial_value(-0.246); log_B0_S_GOM.set_initial_value(3.42); k_S_GOM.set_initial_value(80); log_r_S_SNE.set_initial_value(-0.22); log_B0_S_SNE.set_initial_value(4.1); k_S_SNE.set_initial_value(100); log_n_PB_GB.set_initial_value(-6.2); log_n_BP_SNE.set_initial_value(-7.9); log_c_fb_GB.set_initial_value(-4.7); log_d_fb_GB.set_initial_value(-4.8); log_alpha_fb_GB.set_initial_value(-4.4); log_alpha_fp_GB.set_initial_value(-2.4); log_c_fb_GOM.set_initial_value(-4.8); log_alpha_fb_GOM.set_initial_value(-3.9); log_alpha_fp_GOM.set_initial_value(-3.1); } void model_parameters::preliminary_calculations(void) { prop_GB_P = elem_div(obs_bio_P_GB,obs_bio_P_tot); prop_GOM_P = elem_div(obs_bio_P_GOM,obs_bio_P_tot); prop_SNE_P = elem_div(obs_bio_P_SNE,obs_bio_P_tot); prop_GB_F = elem_div(obs_bio_F_GB,obs_bio_F_tot); prop_GOM_F = elem_div(obs_bio_F_GOM,obs_bio_F_tot); prop_SNE_F = elem_div(obs_bio_F_SNE,obs_bio_F_tot); } void model_parameters::userfunction(void) { r_P_tot = mfexp(log_r_P_tot); k_P_tot = mfexp(log_k_P_tot); B0_P_tot = mfexp(log_B0_P_tot); r_F_tot = mfexp(log_r_F_tot); k_F_tot = mfexp(log_k_F_tot); B0_F_tot = mfexp(log_B0_F_tot); r_B_GB = mfexp(log_r_B_GB); k_B_GB = mfexp(log_k_B_GB); B0_B_GB = mfexp(log_B0_B_GB); r_B_GOM = mfexp(log_r_B_GOM); k_B_GOM = mfexp(log_k_B_GOM); B0_B_GOM = mfexp(log_B0_B_GOM); r_B_SNE = mfexp(log_r_B_SNE); k_B_SNE = mfexp(log_k_B_SNE); B0_B_SNE = mfexp(log_B0_B_SNE); r_S_GB = mfexp(log_r_S_GB); B0_S_GB = mfexp(log_B0_S_GB); r_S_GOM = mfexp(log_r_S_GOM); B0_S_GOM = mfexp(log_B0_S_GOM); r_S_SNE = mfexp(log_r_S_SNE); B0_S_SNE = mfexp(log_B0_S_SNE); n_PB_GB = mfexp(log_n_PB_GB); n_BP_SNE = mfexp(log_n_BP_SNE); // Type 3 functional response for interaction between B and F in Georges Bank c_fb_GB = mfexp(log_c_fb_GB); d_fb_GB = mfexp(log_d_fb_GB); alpha_fb_GB = mfexp(log_alpha_fb_GB); alpha_fp_GB = mfexp(log_alpha_fp_GB); // Type 3 functional response for interaction between B and F in Gulf of Maine c_fb_GOM = mfexp(log_c_fb_GOM); //d_fb_GOM = mfexp(log_d_fb_GOM); alpha_fb_GOM = mfexp(log_alpha_fb_GOM); alpha_fp_GOM = mfexp(log_alpha_fp_GOM); //cout statements useful for viewing parameters cout << "r_P_tot " << '\t' << r_P_tot << endl; cout << "k_P_tot " << '\t' << k_P_tot << endl; cout << "B0_P_tot" << '\t' << B0_P_tot << endl; cout << "r_F_tot " << '\t' << r_F_tot << endl; cout << "k_F_tot " << '\t' << k_F_tot << endl; cout << "B0_F_tot" << '\t' << B0_F_tot << endl; cout << "r_B_GB " << '\t' << r_B_GB << endl; cout << "k_B_GB " << '\t' << k_B_GB << endl; cout << "B0_B_GB " << '\t' << B0_B_GB << endl; cout << "r_B_GOM " << '\t' << r_B_GOM << endl; cout << "k_B_GOM " << '\t' << k_B_GOM << endl; cout << "B0_B_GOM " << '\t' << B0_B_GOM << endl; cout << "r_B_SNE " << '\t' << r_B_SNE << endl; cout << "k_B_SNE " << '\t' << k_B_SNE << endl; cout << "B0_B_SNE " << '\t' << B0_B_SNE << endl; cout << "r_S_GB " << '\t' << r_S_GB << endl; cout << "k_S_GB " << '\t' << k_S_GB << endl; cout << "B0_S_GB " << '\t' << B0_S_GB << endl; cout << "r_S_GOM " << '\t' << r_S_GOM << endl; cout << "k_S_GOM " << '\t' << k_S_GOM << endl; cout << "B0_S_GOM " << '\t' << B0_S_GOM << endl; cout << "r_S_SNE " << '\t' << r_S_SNE << endl; cout << "k_S_SNE " << '\t' << k_S_SNE << endl; cout << "B0_S_SNE " << '\t' << B0_S_SNE << endl; cout << "n_PB_GB " << '\t' << n_PB_GB << endl; cout << "n_BP_SNE " << '\t' << n_BP_SNE << endl; // Type 3 functional response for interaction between B and F in Georges Bank cout << "c_fb_GB " << '\t' << c_fb_GB << endl; cout << "d_fb_GB " << '\t' << d_fb_GB << endl; cout << "alpha_fb_GB" << '\t' << alpha_fb_GB << endl; cout << "alpha_fp_GB" << '\t' << alpha_fp_GB << endl; // Type 3 functional response for interaction between B and F in Gulf of Maine cout << "c_fb_GOM " << '\t' << c_fb_GOM << endl; //cout << "d_fb_GOM " << '\t' << d_fb_GOM << endl; cout << "alpha_fb_GOM" << '\t' << alpha_fb_GOM << endl; cout << "alpha_fp_GOM" << '\t' << alpha_fp_GOM << endl; //reset fpens to 0.0 fpenP_tot = 0.0; fpenF_tot = 0.0; fpenB_GB = 0.0; fpenB_GOM = 0.0; fpenB_SNE = 0.0; fpenS_SNE = 0.0; fpenS_GOM = 0.0; fpenS_GB = 0.0; //define sdreport numbers sd_r_P_tot= r_P_tot; sd_k_P_tot = k_P_tot; sd_B0_P_tot = B0_P_tot; sd_r_F_tot = r_F_tot; sd_k_F_tot = k_F_tot; sd_B0_F_tot = B0_F_tot; sd_r_B_GB = r_B_GB; sd_k_B_GB = k_B_GB; sd_B0_B_GB = B0_B_GB; sd_r_B_GOM = r_B_GOM; sd_k_B_GOM = k_B_GOM; sd_B0_B_GOM = B0_B_GOM; sd_r_B_SNE = r_B_SNE; sd_k_B_SNE = k_B_SNE; sd_B0_B_SNE = B0_B_SNE; sd_r_S_GB = r_S_GB; sd_B0_S_GB = B0_S_GB; sd_r_S_GOM = r_S_GOM; sd_B0_S_GOM = B0_S_GOM; sd_r_S_SNE = r_S_SNE; sd_B0_S_SNE = B0_S_SNE; sd_n_PB_GB = n_PB_GB; sd_n_BP_SNE = n_BP_SNE; // Type 3 functional response for interaction between B and F in Georges Bank sd_c_fb_GB = c_fb_GB; sd_d_fb_GB = d_fb_GB; sd_alpha_fb_GB = alpha_fb_GB; sd_alpha_fp_GB = alpha_fp_GB; // Type 3 functional response for interaction between B and F in Gilf of Maine sd_c_fb_GOM = c_fb_GOM; //sd_d_fb_GOM = d_fb_GOM; sd_alpha_fb_GOM = alpha_fb_GOM; sd_alpha_fp_GOM = alpha_fp_GOM; //initial biomass pred_bio_P_tot(1) = B0_P_tot; pred_bio_F_tot(1) = B0_F_tot; pred_bio_B_GB(1) = B0_B_GB; pred_bio_B_GOM(1) = B0_B_GOM; pred_bio_B_SNE(1) = B0_B_SNE; pred_bio_S_SNE(1) = B0_S_SNE; pred_bio_S_GOM(1) = B0_S_GOM; pred_bio_S_GB(1) = B0_S_GB; pred_bio_P_GB(1) = prop_GB_P(1)*pred_bio_P_tot(1); pred_bio_P_GOM(1) = prop_GOM_P(1)*pred_bio_P_tot(1); pred_bio_P_SNE(1) = prop_SNE_P(1)*pred_bio_P_tot(1); pred_bio_F_GB(1) = prop_GB_F(1)*pred_bio_F_tot(1); pred_bio_F_GOM(1) = prop_GOM_F(1)*pred_bio_F_tot(1); pred_bio_F_SNE(1) = prop_SNE_F(1)*pred_bio_F_tot(1); pred_bio_B_tot(1)=pred_bio_B_GB(1)+pred_bio_B_GOM(1)+pred_bio_B_SNE(1); //loop through all years to calculate predicted biomass for (i = 1; i<= nyrs-1; i++) { pred_bio_P_tot(i+1)=posfun(pred_bio_P_tot(i)+r_P_tot*pred_bio_P_tot(i)*(1-pred_bio_P_tot(i)/k_P_tot)-obs_cat_P_tot(i) -n_PB_GB*(prop_GB_P(i)*pred_bio_P_tot(i))*pred_bio_B_GB(i) ,0.01,fpenP_tot); pred_bio_F_tot(i+1)=posfun(pred_bio_F_tot(i)+r_F_tot*pred_bio_F_tot(i)*(1-pred_bio_F_tot(i)/k_F_tot)-obs_cat_F_tot(i) + (d_fb_GB*(prop_GB_F(i)*pred_bio_F_tot(i))*(pred_bio_B_GB(i)*pred_bio_B_GB(i)))/ (1+alpha_fb_GB*(pred_bio_B_GB(i)*pred_bio_B_GB(i))+alpha_fp_GB*((prop_GB_P(i)*pred_bio_P_tot(i))*(prop_GB_P(i)*pred_bio_P_tot(i)))) //+ (d_fb_GOM*(prop_GOM_F(i)*pred_bio_F_tot(i))*(pred_bio_B_GOM(i)*pred_bio_B_GOM(i)))/ //(1+alpha_fb_GOM*(pred_bio_B_GOM(i)*pred_bio_B_GOM(i)) + alpha_fp_GOM*( (prop_GOM_P(i)*pred_bio_P_tot(i))*(prop_GOM_P(i)*pred_bio_P_tot(i)))) ,0.01,fpenF_tot); pred_bio_B_GB(i+1)=posfun(pred_bio_B_GB(i)+r_B_GB*pred_bio_B_GB(i)*(1-pred_bio_B_GB(i)/k_B_GB)-obs_cat_B_GB(i) - (c_fb_GB*(prop_GB_F(i)*pred_bio_F_tot(i))*(pred_bio_B_GB(i)*pred_bio_B_GB(i)))/ (1+alpha_fb_GB*(pred_bio_B_GB(i)*pred_bio_B_GB(i))+alpha_fp_GB*((prop_GB_P(i)*pred_bio_P_tot(i))*(prop_GB_P(i)*pred_bio_P_tot(i)))) ,0.01,fpenB_GB); pred_bio_B_GOM(i+1)=posfun(pred_bio_B_GOM(i)+r_B_GOM*pred_bio_B_GOM(i)*(1-pred_bio_B_GOM(i)/k_B_GOM)-obs_cat_B_GOM(i) - (c_fb_GOM*(prop_GOM_F(i)*pred_bio_F_tot(i))*(pred_bio_B_GOM(i)*pred_bio_B_GOM(i)))/ (1+alpha_fb_GOM*(pred_bio_B_GOM(i)*pred_bio_B_GOM(i)) + alpha_fp_GOM*( (prop_GOM_P(i)*pred_bio_P_tot(i))*(prop_GOM_P(i)*pred_bio_P_tot(i)))) ,0.01,fpenB_GOM); pred_bio_B_SNE(i+1)=posfun(pred_bio_B_SNE(i)+r_B_SNE*pred_bio_B_SNE(i)*(1-pred_bio_B_SNE(i)/k_B_SNE)-obs_cat_B_SNE(i) -n_BP_SNE*pred_bio_B_SNE(i)*(prop_SNE_P(i)*pred_bio_P_tot(i)) ,0.01,fpenB_SNE); pred_bio_S_GOM(i+1)=posfun(pred_bio_S_GOM(i)+r_S_GOM*pred_bio_S_GOM(i)*(1-pred_bio_S_GOM(i)/k_S_GOM)-obs_cat_S_GOM(i) ,0.01,fpenS_GOM); pred_bio_S_SNE(i+1)=posfun(pred_bio_S_SNE(i)+r_S_SNE*pred_bio_S_SNE(i)*(1-pred_bio_S_SNE(i)/k_S_SNE)-obs_cat_S_SNE(i) ,0.01,fpenS_SNE); pred_bio_S_GB(i+1)=posfun(pred_bio_S_GB(i)+r_S_GB*pred_bio_S_GB(i)*(1-pred_bio_S_GB(i)/k_S_GB)-obs_cat_S_GB(i) ,0.01,fpenS_GB); } //tell us about fpens if(fpenP_tot>0) cout << "FPEN P_tot="<< endl << fpenP_tot << endl; if(fpenF_tot>0) cout << "FPEN F_tot="<< endl << fpenF_tot << endl; if(fpenB_GB>0) cout << "FPEN B_GB= "<< endl << fpenB_GB << endl; if(fpenB_GOM>0) cout << "FPEN B_GOM="<< endl << fpenB_GOM << endl; if(fpenB_SNE>0) cout << "FPEN B_SNE="<< endl << fpenB_SNE << endl; if(fpenS_GOM>0) cout << "FPEN S_GOM="<< endl << fpenS_GOM << endl; if(fpenS_SNE>0) cout << "FPEN S_SNE="<< endl << fpenS_SNE << endl; if(fpenS_GB>0) cout << "FPEN S_GB= "<< endl << fpenS_GB << endl; //the objective function for total biomass of migrating Planktivores and Piscivores dvar_vector resid_P_tot = (log(pred_bio_P_tot(1,nyrs)+1.e-3) - log(obs_bio_P_tot(1,nyrs)+1.e-3)); dvariable ssq_P_tot = norm2(resid_P_tot) + square(log(k_pseudo_P_tot) - log(k_P_tot)); dvar_vector resid_F_tot = (log(pred_bio_F_tot(1,nyrs)+1.e-3) - log(obs_bio_F_tot(1,nyrs)+1.e-3)); dvariable ssq_F_tot = norm2(resid_F_tot) + square(log(k_pseudo_F_tot) - log(k_F_tot)); // additional objective function of Benthivores (GB, GoM, SNE) dvar_vector resid_B_GB = (log(pred_bio_B_GB(1,nyrs)+1.e-3) - log(obs_bio_B_GB(1,nyrs)+1.e-3)); dvariable ssq_B_GB = norm2(resid_B_GB) + square(log(k_pseudo_B_GB) - log(k_B_GB)); dvar_vector resid_B_GOM = (log(pred_bio_B_GOM(1,nyrs)+1.e-3) - log(obs_bio_B_GOM(1,nyrs)+1.e-3)); dvariable ssq_B_GOM = norm2(resid_B_GOM) + square(log(k_pseudo_B_GOM) - log(k_B_GOM)); dvar_vector resid_B_SNE = (log(pred_bio_B_SNE(1,nyrs)+1.e-3) - log(obs_bio_B_SNE(1,nyrs)+1.e-3)); dvariable ssq_B_SNE = norm2(resid_B_SNE) + square(log(k_pseudo_B_SNE) - log(k_B_SNE)); dvar_vector resid_S_GOM = (log(pred_bio_S_GOM(1,nyrs)+1.e-3) - log(obs_bio_S_GOM(1,nyrs)+1.e-3)); dvariable ssq_S_GOM = norm2(resid_S_GOM); dvar_vector resid_S_SNE = (log(pred_bio_S_SNE(1,nyrs)+1.e-3) - log(obs_bio_S_SNE(1,nyrs)+1.e-3)); dvariable ssq_S_SNE = norm2(resid_S_SNE); dvar_vector resid_S_GB = (log(pred_bio_S_GB(1,nyrs)+1.e-3) - log(obs_bio_S_GB(1,nyrs)+1.e-3)); dvariable ssq_S_GB = norm2(resid_S_GB) ; f = ssq_P_tot + ssq_F_tot + ssq_B_GB + ssq_B_GOM + ssq_B_SNE + ssq_S_GOM +ssq_S_SNE + ssq_S_GB; cout << "obj func value - SSR" << '\t' << f << endl; cout << "ssqP_tot " << "\t" << ssq_P_tot << endl; cout << "ssqF_tot " << "\t" << ssq_F_tot << endl; cout << "ssqB_GB " << "\t" << ssq_B_GB << endl; cout << "ssqB_GOM " << "\t" << ssq_B_GOM << endl; cout << "ssqB_SNE " << "\t" << ssq_B_SNE << endl; cout << "ssqS_GB " << "\t" << ssq_S_GB << endl; cout << "ssqS_GOM " << "\t" << ssq_S_GOM << endl; cout << "ssqS_SNE " << "\t" << ssq_S_SNE << endl; cout << endl; //calculate Nll and AIC dvariable nll = 0.5*y*log(f); dvariable AIC = 2*nll + 2*p*(y/(y-p-1)); cout << "Negative Ln Likelihood (-Ln(L))" << "\t" << nll << endl; cout << "AIC" << "\t" << AIC << endl << endl; } void model_parameters::set_runtime(void) { dvector temp1("{40000;}"); maximum_function_evaluations.allocate(temp1.indexmin(),temp1.indexmax()); maximum_function_evaluations=temp1; } void model_parameters::report() { adstring ad_tmp=initial_params::get_reportfile_name(); ofstream report((char*)(adprogram_name + ad_tmp)); if (!report) { cerr << "error trying to open report file" << adprogram_name << ".rep"; return; } report<<"observed biomass_P_tot" << obs_bio_P_tot << endl; report<<"predicted biomass_P_tot" << pred_bio_P_tot << endl; report<<"obs_catch_P_tot" << obs_cat_P_tot << endl; report<<""<