2# pragma clang diagnostic push
3# pragma clang diagnostic ignored "-Wunknown-warning-option"
7# pragma clang diagnostic pop
15# pragma GCC diagnostic ignored "-Warray-bounds"
44struct LOM_t : vector<matrix<Type> > {
46 (*this).resize(LENGTH(x));
47 for(
int i = 0; i < LENGTH(x); i++){
48 SEXP m = VECTOR_ELT(x, i);
49 (*this)(i) = asMatrix<Type>(m);
90Type objective_function<Type>::operator() () {
91 using namespace density;
97 DATA_INTEGER(estimateMode);
98 DATA_INTEGER(msmMode);
104 DATA_IVECTOR(suitMode);
107 DATA_INTEGER(initMode);
108 DATA_IVECTOR(forecast);
112 DATA_INTEGER( styr );
113 DATA_INTEGER( endyr );
114 DATA_INTEGER( projyr );
116 DATA_INTEGER( srr_mse_switchyr );
117 DATA_IVECTOR( suit_styr );
118 DATA_IVECTOR( suit_endyr );
119 DATA_INTEGER( srr_hat_styr );
120 DATA_INTEGER( srr_hat_endyr );
122 int nyrs = projyr - styr + 1;
123 int nyrs_hind = endyr - styr + 1;
127 int nyrs_srrmean = srr_mse_switchyr - styr + 1;
129 srr_hat_styr = srr_hat_styr - styr;
130 srr_hat_endyr = srr_hat_endyr - styr;
131 if(nyrs_srrmean > nyrs_hind){nyrs_srrmean = nyrs_hind;}
132 if(srr_hat_styr == 0){srr_hat_styr = 1;}
135 DATA_INTEGER( nspp );
139 vector<int> nyrs_suit(nspp);
140 for(
int sp = 0; sp < nspp; sp++){
141 suit_endyr(sp) = suit_endyr(sp) - styr;
142 suit_styr(sp) = suit_styr(sp) - styr;
143 nyrs_suit(sp) = suit_endyr(sp) - suit_styr(sp) + 1;
146 DATA_IVECTOR( pop_wt_index );
147 DATA_IVECTOR( ssb_wt_index );
148 DATA_IVECTOR( pop_age_transition_index );
149 DATA_IVECTOR( estDynamics );
152 pop_age_transition_index -= 1;
156 DATA_INTEGER(srr_fun);
157 DATA_INTEGER(srr_pred_fun);
158 DATA_INTEGER(proj_mean_rec);
161 DATA_INTEGER(srr_est_mode);
162 DATA_VECTOR(srr_prior);
163 DATA_VECTOR(srr_prior_sd);
164 DATA_INTEGER( niter );
165 DATA_VECTOR( Bmsy_lim );
170 DATA_INTEGER(DynamicHCR);
171 DATA_VECTOR(Ptarget);
173 DATA_VECTOR(Ftarget_percent);
174 DATA_VECTOR(Flimit_percent);
177 DATA_VECTOR(QnormHCR);
183 int sp, sex, age, ln, yr;
185 int flt_yr, flt_sex, comp_type;
186 int fsh_ind, index_ind, comp_ind, yr_ind;
187 int wt_idx_pop, wt_idx_ssb, wt_idx_flt;
189 if(msmMode == 0) { niter = 1; }
197 DATA_IVECTOR( nsex );
198 int max_sex =
imax(nsex);
199 DATA_VECTOR( spawn_month );
200 DATA_IVECTOR( nages );
201 DATA_IVECTOR( minage );
202 DATA_IVECTOR( nlengths );
203 DATA_MATRIX(lengths);
204 DATA_IVECTOR( nlengths_pop );
205 DATA_MATRIX( lengths_pop );
206 DATA_IMATRIX( pop_to_data_bin );
207 DATA_ARRAY( NByageFixed );
208 DATA_VECTOR( MSSB0 );
211 int max_nlengths =
imax(nlengths);
214 int max_nlengths_pop =
imax(nlengths_pop);
221 matrix<int> pop_bin_lo(nspp, max_nlengths); pop_bin_lo.setZero();
222 matrix<int> pop_bin_hi(nspp, max_nlengths); pop_bin_hi.setZero();
223 for(
int sp_i = 0; sp_i < nspp; sp_i++){
224 for(
int d = 0; d < nlengths(sp_i); d++){ pop_bin_lo(sp_i, d) = -1; pop_bin_hi(sp_i, d) = -2; }
225 for(
int lp = 0; lp < nlengths_pop(sp_i); lp++){
226 int d = pop_to_data_bin(sp_i, lp);
227 if(pop_bin_lo(sp_i, d) < 0) pop_bin_lo(sp_i, d) = lp;
228 pop_bin_hi(sp_i, d) = lp;
231 int max_age =
imax(nages);
234 int max_bin = (max_age > max_nlengths_pop) ? max_age : max_nlengths_pop;
237 DATA_IVECTOR(M1_model);
239 DATA_IVECTOR(M1_use_prior);
240 DATA_IVECTOR(M2_use_prior);
241 DATA_VECTOR(M_prior);
242 DATA_VECTOR(M_prior_sd);
245 DATA_IVECTOR(growth_model);
246 DATA_IVECTOR(growth_sd_style);
247 DATA_IVECTOR(growth_sd_form);
248 DATA_IVECTOR(growth_plus_length);
249 DATA_VECTOR(plus_group_decay);
250 DATA_IMATRIX(sel_dn6_ends);
251 DATA_IVECTOR(mat_len_use);
252 DATA_MATRIX(mat_len_pars);
253 DATA_VECTOR(growth_age_L1);
281 DATA_IVECTOR(linkage_process);
282 DATA_IVECTOR(linkage_param);
283 DATA_IVECTOR(linkage_species);
284 DATA_IVECTOR(linkage_sex);
285 DATA_IVECTOR(linkage_age_bin);
286 DATA_IVECTOR(linkage_fleet);
287 DATA_IVECTOR(linkage_X_col);
288 DATA_IVECTOR(linkage_link);
292 int rec_floor_on = 0;
293 for (
int i = 0; i < linkage_link.size(); ++i) {
296 DATA_IVECTOR(linkage_re_index);
299 DATA_IVECTOR(linkage_re_sigma);
300 DATA_IVECTOR(linkage_re_integrate);
301 DATA_IVECTOR(linkage_re_slot);
302 DATA_IVECTOR(linkage_re_struct);
303 DATA_IVECTOR(linkage_re_rho);
304 DATA_IVECTOR(linkage_re_sigma_prior_family);
305 DATA_IVECTOR(linkage_re_rho_prior_family);
306 DATA_VECTOR(linkage_re_rho_prior_p1);
307 DATA_VECTOR(linkage_re_rho_prior_p2);
308 DATA_IVECTOR(linkage_re_obs);
310 DATA_VECTOR(linkage_re_obs_sd);
311 DATA_VECTOR(linkage_re_obs_value);
312 DATA_IVECTOR(linkage_re_obs_mask);
313 DATA_IVECTOR(linkage_re_obsvec_idx);
314 DATA_VECTOR(linkage_re_sigma_prior_p1);
315 DATA_VECTOR(linkage_re_sigma_prior_p2);
316 DATA_IVECTOR(linkage_is_intercept);
317 DATA_IVECTOR(linkage_prior_family);
318 DATA_VECTOR(linkage_prior_p1);
319 DATA_VECTOR(linkage_prior_p2);
320 DATA_MATRIX(linkage_X);
323 DATA_IVECTOR(flt_type);
324 DATA_VECTOR(flt_month);
325 DATA_IVECTOR(flt_sel_type);
326 DATA_IVECTOR(flt_sel_dim);
327 DATA_IVECTOR(flt_n_sel_bins);
328 DATA_IVECTOR(flt_sel_cap_bin);
329 DATA_IVECTOR(flt_varying_sel);
330 DATA_IVECTOR(flt_spp);
331 DATA_IVECTOR(bin_first_selected);
332 DATA_IVECTOR(sel_norm_bin1);
333 DATA_IVECTOR(sel_norm_bin2);
334 DATA_IVECTOR(sel_norm_scope);
335 DATA_IVECTOR(flt_sel_start_yr);
336 DATA_IVECTOR(flt_sel_pen_first_bin);
337 DATA_IVECTOR(flt_sel_lead);
338 DATA_IVECTOR(flt_q_lead);
339 DATA_IVECTOR(flt_sel_pen_last_bin);
340 DATA_IVECTOR(flt_sel_shape_mode);
341 DATA_VECTOR(flt_sel_avgsel_pen);
342 DATA_IVECTOR(comp_ll_type);
343 DATA_IVECTOR(comp_accum_young);
344 DATA_IVECTOR(comp_accum_old);
345 DATA_IVECTOR(caal_ll_type);
346 DATA_IVECTOR(flt_units);
347 DATA_IVECTOR(flt_wt_index);
348 DATA_IVECTOR(flt_age_transition_index);
349 DATA_IVECTOR(flt_ageing_error_index);
350 DATA_IVECTOR(est_index_q);
351 DATA_IVECTOR(index_varying_q);
352 DATA_IVECTOR(est_sigma_index);
353 DATA_IVECTOR(est_sigma_fsh);
356 DATA_IMATRIX( catch_ctl );
357 DATA_IMATRIX( catch_n );
358 DATA_MATRIX( catch_obs );
361 DATA_IMATRIX( index_ctl );
362 DATA_MATRIX( index_n );
363 DATA_MATRIX( index_obs );
364 DATA_VECTOR( index_log_q_prior );
365 DATA_IVECTOR( index_ll_type );
366 DATA_STRUCT( index_cov_mat,
LOM_t );
367 DATA_VECTOR( index_cov_const );
381 DATA_VECTOR( obsvec );
382 DATA_VECTOR_INDICATOR( keep, obsvec );
383 DATA_IVECTOR( catch_obsvec_idx );
384 DATA_IVECTOR( index_obsvec_idx );
385 DATA_IVECTOR( comp_obsvec_idx );
386 DATA_IVECTOR( caal_obsvec_idx );
387 DATA_IVECTOR( diet_obsvec_idx );
388 DATA_INTEGER( osa_mode );
389 DATA_INTEGER( adreport_sel );
390 DATA_SCALAR( comp_offset );
407 DATA_IVECTOR( simulate_state );
408 DATA_IVECTOR( simulate_period );
411 DATA_IMATRIX( comp_ctl );
412 DATA_MATRIX( comp_n );
413 DATA_MATRIX( comp_obs );
414 DATA_IMATRIX( caal_ctl );
415 DATA_MATRIX( caal_n );
419 DATA_IMATRIX( equil_catch_ctl );
420 DATA_MATRIX( equil_catch_obs );
421 DATA_MATRIX( caal_obs );
424 DATA_IMATRIX( emp_sel_ctl );
425 DATA_MATRIX( emp_sel_obs );
426 DATA_ARRAY( age_trans_matrix);
427 DATA_ARRAY( age_error );
430 DATA_ARRAY( weight_obs );
433 DATA_IVECTOR(diet_ll_type);
435 DATA_ARRAY( ration_data );
436 DATA_MATRIX( diet_obs );
437 DATA_IMATRIX( diet_ctl );
438 DATA_INTEGER(n_stomach_obs);
439 DATA_IVECTOR(stomach_id);
442 DATA_MATRIX( env_index );
446 DATA_VECTOR( other_food );
447 DATA_VECTOR( Pvalue );
449 DATA_IVECTOR( Cindex );
460 DATA_MATRIX( sex_ratio );
461 DATA_MATRIX( maturity );
462 DATA_SCALAR(bias_adjust_obs);
463 DATA_SCALAR(bias_adjust_proc);
471 PARAMETER_VECTOR( log_pop_scalar );
474 PARAMETER_MATRIX( rec_pars );
475 PARAMETER_VECTOR( R_log_sd );
476 PARAMETER_MATRIX( rec_dev );
477 PARAMETER_MATRIX( init_dev );
480 PARAMETER_ARRAY( log_M1 );
481 PARAMETER_ARRAY( log_M1_dev );
482 PARAMETER_ARRAY( M1_beta );
483 PARAMETER_ARRAY( M1_rho );
484 PARAMETER_ARRAY( M1_dev_log_sd );
487 PARAMETER_ARRAY(log_growth_pars);
489 PARAMETER_ARRAY(growth_log_sd);
490 PARAMETER_MATRIX(weight_length_pars);
494 PARAMETER_VECTOR(beta_linkage);
500 PARAMETER_VECTOR(beta_linkage_re);
503 PARAMETER_VECTOR(beta_linkage_re_pen);
504 PARAMETER_VECTOR(log_sigma_linkage);
505 PARAMETER_VECTOR(trans_rho_linkage);
506 PARAMETER_VECTOR(beta_linkage_obs);
507 PARAMETER_VECTOR(log_obs_sd_linkage);
510 PARAMETER_VECTOR( log_Flimit );
511 PARAMETER_VECTOR( log_Ftarget );
512 PARAMETER_VECTOR( log_Finit );
513 PARAMETER_VECTOR( proj_F_prop );
514 PARAMETER_MATRIX( log_F );
517 PARAMETER_VECTOR( index_log_q );
518 PARAMETER_MATRIX( index_q_beta );
519 PARAMETER_MATRIX( index_q_dev );
520 PARAMETER_VECTOR( index_q_log_sd );
521 PARAMETER_VECTOR( index_q_dev_log_sd );
524 PARAMETER_ARRAY( sel_coff );
525 PARAMETER_ARRAY( sel_coff_dev );
526 PARAMETER_ARRAY( log_sel_slp );
527 PARAMETER_ARRAY( sel_inf );
528 PARAMETER_ARRAY( log_sel_slp_dev );
529 PARAMETER_ARRAY( sel_inf_dev );
530 PARAMETER_ARRAY( log_sel_apical );
531 PARAMETER_ARRAY( sel_dn6 );
532 PARAMETER_VECTOR( sel_dev_log_sd );
533 PARAMETER_MATRIX( sel_curve_pen );
537 PARAMETER_VECTOR( index_log_sd );
538 PARAMETER_VECTOR( catch_log_sd );
539 PARAMETER_VECTOR( comp_weights );
540 PARAMETER_VECTOR( caal_weights );
541 vector<Type> DM_pars_comp = exp(comp_weights);
542 vector<Type> DM_pars_caal = exp(caal_weights);
544 PARAMETER_VECTOR( diet_comp_weights );
545 vector<Type> DM_diet_pars = exp(diet_comp_weights);
548 PARAMETER_VECTOR( log_gam_a );
549 PARAMETER_VECTOR( log_gam_b );
552 PARAMETER_MATRIX( log_phi );
560 int n_flt = flt_type.size();
561 vector<int> joint_adjust(comp_obs.rows()); joint_adjust.setZero();
563 Type ricker_intercept = 0.0;
566 array<Type> growth_matrix(nspp * 2 + n_flt, max_sex, max_age, max_nlengths_pop, nyrs); growth_matrix.setZero();
567 array<Type> weight_hat(nspp * 2 + n_flt, max_sex, max_age, nyrs); weight_hat.setZero();
568 array<Type> mat_weight_hat(nspp * 2 + n_flt, max_sex, max_age, nyrs); mat_weight_hat.setZero();
569 array<Type> length_hat(nspp * 2 + n_flt, max_sex, max_age, nyrs); length_hat.setZero();
572 vector<Type> pop_scalar = exp(log_pop_scalar);
573 vector<Type> avg_R(nspp); avg_R.setZero();
574 matrix<Type> R_hat(nspp, nyrs); R_hat.setZero();
575 matrix<Type> mort_sum(nspp, max_age); mort_sum.setZero();
578 array<Type> sel_init(nspp, max_sex, max_age); sel_init.setZero();
584 array<Type> N_eq(nspp, max_sex, max_age); N_eq.setZero();
585 matrix<Type> R0(nspp, nyrs); R0.setZero();
586 matrix<Type> alpha(nspp, nyrs); alpha.setZero();
587 matrix<Type> Beta(nspp, nyrs); Beta.setZero();
588 matrix<Type> steepness(nspp, nyrs); steepness.setZero();
589 vector<Type> R_init(nspp); R_init.setZero();
590 matrix<Type> R(nspp, nyrs); R.setZero();
591 array<Type> biomass_at_age(nspp, max_sex, max_age, nyrs); biomass_at_age.setZero();
592 matrix<Type> biomass(nspp, nyrs); biomass.setZero();
593 matrix<Type> exploitable_biomass(nspp, nyrs); exploitable_biomass.setZero();
594 matrix<Type> ssb(nspp, nyrs); ssb.setZero();
595 matrix<Type> biomass_depletion(nspp, nyrs); biomass_depletion.setZero();
596 matrix<Type> ssb_depletion(nspp, nyrs); ssb_depletion.setZero();
597 array<Type> M_at_age(nspp, max_sex, max_age, nyrs); M_at_age.setZero();
598 array<Type> M_at_age_dB0(nspp, max_sex, max_age, nyrs); M_at_age_dB0.setZero();
599 array<Type> M_at_age_dBF(nspp, max_sex, max_age, nyrs); M_at_age_dBF.setZero();
600 array<Type> M1_at_age(nspp, max_sex, max_age, nyrs); M1_at_age.setZero();
601 array<Type> N_at_age(nspp, max_sex, max_age, nyrs); N_at_age.setZero();
602 array<Type> avgN_at_age(nspp, max_sex, max_age, nyrs); avgN_at_age.setZero();
603 array<Type> avgN_at_age_dB0(nspp, max_sex, max_age, nyrs); avgN_at_age_dB0.setZero();
604 array<Type> avgN_at_age_dBF(nspp, max_sex, max_age, nyrs); avgN_at_age_dBF.setZero();
605 array<Type> Z_at_age(nspp, max_sex, max_age, nyrs); Z_at_age.setZero();
606 vector<Type> R_sd(nspp); R_sd.setZero();
607 vector<Type> zero_N_pen(nspp); zero_N_pen.setZero();
610 array<Type> sel_at_age(n_flt, max_sex, max_age, nyrs); sel_at_age.setZero();
611 array<Type> sel_at_length(n_flt, max_sex, max_nlengths_pop, nyrs); sel_at_length.setZero();
612 array<Type> avg_sel(n_flt, max_sex, nyrs_hind); avg_sel.setZero();
613 array<Type> non_par_sel(n_flt, max_sex, max_bin, nyrs); non_par_sel.setZero();
614 array<Type> log_non_par_sel(n_flt, max_sex, max_bin, nyrs); log_non_par_sel.setZero();
615 vector<Type> sel_dev_sd(n_flt); sel_dev_sd.setZero();
618 matrix<Type> F_spp(nspp, nyrs); F_spp.setZero();
619 matrix<Type> F_flt(n_flt, nyrs); F_flt.setZero();
620 array<Type> F_flt_age(n_flt, max_sex, max_age, nyrs); F_flt_age.setZero();
621 array<Type> Flimit_at_age(nspp, max_sex, max_age, nyrs); Flimit_at_age.setZero();
622 array<Type> Ftarget_at_age(nspp, max_sex, max_age, nyrs); Ftarget_at_age.setZero();
623 array<Type> F_at_age(nspp, max_sex, max_age, nyrs); F_at_age.setZero();
624 vector<Type> catch_hat(catch_obs.rows()); catch_hat.setZero();
625 vector<Type> max_catch_hat(catch_obs.rows()); max_catch_hat.setZero();
629 vector<Type> catch_sd(catch_obs.rows()); catch_sd.setZero();
632 vector<Type> catch_analytical_sd(n_flt); catch_analytical_sd.setZero();
633 vector<Type> catch_n_obs(n_flt); catch_n_obs.setZero();
636 array<Type> NByage0(nspp, max_sex, max_age, nyrs); NByage0.setZero();
637 array<Type> NByageF(nspp, max_sex, max_age, nyrs); NByageF.setZero();
638 array<Type> N_at_age_dB0(nspp, max_sex, max_age, nyrs); N_at_age_dB0.setZero();
639 array<Type> N_at_age_dBF(nspp, max_sex, max_age, nyrs); N_at_age_dBF.setZero();
640 matrix<Type> DynamicSB0(nspp, nyrs); DynamicSB0.setZero();
641 matrix<Type> DynamicB0(nspp, nyrs); DynamicB0.setZero();
642 matrix<Type> DynamicSBF(nspp, nyrs); DynamicSBF.setZero();
646 array<Type> NbyageSPR(4, nspp, max_age); NbyageSPR.setZero();
647 vector<Type> SPRlimit(nspp); SPRlimit.setZero();
648 vector<Type> SPRtarget(nspp); SPRtarget.setZero();
649 vector<Type> SPR0(nspp); SPR0.setZero();
650 vector<Type> SPRFinit(nspp); SPRFinit.setZero();
651 matrix<Type> SB0(nspp, nyrs); SB0.setZero();
652 matrix<Type> SBF(nspp, nyrs); SBF.setZero();
653 matrix<Type> B0(nspp, nyrs); B0.setZero();
654 vector<Type> Flimit = exp(log_Flimit);
655 vector<Type> Ftarget = exp(log_Ftarget);
656 vector<Type> Finit = exp(log_Finit);
657 vector<Type> index_q_mult(index_q_beta.cols()); index_q_mult.setZero();
658 vector<Type> M1_mult(M1_beta.dim(2)); M1_mult.setZero();
659 vector<Type> beta_q_tmp(index_q_beta.cols()); beta_q_tmp.setZero();
660 vector<Type> env_q_tmp(index_q_beta.cols()); env_q_tmp.setZero();
661 vector<Type> beta_M1_tmp(M1_beta.dim(2)); beta_M1_tmp.setZero();
662 vector<Type> env_M1_tmp(M1_beta.dim(2)); env_M1_tmp.setZero();
663 matrix<Type> proj_F(nspp, nyrs); proj_F.setZero();
666 vector<Type> index_q_sd(n_flt); index_q_sd.setZero();
667 vector<Type> index_q_dev_sd(n_flt); index_q_dev_sd.setZero();
668 vector<Type> index_hat(index_obs.rows()); index_hat.setZero();
674 vector<Type> index_trunc_tries_sim(index_obs.rows()); index_trunc_tries_sim.setZero();
675 vector<Type> index_trunc_rejects_sim(index_obs.rows()); index_trunc_rejects_sim.setZero();
679 vector<Type> index_trunc_sd_sim(index_obs.rows()); index_trunc_sd_sim.setZero();
684 vector<Type> index_trunc_budget_sim(index_obs.rows()); index_trunc_budget_sim.setZero();
685 const int index_trunc_max_tries = 100;
691 vector<Type> index_sd(index_obs.rows()); index_sd.setZero();
692 vector<Type> index_analytical_sd(n_flt); index_analytical_sd.setZero();
693 vector<Type> index_q_analytical(n_flt); index_q_analytical.setZero();
694 matrix<Type> index_q(n_flt, nyrs_hind); index_q.setZero();
695 vector<Type> index_n_obs(n_flt); index_n_obs.setZero();
707 int max_age_cols =
static_cast<int>(comp_obs.cols());
708 for(
int comp_row = 0; comp_row < comp_ctl.rows(); comp_row++){
709 int comp_row_sp = comp_ctl(comp_row, 1) - 1;
710 if((comp_row_sp < 0) | (comp_row_sp >= nspp)){
711 error(
"comp_data Species on row %d is not in 1..nspp", comp_row + 1);
713 int comp_row_cols = (comp_ctl(comp_row, 2) == 3) ? nages(comp_row_sp) * 2 : nages(comp_row_sp);
714 if(comp_row_cols > max_age_cols){ max_age_cols = comp_row_cols; }
716 vector<Type> n_hat(comp_obs.rows()) ; n_hat.setZero() ;
717 matrix<Type> age_hat(comp_obs.rows(), max_age_cols); age_hat.setZero();
718 matrix<Type> age_obs_hat(comp_obs.rows(), max_age_cols); age_obs_hat.setZero();
719 matrix<Type> comp_hat = comp_obs; comp_hat.setZero();
720 matrix<Type> caal_hat = caal_obs; caal_hat.setZero();
721 array<Type> pred_CAAL(n_flt, max_sex, max_age, max_nlengths, nyrs); pred_CAAL.setZero();
724 array<Type> consumption_at_age( nspp, max_sex, max_age, nyrs ); consumption_at_age.setZero();
725 matrix<Type> fT( nspp, nyrs ); fT.setZero();
728 array<Type> diet_prop(nspp * max_sex, nspp * max_sex, max_age, max_age, nyrs); diet_prop.setZero();
729 array<Type> diet_prop_hat(nspp * max_sex, nspp * max_sex, max_age, max_age, nyrs); diet_prop_hat.setZero();
730 array<Type> other_food_diet_prop(nspp, max_sex, max_age, nyrs); other_food_diet_prop.setZero();
731 matrix<Type> diet_hat = diet_obs; diet_hat.setZero();
734 array<Type> avail_food(nspp, max_sex, max_age, nyrs); avail_food.setZero();
735 array<Type> avail_food_dB0(nspp, max_sex, max_age, nyrs); avail_food_dB0.setZero();
736 array<Type> avail_food_dBF(nspp, max_sex, max_age, nyrs); avail_food_dBF.setZero();
737 array<Type> stom_div_bio(nspp * max_sex, nspp * max_sex, max_age, max_age, nyrs); stom_div_bio.setZero();
738 array<Type> suitability(nspp * max_sex, nspp * max_sex, max_age, max_age, nyrs); suitability.setZero();
739 array<Type> suit_other(nspp, max_sex, max_age, nyrs); suit_other.setZero();
740 array<Type> other_diet_prop_hat(nspp, max_sex, max_age, nyrs); other_diet_prop_hat.setZero();
743 vector<Type> gam_a = exp(log_gam_a);
744 vector<Type> gam_b = exp(log_gam_b);
745 matrix<Type> vulnerability(nspp, nspp); vulnerability.setZero();
746 vector<Type> vulnerability_other(nspp); vulnerability_other.setZero();
749 array<Type> M2_at_age(nspp, max_sex, max_age, nyrs); M2_at_age.setZero();
750 array<Type> M2_at_age_dB0(nspp, max_sex, max_age, nyrs); M2_at_age_dB0.setZero();
751 array<Type> M2_at_age_dBF(nspp, max_sex, max_age, nyrs); M2_at_age_dBF.setZero();
752 array<Type> M2_prop(nspp * max_sex, nspp * max_sex, max_age, max_age, nyrs); M2_prop.setZero();
753 array<Type> B_eaten(nspp * max_sex, nspp * max_sex, max_age, max_age, nyrs); B_eaten.setZero();
754 array<Type> B_eaten_as_prey(nspp, max_sex, max_age, nyrs); B_eaten_as_prey.setZero();
761 R_sd = exp(R_log_sd);
762 sel_dev_sd = exp(sel_dev_log_sd) ;
763 index_q_sd = exp(index_q_log_sd) ;
764 index_q_dev_sd = exp(index_q_dev_log_sd) ;
778 vector<Type> beta_linkage_re_drawn_sim(linkage_re_sigma.size());
779 beta_linkage_re_drawn_sim.setZero();
780 if (log_sigma_linkage.size() > 0 && simulate_period(0) == 1) {
781 int n_grp = log_sigma_linkage.size();
786 vector<int> grp_used(n_grp), grp_draw(n_grp);
789 for (
int i = 0; i < linkage_re_index.size(); ++i) {
790 if (linkage_re_index(i) < 0)
continue;
791 int grp = linkage_re_sigma(linkage_re_index(i));
796 int proc = linkage_process(i);
797 if (proc < 0 || proc >= simulate_state.size() || simulate_state(proc) != 1) {
802 for (
int grp = 0; grp < n_grp; ++grp) {
803 if (grp_used(grp) == 0 || grp_draw(grp) == 0)
continue;
808 if (linkage_re_obs(grp) >= 0)
continue;
811 int len = slots.size();
812 if (len == 0)
continue;
814 Type sigma = exp(log_sigma_linkage(grp));
815 vector<Type> re(len);
816 int st = linkage_re_struct(grp);
821 re(0) = linkage_re_integrate(slots(0))
822 ? beta_linkage_re(linkage_re_slot(slots(0)))
823 : beta_linkage_re_pen(linkage_re_slot(slots(0)));
824 for (
int t = 1; t < len; ++t) re(t) = re(t - 1) + rnorm(Type(0), sigma);
826 Type rho =
rho_trans(trans_rho_linkage(linkage_re_rho(grp)));
827 AR1(rho).simulate(re);
830 for (
int t = 0; t < len; ++t) re(t) = rnorm(Type(0), sigma);
833 for (
int t = 0; t < len; ++t) {
834 if (linkage_re_integrate(slots(t))) {
835 beta_linkage_re(linkage_re_slot(slots(t))) = re(t);
837 beta_linkage_re_pen(linkage_re_slot(slots(t))) = re(t);
841 if (!(st ==
RCEATTLE_RE_RW && t == 0)) beta_linkage_re_drawn_sim(slots(t)) = 1;
845 REPORT(beta_linkage_re_drawn_sim);
853 vector<Type> beta_linkage_re_all(linkage_re_sigma.size());
854 for (
int s = 0; s < beta_linkage_re_all.size(); ++s) {
855 beta_linkage_re_all(s) = linkage_re_integrate(s)
856 ? beta_linkage_re(linkage_re_slot(s))
857 : beta_linkage_re_pen(linkage_re_slot(s));
867 vector<Type> beta_linkage_re_sim = beta_linkage_re_all;
868 REPORT(beta_linkage_re_sim);
875 vector<Type> beta_linkage_eff = beta_linkage;
876 for (
int i = 0; i < beta_linkage_eff.size(); ++i) {
877 if (linkage_re_index(i) >= 0) {
878 Type z = beta_linkage_re_all(linkage_re_index(i));
881 int grp = linkage_re_sigma(linkage_re_index(i));
882 if (linkage_re_obs(grp) >= 0) z *= beta_linkage_obs(linkage_re_obs(grp));
883 beta_linkage_eff(i) = z;
890 linkage_process, linkage_param,
891 linkage_species, linkage_sex, linkage_age_bin, linkage_fleet,
892 linkage_X_col, linkage_link, linkage_X, beta_linkage_eff};
898 matrix<Type> q_linkage_offset(n_flt, nyrs_hind); q_linkage_offset.setZero();
899 matrix<Type> q_linkage_offset_nat(n_flt, nyrs_hind); q_linkage_offset_nat.setZero();
900 matrix<Type> q_linkage_log_mult(n_flt, nyrs_hind); q_linkage_log_mult.setZero();
908 REPORT(q_linkage_offset);
909 REPORT(q_linkage_offset_nat);
910 REPORT(q_linkage_log_mult);
912 for(flt = 0; flt < n_flt; flt++){
913 for(yr = 0; yr < nyrs_hind; yr++){
917 index_q(flt, yr) = exp((index_log_q(flt) + q_linkage_offset(flt, yr))
918 * exp(q_linkage_log_mult(flt, yr))
919 + index_q_dev(flt, yr))
920 + q_linkage_offset_nat(flt, yr);
924 if(est_index_q(flt) == 5){
925 beta_q_tmp = index_q_beta.row(flt);
926 env_q_tmp = env_index.row(yr) ;
927 index_q_mult = env_q_tmp * beta_q_tmp;
928 index_q(flt, yr) = exp(index_log_q(flt) + (index_q_mult).sum());
933 matrix<int> r_sexes(diet_obs.rows(), 2); r_sexes.setZero();
934 matrix<int> k_sexes(diet_obs.rows(), 2); k_sexes.setZero();
939 matrix<Type> mature_females = maturity;
940 for( sp = 0; sp < nspp ; sp++) {
942 if(initMode < 3 || initMode == 5){
947 for( age = 0 ; age < nages(sp); age++ ) {
949 mature_females( sp, age ) = maturity( sp, age ) * sex_ratio(sp, age);
960 array<Type> recruitment_linkage_offset(nspp,
963 array<Type> recruitment_linkage_offset_nat(nspp,
966 recruitment_linkage_offset.setZero();
967 recruitment_linkage_offset_nat.setZero();
970 REPORT(recruitment_linkage_offset);
971 REPORT(recruitment_linkage_offset_nat);
974 array<Type> M_linkage_offset(nspp, max_sex, max_age, nyrs);
975 array<Type> M_linkage_offset_nat(nspp, max_sex, max_age, nyrs);
976 M_linkage_offset.setZero();
977 M_linkage_offset_nat.setZero();
980 REPORT(M_linkage_offset);
981 REPORT(M_linkage_offset_nat);
987 growth_linkage_offset.setZero();
988 growth_linkage_offset_nat.setZero();
991 REPORT(growth_linkage_offset);
992 REPORT(growth_linkage_offset_nat);
998 for(sp = 0; sp < nspp; sp++){
999 for(yr = 0; yr < nyrs; yr++){
1015 for(sp = 0; sp < nspp; sp++){
1016 for(sex = 0; sex < nsex(sp); sex ++){
1017 for(yr = 0; yr < nyrs; yr++){
1019 growth_parameters(sp, sex, yr, par) = exp(
1020 log_growth_pars(sp, sex, par)
1021 + growth_linkage_offset(sp, sex, yr, par)
1022 ) + growth_linkage_offset_nat(sp, sex, yr, par);
1027 REPORT(growth_parameters);
1071 array<Type> spawn_output(nspp, max_age, nyrs); spawn_output.setZero();
1072 for(sp = 0; sp < nspp; sp++){
1073 wt_idx_ssb = 2 * sp + 1;
1074 for(age = 0; age < nages(sp); age++){
1075 for(yr = 0; yr < nyrs; yr++){
1076 if(mat_len_use(sp) == 1){
1077 spawn_output(sp, age, yr) = mat_weight_hat(wt_idx_ssb, 0, age, yr) * ((nsex(sp) == 1) ? sex_ratio(sp, age) : Type(1.0));
1079 spawn_output(sp, age, yr) = weight_hat(wt_idx_ssb, 0, age, yr) * mature_females(sp, age);
1084 REPORT(spawn_output);
1090 array<Type> sel_slp_off (2, n_flt, max_sex, nyrs); sel_slp_off.setZero();
1091 array<Type> sel_slp_off_nat (2, n_flt, max_sex, nyrs); sel_slp_off_nat.setZero();
1092 array<Type> sel_inf_off (2, n_flt, max_sex, nyrs); sel_inf_off.setZero();
1093 array<Type> sel_inf_off_nat (2, n_flt, max_sex, nyrs); sel_inf_off_nat.setZero();
1094 array<Type> sel_coff_off (n_flt, max_sex, max_bin, nyrs); sel_coff_off.setZero();
1095 array<Type> sel_coff_off_nat (n_flt, max_sex, max_bin, nyrs); sel_coff_off_nat.setZero();
1096 array<Type> sel_apical_off (n_flt, max_sex, nyrs); sel_apical_off.setZero();
1097 array<Type> sel_apical_off_nat (n_flt, max_sex, nyrs); sel_apical_off_nat.setZero();
1098 array<Type> sel_dn6_off (6, n_flt, max_sex, nyrs); sel_dn6_off.setZero();
1099 array<Type> sel_dn6_off_nat (6, n_flt, max_sex, nyrs); sel_dn6_off_nat.setZero();
1104 int sel_apical_on = 0;
1105 for (
int i = 0; i < linkage_process.size(); i++) {
1110 sel_slp_off, sel_inf_off, sel_coff_off, sel_apical_off, sel_dn6_off,
1113 sel_slp_off_nat, sel_inf_off_nat, sel_coff_off_nat, sel_apical_off_nat, sel_dn6_off_nat,
1155 sel_slp_off, sel_slp_off_nat,
1156 sel_inf_off, sel_inf_off_nat,
1157 sel_coff_off, sel_coff_off_nat,
1158 sel_apical_on, log_sel_apical,
1159 sel_apical_off, sel_apical_off_nat,
1160 sel_dn6, sel_dn6_off, sel_dn6_off_nat, sel_dn6_ends
1167 for(flt = 0; flt < n_flt; flt++){
1169 if(growth_model(sp) == 0 || flt_sel_dim(flt) != 1 || flt_sel_type(flt) == 0)
continue;
1170 int wt_idx_sel = nspp * 2 + flt;
1171 for(sex = 0; sex < nsex(sp); sex++){
1172 for(age = 0; age < nages(sp); age++){
1173 for(yr = 0; yr < nyrs; yr++){
1174 Type num = 0, den = 0;
1178 for(
int ln = 0; ln < nlengths_pop(sp); ln++){
1181 Type lenmid = (ln < nlengths_pop(sp) - 1)
1182 ? (lengths_pop(sp, ln) + lengths_pop(sp, ln + 1)) / Type(2.0)
1183 : (nlengths_pop(sp) < 2
1184 ? lengths_pop(sp, ln)
1185 : lengths_pop(sp, ln) + (lengths_pop(sp, ln) - lengths_pop(sp, ln - 1)) / Type(2.0));
1186 Type p_sel = growth_matrix(wt_idx_sel, sex, age, ln, yr) * sel_at_length(flt, sex, ln, yr);
1187 num += p_sel * weight_length_pars(sp, 0) * pow(lenmid, weight_length_pars(sp, 1));
1191 weight_hat(wt_idx_sel, sex, age, yr) = num / (den + Type(1e-30));
1200 calculate_temperature_function(fT, nspp, nyrs, Ceq, Cindex, Qc, Tcm, Tco, Tcl, CK1, CK4, env_index);
1203 calculate_ration(consumption_at_age, nspp, nyrs, nyrs_hind, nsex, nages, Ceq, CA, CB, fday, Pvalue, fT, ration_data, weight_hat);
1212 length_hat, weight_hat, vulnerability, vulnerability_other, gam_a, gam_b);
1218 diet_obs, diet_ctl, diet_prop);
1222 diet_prop, other_food_diet_prop);
1229 F_flt_age.setZero();
1231 Ftarget_at_age.setZero();
1232 Flimit_at_age.setZero();
1233 for(flt = 0; flt < n_flt; flt++) {
1237 if(flt_type(flt) == 1){
1238 for(age = 0; age < nages(sp); age++) {
1239 for(sex = 0; sex < nsex(sp); sex ++){
1240 for(yr = 0; yr < nyrs; yr++) {
1243 if( yr < nyrs_hind){
1244 F_flt_age(flt, sex, age, yr) = sel_at_age(flt, sex, age, yr) * exp(log_F(flt, yr));
1249 if( yr >= nyrs_hind){
1257 proj_F(sp, yr) = Ftarget(sp);
1261 proj_F(sp, yr) = Ftarget(sp);
1265 proj_F(sp, yr) = Ftarget(sp);
1269 proj_F(sp, yr) = Ftarget(sp) * Fmult(sp);
1273 proj_F(sp, yr) = Ftarget(sp);
1277 proj_F(sp, yr) = Ftarget(sp) = Flimit(sp) + QnormHCR(sp);
1281 proj_F(sp, yr) = Ftarget(sp);
1286 if((forecast(sp) == 0) | (estDynamics(sp) > 0)){
1289 F_flt_age(flt, sex, age, yr) = sel_at_age(flt, sex, age, yr) * proj_F_prop(flt) * proj_F(sp, yr);
1293 F_at_age(sp, sex, age, yr) += F_flt_age(flt, sex, age, yr);
1296 Flimit_at_age(sp, sex, age, yr) += sel_at_age(flt, sex, age, yr) * proj_F_prop(flt) * Flimit(sp);
1297 Ftarget_at_age(sp, sex, age, yr) += sel_at_age(flt, sex, age, yr) * proj_F_prop(flt) * Ftarget(sp);
1303 for(yr = 0; yr < nyrs; yr++) {
1305 if( yr < nyrs_hind){
1306 F_flt(flt, yr) = exp(log_F(flt, yr));
1307 F_spp(sp, yr) += exp(log_F(flt, yr));
1311 if( yr >= nyrs_hind){
1312 F_flt(flt, yr) = proj_F_prop(flt) * proj_F(sp, yr);
1313 F_spp(sp, yr) += proj_F_prop(flt) * proj_F(sp, yr);
1325 for(sp = 0; sp < nspp; sp++){
1326 for(sex = 0; sex < nsex(sp); sex++){
1327 for(age = 0; age < nages(sp); age++){
1328 sel_init(sp, sex, age) = 1.0;
1333 for(sp = 0; sp < nspp; sp++){
1335 for(flt = 0; flt < n_flt; flt++){
1336 if((flt_type(flt) == 1) && (flt_spp(flt) == sp)) n_fsh++;
1339 for(sex = 0; sex < nsex(sp); sex++){
1340 for(age = 0; age < nages(sp); age++){
1342 for(flt = 0; flt < n_flt; flt++){
1343 if((flt_type(flt) == 1) && (flt_spp(flt) == sp)){
1344 acc += sel_at_age(flt, sex, age, 0);
1347 sel_init(sp, sex, age) = acc / Type(n_fsh);
1367 int rec_srr_single_density = !((srr_fun == 0) && (srr_pred_fun > 0));
1368 REPORT(rec_srr_single_density);
1375 matrix<Type> rec_dev_drawn_sim(rec_dev.rows(), rec_dev.cols());
1376 matrix<Type> init_dev_drawn_sim(init_dev.rows(), init_dev.cols());
1377 array<Type> log_M1_dev_drawn_sim(log_M1_dev.dim);
1378 rec_dev_drawn_sim.setZero();
1379 init_dev_drawn_sim.setZero();
1380 log_M1_dev_drawn_sim.setZero();
1382 for(sp = 0; sp < nspp; sp++){
1392 if(simulate_state(0) == 1 && simulate_period(0) == 1 && rec_srr_single_density){
1393 for(yr = 0; yr < nyrs_hind; yr++){
1394 rec_dev(sp, yr) = rnorm(-bias_adjust_proc*
square(R_sd(sp))/2.0, R_sd(sp));
1395 rec_dev_drawn_sim(sp, yr) = 1;
1404 if(simulate_state(0) == 1 && simulate_period(0) == 1 && rec_srr_single_density &&
1405 (initMode > 1) && (initMode != 5)){
1406 for(age = 1; age < nages(sp); age++){
1407 init_dev(sp, age - 1) = rnorm(-bias_adjust_proc*
square(R_sd(sp))/2.0, R_sd(sp));
1408 init_dev_drawn_sim(sp, age - 1) = 1;
1423 if(simulate_state(1) == 1 && simulate_period(0) == 1){
1424 for(sp = 0; sp < nspp; sp++){
1425 int num_re_sexes = (M1_model(sp) == 2 && nsex(sp) > 1) ? 2 : 1;
1427 if((M1_re(sp) == 1) || (M1_re(sp) == 4)){
1428 Type sigma_M = exp(M1_dev_log_sd(sp, 0));
1429 Type rho_M_a =
rho_trans(M1_rho(sp, 0, 0));
1430 Type Sigma_M = pow(pow(sigma_M, 2) / (1.0 - pow(rho_M_a, 2)), 0.5);
1431 for(
int s = 0; s < num_re_sexes; s++){
1432 vector<Type> M_re_age(nages(sp));
1433 AR1(rho_M_a).simulate(M_re_age);
1434 M_re_age *= Sigma_M;
1435 int sex_end = (num_re_sexes == 1) ? nsex(sp) : s + 1;
1436 for(
int sex = s; sex < sex_end; sex++){
1437 for(age = 0; age < nages(sp); age++){
1438 for(yr = 0; yr < nyrs; yr++){
1439 log_M1_dev(sp, sex, age, yr) = M_re_age(age);
1440 log_M1_dev_drawn_sim(sp, sex, age, yr) = 1;
1447 if((M1_re(sp) == 2) || (M1_re(sp) == 5)){
1448 Type sigma_M = exp(M1_dev_log_sd(sp, 0));
1449 Type rho_M_y =
rho_trans(M1_rho(sp, 0, 1));
1450 Type Sigma_M = pow(pow(sigma_M, 2) / (1.0 - pow(rho_M_y, 2)), 0.5);
1451 for(
int s = 0; s < num_re_sexes; s++){
1452 vector<Type> M_re_yr(nyrs_hind);
1453 AR1(rho_M_y).simulate(M_re_yr);
1455 int sex_end = (num_re_sexes == 1) ? nsex(sp) : s + 1;
1456 for(
int sex = s; sex < sex_end; sex++){
1457 for(yr = 0; yr < nyrs_hind; yr++){
1458 for(age = 0; age < nages(sp); age++){
1459 log_M1_dev(sp, sex, age, yr) = M_re_yr(yr);
1460 log_M1_dev_drawn_sim(sp, sex, age, yr) = 1;
1467 if((M1_re(sp) == 3) || (M1_re(sp) == 6)){
1468 Type sigma_M = exp(M1_dev_log_sd(sp, 0));
1469 Type rho_M_a =
rho_trans(M1_rho(sp, 0, 0));
1470 Type rho_M_y =
rho_trans(M1_rho(sp, 0, 1));
1471 Type Sigma_M = pow(pow(sigma_M, 2) / ((1.0 - pow(rho_M_y, 2)) * (1.0 - pow(rho_M_a, 2))), 0.5);
1472 for(
int s = 0; s < num_re_sexes; s++){
1473 array<Type> M_re_a_yr(nages(sp), nyrs_hind);
1476 SEPARABLE(AR1(rho_M_y), AR1(rho_M_a)).simulate(M_re_a_yr);
1477 int sex_end = (num_re_sexes == 1) ? nsex(sp) : s + 1;
1478 for(
int sex = s; sex < sex_end; sex++){
1479 for(age = 0; age < nages(sp); age++){
1480 for(yr = 0; yr < nyrs_hind; yr++){
1481 log_M1_dev(sp, sex, age, yr) = Sigma_M * M_re_a_yr(age, yr);
1482 log_M1_dev_drawn_sim(sp, sex, age, yr) = 1;
1494 matrix<Type> rec_dev_sim = rec_dev;
1495 matrix<Type> init_dev_sim = init_dev;
1496 array<Type> log_M1_dev_sim = log_M1_dev;
1497 REPORT(rec_dev_sim);
1498 REPORT(init_dev_sim);
1499 REPORT(log_M1_dev_sim);
1500 REPORT(rec_dev_drawn_sim);
1501 REPORT(init_dev_drawn_sim);
1502 REPORT(log_M1_dev_drawn_sim);
1509 for(
int iter = 0; iter < niter; iter++) {
1512 for(sp = 0; sp < nspp; sp++) {
1513 for(sex = 0; sex < nsex(sp); sex ++){
1515 for(
int i = 0; i < M1_beta.dim(2); i++){
1516 beta_M1_tmp(i) = M1_beta(sp, sex, i);
1518 for(age = 0; age < nages(sp); age++) {
1519 for(yr = 0; yr < nyrs; yr++) {
1521 env_M1_tmp = env_index.row(yr);
1522 M1_mult = env_M1_tmp * beta_M1_tmp;
1528 M1_at_age(sp, sex, age, yr) = exp(
1529 log_M1(sp, sex, age)
1530 + log_M1_dev(sp, sex, age, yr)
1532 + M_linkage_offset(sp, sex, age, yr)
1533 ) + M_linkage_offset_nat(sp, sex, age, yr);
1534 M_at_age(sp, sex, age, yr) = M1_at_age(sp, sex, age, yr) + M2_at_age(sp, sex, age, yr);
1535 M_at_age_dB0(sp, sex, age, yr) = M1_at_age(sp, sex, age, yr) + M2_at_age_dB0(sp, sex, age, yr);
1536 M_at_age_dBF(sp, sex, age, yr) = M1_at_age(sp, sex, age, yr) + M2_at_age_dBF(sp, sex, age, yr);
1537 Z_at_age(sp, sex, age, yr) = M1_at_age(sp, sex, age, yr) + F_at_age(sp, sex, age, yr) + M2_at_age(sp, sex, age, yr);
1549 SPRtarget.setZero();
1554 for(sp = 0; sp < nspp; sp++) {
1557 int term_yr = nyrs_hind - 1;
1558 wt_idx_ssb = 2 * sp + 1;
1564 vector<Type> Z_unfished(na), Z_limit(na), Z_target(na), Z_init(na);
1565 vector<Type> wt_term(na), wt_first(na), mature_at_age(na);
1566 Type female_split = (nsex(sp) == 1) ? Type(1.0) : sex_ratio(sp, 0);
1568 for(age = 0; age < na; age++){
1569 Z_unfished(age) = M_at_age(sp, 0, age, term_yr);
1570 Z_limit(age) = M_at_age(sp, 0, age, term_yr) + Flimit_at_age(sp, 0, age, term_yr);
1571 Z_target(age) = M_at_age(sp, 0, age, term_yr) + Ftarget_at_age(sp, 0, age, term_yr);
1572 Z_init(age) = M_at_age(sp, 0, age, 0) + Finit(sp) * sel_init(sp, 0, age);
1577 wt_term(age) = spawn_output(sp, age, term_yr);
1578 wt_first(age) = spawn_output(sp, age, 0);
1579 mature_at_age(age) = female_split;
1593 for(age = 0; age < na; age++){
1594 NbyageSPR(0, sp, age) = n_unfished(age);
1595 NbyageSPR(1, sp, age) = n_limit(age);
1596 NbyageSPR(2, sp, age) = n_target(age);
1597 NbyageSPR(3, sp, age) = n_init(age);
1606 zero_N_pen.setZero();
1607 for( sp = 0; sp < nspp ; sp++) {
1610 if((msmMode > 0) & (srr_fun > 1)){
1611 for(yr = 0; yr < nyrs; yr++){ steepness(sp, yr) = 0; }
1612 R_init(sp) = R0(sp, 0);
1613 }
else switch(srr_fun){
1616 for(yr = 0; yr < nyrs; yr++){ steepness(sp, yr) = 0.99; }
1618 R_init(sp) = R0(sp, 0);
1623 for(yr = 0; yr < nyrs; yr++){ steepness(sp, yr) = 0.99; }
1625 R_init(sp) = R0(sp, 0);
1632 for(yr = 0; yr < nyrs; yr++){
1633 steepness(sp, yr) = alpha(sp, yr) * SPR0(sp)/(4.0 + alpha(sp, yr) * SPR0(sp));
1639 R0(sp, 0) = (alpha(sp, 0) - 1.0/SPR0(sp)) / Beta(sp, 0);
1640 R_init(sp) = (alpha(sp, 0) - 1.0/SPRFinit(sp)) / Beta(sp, 0);
1642 if (rec_floor_on) { Type pen_R = 0; R0(sp, 0) =
posfun(R0(sp, 0), Type(1e-3), pen_R); R_init(sp) =
posfun(R_init(sp), Type(1e-3), pen_R); zero_N_pen(sp) += pen_R; }
1649 for(yr = 0; yr < nyrs; yr++){
1650 steepness(sp, yr) = alpha(sp, yr) * SPR0(sp)/(4.0 + alpha(sp, yr) * SPR0(sp));
1654 R0(sp, 0) = (alpha(sp, 0) - 1.0/SPR0(sp)) / Beta(sp, 0);
1655 R_init(sp) = (alpha(sp, 0) - 1.0/SPRFinit(sp)) / Beta(sp, 0);
1657 if (rec_floor_on) { Type pen_R = 0; R0(sp, 0) =
posfun(R0(sp, 0), Type(1e-3), pen_R); R_init(sp) =
posfun(R_init(sp), Type(1e-3), pen_R); zero_N_pen(sp) += pen_R; }
1664 for(yr = 0; yr < nyrs; yr++){
1665 { Type aS = alpha(sp, yr) * SPR0(sp);
1666 if (rec_floor_on) { Type pen_d = 0; aS =
posfun(aS, Type(1e-3), pen_d); }
1667 steepness(sp, yr) = 0.2 * exp(0.8*log(aS)); }
1672 ricker_intercept = alpha(sp, 0) * SPR0(sp) - 1.0;
1673 ricker_intercept =
posfun(ricker_intercept, Type(0.001), pen_rk) + 1.0;
1677 R0(sp, 0) = log(ricker_intercept)/(Beta(sp, 0) * SPR0(sp)/1000000.0);
1680 ricker_intercept = alpha(sp, 0) * SPRFinit(sp) - 1.0;
1681 ricker_intercept =
posfun(ricker_intercept, Type(0.001), pen_rk) + 1.0;
1682 R_init(sp) = log(ricker_intercept)/(Beta(sp, 0) * SPRFinit(sp)/1000000.0);
1683 zero_N_pen(sp) += pen_rk;
1690 for(yr = 0; yr < nyrs; yr++){
1691 { Type aS = alpha(sp, yr) * SPR0(sp);
1692 if (rec_floor_on) { Type pen_d = 0; aS =
posfun(aS, Type(1e-3), pen_d); }
1693 steepness(sp, yr) = 0.2 * exp(0.8*log(aS)); }
1698 ricker_intercept = alpha(sp, 0) * SPR0(sp) - 1.0;
1699 ricker_intercept =
posfun(ricker_intercept, Type(0.001), pen_rk) + 1.0;
1701 R0(sp, 0) = log(ricker_intercept)/(Beta(sp, 0) * SPR0(sp)/1000000.0);
1704 ricker_intercept = alpha(sp, 0) * SPRFinit(sp) - 1.0;
1705 ricker_intercept =
posfun(ricker_intercept, Type(0.001), pen_rk) + 1.0;
1706 R_init(sp) = log(ricker_intercept)/(Beta(sp, 0) * SPRFinit(sp)/1000000.0);
1707 zero_N_pen(sp) += pen_rk;
1712 error(
"Invalid 'srr_fun'");
1722 if((srr_fun < 2) & (srr_pred_fun > 1) & (msmMode == 0)){
1723 for(yr = 0; yr < nyrs; yr++){
1724 if((srr_pred_fun == 2) | (srr_pred_fun == 3)){
1725 steepness(sp, yr) = alpha(sp, yr) * SPR0(sp)/(4.0 + alpha(sp, yr) * SPR0(sp));
1727 if((srr_pred_fun == 4) | (srr_pred_fun == 5)){
1728 { Type aS = alpha(sp, yr) * SPR0(sp);
1729 if (rec_floor_on) { Type pen_d = 0; aS =
posfun(aS, Type(1e-3), pen_d); }
1730 steepness(sp, yr) = 0.2 * exp(0.8*log(aS)); }
1736 if((srr_fun < 2) & (srr_pred_fun > 1) & (msmMode > 0)){
1737 for(yr = 0; yr < nyrs; yr++){ steepness(sp, yr) = 0; }
1745 for(sp = 0; sp < nspp; sp++) {
1749 sex_ratio(sp, 0) = 1.0;
1758 for(age = 0; age < nages(sp); age++){
1759 for(sex = 0; sex < nsex(sp); sex ++){
1761 switch(estDynamics(sp)){
1768 R(sp, 0) = R_init(sp) * exp(rec_dev(sp, 0));
1769 N_at_age(sp, 0, 0, 0) = R(sp, 0) * sex_ratio(sp, 0);
1774 N_at_age(sp, 1, 0, 0) = R(sp, 0) * (1-sex_ratio(sp, 0));
1780 N_eq(sp, 0, 0) = R_init(sp) * exp(init_level) * sex_ratio(sp, 0);
1782 N_eq(sp, 1, 0) = R_init(sp) * exp(init_level) * (1-sex_ratio(sp, 0));
1789 N_at_age(sp, 0, age, 0) = exp(init_dev(sp, age-1)) * sex_ratio(sp, 0);
1791 N_at_age(sp, 1, age, 0) = exp(init_dev(sp, age-1)) * (1-sex_ratio(sp, 0));
1795 N_eq(sp, 0, age) = N_at_age(sp, 0, age, 0);
1797 N_eq(sp, 1, age) = N_at_age(sp, 1, age, 0);
1816 Type init_log_scalar = init_level;
1818 init_log_scalar += rec_dev(sp, 0);
1824 if((initMode == 1) | (initMode == 2) | (initMode == 3) | (initMode == 5)){
1825 mort_sum(sp, age) = 0;
1826 for(
int age_tmp = 0; age_tmp < age; age_tmp++){
1827 mort_sum(sp, age) += M1_at_age(sp, sex, age_tmp, 0) + Finit(sp);
1835 mort_sum(sp, age) = 0;
1836 for(
int age_tmp = 0; age_tmp < age; age_tmp++){
1837 mort_sum(sp, age) += M1_at_age(sp, sex, age_tmp, 0)
1838 + Finit(sp) * sel_init(sp, sex, age_tmp);
1843 mort_sum(sp, age) = 0;
1844 for(
int age_tmp = 0; age_tmp < age; age_tmp++){
1845 mort_sum(sp, age) += M1_at_age(sp, sex, age_tmp, 0);
1847 mort_sum(sp, age) += Finit(sp);
1851 if((age > 0) & (age < nages(sp) - 1)) {
1854 N_at_age(sp, 0, age, 0) = R_init(sp) * exp( - mort_sum(sp, age) + init_dev(sp, age - 1) + init_log_scalar) * sex_ratio(sp, 0);
1855 N_eq(sp, 0, age) = R_init(sp) * exp( - mort_sum(sp, age) + init_log_scalar) * sex_ratio(sp, 0);
1858 N_at_age(sp, 1, age, 0) = R_init(sp) * exp( - mort_sum(sp, age) + init_dev(sp, age - 1) + init_log_scalar) * (1-sex_ratio(sp, 0));
1859 N_eq(sp, 1, age) = R_init(sp) * exp( - mort_sum(sp, age) + init_log_scalar) * (1-sex_ratio(sp, 0));
1864 if(age == (nages(sp) - 1)) {
1870 Type Z_plus = M1_at_age(sp, sex, nages(sp) - 1, 0) + Finit(sp) *
1871 ((initMode == 6) ? sel_init(sp, sex, nages(sp) - 1) : Type(1.0));
1872 Type plus_grp = 1 - exp(-Z_plus);
1875 N_at_age(sp, 0, age, 0) = R_init(sp) * exp( - mort_sum(sp, age) + init_dev(sp, age - 1) + init_log_scalar) / plus_grp * sex_ratio(sp, 0);
1876 N_eq(sp, 0, age) = R_init(sp) * exp( - mort_sum(sp, age) + init_log_scalar) / plus_grp * sex_ratio(sp, 0);
1880 N_at_age(sp, 1, age, 0) = R_init(sp) * exp( - mort_sum(sp, age) + init_dev(sp, age - 1) + init_log_scalar) / plus_grp * (1-sex_ratio(sp, 0));
1881 N_eq(sp, 1, age) = R_init(sp) * exp( - mort_sum(sp, age) + init_log_scalar) / plus_grp * (1-sex_ratio(sp, 0));
1889 N_at_age(sp, sex, age, 0) = pop_scalar(sp) * NByageFixed(sp, sex, age, 0);
1893 N_at_age(sp, sex, age, 0) = pop_scalar(sp) * NByageFixed(sp, sex, age, 0);
1897 error(
"Invalid 'estDynamics'");
1901 wt_idx_pop = 2 * sp;
1902 biomass_at_age(sp, sex, age, 0) = N_at_age(sp, sex, age, 0) * weight_hat( wt_idx_pop, sex, age, 0);
1903 biomass(sp, 0) += N_at_age(sp, sex, age, 0) * weight_hat( wt_idx_pop, sex, age, 0);
1907 wt_idx_ssb = 2 * sp + 1;
1908 ssb(sp, 0) += N_at_age(sp, 0, age, 0) * exp(-Z_at_age(sp, 0, age, 0) * spawn_month(sp)/12) * spawn_output(sp, age, 0);
1915 for(sp = 0; sp < nspp; sp++) {
1916 for(yr = 1; yr < nyrs_hind; yr++) {
1919 int srr_switch = srr_fun;
1920 if(yr >= nyrs_srrmean){
1921 srr_switch = srr_pred_fun;
1932 int spawn_yr = yr - minage(sp);
1933 int srr_use = (spawn_yr < 0) ? 0 : srr_switch;
1934 Type ssb_tmp = (spawn_yr < 0) ? Type(0.0) : ssb(sp, spawn_yr);
1937 Type rec_mean = (spawn_yr < 0) ? R_init(sp) : R0(sp, yr);
1939 R(sp, yr) =
calculate_recruitment(srr_use, rec_mean, ssb_tmp, alpha(sp, yr), Beta(sp, yr), rec_dev(sp, yr), SPR0(sp));
1942 if (rec_floor_on) { Type pen_R = 0; R(sp, yr) =
posfun(R(sp, yr), Type(1e-3), pen_R); zero_N_pen(sp) += pen_R; }
1944 N_at_age(sp, 0, 0, yr) = R(sp, yr) * sex_ratio(sp, 0);
1946 N_at_age(sp, 1, 0, yr) = R(sp, yr) * (1.0-sex_ratio(sp, 0));
1951 for(age = 0; age < nages(sp); age++){
1952 for(sex = 0; sex < nsex(sp); sex ++){
1954 switch(estDynamics(sp)){
1958 if(age < (nages(sp) - 1)) {
1959 N_at_age(sp, sex, age + 1, yr) = N_at_age(sp, sex, age, yr - 1) * exp(-Z_at_age(sp, sex, age, yr-1));
1963 if(age == (nages(sp) - 1)) {
1964 N_at_age(sp, sex, age, yr) = N_at_age(sp, sex, age - 1, yr - 1) * exp(-Z_at_age(sp, sex, age-1, yr-1)) + N_at_age(sp, sex, age, yr - 1) * exp(-Z_at_age(sp, sex, age, yr-1));
1969 N_at_age(sp, sex, age, yr) = pop_scalar(sp) * NByageFixed(sp, sex, age, yr);
1973 N_at_age(sp, sex, age, yr) = pop_scalar(sp) * NByageFixed(sp, sex, age, yr);
1977 error(
"Invalid 'estDynamics'");
1981 { Type pen_N = 0; N_at_age(sp, sex, age, yr) =
posfun(N_at_age(sp, sex, age, yr), Type(0.001), pen_N); zero_N_pen(sp) += pen_N; }
1984 wt_idx_pop = 2 * sp ;
1985 biomass_at_age(sp, sex, age, yr) = N_at_age(sp, sex, age, yr) * weight_hat( wt_idx_pop, sex, age, yr );
1986 biomass(sp, yr) += biomass_at_age(sp, sex, age, yr);
1990 wt_idx_ssb = 2 * sp + 1;
1991 ssb(sp, yr) += N_at_age(sp, 0, age, yr) * exp(-Z_at_age(sp, 0, age, yr) * spawn_month(sp)/12.0) * spawn_output(sp, age, yr);
2001 for(sp = 0; sp < nspp; sp++) {
2002 for(yr = 0; yr < nyrs_srrmean; yr++) {
2003 avg_R(sp) += R(sp, yr)/Type(nyrs_srrmean);
2010 N_at_age_dBF.setZero();
2011 N_at_age_dB0.setZero();
2015 DynamicB0.setZero();
2016 DynamicSB0.setZero();
2017 DynamicSBF.setZero();
2018 for(sp = 0; sp < nspp; sp++) {
2019 for(yr = 0; yr < nyrs; yr++) {
2024 for(sex = 0; sex < nsex(sp); sex ++){
2025 for(age = 0; age < nages(sp); age++){
2026 NByage0(sp, sex, age , 0) = NByageF(sp, sex, age , 0) = N_at_age_dBF(sp, sex, age, 0) = N_at_age_dB0(sp, sex, age, 0) = N_at_age(sp,sex,age,0);
2034 if((proj_mean_rec == 1) & (srr_pred_fun < 2)){
2036 NByage0(sp, 0, 0, yr) = avg_R(sp);
2037 NByageF(sp, 0, 0, yr) = avg_R(sp);
2044 N_at_age_dBF(sp, 0, 0, yr) = N_at_age_dB0(sp, 0, 0, yr) = R(sp, yr);
2046 if(yr >= nyrs_hind){
2047 N_at_age_dBF(sp, 0, 0, yr) = N_at_age_dB0(sp, 0, 0, yr) = exp(log(avg_R(sp)) + rec_dev(sp, yr));
2060 if((proj_mean_rec == 0) | (srr_pred_fun >= 2)){
2065 int rp_yr = yr - minage(sp);
2066 if(rp_yr < 0){ rp_yr = 0; }
2069 NByage0(sp, 0, 0, yr) =
calculate_recruitment(srr_pred_fun, R0(sp, yr), SB0(sp, rp_yr), alpha(sp, yr), Beta(sp, yr), Type(0.0), SPR0(sp));
2070 NByageF(sp, 0, 0, yr) =
calculate_recruitment(srr_pred_fun, R0(sp, yr), SBF(sp, rp_yr), alpha(sp, yr), Beta(sp, yr), Type(0.0), SPR0(sp));
2075 Type rdev = rec_dev(sp, yr);
2076 if(yr < minage(sp)){
2077 Type R_early = (yr < nyrs_hind) ? R(sp, yr) : R_init(sp) * exp(rdev);
2078 N_at_age_dB0(sp, 0, 0, yr) = R_early;
2079 N_at_age_dBF(sp, 0, 0, yr) = R_early;
2084 if((srr_fun != srr_pred_fun) & (yr < nyrs_srrmean)){
2085 Type R_curve =
calculate_recruitment(srr_pred_fun, R0(sp, yr), ssb(sp, rp_yr), alpha(sp, yr), Beta(sp, yr), Type(0.0), SPR0(sp));
2087 if (rec_floor_on) { Type pen_R = 0; R_curve =
posfun(R_curve, Type(1e-3), pen_R); zero_N_pen(sp) += pen_R; }
2088 rdev = log(R(sp, yr)) - log(R_curve);
2091 N_at_age_dB0(sp, 0, 0, yr) =
calculate_recruitment(srr_pred_fun, R0(sp, yr), DynamicSB0(sp, rp_yr), alpha(sp, yr), Beta(sp, yr), rdev, SPR0(sp));
2092 N_at_age_dBF(sp, 0, 0, yr) =
calculate_recruitment(srr_pred_fun, R0(sp, yr), DynamicSBF(sp, rp_yr), alpha(sp, yr), Beta(sp, yr), rdev, SPR0(sp));
2100 NByage0(sp, 0, 0, yr) = NByage0(sp, 0, 0, yr) * sex_ratio(sp, 0);
2101 NByageF(sp, 0, 0, yr) = NByageF(sp, 0, 0, yr) * sex_ratio(sp, 0);
2102 N_at_age_dB0(sp, 0, 0, yr) = N_at_age_dB0(sp, 0, 0, yr) * sex_ratio(sp, 0);
2103 N_at_age_dBF(sp, 0, 0, yr) = N_at_age_dBF(sp, 0, 0, yr) * sex_ratio(sp, 0);
2107 NByage0(sp, 1, 0, yr) = NByage0(sp, 0, 0, yr) / sex_ratio(sp, 0) * (1.0-sex_ratio(sp, 0));
2108 NByageF(sp, 1, 0, yr) = NByageF(sp, 0, 0, yr) / sex_ratio(sp, 0) * (1.0-sex_ratio(sp, 0));
2109 N_at_age_dB0(sp, 1, 0, yr) = N_at_age_dB0(sp, 0, 0, yr) / sex_ratio(sp, 0) * (1.0-sex_ratio(sp, 0));
2110 N_at_age_dBF(sp, 1, 0, yr) = N_at_age_dBF(sp, 0, 0, yr) / sex_ratio(sp, 0) * (1.0-sex_ratio(sp, 0));
2115 for(sex = 0; sex < nsex(sp); sex ++){
2116 for(age = 1; age < nages(sp)-1; age++) {
2117 NByage0(sp, sex, age, yr) = NByage0(sp, sex, age-1, yr-1) * exp(-M_at_age(sp, sex, age-1, yr-1));
2119 NByageF(sp, sex, age, yr) = NByageF(sp, sex, age-1, yr-1) * exp(-M_at_age(sp, sex, age-1, yr-1) - Ftarget_at_age(sp, sex, age-1, yr-1));
2124 N_at_age_dB0(sp, sex, age, yr) = N_at_age_dB0(sp, sex, age-1, yr-1) * exp(-M_at_age_dB0(sp, sex, age-1, yr - 1));
2126 N_at_age_dBF(sp, sex, age, yr) = N_at_age_dBF(sp, sex, age-1, yr-1) * exp(-M_at_age_dBF(sp, sex, age-1, yr - 1) - Ftarget_at_age(sp, sex, age-1, yr-1));
2130 NByage0(sp, sex, nages(sp)-1, yr) = NByage0(sp, sex, nages(sp)-2, yr - 1) * exp(-M_at_age(sp, sex, nages(sp)-2, yr - 1)) + NByage0(sp, sex, nages(sp)-1, yr - 1) * exp(-M_at_age(sp, sex, nages(sp)-1, yr - 1));
2132 NByageF(sp, sex, nages(sp)-1, yr) = NByageF(sp, sex, nages(sp)-2, yr - 1) * exp(-M_at_age(sp, sex, nages(sp)-2, yr - 1) - Ftarget_at_age(sp, sex, nages(sp)-2, yr-1)) + NByageF(sp, sex, nages(sp)-1, yr - 1) * exp(-M_at_age(sp, sex, nages(sp)-1, yr - 1) - Ftarget_at_age(sp, sex, nages(sp)-1, yr-1));
2134 N_at_age_dB0(sp, sex, nages(sp)-1, yr) = N_at_age_dB0(sp, sex, nages(sp)-2, yr - 1) * exp(-M_at_age_dB0(sp, sex, nages(sp)-2, yr - 1)) + N_at_age_dB0(sp, sex, nages(sp)-1, yr - 1) * exp(-M_at_age_dB0(sp, sex, nages(sp)-1, yr - 1));
2136 N_at_age_dBF(sp, sex, nages(sp)-1, yr) = N_at_age_dBF(sp, sex, nages(sp)-2, yr - 1) * exp(-M_at_age_dBF(sp, sex, nages(sp)-2, yr - 1) - Ftarget_at_age(sp, sex, nages(sp)-2, yr-1)) + N_at_age_dBF(sp, sex, nages(sp)-1, yr - 1) * exp(-M_at_age_dBF(sp, sex, nages(sp)-1, yr - 1) - Ftarget_at_age(sp, sex, nages(sp)-1, yr-1));
2143 if(estDynamics(sp) > 0){
2144 for(sex = 0; sex < nsex(sp); sex ++){
2145 for(age = 0; age < nages(sp); age++){
2146 Type n_fixed = (yr < nyrs_hind) ? N_at_age(sp, sex, age, yr) :
2147 pop_scalar(sp) * NByageFixed(sp, sex, age, yr);
2148 N_at_age_dB0(sp, sex, age, yr) = n_fixed;
2149 N_at_age_dBF(sp, sex, age, yr) = n_fixed;
2156 for(age = 0; age < nages(sp); age++) {
2158 wt_idx_ssb = 2 * sp + 1;
2162 SB0(sp, yr) += NByage0(sp, 0, age, yr) * spawn_output(sp, age, nyrs_hind - 1) * exp(-M_at_age(sp, 0, age, yr) * spawn_month(sp)/12.0);
2163 SBF(sp, yr) += NByageF(sp, 0, age, yr) * spawn_output(sp, age, nyrs_hind - 1) * exp(-(M_at_age(sp, 0, age, yr) + Ftarget_at_age(sp, 0, age, yr)) * spawn_month(sp)/12.0);
2164 DynamicSB0(sp, yr) += N_at_age_dB0(sp, 0, age, yr) * spawn_output(sp, age, yr) * exp(-M_at_age_dB0(sp, 0, age, yr) * spawn_month(sp)/12.0);
2165 DynamicSBF(sp, yr) += N_at_age_dBF(sp, 0, age, yr) * spawn_output(sp, age, yr) * exp(-(M_at_age_dBF(sp, 0, age, yr) + Ftarget_at_age(sp, 0, age, yr)) * spawn_month(sp)/12.0);
2167 for(sex = 0; sex < nsex(sp); sex ++){
2169 wt_idx_pop = 2 * sp;
2170 B0(sp, yr) += NByage0(sp, sex, age, yr) * weight_hat( wt_idx_pop, sex, age, nyrs_hind - 1 );
2171 DynamicB0(sp, yr) += N_at_age_dB0(sp, sex,age, yr) * weight_hat( wt_idx_pop, sex, age, yr );
2178 SB0(sp, yr) = MSSB0(sp);
2179 B0(sp, yr) = MSB0(sp);
2186 for(sp = 0; sp < nspp; sp++) {
2187 for(yr = nyrs_hind; yr < nyrs; yr++){
2191 Type ref_SB0 = (DynamicHCR == 1) ? DynamicSB0(sp, yr-1) : SB0(sp, nyrs-1);
2192 Type ref_SBF = (DynamicHCR == 1) ? DynamicSBF(sp, yr-1) : SBF(sp, nyrs-1);
2196 proj_F(sp, yr) = 0.0;
2216 if(ssb(sp, yr-1) < ref_SBF){
2217 proj_F(sp, yr) = Ftarget(sp) * (((ssb(sp, yr-1)/ref_SBF)-Alpha(sp))/(1-Alpha(sp)));
2219 if((ssb(sp, nyrs_hind-1) < ref_SB0 * Plimit(sp)) || (ssb(sp, yr-1) / ref_SBF < Alpha(sp))){
2220 proj_F(sp, yr) = 0.0;
2225 if(ssb(sp, yr-1) < ref_SB0 * Ptarget(sp)){
2226 proj_F(sp, yr) = (Flimit(sp) + QnormHCR(sp)) * (ref_SB0 * Ptarget(sp) * (ssb(sp, yr-1) - ref_SB0 * Plimit(sp))) / (ssb(sp, yr-1) * (ref_SB0 * (Ptarget(sp) - Plimit(sp))));
2228 if(ssb(sp, yr-1) < ref_SB0 * Plimit(sp)){
2229 proj_F(sp, yr) = 0.0;
2234 if(ssb(sp, yr-1) < ref_SB0 * Ptarget(sp)){
2235 proj_F(sp, yr) = Ftarget(sp) * ((ssb(sp, yr-1)/(ref_SB0 * Plimit(sp)))-1);
2237 if(ssb(sp, yr-1) < ref_SB0 * Plimit(sp)){
2238 proj_F(sp, yr) = 0.0;
2245 if((forecast(sp) == 0) | (estDynamics(sp) > 0)){
2246 proj_F(sp, yr) = 0.0;
2250 for(age = 0; age < nages(sp); age++) {
2251 for(sex = 0; sex < nsex(sp); sex ++){
2252 F_at_age(sp, sex, age, yr) = 0.0;
2257 F_spp(sp, yr) = proj_F(sp, yr);
2258 for(flt = 0; flt < n_flt; flt++) {
2259 if((sp == flt_spp(flt)) & (flt_type(flt) == 1)){
2260 F_flt(flt, yr) = proj_F_prop(flt) * proj_F(sp, yr);
2261 for(age = 0; age < nages(sp); age++) {
2262 for(sex = 0; sex < nsex(sp); sex ++){
2263 F_flt_age(flt, sex, age, yr) = sel_at_age(flt, sex, age, nyrs_hind - 1) * proj_F_prop(flt) * proj_F(sp, yr);
2264 if(flt_type(flt) == 1){
2265 F_at_age(sp, sex, age, yr) += F_flt_age(flt, sex, age, yr);
2274 for(age = 0; age < nages(sp); age++) {
2275 for(sex = 0; sex < nsex(sp); sex ++){
2276 M_at_age(sp, sex, age, yr) = M1_at_age(sp, sex, age, yr) + M2_at_age(sp, sex, age, yr);
2277 Z_at_age(sp, sex, age, yr) = M1_at_age(sp, sex, age, yr) + F_at_age(sp, sex, age, yr) + M2_at_age(sp, sex, age, yr);
2285 if(proj_mean_rec == 1){
2286 R(sp, yr) = avg_R(sp);
2290 if(proj_mean_rec == 0){
2295 int proj_spawn_yr = yr - minage(sp);
2296 int proj_srr_use = (proj_spawn_yr < 0) ? 0 : srr_pred_fun;
2297 Type ssb_tmp = (proj_spawn_yr < 0) ? Type(0.0) : ssb(sp, proj_spawn_yr);
2298 Type proj_rec_mean = (proj_spawn_yr < 0) ? R_init(sp) : R0(sp, yr);
2300 R(sp, yr) =
calculate_recruitment(proj_srr_use, proj_rec_mean, ssb_tmp, alpha(sp, yr), Beta(sp, yr), rec_dev(sp, yr), SPR0(sp));
2303 N_at_age(sp, 0, 0 , yr) = R(sp, yr) * sex_ratio(sp, 0);
2305 N_at_age(sp, 1, 0 , yr) = R(sp, yr) * (1 - sex_ratio(sp, 0));
2310 for(age = 0; age < nages(sp); age++) {
2311 for(sex = 0; sex < nsex(sp); sex ++){
2312 switch(estDynamics(sp)){
2316 if(age < (nages(sp) - 1)) {
2317 N_at_age(sp, sex, age + 1, yr) = N_at_age(sp, sex, age, yr - 1) * exp(-Z_at_age(sp, sex, age, yr-1));
2321 if(age == (nages(sp) - 1)) {
2322 N_at_age(sp, sex, age, yr) = N_at_age(sp, sex, age - 1, yr - 1) * exp(-Z_at_age(sp, sex, age-1, yr-1)) + N_at_age(sp, sex, age, yr - 1) * exp(-Z_at_age(sp, sex, age, yr-1));
2327 N_at_age(sp, sex, age, yr) = pop_scalar(sp) * NByageFixed(sp, sex, age, yr);
2331 N_at_age(sp, sex, age, yr) = pop_scalar(sp) * NByageFixed(sp, sex, age, yr);
2335 error(
"Invalid 'estDynamics'");
2339 wt_idx_pop = 2 * sp;
2340 biomass_at_age(sp, sex, age, yr) = N_at_age(sp, sex, age, yr) * weight_hat( wt_idx_pop, sex, age, nyrs_hind-1 );
2341 biomass(sp, yr) += biomass_at_age(sp, sex, age, yr);
2345 wt_idx_ssb = 2 * sp + 1;
2346 ssb(sp, yr) += N_at_age(sp, 0, age, yr) * exp(-Z_at_age(sp, 0, age, yr) * spawn_month(sp)/12.0) * spawn_output(sp, age, nyrs_hind-1);
2357 const int first_yr = 0;
2358 if (R0.cols() != nyrs || alpha.cols() != nyrs || Beta.cols() != nyrs) {
2359 error(
"Section 6.9: R0/alpha/Beta column count does not equal nyrs; "
2360 "recruitment-parameter matrices were sized inconsistently.");
2362 for(sp = 0; sp < nspp; sp++) {
2367 if((msmMode > 0) & (srr_pred_fun > 1)){
2368 R_hat(sp, first_yr) = R_init(sp);
2370 switch(srr_pred_fun){
2372 R_hat(sp, first_yr) = R0(sp, first_yr);
2376 R_hat(sp, first_yr) = R0(sp, first_yr);
2380 R_hat(sp, first_yr) = (alpha(sp, first_yr) - 1/SPRFinit(sp)) / Beta(sp, first_yr);
2384 R_hat(sp, first_yr) = (alpha(sp, first_yr) - 1/SPRFinit(sp)) / Beta(sp, first_yr);
2388 { Type aS = alpha(sp, first_yr) * SPRFinit(sp);
2389 if (rec_floor_on) { Type pen_d = 0; aS =
posfun(aS, Type(1e-3), pen_d); }
2390 R_hat(sp, first_yr) = log(aS) / (Beta(sp, first_yr) * SPRFinit(sp)/1000000.0); }
2394 { Type aS = alpha(sp, first_yr) * SPRFinit(sp);
2395 if (rec_floor_on) { Type pen_d = 0; aS =
posfun(aS, Type(1e-3), pen_d); }
2396 R_hat(sp, first_yr) = log(aS) / (Beta(sp, first_yr) * SPRFinit(sp)/1000000.0); }
2399 error(
"Invalid 'srr_pred_fun'");
2403 if (rec_floor_on) { Type pen_R = 0; R_hat(sp, first_yr) =
posfun(R_hat(sp, first_yr), Type(1e-3), pen_R); zero_N_pen(sp) += pen_R; }
2406 for(yr = 1; yr < nyrs; yr++){
2417 int hat_spawn_yr = yr - minage(sp);
2418 int hat_srr_use = (hat_spawn_yr < 0) ? 0 : srr_pred_fun;
2419 Type ssb_tmp = (hat_spawn_yr < 0) ? Type(0.0) : ssb(sp, hat_spawn_yr);
2420 Type hat_rec_mean = (hat_spawn_yr < 0) ? R_init(sp) : R0(sp, yr);
2423 R_hat(sp, yr) =
calculate_recruitment(hat_srr_use, hat_rec_mean, ssb_tmp, alpha(sp, yr), Beta(sp, yr), Type(0.0), SPR0(sp));
2425 if (rec_floor_on) { Type pen_R = 0; R_hat(sp, yr) =
posfun(R_hat(sp, yr), Type(1e-3), pen_R); zero_N_pen(sp) += pen_R; }
2432 for(sp = 0; sp < nspp; sp++) {
2433 for(sex = 0; sex < nsex(sp); sex ++){
2434 for(age = 0; age < nages(sp); age++) {
2435 for(yr = 0; yr < nyrs; yr++) {
2437 avgN_at_age(sp, sex, age, yr) = N_at_age(sp, sex, age, yr) * (1 - exp(-Z_at_age(sp, sex, age, yr))) / Z_at_age(sp, sex, age, yr);
2438 avgN_at_age_dB0(sp, sex, age, yr) = N_at_age_dB0(sp, sex, age, yr) * (1 - exp(-M_at_age_dB0(sp, sex, age, yr))) / M_at_age_dB0(sp, sex, age, yr);
2439 avgN_at_age_dBF(sp, sex, age, yr) = N_at_age_dBF(sp, sex, age, yr) * (1 - exp(-M_at_age_dBF(sp, sex, age, yr) - Ftarget_at_age(sp, sex, age, yr))) / (M_at_age_dBF(sp, sex, age, yr) + Ftarget_at_age(sp, sex, age, yr));
2457 nspp, nyrs, suit_styr, suit_endyr, nyrs_suit, msmMode,
2458 nsex, nages, suitMode, diet_prop, avgN_at_age, weight_hat, other_food_diet_prop);
2462 if((msmMode == 1) | (msmMode == 2)) {
2464 M2_at_age, M2_at_age_dB0, M2_at_age_dBF, M2_prop,
2465 B_eaten, B_eaten_as_prey, diet_prop_hat, other_diet_prop_hat,
2466 nspp, nyrs, nsex, nages, msmMode,
2467 avgN_at_age, avgN_at_age_dB0, avgN_at_age_dBF,
2468 suitability, suit_other, weight_hat, consumption_at_age, other_food);
2480 for(index_ind = 0; index_ind < index_ctl.rows(); index_ind++){
2482 index = index_ctl(index_ind, 0) - 1;
2483 sp = index_ctl(index_ind, 1) - 1;
2484 flt_yr = index_ctl(index_ind, 2);
2485 wt_idx_flt = nspp * 2 + index;
2486 mo = index_n(index_ind, 0);
2488 index_hat(index_ind) = 0.0;
2491 flt_yr = flt_yr - styr;
2493 else if(flt_yr < 0){
2494 flt_yr = -flt_yr - styr;
2497 for(age = 0; age < nages(sp); age++) {
2498 for(sex = 0; sex < nsex(sp); sex++){
2514 if(flt_type(index) == 1){
2515 n_index = N_at_age(sp, sex, age, flt_yr) * (1.0 - exp( - Z_at_age(sp, sex, age, flt_yr))) / Z_at_age(sp, sex, age, flt_yr);
2517 n_index = N_at_age(sp, sex, age, flt_yr) * exp( - (mo/12.0) * Z_at_age(sp, sex, age, flt_yr));
2521 if(flt_units(index) == 1){
2522 index_hat(index_ind) += n_index * sel_at_age(index, sex, age, flt_yr) * weight_hat(wt_idx_flt, sex, age, flt_yr );
2525 if(flt_units(index) == 2){
2526 index_hat(index_ind) += n_index * sel_at_age(index, sex, age, flt_yr);
2534 index_n_obs.setZero();
2535 index_q_analytical.setZero();
2536 for(index_ind = 0; index_ind < index_ctl.rows(); index_ind++){
2540 index = index_ctl(index_ind, 0) - 1;
2541 sp = index_ctl(index_ind, 1) - 1;
2542 flt_yr = index_ctl(index_ind, 2);
2545 flt_yr = flt_yr - styr;
2548 mo = index_n(index_ind, 0);
2549 if(flt_yr < nyrs_hind){
2552 if(est_sigma_index(index) > 0) {
2553 index_n_obs(index) += 1;
2554 index_q_analytical(index) += log(index_obs(index_ind, 0) / index_hat(index_ind));
2558 if(est_sigma_index(index) == 0 ) {
2559 index_n_obs(index) += 1 /
square(index_obs(index_ind, 1));
2560 index_q_analytical(index) += log(index_obs(index_ind, 0) / index_hat(index_ind)) /
square(index_obs(index_ind, 1));
2567 for(index = 0 ; index < n_flt; index ++){
2568 index_q_analytical(index) = exp(index_q_analytical(index) / index_n_obs(index));
2571 if(est_index_q(index) == 3){
2572 for(yr = 0; yr < nyrs_hind; yr++){
2573 index_q(index, yr) = index_q_analytical(index);
2584 vector<Type> index_obs_sum(n_flt); index_obs_sum.setZero();
2585 vector<Type> index_hat_sum(n_flt); index_hat_sum.setZero();
2586 for(index_ind = 0; index_ind < index_ctl.rows(); index_ind++){
2587 index = index_ctl(index_ind, 0) - 1;
2588 flt_yr = index_ctl(index_ind, 2);
2590 flt_yr = flt_yr - styr;
2591 if(flt_yr < nyrs_hind){
2592 index_obs_sum(index) += index_obs(index_ind, 0);
2593 index_hat_sum(index) += index_hat(index_ind);
2597 for(index = 0; index < n_flt; index++){
2598 if(est_index_q(index) == 7){
2599 Type q_arith = index_obs_sum(index) / index_hat_sum(index);
2600 for(yr = 0; yr < nyrs_hind; yr++){
2601 index_q(index, yr) = q_arith;
2608 for(index_ind = 0; index_ind < index_ctl.rows(); index_ind++){
2610 index = index_ctl(index_ind, 0) - 1;
2611 flt_yr = index_ctl(index_ind, 2);
2614 flt_yr = flt_yr - styr;
2616 else if(flt_yr < 0){
2617 flt_yr = -flt_yr - styr;
2621 int yr_ind = (flt_yr < nyrs_hind) ? flt_yr : (nyrs_hind - 1);
2623 index_hat(index_ind) = index_q(index, yr_ind) * index_hat(index_ind);
2631 index_n_obs.setZero();
2632 index_analytical_sd.setZero();
2633 for(index_ind = 0; index_ind < index_ctl.rows(); index_ind++){
2635 index = index_ctl(index_ind, 0) - 1;
2636 flt_yr = index_ctl(index_ind, 2);
2639 flt_yr = flt_yr - styr;
2641 if((flt_yr < nyrs_hind) && (index_obs(index_ind, 0) > 0)){
2642 index_n_obs(index) += 1;
2643 index_analytical_sd(index) +=
square( log(index_obs(index_ind, 0)) - log(index_hat(index_ind)));
2648 for(index = 0 ; index < n_flt; index ++){
2649 if(index_n_obs(index) > 0){
2650 index_analytical_sd(index) =
concentrated_lognormal_sd(index_analytical_sd(index) / index_n_obs(index), bias_adjust_obs);
2659 for(fsh_ind = 0; fsh_ind < catch_ctl.rows(); fsh_ind++){
2661 flt = catch_ctl(fsh_ind, 0) - 1;
2662 sp = catch_ctl(fsh_ind, 1) - 1;
2663 flt_yr = catch_ctl(fsh_ind, 2);
2664 mo = catch_n(fsh_ind, 0);
2665 wt_idx_flt = nspp * 2 + flt;
2667 catch_hat(fsh_ind) = 0.0;
2668 max_catch_hat(fsh_ind) = 0.0;
2671 flt_yr = flt_yr - styr;
2673 else if(flt_yr < 0){
2674 flt_yr = -flt_yr - styr;
2677 for(sex = 0; sex < nsex(sp); sex ++){
2678 for(age = 0; age < nages(sp); age++) {
2681 if(flt_units(flt) == 1){
2682 catch_hat(fsh_ind) += F_flt_age(flt, sex, age, flt_yr) / Z_at_age(sp, sex, age, flt_yr) * (1.0 - exp(-Z_at_age(sp, sex, age, flt_yr))) * N_at_age(sp, sex, age, flt_yr) * weight_hat( wt_idx_flt, sex, age, flt_yr );
2683 max_catch_hat(fsh_ind) += N_at_age(sp, sex, age, flt_yr) * weight_hat( wt_idx_flt, sex, age, flt_yr ) * sel_at_age(flt, sex, age, flt_yr) * proj_F_prop(flt);
2687 if(flt_units(flt) == 2){
2688 catch_hat(fsh_ind) += F_flt_age(flt, sex, age, flt_yr) / Z_at_age(sp, sex, age, flt_yr) * (1.0 - exp(-Z_at_age(sp, sex, age, flt_yr))) * N_at_age(sp, sex, age, flt_yr);
2689 max_catch_hat(fsh_ind) += N_at_age(sp, sex, age, flt_yr) * sel_at_age(flt, sex, age, flt_yr) * proj_F_prop(flt);
2703 vector<Type> equil_catch_hat(equil_catch_ctl.rows()); equil_catch_hat.setZero();
2704 for(
int eq_ind = 0; eq_ind < equil_catch_ctl.rows(); eq_ind++){
2705 flt = equil_catch_ctl(eq_ind, 0) - 1;
2706 sp = equil_catch_ctl(eq_ind, 1) - 1;
2707 wt_idx_flt = nspp * 2 + flt;
2708 for(sex = 0; sex < nsex(sp); sex++){
2709 for(age = 0; age < nages(sp); age++){
2710 Type s_a = sel_at_age(flt, sex, age, 0);
2711 Type Z_a = M1_at_age(sp, sex, age, 0) + Finit(sp) * s_a;
2712 Type baranov = Finit(sp) * s_a / Z_a * (1.0 - exp(-Z_a)) * N_eq(sp, sex, age);
2713 if(flt_units(flt) == 1){
2714 equil_catch_hat(eq_ind) += baranov * weight_hat( wt_idx_flt, sex, age, 0 );
2716 if(flt_units(flt) == 2){
2717 equil_catch_hat(eq_ind) += baranov;
2734 catch_n_obs.setZero();
2735 catch_analytical_sd.setZero();
2736 for(fsh_ind = 0; fsh_ind < catch_ctl.rows(); fsh_ind++){
2738 flt = catch_ctl(fsh_ind, 0) - 1;
2739 flt_yr = catch_ctl(fsh_ind, 2);
2741 if((flt_yr > 0) && (flt_yr <= endyr) && (flt_type(flt) == 1) && (catch_obs(fsh_ind, 0) > 0)){
2742 catch_n_obs(flt) += 1;
2743 catch_analytical_sd(flt) +=
square( log(catch_obs(fsh_ind, 0)) - log(catch_hat(fsh_ind)) );
2747 for(flt = 0; flt < n_flt; flt++){
2748 if(catch_n_obs(flt) > 0){
2755 exploitable_biomass.setZero();
2757 for(flt = 0; flt < n_flt; flt++) {
2760 wt_idx_flt = nspp * 2 + flt;
2762 if(flt_type(flt) == 1){
2763 for(yr = 0; yr < nyrs; yr++) {
2764 for(age = 0; age < nages(sp); age++) {
2765 for(sex = 0; sex < nsex(sp); sex ++){
2766 exploitable_biomass(sp, yr) += N_at_age(sp, sex, age, yr) * weight_hat( wt_idx_flt, sex, age, yr ) * sel_at_age(flt, sex, age, yr) * proj_F_prop(flt);
2780 age_obs_hat.setZero();
2782 for(comp_ind = 0; comp_ind < comp_hat.rows(); comp_ind++){
2784 flt = comp_ctl(comp_ind, 0) - 1;
2785 sp = comp_ctl(comp_ind, 1) - 1;
2786 flt_sex = comp_ctl(comp_ind, 2);
2787 comp_type = comp_ctl(comp_ind, 3);
2788 yr = comp_ctl(comp_ind, 4);
2789 mo = (growth_model(sp) > 0) ? flt_month(flt) : comp_n(comp_ind, 0);
2790 int wtind = nspp * 2 + flt;
2791 n_hat(comp_ind) = 0.0;
2805 Frate = exp(log_F(flt, yr));
2809 if(yr >= nyrs_hind){
2810 yr_ind = nyrs_hind - 1;
2811 Frate = proj_F_prop(flt) * proj_F(sp, yr);
2815 if(growth_model(sp) > 0){
2816 for(age = 0; age < nages(sp); age++) {
2817 for(ln = 0; ln < nlengths(sp); ln++) {
2818 for(sex = 0; sex < nsex(sp); sex ++){
2820 switch(flt_type(flt)){
2822 if(flt_sel_dim(flt) == 1){
2826 for(
int lp = pop_bin_lo(sp, ln); lp <= pop_bin_hi(sp, ln); lp++){
2827 ps_ln += sel_at_length(flt, sex, lp, yr) * growth_matrix(wtind, sex, age, lp, yr);
2829 pred_CAAL(flt, sex, age, ln, yr) = ps_ln * (Frate / Z_at_age(sp, sex, age, yr) * (1 - exp(-Z_at_age(sp, sex, age, yr))) * N_at_age(sp, sex, age, yr));
2836 if(flt_sel_dim(flt) == 1){
2840 for(
int lp = pop_bin_lo(sp, ln); lp <= pop_bin_hi(sp, ln); lp++){
2841 ps_ln += sel_at_length(flt, sex, lp, yr) * growth_matrix(wtind, sex, age, lp, yr);
2843 pred_CAAL(flt, sex, age, ln, yr) = ps_ln * (N_at_age(sp, sex, age, yr) * index_q(flt, yr_ind) * exp( - Type(mo/12.0) * Z_at_age(sp, sex, age, yr)));
2853 for(age = 0; age < nages(sp); age++) {
2854 for(ln = 0; ln < nlengths(sp); ln++) {
2861 for(sex = 0; sex < nsex(sp); sex ++){
2862 age_hat(comp_ind, age ) += pred_CAAL(flt, sex, age, ln, yr);
2868 age_hat(comp_ind, age ) += pred_CAAL(flt, sex, age, ln, yr);
2872 for(sex = 0; sex < nsex(sp); sex ++){
2873 age_hat(comp_ind, age + nages(sp) * sex ) += pred_CAAL(flt, sex, age, ln, yr);
2885 for(sex = 0; sex < nsex(sp); sex ++){
2886 comp_hat(comp_ind, ln ) += pred_CAAL(flt, sex, age, ln, yr);
2892 comp_hat(comp_ind, ln ) += pred_CAAL(flt, sex, age, ln, yr);
2896 for(sex = 0; sex < nsex(sp); sex ++){
2897 comp_hat(comp_ind, ln + nlengths(sp) * sex ) += pred_CAAL(flt, sex, age, ln, yr) ;
2906 for(
int obs_age = 0; obs_age < nages(sp); obs_age++) {
2907 for(
int true_age = 0; true_age < nages(sp); true_age++) {
2908 age_obs_hat(comp_ind, obs_age) += age_hat(comp_ind, true_age ) * age_error(flt_ageing_error_index(flt), true_age, obs_age);
2914 for(
int obs_age = nages(sp); obs_age < nages(sp) * 2; obs_age++) {
2915 for(
int true_age = nages(sp); true_age < nages(sp) * 2; true_age++) {
2918 int true_age_tmp = true_age - nages(sp);
2919 int obs_age_tmp = obs_age - nages(sp);
2921 age_obs_hat(comp_ind, obs_age) += age_hat(comp_ind, true_age ) * age_error(flt_ageing_error_index(flt), true_age_tmp, obs_age_tmp);
2927 if( comp_type == 0) {
2928 joint_adjust(comp_ind) = 1;
2930 joint_adjust(comp_ind) = 2;
2932 for(age = 0; age < nages(sp) * joint_adjust(comp_ind); age++) {
2933 comp_hat(comp_ind, age ) = age_obs_hat(comp_ind, age );
2940 if(growth_model(sp) == 0){
2941 for(age = 0; age < nages(sp); age++) {
2943 switch(flt_type(flt)){
2947 for(sex = 0; sex < nsex(sp); sex ++){
2949 age_hat(comp_ind, age ) += F_flt_age(flt, sex, age, yr) / Z_at_age(sp, sex, age, yr) * (1 - exp(-Z_at_age(sp, sex, age, yr))) * N_at_age(sp, sex, age, yr);
2956 age_hat(comp_ind, age ) = F_flt_age(flt, sex, age, yr) / Z_at_age(sp, sex, age, yr) * (1 - exp(-Z_at_age(sp, sex, age, yr))) * N_at_age(sp, sex, age, yr);
2960 for(sex = 0; sex < nsex(sp); sex ++){
2962 age_hat(comp_ind, age + nages(sp) * sex ) = F_flt_age(flt, sex, age, yr) / Z_at_age(sp, sex, age, yr) * (1 - exp(-Z_at_age(sp, sex, age, yr))) * N_at_age(sp, sex, age, yr);
2972 for(sex = 0; sex < nsex(sp); sex ++){
2974 age_hat(comp_ind, age ) += N_at_age(sp, sex, age, yr) * sel_at_age(flt, sex, age, yr) * index_q(flt, yr_ind) * exp( - Type(mo/12.0) * Z_at_age(sp, sex, age, yr));
2981 age_hat(comp_ind, age ) = N_at_age(sp, sex, age, yr) * sel_at_age(flt, sex, age, yr) * index_q(flt, yr_ind) * exp( - Type(mo/12.0) * Z_at_age(sp, sex, age, yr));
2985 for(sex = 0; sex < nsex(sp); sex ++){
2987 age_hat(comp_ind, age + nages(sp) * sex ) = N_at_age(sp, sex, age, yr) * sel_at_age(flt, sex, age, yr) * index_q(flt, yr_ind) * exp( - Type(mo/12.0) * Z_at_age(sp, sex, age, yr));
2996 for(
int obs_age = 0; obs_age < nages(sp); obs_age++) {
2997 for(
int true_age = 0; true_age < nages(sp); true_age++) {
2998 age_obs_hat(comp_ind, obs_age) += age_hat(comp_ind, true_age ) * age_error(flt_ageing_error_index(flt), true_age, obs_age);
3004 for(
int obs_age = nages(sp); obs_age < nages(sp) * 2; obs_age++) {
3005 for(
int true_age = nages(sp); true_age < nages(sp) * 2; true_age++) {
3008 int true_age_tmp = true_age - nages(sp);
3009 int obs_age_tmp = obs_age - nages(sp);
3011 age_obs_hat(comp_ind, obs_age) += age_hat(comp_ind, true_age ) * age_error(flt_ageing_error_index(flt), true_age_tmp, obs_age_tmp);
3017 if( comp_type == 0) {
3018 joint_adjust(comp_ind) = 1;
3020 joint_adjust(comp_ind) = 2;
3022 for(age = 0; age < nages(sp) * joint_adjust(comp_ind); age++) {
3023 comp_hat(comp_ind, age ) = age_obs_hat(comp_ind, age );
3031 if( comp_type == 1) {
3032 for(ln = 0; ln < nlengths(sp); ln++) {
3033 for(age = 0; age < nages(sp); age++) {
3038 if((flt_sex > 0) & (flt_sex < 3)){
3041 comp_hat(comp_ind, ln ) += age_hat(comp_ind, age) * age_trans_matrix(flt_age_transition_index(flt), sex, age, ln );
3048 for(ln = nlengths(sp); ln < nlengths(sp) * 2; ln++) {
3049 for(age = nages(sp); age < nages(sp) * 2; age++) {
3052 int obs_log_tmp = ln;
3053 int obs_age_tmp = age;
3055 obs_age_tmp = age - nages(sp);
3056 obs_log_tmp = ln - nlengths(sp);
3059 comp_hat(comp_ind, ln ) += age_hat(comp_ind, age) * age_trans_matrix(flt_age_transition_index(flt), sex, obs_age_tmp, obs_log_tmp );
3068 comp_hat.row(comp_ind) /=
posfun(comp_hat.row(comp_ind).sum(), Type(0.001), penalty);
3076 for(
int caal_ind = 0; caal_ind < caal_hat.rows(); caal_ind++){
3078 flt = caal_ctl(caal_ind, 0) - 1;
3079 sp = caal_ctl(caal_ind, 1) - 1;
3080 flt_sex = caal_ctl(caal_ind, 2);
3081 yr = caal_ctl(caal_ind, 3);
3082 ln = caal_ctl(caal_ind, 4) - 1;
3083 mo = flt_month(flt);
3085 if(growth_model(sp) == 0)
continue;
3093 int wtind = nspp * 2 + flt;
3106 Frate = exp(log_F(flt, yr));
3110 if(yr >= nyrs_hind){
3111 yr_ind = nyrs_hind - 1;
3112 Frate = proj_F_prop(flt) * proj_F(sp, yr);
3116 for(age = 0; age < nages(sp); age++) {
3118 switch(flt_type(flt)){
3120 if(flt_sel_dim(flt) == 1){
3124 for(
int lp = pop_bin_lo(sp, ln); lp <= pop_bin_hi(sp, ln); lp++){
3125 ps_ln += sel_at_length(flt, sex, lp, yr) * growth_matrix(wtind, sex, age, lp, yr);
3127 pred_CAAL(flt, sex, age, ln, yr) = ps_ln * (Frate / Z_at_age(sp, sex, age, yr) * (1 - exp(-Z_at_age(sp, sex, age, yr))) * N_at_age(sp, sex, age, yr));
3134 if(flt_sel_dim(flt) == 1){
3138 for(
int lp = pop_bin_lo(sp, ln); lp <= pop_bin_hi(sp, ln); lp++){
3139 ps_ln += sel_at_length(flt, sex, lp, yr) * growth_matrix(wtind, sex, age, lp, yr);
3141 pred_CAAL(flt, sex, age, ln, yr) = ps_ln * (N_at_age(sp, sex, age, yr) * index_q(flt, yr_ind) * exp( - Type(mo/12.0) * Z_at_age(sp, sex, age, yr)) );
3149 for(
int obs_age = 0; obs_age < nages(sp); obs_age++) {
3150 for(
int true_age = 0; true_age < nages(sp); true_age++) {
3151 caal_hat(caal_ind, obs_age) += pred_CAAL(flt, sex, true_age, ln, yr) * age_error(flt_ageing_error_index(flt), true_age, obs_age);
3157 caal_hat.row(caal_ind) /=
posfun(caal_hat.row(caal_ind).sum(), Type(0.0001), penalty);
3168 if((msmMode > 2) || (
imax(suitMode) > 0)) {
3170 minage, nsex, nages, diet_obs, diet_ctl,
3171 avgN_at_age, diet_prop_hat, diet_hat);
3181 biomass_depletion.setZero();
3182 ssb_depletion.setZero();
3183 for(sp = 0; sp < nspp; sp++){
3184 for(yr = 0; yr < nyrs; yr++){
3186 if(DynamicHCR == 0){
3187 biomass_depletion(sp, yr) = biomass(sp, yr)/B0(sp, nyrs-1);
3188 ssb_depletion(sp, yr) = ssb(sp, yr)/SB0(sp, nyrs-1);
3191 if(DynamicHCR == 1){
3192 biomass_depletion(sp, yr) = biomass(sp, yr)/DynamicB0(sp, yr);
3193 ssb_depletion(sp, yr) = ssb(sp, yr)/DynamicSB0(sp, yr);
3200 if((HCR == 0) & (msmMode > 0) & (DynamicHCR == 0)){
3201 biomass_depletion(sp, yr) = biomass(sp, yr)/biomass(sp, nyrs-1);
3202 ssb_depletion(sp, yr) = ssb(sp, yr)/ssb(sp, nyrs-1);
3222 int n_col = std::max(n_flt, nspp);
3230 JNLL_SEL_NONPARAM = 4,
3237 JNLL_SRR_PENALTY = 11,
3238 JNLL_REFPT_PENALTY = 12,
3239 JNLL_ZERO_N_PENALTY = 13,
3243 JNLL_RATION_PENALTY = 17,
3245 JNLL_LINKAGE_PRIOR = 19,
3246 JNLL_LINKAGE_RE = 20,
3247 JNLL_EQUIL_CATCH = 21,
3250 matrix<Type> jnll_comp(JNLL_N_ROWS, n_col); jnll_comp.setZero();
3251 matrix<Type> unweighted_jnll_comp(JNLL_N_ROWS, n_col); unweighted_jnll_comp.setZero();
3262 Type index_std_dev = 0;
3263 for(index_ind = 0; index_ind < index_obs.rows(); index_ind++) {
3265 index = index_ctl(index_ind, 0) - 1;
3266 sp = index_ctl(index_ind, 1) - 1;
3267 flt_yr = index_ctl(index_ind, 2);
3268 int family = index_ll_type(index);
3270 switch (est_sigma_index(index)) {
3271 case 0: index_std_dev = index_obs(index_ind, 1);
break;
3272 case 1: index_std_dev = exp(index_log_sd(index));
break;
3273 case 2: index_std_dev = index_analytical_sd(index);
break;
3274 default: error(
"Invalid 'Estimate_sigma_index'");
3276 index_sd(index_ind) = index_std_dev;
3279 bool fit_row = (flt_yr > 0) && (flt_yr <= endyr) && (flt_type(index) > 0) && (index_obs(index_ind, 0) > 0);
3282 if(fit_row && (family == 0)){
3283 int pos = index_obsvec_idx(index_ind);
3285 Type index_mu = log(index_hat(index_ind)) - bias_adjust_obs*
square(index_std_dev)/2.0;
3286 jnll_comp(JNLL_INDEX, index) -= keep(pos) * dnorm(obsvec(pos), index_mu, index_std_dev,
true);
3289 obsvec(pos), index_mu, index_std_dev, keep.cdf_lower(pos), keep.cdf_upper(pos));
3296 if(fit_row && ((family == 3) || (family == 4))){
3297 Type log_Z = (family == 4) ? log(pnorm(index_hat(index_ind) / index_std_dev)) : Type(0.0);
3299 jnll_comp(JNLL_INDEX, index) -= dnorm(index_obs(index_ind, 0), index_hat(index_ind), index_std_dev,
true);
3300 jnll_comp(JNLL_INDEX, index) += log_Z;
3303 int pos = index_obsvec_idx(index_ind);
3305 jnll_comp(JNLL_INDEX, index) -= keep(pos) * dnorm(obsvec(pos), index_hat(index_ind), index_std_dev,
true);
3306 jnll_comp(JNLL_INDEX, index) += keep(pos) * log_Z;
3310 obsvec(pos), index_hat(index_ind), index_std_dev,
3311 keep.cdf_lower(pos), keep.cdf_upper(pos));
3314 obsvec(pos), index_hat(index_ind), index_std_dev,
3315 keep.cdf_lower(pos), keep.cdf_upper(pos));
3325 bool sim_row = (flt_yr <= 0) || (flt_yr > endyr) || (index_obs(index_ind, 0) > 0);
3326 if(sim_row && (flt_type(index) > 0) && (family == 0)){
3327 index_obs(index_ind, 0) = exp(rnorm(log(index_hat(index_ind)) - bias_adjust_obs*
square(index_std_dev)/2.0, index_std_dev));
3328 int sim_pos = index_obsvec_idx(index_ind);
3330 obsvec(sim_pos) = log(index_obs(index_ind, 0));
3333 if(sim_row && (flt_type(index) > 0) && (family == 3)){
3336 Type sim_draw = rnorm(index_hat(index_ind), index_std_dev);
3338 while((sim_draw <= Type(0)) && (tn_tries < index_trunc_max_tries)){
3339 index_trunc_rejects_sim(index_ind) += 1;
3340 sim_draw = rnorm(index_hat(index_ind), index_std_dev);
3343 index_trunc_tries_sim(index_ind) += tn_tries + 1;
3344 index_trunc_sd_sim(index_ind) = index_std_dev;
3345 index_trunc_budget_sim(index_ind) = index_trunc_max_tries;
3346 index_obs(index_ind, 0) = sim_draw;
3348 if(sim_row && (flt_type(index) > 0) && (family == 4)){
3350 Type a = pnorm(-index_hat(index_ind) / index_std_dev);
3351 Type u = a + (Type(1.0) - a) * runif(Type(0.0), Type(1.0));
3352 index_obs(index_ind, 0) = index_hat(index_ind) + index_std_dev * qnorm(u);
3355 if((flt_type(index) > 0) && ((family == 3) || (family == 4))){
3356 int sim_pos = index_obsvec_idx(index_ind);
3359 if(index_obs(index_ind, 0) > Type(0)) obsvec(sim_pos) = log(index_obs(index_ind, 0));
3361 obsvec(sim_pos) = index_obs(index_ind, 0);
3372 for(index = 0; index < n_flt; index++){
3373 if((flt_type(index) > 0) && (index_ll_type(index) == 1 || index_ll_type(index) == 2)){
3375 for(index_ind = 0; index_ind < index_obs.rows(); index_ind++){
3376 if((index_ctl(index_ind, 0) - 1) == index){
3377 flt_yr = index_ctl(index_ind, 2);
3378 if((flt_yr > 0) && (flt_yr <= endyr) && (index_obs(index_ind, 0) > 0)) n_mvn++;
3383 vector<Type> resid(n_mvn);
3384 vector<Type> mu(n_mvn);
3385 vector<int> posv(n_mvn);
3386 vector<int> rowv(n_mvn);
3388 for(index_ind = 0; index_ind < index_obs.rows(); index_ind++){
3389 if((index_ctl(index_ind, 0) - 1) == index){
3390 flt_yr = index_ctl(index_ind, 2);
3391 if((flt_yr > 0) && (flt_yr <= endyr) && (index_obs(index_ind, 0) > 0)){
3392 resid(k) = index_obs(index_ind, 0) - index_hat(index_ind);
3393 mu(k) = index_hat(index_ind);
3394 posv(k) = index_obsvec_idx(index_ind);
3395 rowv(k) = index_ind;
3403 Type dens = MVNORM(index_cov_mat(index))(resid);
3404 jnll_comp(JNLL_INDEX, index) += (index_ll_type(index) == 2) ? dens : (dens - index_cov_const(index));
3408 Eigen::LLT<Eigen::Matrix<Type, Eigen::Dynamic, Eigen::Dynamic> > llt(index_cov_mat(index));
3409 matrix<Type> Lmat = llt.matrixL();
3410 matrix<Type> muc(n_mvn, 1);
3411 for(k = 0; k < n_mvn; k++) muc(k, 0) = mu(k);
3412 matrix<Type> mwhite = Lmat.template triangularView<Eigen::Lower>().solve(muc);
3413 for(k = 0; k < n_mvn; k++){
3416 jnll_comp(JNLL_INDEX, index) -= keep(pos) * dnorm(obsvec(pos), mwhite(k, 0), Type(1.0),
true);
3419 obsvec(pos), mwhite(k, 0), Type(1.0),
3420 keep.cdf_lower(pos), keep.cdf_upper(pos));
3430 vector<Type> sim_dev = MVNORM(index_cov_mat(index)).simulate();
3433 bool any_nonpos =
false;
3434 for(k = 0; k < n_mvn; k++){
3435 if(mu(k) + sim_dev(k) <= Type(0)) any_nonpos =
true;
3437 if(!any_nonpos)
break;
3438 if(mvn_tries >= index_trunc_max_tries * n_mvn)
break;
3439 for(k = 0; k < n_mvn; k++){
3440 if(mu(k) + sim_dev(k) <= Type(0)) index_trunc_rejects_sim(rowv(k)) += 1;
3442 sim_dev = MVNORM(index_cov_mat(index)).simulate();
3445 for(k = 0; k < n_mvn; k++){
3446 index_trunc_tries_sim(rowv(k)) += mvn_tries + 1;
3447 index_trunc_sd_sim(rowv(k)) = sqrt(index_cov_mat(index)(k, k));
3448 index_trunc_budget_sim(rowv(k)) = index_trunc_max_tries * n_mvn;
3449 index_obs(rowv(k), 0) = mu(k) + sim_dev(k);
3451 int sim_pos = posv(k);
3452 if((sim_pos >= 0) && (osa_mode == 0) && (index_obs(rowv(k), 0) > Type(0))){
3453 obsvec(sim_pos) = log(index_obs(rowv(k), 0));
3463 matrix<Type> index_obs_sim = index_obs;
3464 REPORT(index_obs_sim);
3465 REPORT(index_trunc_tries_sim);
3466 REPORT(index_trunc_rejects_sim);
3467 REPORT(index_trunc_sd_sim);
3468 REPORT(index_trunc_budget_sim);
3474 Type fsh_std_dev = 0;
3475 for(fsh_ind = 0; fsh_ind < catch_obs.rows(); fsh_ind++) {
3477 flt = catch_ctl(fsh_ind, 0) - 1;
3478 sp = catch_ctl(fsh_ind, 1) - 1;
3479 flt_yr = catch_ctl(fsh_ind, 2);
3482 switch (est_sigma_fsh(flt)) {
3483 case 0: fsh_std_dev = catch_obs(fsh_ind, 1);
break;
3484 case 1: fsh_std_dev = exp(catch_log_sd(flt));
break;
3485 case 2: fsh_std_dev = catch_analytical_sd(flt);
break;
3486 default: error(
"Invalid 'Estimate_sigma_catch'");
3488 catch_sd(fsh_ind) = fsh_std_dev;
3491 if((flt_yr > 0) && (flt_yr <= endyr) && (flt_type(flt) == 1) && (catch_obs(fsh_ind, 0) > 0)){
3492 int pos = catch_obsvec_idx(fsh_ind);
3494 Type catch_mu = log(catch_hat(fsh_ind)) - bias_adjust_obs*
square(fsh_std_dev)/2.0;
3495 jnll_comp(JNLL_CATCH, flt) -= keep(pos) * dnorm(obsvec(pos), catch_mu, fsh_std_dev,
true) ;
3498 obsvec(pos), catch_mu, fsh_std_dev, keep.cdf_lower(pos), keep.cdf_upper(pos));
3508 catch_obs(fsh_ind, 0) = exp(rnorm(log(catch_hat(fsh_ind)) - bias_adjust_obs*
square(fsh_std_dev)/2.0, fsh_std_dev));
3509 int sim_pos = catch_obsvec_idx(fsh_ind);
3511 obsvec(sim_pos) = log(catch_obs(fsh_ind, 0));
3520 for(
int eq_ind = 0; eq_ind < equil_catch_ctl.rows(); eq_ind++){
3521 int eq_flt = equil_catch_ctl(eq_ind, 0) - 1;
3522 if((equil_catch_obs(eq_ind, 0) > 0) && (flt_type(eq_flt) == 1)){
3523 Type eq_sd = equil_catch_obs(eq_ind, 1);
3524 Type eq_mu = log(equil_catch_hat(eq_ind)) - bias_adjust_obs*
square(eq_sd)/2.0;
3525 jnll_comp(JNLL_EQUIL_CATCH, eq_flt) -=
3526 dnorm(log(equil_catch_obs(eq_ind, 0)), eq_mu, eq_sd,
true);
3531 equil_catch_obs(eq_ind, 0) = exp(rnorm(eq_mu, eq_sd));
3539 matrix<Type> catch_obs_sim = catch_obs;
3540 matrix<Type> equil_catch_obs_sim = equil_catch_obs;
3541 vector<Type> obsvec_sim = obsvec;
3542 REPORT(catch_obs_sim);
3543 REPORT(equil_catch_obs_sim);
3553 Type comp_prop_offset = comp_offset;
3554 matrix<Type> comp_sim = comp_obs;
3556 for(comp_ind = 0; comp_ind < comp_obs.rows(); comp_ind++) {
3558 flt = comp_ctl(comp_ind, 0) - 1;
3559 sp = comp_ctl(comp_ind, 1) - 1;
3560 flt_sex = comp_ctl(comp_ind, 2);
3561 comp_type = comp_ctl(comp_ind, 3);
3562 yr = comp_ctl(comp_ind, 4);
3565 joint_adjust(comp_ind) = 1;
3567 joint_adjust(comp_ind) = 2;
3569 int nbins_blk = (comp_type == 0) ? nages(sp) : nlengths(sp);
3571 if((comp_type == 0) || (comp_type == 1)) n_comp = nbins_blk * joint_adjust(comp_ind);
3573 vector<Type> comp_obs_tmp = comp_obs.row(comp_ind).segment(0, n_comp);
3574 vector<Type> comp_hat_tmp = comp_hat.row(comp_ind).segment(0, n_comp);
3578 fold_comp_tails(comp_obs_tmp, comp_hat_tmp, n_comp, nbins_blk, joint_adjust(comp_ind),
3579 comp_accum_young(flt), comp_accum_old(flt));
3581 if((yr <= endyr) && (yr > 0) && (flt_type(flt) > 0) && (comp_n(comp_ind, 1) > 0)){
3582 comp_row_nll(comp_ll_type(flt), osa_mode, comp_obs_tmp, comp_hat_tmp,
3583 comp_prop_offset, comp_n(comp_ind, 1), comp_weights(flt), DM_pars_comp(flt),
3584 obsvec, keep, comp_obsvec_idx(comp_ind),
"comp_ll_type",
3585 jnll_comp(JNLL_COMP, flt), unweighted_jnll_comp(JNLL_COMP, flt));
3591 int nbin_raw = ((comp_type == 0) ? nages(sp) : nlengths(sp)) * joint_adjust(comp_ind);
3592 vector<Type> sim_p = comp_hat.row(comp_ind).segment(0, nbin_raw);
3593 Type sim_tot = sim_p.sum();
3594 Type n_nom = comp_n(comp_ind, 1);
3597 vector<Type> sim_out(nbin_raw); sim_out.setZero();
3599 if((sim_tot > Type(0)) && (n_nom > Type(0))){
3600 vector<Type> p = sim_p / sim_tot;
3601 if(comp_ll_type(flt) == 1){
3603 vector<Type> sim_alphas = p * n_nom * DM_pars_comp(flt);
3611 for(
int b = 0; b < nbin_raw; b++){
3612 comp_sim(comp_ind, b) = sim_out(b);
3616 for(
int b = nbin_raw; b < comp_sim.cols(); b++){
3617 comp_sim(comp_ind, b) = Type(0);
3623 matrix<Type> comp_obs_sim = comp_sim;
3624 REPORT(comp_obs_sim);
3630 matrix<Type> caal_sim = caal_obs;
3632 for(
int caal_ind = 0; caal_ind < caal_hat.rows(); caal_ind++){
3634 flt = caal_ctl(caal_ind, 0) - 1;
3635 sp = caal_ctl(caal_ind, 1) - 1;
3636 flt_sex = caal_ctl(caal_ind, 2);
3637 yr = caal_ctl(caal_ind, 3);
3638 ln = caal_ctl(caal_ind, 4) - 1;
3640 int n_caal = nages(sp);
3642 vector<Type> caal_obs_tmp = caal_obs.row(caal_ind).segment(0, n_caal);
3643 vector<Type> caal_hat_tmp = caal_hat.row(caal_ind).segment(0, n_caal);
3645 if((yr <= endyr) && (yr > 0) && (flt_type(flt) > 0) && (caal_n(caal_ind, 0) > 0)){
3646 comp_row_nll(caal_ll_type(flt), osa_mode, caal_obs_tmp, caal_hat_tmp,
3647 comp_prop_offset, caal_n(caal_ind, 0), caal_weights(flt), DM_pars_caal(flt),
3648 obsvec, keep, caal_obsvec_idx(caal_ind),
"caal_ll_type",
3649 jnll_comp(JNLL_CAAL, flt), unweighted_jnll_comp(JNLL_CAAL, flt));
3654 vector<Type> sim_p = caal_hat.row(caal_ind).segment(0, n_caal);
3655 Type sim_tot = sim_p.sum();
3656 Type n_nom = caal_n(caal_ind, 0);
3657 vector<Type> sim_out(n_caal); sim_out.setZero();
3659 if((sim_tot > Type(0)) && (n_nom > Type(0))){
3660 vector<Type> p = sim_p / sim_tot;
3661 if(caal_ll_type(flt) == 1){
3662 vector<Type> sim_alphas = p * n_nom * DM_pars_caal(flt);
3668 for(
int b = 0; b < n_caal; b++){
3669 caal_sim(caal_ind, b) = sim_out(b);
3671 for(
int b = n_caal; b < caal_sim.cols(); b++){
3672 caal_sim(caal_ind, b) = Type(0);
3678 matrix<Type> caal_obs_sim = caal_sim;
3679 REPORT(caal_obs_sim);
3686 matrix<Type> diet_sim = diet_obs;
3688 if((msmMode > 2) || (
imax(suitMode) > 0)) {
3692 for (
int i = 0; i < n_stomach_obs; ++i) {
3697 int start_j = current_j;
3698 while((current_j < diet_ctl.rows()) && (stomach_id(current_j) == i)) {
3701 int n_prey = current_j - start_j;
3702 if (n_prey == 0)
continue;
3704 int rsp = diet_ctl(start_j, 0) - 1;
3705 Type N_s = diet_obs(start_j, 0);
3707 if (suitMode(rsp) <= 0)
continue;
3710 vector<Type> obs_diet_prop(n_prey + 1); obs_diet_prop.setZero();
3711 vector<Type> pred_diet_prop(n_prey + 1); pred_diet_prop.setZero();
3713 for (
int k = 0; k < n_prey; ++k) {
3714 obs_diet_prop(k) = diet_obs(start_j + k, 1);
3715 pred_diet_prop(k) = diet_hat(start_j + k, 1);
3718 Type sum_obs_p = obs_diet_prop.head(n_prey).sum();
3719 if (sum_obs_p > 1.0) sum_obs_p = 1.0;
3720 obs_diet_prop(n_prey) = 1.0 - sum_obs_p;
3722 Type sum_est_p = pred_diet_prop.head(n_prey).sum();
3723 pred_diet_prop(n_prey) =
posfun(1.0 - sum_est_p, Type(0.00001), penalty);
3726 obs_diet_prop += comp_offset;
3727 pred_diet_prop += comp_offset;
3729 obs_diet_prop /= obs_diet_prop.sum();
3730 pred_diet_prop /= pred_diet_prop.sum();
3732 vector<Type> obs_diet_content = obs_diet_prop * N_s;
3737 Type stomach_log_likelihood = 0;
3738 Type unweighted_stomach_log_likelihood = 0;
3739 Type DM_diet_par = DM_diet_pars(rsp);
3741 vector<Type> diet_alphas = pred_diet_prop * N_s * DM_diet_par;
3742 vector<Type> unweighted_diet_alphas = pred_diet_prop * N_s;
3745 switch(diet_ll_type(rsp)){
3748 stomach_log_likelihood = dmultinom(obs_diet_content, pred_diet_prop,
true);
3750 unweighted_jnll_comp(JNLL_STOMACH, rsp) -= stomach_log_likelihood;
3751 jnll_comp(JNLL_STOMACH, rsp) -= diet_comp_weights(rsp) * stomach_log_likelihood;
3754 stomach_log_likelihood =
ddirmultinom(obs_diet_content, diet_alphas,
true);
3755 unweighted_stomach_log_likelihood =
ddirmultinom(obs_diet_content, unweighted_diet_alphas,
true);
3757 unweighted_jnll_comp(JNLL_STOMACH, rsp) -= unweighted_stomach_log_likelihood;
3758 jnll_comp(JNLL_STOMACH, rsp) -= stomach_log_likelihood;
3762 error(
"Invalid 'diet_ll_type'");
3766 int start = diet_obsvec_idx(i);
3768 vector<Type> osa_x = obsvec.segment(start, n_prey + 1);
3769 if(diet_ll_type(rsp) == 1){
3770 jnll_comp(JNLL_STOMACH, rsp) -=
ddirmultinom_osa(osa_x, diet_alphas, keep.segment(start, n_prey + 1), 1, 1);
3772 jnll_comp(JNLL_STOMACH, rsp) -=
dmultinom_osa(osa_x, pred_diet_prop, keep.segment(start, n_prey + 1), 1, 1, osa_mode == 2);
3780 vector<Type> sim_p(n_prey + 1);
3781 Type prey_sum = 0.0;
3782 for(
int k = 0; k < n_prey; k++){
3783 sim_p(k) = diet_hat(start_j + k, 1);
3784 prey_sum += sim_p(k);
3786 sim_p(n_prey) = (prey_sum < Type(1.0)) ? Type(1.0) - prey_sum : Type(0.0);
3787 Type sim_tot = sim_p.sum();
3788 if(sim_tot > Type(0)) sim_p /= sim_tot;
3790 if((N_s > Type(0)) && (sim_tot > Type(0))){
3791 vector<Type> sim_counts(n_prey + 1);
3792 switch(diet_ll_type(rsp)){
3795 Type n_eff = N_s * diet_comp_weights(rsp);
3800 vector<Type> sim_alphas = sim_p * N_s * DM_diet_par;
3805 error(
"Invalid 'diet_ll_type'");
3809 Type n_drawn = sim_counts.sum();
3810 for(
int k = 0; k < n_prey; k++){
3811 diet_sim(start_j + k, 1) = (n_drawn > Type(0))
3812 ? sim_counts(k) / n_drawn
3822 matrix<Type> diet_obs_sim = diet_sim;
3823 REPORT(diet_obs_sim);
3832 for(flt = 0; flt < n_flt; flt++){
3834 bool sel_is_length = (flt_sel_dim(flt) == 1);
3835 int nbins = sel_is_length ? nlengths_pop(sp) : nages(sp);
3837 if(flt_type(flt) > 0 && flt_sel_lead(flt) == 1){
3842 if(flt_sel_type(flt) == 2) {
3844 if((flt_varying_sel(flt) == 1) || (flt_varying_sel(flt) == 4)){
3845 nyrs_tmp = nyrs_hind;
3848 for(yr = 0; yr < nyrs_tmp; yr++){
3852 for(sex = 0; sex < nsex(sp); sex++){
3853 for(age = 0; age < (nbins - 1); age++) {
3854 Type sel_ratio_tmp = log_non_par_sel(flt, sex, age, yr) - log_non_par_sel(flt, sex, age + 1, yr);
3855 jnll_comp(JNLL_SEL_NONPARAM, flt) += sel_curve_pen(flt, 0) *
square( (CppAD::abs(sel_ratio_tmp) + sel_ratio_tmp)/2.0);
3860 for(sex = 0; sex < nsex(sp); sex++){
3861 vector<Type> sel_tmp(nbins); sel_tmp.setZero();
3862 for(age = 0; age < nbins; age++) {
3863 sel_tmp(age) = log_non_par_sel(flt, sex, age, yr);
3866 for(
int a2 = 0; a2 < sel_d2.size(); a2++) {
3867 jnll_comp(JNLL_SEL_NONPARAM, flt) += sel_curve_pen(flt, 1) * sel_d2(a2) * sel_d2(a2);
3874 if(flt_varying_sel(flt) == 4){
3876 for(sex = 0; sex < nsex(sp); sex++){
3877 for(age = 0; age < (nbins - 1); age++) {
3878 jnll_comp(JNLL_SEL_DEV, flt) -= dnorm(log_non_par_sel(flt, sex, age, yr), log_non_par_sel(flt, sex, age, yr - 1), sel_dev_sd(flt),
true);
3882 }
else if(flt_varying_sel(flt) == 1){
3883 for(sex = 0; sex < nsex(sp); sex++){
3884 for(
int bin = bin_first_selected(flt); bin < flt_n_sel_bins(flt); bin++) {
3885 jnll_comp(JNLL_SEL_DEV, flt) -= dnorm(sel_coff_dev(flt, sex, bin, yr), Type(0.0), sel_dev_sd(flt),
true);
3891 for(sex = 0; sex < nsex(sp); sex++){
3892 jnll_comp(JNLL_SEL_NONPARAM, flt) += 2.0 *
square(avg_sel(flt, sex, yr));
3902 if(flt_sel_type(flt) == 9) {
3905 if(flt_varying_sel(flt) == 4){
3906 nyrs_tmp = nyrs_hind;
3911 int start_yr = flt_sel_start_yr(flt);
3912 int shape_a0 = flt_sel_pen_first_bin(flt);
3913 if(shape_a0 < 0) shape_a0 = bin_first_selected(flt);
3914 int shape_a1 = flt_sel_pen_last_bin(flt);
3915 if(shape_a1 < 0) shape_a1 = nbins - 2;
3917 if(shape_a1 > nbins - 2) shape_a1 = nbins - 2;
3918 int shape_mode = flt_sel_shape_mode(flt);
3919 for(sex = 0; sex < nsex(sp); sex++){
3920 for(yr = start_yr; yr < nyrs_tmp; yr++){
3924 for(age = shape_a0; age <= shape_a1; age++) {
3925 Type d = log_non_par_sel(flt, sex, age, yr) - log_non_par_sel(flt, sex, age + 1, yr);
3927 jnll_comp(JNLL_SEL_NONPARAM, flt) += sel_curve_pen(flt, 0) * d * d;
3928 else if(sel_curve_pen(flt, 0) >= 0)
3929 jnll_comp(JNLL_SEL_NONPARAM, flt) += sel_curve_pen(flt, 0) *
square( (CppAD::abs(d) + d)/2.0 );
3931 jnll_comp(JNLL_SEL_NONPARAM, flt) += -sel_curve_pen(flt, 0) *
square( (CppAD::abs(d) - d)/2.0 );
3935 if((yr > start_yr) || (start_yr == 0)){
3936 vector<Type> ls(nbins); ls.setZero();
3937 for(age = 0; age < nbins; age++) ls(age) = log_non_par_sel(flt, sex, age, yr);
3939 for(
int a2 = 0; a2 < d2.size(); a2++) jnll_comp(JNLL_SEL_DEV, flt) += sel_curve_pen(flt, 1) * d2(a2) * d2(a2);
3944 for(age = 0; age < nbins; age++) {
3945 Type dd = log_non_par_sel(flt, sex, age, yr) - log_non_par_sel(flt, sex, age, yr - 1);
3946 jnll_comp(JNLL_SEL_DEV, flt) += dd * dd / (2.0 * sel_dev_sd(flt) * sel_dev_sd(flt));
3952 for(
int bin = 0; bin < flt_n_sel_bins(flt); bin++){
3953 for(yr = start_yr; yr < nyrs_tmp; yr++){
3954 jnll_comp(JNLL_SEL_DEV, flt) += sel_curve_pen(flt, 2) * sel_coff_dev(flt, sex, bin, yr) * sel_coff_dev(flt, sex, bin, yr);
3960 if(flt_sel_avgsel_pen(flt) > 0){
3961 int n_base = flt_n_sel_bins(flt) - bin_first_selected(flt);
3962 vector<Type> base(n_base);
3963 for(
int bin = 0; bin < n_base; bin++){
3964 base(bin) = sel_coff(flt, sex, bin + bin_first_selected(flt));
3967 jnll_comp(JNLL_SEL_NONPARAM, flt) += flt_sel_avgsel_pen(flt) * avgsel * avgsel;
3975 if(flt_sel_type(flt) == 13) {
3976 int n_sel_bins = flt_n_sel_bins(flt);
3977 int start_yr = flt_sel_start_yr(flt);
3978 for(sex = 0; sex < nsex(sp); sex++){
3982 vector<Type> base(nbins);
3983 for(
int bin = 0; bin < nbins; bin++){
3984 base(bin) = sel_coff(flt, sex, (bin < n_sel_bins ? bin : n_sel_bins - 1));
3986 vector<Type> est(n_sel_bins);
3987 for(
int bin = 0; bin < n_sel_bins; bin++) est(bin) = base(bin);
3990 for(
int bin = 0; bin < nbins; bin++) base(bin) -= ctr;
3993 for(
int bin = 0; bin < (nbins - 1); bin++) {
3994 Type d = base(bin) - base(bin + 1);
3995 jnll_comp(JNLL_SEL_NONPARAM, flt) += sel_curve_pen(flt, 0) *
square( (CppAD::abs(d) + d)/2.0 );
3999 for(
int a2 = 0; a2 < d2.size(); a2++) {
4000 jnll_comp(JNLL_SEL_NONPARAM, flt) += sel_curve_pen(flt, 1) * d2(a2) * d2(a2);
4003 jnll_comp(JNLL_SEL_NONPARAM, flt) += 2.0 *
square(avg_base);
4007 bool scored = (flt_varying_sel(flt) == 1) || (flt_varying_sel(flt) == 4);
4008 int yr_lo = (flt_varying_sel(flt) == 4) ? start_yr + 1 : 0;
4010 for(yr = yr_lo; yr < nyrs_hind; yr++){
4011 for(
int bin = bin_first_selected(flt); bin < n_sel_bins; bin++) {
4012 jnll_comp(JNLL_SEL_DEV, flt) -= dnorm(sel_coff_dev(flt, sex, bin, yr), Type(0.0), sel_dev_sd(flt),
true);
4024 bool asc_limb = (flt_sel_type(flt) == 1) || (flt_sel_type(flt) == 3) || (flt_sel_type(flt) == 8);
4025 bool desc_limb = (flt_sel_type(flt) == 3) || (flt_sel_type(flt) == 4) || (flt_sel_type(flt) == 8);
4028 if((flt_varying_sel(flt) == 1) || (flt_varying_sel(flt) == 2)){
4029 for(sex = 0; sex < nsex(sp); sex ++){
4030 for(yr = 0; yr < nyrs_hind; yr++){
4032 jnll_comp(JNLL_SEL_DEV, flt) -= dnorm(sel_inf_dev(0, flt, sex, yr), Type(0.0), sel_dev_sd(flt),
true);
4033 jnll_comp(JNLL_SEL_DEV, flt) -= dnorm(log_sel_slp_dev(0, flt, sex, yr), Type(0.0), 4 * sel_dev_sd(flt),
true);
4036 jnll_comp(JNLL_SEL_DEV, flt) -= dnorm(sel_inf_dev(1, flt, sex, yr), Type(0.0), sel_dev_sd(flt),
true);
4037 jnll_comp(JNLL_SEL_DEV, flt) -= dnorm(log_sel_slp_dev(1, flt, sex, yr), Type(0.0), 4 * sel_dev_sd(flt),
true);
4045 if((flt_varying_sel(flt) == 4) || (flt_varying_sel(flt) == 5)){
4046 for(sex = 0; sex < nsex(sp); sex ++){
4047 for(yr = 1; yr < nyrs_hind; yr++){
4049 jnll_comp(JNLL_SEL_DEV, flt) -= dnorm(log_sel_slp_dev(0, flt, sex, yr) - log_sel_slp_dev(0, flt, sex, yr-1), Type(0.0), sel_dev_sd(flt),
true);
4050 jnll_comp(JNLL_SEL_DEV, flt) -= dnorm(sel_inf_dev(0, flt, sex, yr) - sel_inf_dev(0, flt, sex, yr-1), Type(0.0), 4 * sel_dev_sd(flt),
true);
4052 if((flt_varying_sel(flt) == 4) && desc_limb){
4053 jnll_comp(JNLL_SEL_DEV, flt) -= dnorm(sel_inf_dev(1, flt, sex, yr) - sel_inf_dev(1, flt, sex, yr-1), Type(0.0), sel_dev_sd(flt),
true);
4054 jnll_comp(JNLL_SEL_DEV, flt) -= dnorm(log_sel_slp_dev(1, flt, sex, yr) - log_sel_slp_dev(1, flt, sex, yr-1), Type(0.0), sel_dev_sd(flt) * 4,
true);
4064 if(flt_sel_type(flt) == 11){
4065 int start_yr = flt_sel_start_yr(flt);
4066 int alo = sel_norm_bin1(flt);
int ahi = sel_norm_bin2(flt);
4067 if(alo < 0) alo = bin_first_selected(flt);
4068 if(ahi < 0) ahi = nbins - 1;
4069 for(sex = 0; sex < nsex(sp); sex ++){
4070 for(yr = start_yr + 1; yr < nyrs_hind; yr++){
4071 for(age = alo; age <= ahi; age++){
4072 Type s_now = sel_is_length ? sel_at_length(flt, sex, age, yr) : sel_at_age(flt, sex, age, yr);
4073 Type s_prev = sel_is_length ? sel_at_length(flt, sex, age, yr - 1) : sel_at_age(flt, sex, age, yr - 1);
4074 Type d = log(s_now) - log(s_prev);
4075 jnll_comp(JNLL_SEL_DEV, flt) += sel_curve_pen(flt, 0) * d * d;
4077 Type da1 = sel_inf_dev(1, flt, sex, yr) - sel_inf_dev(1, flt, sex, yr - 1);
4078 jnll_comp(JNLL_SEL_DEV, flt) += sel_curve_pen(flt, 2) * da1 * da1;
4085 if(((flt_varying_sel(flt) == 1) || (flt_varying_sel(flt) == 2)) && (flt_sel_type(flt) == 5)){
4086 for(
int bin = 0; bin < flt_n_sel_bins(flt); bin++){
4087 for(sex = 0; sex < nsex(sp); sex++){
4088 for(yr = 0; yr < nyrs_hind; yr++){
4089 jnll_comp(JNLL_SEL_DEV, flt) -= dnorm(sel_coff_dev(flt, sex, bin, yr), Type(0.0), sel_dev_sd(flt),
true);
4097 if(flt_sel_type(flt) == 6){
4098 int n_sel_bins = flt_n_sel_bins(flt);
4099 array<Type> tmp_AR2(n_sel_bins, nyrs_hind);
4101 for(sex = 0; sex < nsex(sp); sex ++){
4102 for (
int bin = 0; bin < n_sel_bins; bin++) {
4103 for (
int yr = 0; yr < nyrs_hind; yr++) {
4104 tmp_AR2(bin, yr) = sel_coff_dev(flt, sex, bin, yr);
4108 Type rho_a =
rho_trans(sel_curve_pen(flt, 0));
4109 Type rho_y =
rho_trans(sel_curve_pen(flt, 1));
4111 Type Sigma_sig_sel = pow(pow(sel_dev_sd(flt),2) / ((1-pow(rho_y,2))*(1-pow(rho_a,2))),0.5);
4114 jnll_comp(JNLL_SEL_DEV, flt) += SCALE(SEPARABLE(AR1(rho_y),AR1(rho_a)), Sigma_sig_sel)(tmp_AR2);
4120 if(flt_sel_type(flt) == 7){
4121 int n_sel_bins = flt_n_sel_bins(flt);
4122 int num_rows = n_sel_bins * nyrs_hind;
4123 matrix<Type> ay_index(num_rows, 2);
4125 for(sex = 0; sex < nsex(sp); sex ++){
4128 for (
int year = 1; year <= nyrs_hind; ++year) {
4129 for (
int bin = 1; bin <= n_sel_bins; ++bin) {
4130 ay_index(row, 0) = bin;
4131 ay_index(row, 1) = year;
4139 Eigen::SparseMatrix<Type> Q_sparse(num_rows, num_rows);
4140 Q_sparse =
construct_Q(nyrs_hind, n_sel_bins, ay_index,
4141 sel_curve_pen(flt, 0), sel_curve_pen(flt, 1), sel_curve_pen(flt, 2),
4142 log(
square(sel_dev_sd(flt))), 0);
4144 array<Type> tmp_AR2(n_sel_bins, nyrs_hind);
4145 for (
int bin = 0; bin < n_sel_bins; bin++) {
4146 for (
int yr = 0; yr < nyrs_hind; yr++) {
4147 tmp_AR2(bin, yr) = sel_coff_dev(flt, sex, bin, yr);
4150 jnll_comp(JNLL_SEL_DEV, flt) += GMRF(Q_sparse)(tmp_AR2);
4159 for(flt = 0; flt < n_flt; flt++){
4160 if(flt_q_lead(flt) == 1){
4164 if( est_index_q(flt) == 2){
4165 jnll_comp(JNLL_Q_PRIOR, flt) -= dnorm(index_log_q(flt), index_log_q_prior(flt) - bias_adjust_proc*
square(index_q_sd(flt))/2.0, index_q_sd(flt),
true);
4169 bool q_devs = (flt_type(flt) > 0) && ((est_index_q(flt) == 1) || (est_index_q(flt) == 2));
4172 if(q_devs && ((index_varying_q(flt) == 1) || (index_varying_q(flt) == 2))){
4173 for(yr = 0; yr < nyrs_hind; yr++){
4174 jnll_comp(JNLL_Q_DEV, flt) -= dnorm(index_q_dev(flt, yr), Type(0.0), index_q_dev_sd(flt),
true );
4179 if(q_devs && (index_varying_q(flt) == 4)){
4180 for(yr = 1; yr < nyrs_hind; yr++){
4181 jnll_comp(JNLL_Q_DEV, flt) -= dnorm(index_q_dev(flt, yr) - index_q_dev(flt, yr-1), Type(0.0), index_q_dev_sd(flt),
true );
4191 for(sp = 0; sp < nspp; sp++) {
4194 int srr_terms_on = (estDynamics(sp) == 0);
4197 if(srr_terms_on && (srr_est_mode == 2) & ((srr_pred_fun == 2) | (srr_pred_fun == 3))){
4198 jnll_comp(JNLL_SRR_PRIOR, sp) -= dnorm(log(steepness(sp, 0)), log(srr_prior(sp)) - bias_adjust_proc*
square(srr_prior_sd(sp))/2.0, srr_prior_sd(sp),
true);
4202 if(srr_terms_on && (srr_est_mode == 3) & ((srr_pred_fun == 2) | (srr_pred_fun == 3))){
4203 Type beta_alpha = ((1 - srr_prior(sp))/
square(srr_prior_sd(sp)) - 1/srr_prior(sp)) *
square(srr_prior(sp));
4204 Type beta_beta = beta_alpha * (1/srr_prior(sp) - 1);
4205 jnll_comp(JNLL_SRR_PRIOR, sp) -= dbeta(steepness(sp, 0), beta_alpha, beta_beta,
true);
4209 if(srr_terms_on && (srr_est_mode == 2) & ((srr_pred_fun == 4) | (srr_pred_fun == 5))){
4210 jnll_comp(JNLL_SRR_PRIOR, sp) -= dnorm(rec_pars(sp, 1), log(srr_prior(sp)) - bias_adjust_proc*
square(srr_prior_sd(sp))/2.0, srr_prior_sd(sp),
true);
4215 if(srr_terms_on && (!
isNA(Bmsy_lim(sp))) && ((srr_pred_fun == 4) || (srr_pred_fun == 5))){
4216 Type bmsy = 1.0/exp(rec_pars(sp, 2));
4217 bmsy =
posfun(Bmsy_lim(sp)/Type(1000000.0) - bmsy, Type(0.001), penalty);
4218 jnll_comp(JNLL_SRR_PRIOR, sp) += 100 * penalty;
4223 if(initMode > 1 && initMode != 5){
4224 for(age = 1; age < nages(sp); age++) {
4225 jnll_comp(JNLL_INIT_DEV, sp) -= dnorm( init_dev(sp, age - 1), -bias_adjust_proc*
square(R_sd(sp))/2.0, R_sd(sp),
true);
4230 for(yr = 0; yr < nyrs_hind; yr++) {
4231 jnll_comp(JNLL_REC_DEV, sp) -= dnorm( rec_dev(sp, yr), -bias_adjust_proc*
square(R_sd(sp))/2.0, R_sd(sp),
true);
4237 if(srr_terms_on && (srr_fun == 0) & (srr_pred_fun > 0)){
4238 for(yr = srr_hat_styr; yr <= srr_hat_endyr; yr++) {
4239 jnll_comp(JNLL_SRR_PENALTY, sp) -= dnorm( log(R(sp, yr)), log(R_hat(sp,yr)) - bias_adjust_proc*
square(R_sd(sp))/2.0, R_sd(sp),
true);
4252 for(fsh_ind = 0; fsh_ind < catch_ctl.rows(); fsh_ind++){
4253 flt = catch_ctl(fsh_ind, 0) - 1;
4254 sp = catch_ctl(fsh_ind, 1) - 1;
4255 flt_yr = catch_ctl(fsh_ind, 2);
4256 if((flt_type(flt) == 1) && (forecast(sp) == 1) && (estDynamics(sp) == 0)){
4257 if(flt_yr == projyr){
4258 CMSY += catch_hat(fsh_ind);
4263 jnll_comp(JNLL_REFPT_PENALTY, 0) = -
square(CMSY/1000000.0);
4265 for(sp = 0; sp < nspp; sp++) {
4266 if((forecast(sp) == 1) && (estDynamics(sp) == 0)){
4268 Type nothing_useful =
posfun( (ssb_depletion(sp, nyrs-1) - Plimit(sp)), Type(0.0001), penalty); (void) nothing_useful;
4269 jnll_comp(JNLL_REFPT_PENALTY, sp) += 500.0 *
square(CMSY/1000.0) * penalty;
4274 for(sp = 0; sp < nspp; sp++) {
4277 if((forecast(sp) == 1) && (msmMode == 0) && (estDynamics(sp) == 0) && ((DynamicHCR == 0) || (DynamicHCR == 1))){
4281 jnll_comp(JNLL_REFPT_PENALTY, sp) += 200*
square((SPRlimit(sp)/SPR0(sp))-Flimit_percent(sp));
4287 if(DynamicHCR == 0){
4288 jnll_comp(JNLL_REFPT_PENALTY, sp) += 200*
square((ssb(sp, nyrs-1)/SB0(sp, nyrs-1))-Ftarget_percent(sp));
4290 for(yr = 1; yr < nyrs; yr++){
4291 jnll_comp(JNLL_REFPT_PENALTY, sp) += 200*
square((DynamicSBF(sp, yr)/DynamicSB0(sp, yr))-Ftarget_percent(sp));
4298 jnll_comp(JNLL_REFPT_PENALTY, sp) += 200*
square((SPRlimit(sp)/SPR0(sp))-Flimit_percent(sp));
4299 jnll_comp(JNLL_REFPT_PENALTY, sp) += 200*
square((SPRtarget(sp)/SPR0(sp))-Ftarget_percent(sp));
4305 if((forecast(sp) == 1) && (msmMode > 0) && (estDynamics(sp) == 0)){
4307 jnll_comp(JNLL_REFPT_PENALTY, sp) += 200*
square((ssb(sp, nyrs-1)/SB0(sp, nyrs-1))-Flimit_percent(sp));
4310 jnll_comp(JNLL_REFPT_PENALTY, sp) += 200*
square((ssb(sp, nyrs-1)/SB0(sp, nyrs-1))-Ftarget_percent(sp));
4313 jnll_comp(JNLL_REFPT_PENALTY, sp) += 200*
square((ssb(sp, nyrs-1)/SB0(sp, nyrs-1))-Flimit_percent(sp));
4321 for(sp = 0; sp < nspp; sp++){
4322 if(estDynamics(sp) == 0){
4323 jnll_comp(JNLL_ZERO_N_PENALTY, sp) += zero_N_pen(sp);
4329 for(sp = 0; sp < nspp; sp++) {
4332 Type M_prior_mean = log(M_prior(sp)) - bias_adjust_proc*
square(M_prior_sd(sp)) / 2.0;
4336 if( (M1_use_prior(sp) == 1) && (M2_use_prior(sp) == 0) ) {
4337 int nsex_tmp = (M1_model(sp) > 1) ? nsex(sp) : 1;
4338 int nage_tmp = (M1_model(sp) == 3) ? nages(sp) : 1;
4340 for(
int sex = 0; sex < nsex_tmp; sex++) {
4341 for(
int age = 0; age < nage_tmp; age++) {
4342 jnll_comp(JNLL_M_PRIOR, sp) -= dnorm(log_M1(sp, sex, age), M_prior_mean, M_prior_sd(sp),
true);
4349 if( M2_use_prior(sp) == 1 ) {
4350 for(
int sex = 0; sex < nsex(sp); sex++) {
4351 for(
int age = 0; age < nages(sp); age++) {
4352 for(
int yr = 0; yr < nyrs_hind; yr++) {
4353 jnll_comp(JNLL_M_PRIOR, sp) -= dnorm(log(M_at_age(sp, sex, age, yr)), M_prior_mean, M_prior_sd(sp),
true);
4363 int num_re_sexes = (M1_model(sp) == 2 && nsex(sp) > 1) ? 2 : 1;
4366 if( (M1_re(sp) == 1) || (M1_re(sp) == 4) ) {
4367 Type sigma_M = exp(M1_dev_log_sd(sp, 0));
4368 Type rho_M_a =
rho_trans(M1_rho(sp, 0, 0));
4369 Type Sigma_M = pow(pow(sigma_M, 2) / (1.0 - pow(rho_M_a, 2)), 0.5);
4370 vector<Type> M_re_age(nages(sp));
4372 for(
int sex = 0; sex < num_re_sexes; sex++) {
4373 for(
int age = 0; age < nages(sp); age++) {
4374 M_re_age(age) = log_M1_dev(sp, sex, age, 0);
4376 jnll_comp(JNLL_M_RE, sp) += SCALE(AR1(rho_M_a), Sigma_M)(M_re_age);
4381 if( (M1_re(sp) == 2) || (M1_re(sp) == 5) ) {
4382 Type sigma_M = exp(M1_dev_log_sd(sp, 0));
4383 Type rho_M_y =
rho_trans(M1_rho(sp, 0, 1));
4384 Type Sigma_M = pow(pow(sigma_M, 2) / (1.0 - pow(rho_M_y, 2)), 0.5);
4385 vector<Type> M_re_yr(nyrs_hind);
4387 for(
int sex = 0; sex < num_re_sexes; sex++) {
4388 for(
int yr = 0; yr < nyrs_hind; yr++) {
4389 M_re_yr(yr) = log_M1_dev(sp, sex, 0, yr);
4391 jnll_comp(JNLL_M_RE, sp) += SCALE(AR1(rho_M_y), Sigma_M)(M_re_yr);
4396 if( (M1_re(sp) == 3) || (M1_re(sp) == 6) ) {
4397 Type sigma_M = exp(M1_dev_log_sd(sp, 0));
4398 Type rho_M_a =
rho_trans(M1_rho(sp, 0, 0));
4399 Type rho_M_y =
rho_trans(M1_rho(sp, 0, 1));
4400 Type Sigma_M = pow(pow(sigma_M, 2) / ((1.0 - pow(rho_M_y, 2)) * (1.0 - pow(rho_M_a, 2))), 0.5);
4401 array<Type> M_re_a_yr(nages(sp), nyrs_hind);
4403 for(
int sex = 0; sex < num_re_sexes; sex++) {
4404 for(
int age = 0; age < nages(sp); age++) {
4405 for(
int yr = 0; yr < nyrs_hind; yr++) {
4406 M_re_a_yr(age, yr) = log_M1_dev(sp, sex, age, yr);
4411 jnll_comp(JNLL_M_RE, sp) += SCALE(SEPARABLE(AR1(rho_M_y), AR1(rho_M_a)), Sigma_M)(M_re_a_yr);
4422 for (
int i = 0; i < beta_linkage.size(); ++i) {
4423 int fam = linkage_prior_family(i);
4424 if (fam == 0)
continue;
4425 Type p1 = linkage_prior_p1(i);
4426 Type p2 = linkage_prior_p2(i);
4427 int slot_col = linkage_species(i) - 1;
4428 if (slot_col < 0) slot_col = 0;
4429 if (slot_col >= n_col) slot_col = 0;
4431 Type b = beta_linkage(i);
4432 bool base_is_log =
true;
4433 if (linkage_is_intercept(i) == 1) {
4435 int sp_in = linkage_species(i);
4436 int sx_in = linkage_sex(i);
4437 int ab_in = linkage_age_bin(i);
4438 int sp_idx = (sp_in == 0) ? 0 : (sp_in - 1);
4439 int sx_idx = (sx_in == 0) ? 0 : (sx_in - 1);
4440 int ab_idx = (ab_in == 0) ? 0 : (ab_in - 1);
4442 int proc = linkage_process(i);
4443 int param = linkage_param(i);
4448 b = rec_pars(sp_idx, param);
4451 b = log_M1(sp_idx, sx_idx, ab_idx);
4455 b = log_growth_pars(sp_idx, sx_idx, param);
4461 int fl_in = linkage_fleet(i);
4462 int fl_idx = (fl_in == 0) ? 0 : (fl_in - 1);
4463 b = index_log_q(fl_idx);
4466 int fl_in = linkage_fleet(i);
4467 int fl_idx = (fl_in == 0) ? 0 : (fl_in - 1);
4476 int fl_in = linkage_fleet(i);
4477 int fl_idx = (fl_in == 0) ? 0 : (fl_in - 1);
4484 base_is_log =
false;
4486 b = log_sel_apical(fl_idx, sx_idx);
4491 base_is_log =
false;
4496 Type log_prior =
linkage_log_prior(fam, b, (linkage_is_intercept(i) == 1) && base_is_log,
4497 p1, p2, bias_adjust_proc);
4498 jnll_comp(JNLL_LINKAGE_PRIOR, slot_col) -= log_prior;
4499 unweighted_jnll_comp(JNLL_LINKAGE_PRIOR, slot_col) -= log_prior;
4505 if (log_sigma_linkage.size() > 0) {
4506 for (
int g = 0; g < log_sigma_linkage.size(); ++g) {
4507 int fam = linkage_re_sigma_prior_family(g);
4508 if (fam == 0)
continue;
4509 Type sd = exp(log_sigma_linkage(g));
4510 Type log_prior =
linkage_log_prior(fam, sd,
false, linkage_re_sigma_prior_p1(g),
4511 linkage_re_sigma_prior_p2(g), bias_adjust_proc);
4512 jnll_comp(JNLL_LINKAGE_PRIOR, 0) -= log_prior;
4513 unweighted_jnll_comp(JNLL_LINKAGE_PRIOR, 0) -= log_prior;
4520 if (trans_rho_linkage.size() > 0) {
4521 for (
int g = 0; g < linkage_re_rho.size(); ++g) {
4522 int fam = linkage_re_rho_prior_family(g);
4523 if ((fam != 1) && (fam != 4))
continue;
4524 Type rho =
rho_trans(trans_rho_linkage(linkage_re_rho(g)));
4525 Type x = (fam == 4) ? (rho + Type(1)) / Type(2) : rho;
4527 linkage_re_rho_prior_p2(g), bias_adjust_proc);
4528 jnll_comp(JNLL_LINKAGE_PRIOR, 0) -= log_prior;
4529 unweighted_jnll_comp(JNLL_LINKAGE_PRIOR, 0) -= log_prior;
4538 for (
int grp = 0; grp < log_sigma_linkage.size(); ++grp) {
4540 int len = slots.size();
4541 if (len == 0)
continue;
4542 vector<Type> re(len);
4543 for (
int t = 0; t < len; ++t) re(t) = beta_linkage_re_all(slots(t));
4545 int st = linkage_re_struct(grp);
4546 Type sigma = exp(log_sigma_linkage(grp));
4549 jnll_comp(JNLL_LINKAGE_RE, 0), unweighted_jnll_comp(JNLL_LINKAGE_RE, 0));
4553 if (linkage_re_obs(grp) >= 0) {
4554 Type osd = exp(log_obs_sd_linkage(linkage_re_obs(grp)));
4555 for (
int t = 0; t < len; ++t) {
4557 if (linkage_re_obs_mask(s) == 0)
continue;
4558 if (osa_mode == 0) {
4559 Type log_dens = dnorm(linkage_re_obs_value(s), re(t), osd,
true);
4560 jnll_comp(JNLL_LINKAGE_RE, 0) -= log_dens;
4561 unweighted_jnll_comp(JNLL_LINKAGE_RE, 0) -= log_dens;
4565 int pos = linkage_re_obsvec_idx(s);
4567 jnll_comp(JNLL_LINKAGE_RE, 0) -= keep(pos) * dnorm(obsvec(pos), re(t), osd,
true);
4568 unweighted_jnll_comp(JNLL_LINKAGE_RE, 0) -= keep(pos) * dnorm(obsvec(pos), re(t), osd,
true);
4570 if (osa_mode == 2) {
4572 obsvec(pos), re(t), osd, keep.cdf_lower(pos), keep.cdf_upper(pos));
4585 for(flt = 0; flt < n_col; flt++){
4586 for(
int ind = 0; ind < JNLL_N_ROWS; ind++){
4587 bool written_above = (ind == JNLL_COMP) || (ind == JNLL_CAAL) || (ind == JNLL_STOMACH) ||
4588 (ind == JNLL_LINKAGE_PRIOR) || (ind == JNLL_LINKAGE_RE);
4590 unweighted_jnll_comp(ind, flt) = jnll_comp(ind, flt);
4601 REPORT( pop_scalar );
4602 ADREPORT( pop_scalar );
4606 REPORT( avgN_at_age );
4607 REPORT( biomass_at_age );
4608 REPORT( biomass_depletion );
4609 REPORT( ssb_depletion );
4612 REPORT( exploitable_biomass );
4624 REPORT( weight_hat );
4625 REPORT( growth_matrix );
4626 REPORT( length_hat );
4628 ADREPORT( biomass );
4636 ADREPORT( exploitable_biomass );
4637 ADREPORT( biomass_depletion );
4638 ADREPORT( ssb_depletion );
4646 matrix<Type> log_biomass = biomass; log_biomass = log(biomass.array());
4647 matrix<Type> log_ssb = ssb; log_ssb = log(ssb.array());
4648 matrix<Type> log_R = R; log_R = log(R.array());
4649 REPORT( log_biomass );
4652 ADREPORT( log_biomass );
4653 ADREPORT( log_ssb );
4671 if(adreport_sel == 1){
4675 vector<int> sel_first_bin(n_flt); sel_first_bin.setZero();
4676 vector<int> sel_rep_bins(n_flt); sel_rep_bins.setZero();
4677 for(
int flt = 0; flt < n_flt; flt++){
4678 if((flt_type(flt) <= 0) || (flt_sel_lead(flt) != 1) ||
4679 (flt_sel_type(flt) == 0) || (flt_sel_dim(flt) == 1))
continue;
4680 int n_age = nages(flt_spp(flt));
4681 int first = bin_first_selected(flt);
4682 if(first < 0) first = 0;
4683 if(first > n_age) first = n_age;
4684 sel_first_bin(flt) = first;
4685 sel_rep_bins(flt) = n_age - first;
4689 for(
int flt = 0; flt < n_flt; flt++){
4690 n_sel += nsex(flt_spp(flt)) * sel_rep_bins(flt) * nyrs_hind;
4693 vector<Type> log_sel_at_age(n_sel); log_sel_at_age.setZero();
4694 matrix<Type> log_sel_at_age_index(n_sel, 4); log_sel_at_age_index.setZero();
4697 for(
int flt = 0; flt < n_flt; flt++){
4698 if(sel_rep_bins(flt) == 0)
continue;
4699 int sel_sp = flt_spp(flt);
4700 for(
int sel_sex = 0; sel_sex < nsex(sel_sp); sel_sex++){
4701 for(
int sel_age = sel_first_bin(flt); sel_age < nages(sel_sp); sel_age++){
4702 for(
int sel_yr = 0; sel_yr < nyrs_hind; sel_yr++){
4703 log_sel_at_age(i_sel) = log(
max2(sel_at_age(flt, sel_sex, sel_age, sel_yr),
4705 log_sel_at_age_index(i_sel, 0) = Type(flt + 1);
4706 log_sel_at_age_index(i_sel, 1) = Type(sel_sex + 1);
4707 log_sel_at_age_index(i_sel, 2) = Type(minage(sel_sp) + sel_age);
4708 log_sel_at_age_index(i_sel, 3) = Type(styr + sel_yr);
4715 REPORT( log_sel_at_age );
4716 REPORT( log_sel_at_age_index );
4717 ADREPORT( log_sel_at_age );
4728 REPORT( DynamicB0 );
4729 REPORT( DynamicSB0 );
4730 REPORT( DynamicSBF );
4734 REPORT( SPRtarget );
4735 REPORT( steepness );
4741 REPORT( sel_at_age );
4742 REPORT( sel_at_length );
4746 REPORT( index_hat );
4749 vector<Type> log_index_hat = index_hat; log_index_hat = log(index_hat.array());
4750 REPORT( log_index_hat );
4751 ADREPORT( log_index_hat );
4757 REPORT( beta_linkage );
4758 ADREPORT( beta_linkage );
4759 REPORT( beta_linkage_re );
4760 REPORT( beta_linkage_re_pen );
4763 REPORT( beta_linkage_re_all );
4764 REPORT( beta_linkage_obs );
4765 ADREPORT( beta_linkage_obs );
4771 REPORT( F_flt_age );
4773 REPORT( catch_hat );
4774 REPORT( max_catch_hat );
4776 REPORT( catch_analytical_sd );
4780 REPORT( age_obs_hat );
4785 REPORT( equil_catch_hat );
4787 REPORT( pred_CAAL );
4791 REPORT( jnll_comp );
4792 REPORT( unweighted_jnll_comp );
4796 REPORT( consumption_at_age );
4802 REPORT( suitability );
4803 REPORT( M1_at_age );
4804 REPORT( M2_at_age );
4806 REPORT( B_eaten_as_prey );
4808 REPORT( vulnerability );
4809 REPORT( vulnerability_other );
4813 REPORT( suit_other );
4814 REPORT( stom_div_bio );
4815 REPORT( avail_food );
4829 if(estimateMode < 4) {
4830 jnll = jnll_comp.sum();
4836 if(estimateMode > 3) {
4837 jnll = dummy * dummy;
void calculate_temperature_function(matrix< Type > &fT, int nspp, int nyrs, const vector< int > &Ceq, const vector< int > &Cindex, const vector< Type > &Qc, const vector< Type > &Tcm, const vector< Type > &Tco, const vector< Type > &Tcl, const vector< Type > &CK1, const vector< Type > &CK4, const matrix< Type > &env_index)
Temperature-dependent function of consumption (fT) for bioenergetics.
void calculate_ration(array< Type > &consumption_at_age, int nspp, int nyrs, int nyrs_hind, const vector< int > &nsex, const vector< int > &nages, const vector< int > &Ceq, const vector< Type > &CA, const vector< Type > &CB, const vector< Type > &fday, const vector< Type > &Pvalue, matrix< Type > &fT, array< Type > &ration_data, array< Type > &weight_hat)
Annual ration of a predator at age, in kg per predator per year.
One-step-ahead (OSA) residual helpers for composition data.
Type ddirmultinom_osa(vector< Type > obs, vector< Type > alpha, data_indicator< vector< Type >, Type > keep, int do_osa, int give_log)
Keep-aware Dirichlet-multinomial log-density via conditional beta-binomials.
Type dmultinom_osa(vector< Type > x, vector< Type > p, data_indicator< vector< Type >, Type > keep, int do_osa, int give_log, int do_cdf=0)
Keep-aware multinomial log-density via conditional binomials.
Type osa_norm_cdf_terms(Type x, Type mu, Type sd, Type cdf_lower, Type cdf_upper)
One-step-ahead CDF terms for a normal observation.
Type osa_trunc_norm_cdf_terms(Type x, Type mu, Type sd, Type cdf_lower, Type cdf_upper)
One-step-ahead CDF terms for a normal left-truncated at zero.
Random draws for composition-style observations, used by SIMULATE.
vector< Type > rdirmultinom_rce(Type N, vector< Type > alpha)
Draw Dirichlet-multinomial counts.
vector< Type > rmultinom_rce(Type N, vector< Type > p)
Draw multinomial counts by sequential conditional binomials.
void organize_diet_obs(const int &nspp, const int &nyrs, const int &nyrs_hind, const int &styr, const vector< int > &minage, const vector< int > &nsex, matrix< Type > &diet_obs, matrix< int > &diet_ctl, array< Type > &diet_prop)
Parses empirical diet observations and maps them into a 5D proportion array.
void predict_stomach_content(const int &nspp, const int &nyrs_hind, const int &styr, const vector< int > &suit_styr, const vector< int > &suit_endyr, const vector< int > &minage, const vector< int > &nsex, const vector< int > &nages, matrix< Type > &diet_obs, matrix< int > &diet_ctl, array< Type > &avgN_at_age, array< Type > &diet_prop_hat, matrix< Type > &diet_hat)
Expected stomach content proportions given the modeled population state.
void calculate_other_food_diet_prop(const int &nspp, const int &nyrs, const vector< int > &nsex, const vector< int > &nages, const vector< Type > &other_food, array< Type > &diet_prop, array< Type > &other_food_diet_prop)
Residual stomach content: the "other food" not explicitly modeled.
void calculate_weight(array< Type > &weight_hat, array< Type > &length_hat, array< Type > &growth_matrix, array< Type > &mat_weight_hat, array< Type > &weight_obs, const vector< int > &growth_model, const vector< int > &growth_sd_style, const vector< int > &growth_sd_form, const vector< int > &growth_plus_length, const vector< Type > &plus_group_decay, const int &nspp, const int &nyrs, const int &nyrs_hind, const int &n_flt, const vector< int > &flt_spp, vector< Type > flt_month, const vector< int > &nsex, const vector< int > &minage, const vector< Type > &growth_age_L1, const vector< int > &nages, const vector< int > &nlengths, const vector< int > &pop_wt_index, const vector< int > &ssb_wt_index, const vector< int > &flt_wt_index, vector< Type > spawn_month, matrix< Type > &lengths, const vector< int > &nlengths_pop, matrix< Type > &lengths_pop, array< Type > &growth_parameters, array< Type > &growth_log_sd, matrix< Type > weight_length_pars, const vector< int > &mat_len_use, matrix< Type > &mat_len_pars, array< Type > &log_M1)
Population, SSB and fleet weight-at-age (kg) for every species and fleet.
Small differentiable (AD-safe) utilities used across the CEATTLE template: numeric guards and transfo...
Type concentrated_lognormal_sd(Type mean_sq_resid, Type bias_adjust)
Concentrated (analytical) sd of a lognormal observation likelihood.
Eigen::SparseMatrix< Type > construct_Q(int n_years, int n_ages, matrix< Type > ay_Index, Type rho_y, Type rho_a, Type rho_c, Type log_sigma2, int Var_Param)
Construct a sparse GMRF precision matrix separable along year, age, and cohort.
Type log_mean_exp(const vector< Type > &x)
log(mean(exp(x))) over a non-empty vector, computed so it cannot overflow.
Type imax(const vector< Type > &x)
Type max2(Type x, Type y)
Type ddirmultinom(vector< Type > obs, vector< Type > alpha, int do_log)
Type posfun(Type x, Type eps, Type &penalty)
vector< Type > first_difference(const vector< Type > &x)
Likelihood math for section 13 of ceattle.cpp: the composition row density and linkage prior families...
Type linkage_log_prior(int family, Type value, bool value_is_log, Type p1, Type p2, Type bias_adjust_proc)
Log density of a linkage prior on the natural scale.
void fold_comp_tails(vector< Type > &obs, vector< Type > &hat, int &n_comp, int nbins_blk, int nblk, int yng, int old)
Composition tail accumulation (AFSC ac_yng / ac_old).
void comp_row_nll(int ll_type, int osa_mode, vector< Type > obs_prop, vector< Type > hat_prop, Type offset, Type n_samp, Type weight, Type dm_theta, vector< Type > &obsvec, data_indicator< vector< Type >, Type > &keep, int osa_start, const char *type_name, Type &nll, Type &unweighted_nll)
Negative log-likelihood of one composition row: an age or length composition, or one length bin of co...
#define RCEATTLE_SEL_DN_PEAK
#define RCEATTLE_N_REC_PARAMS
#define RCEATTLE_SEL_APICAL
#define RCEATTLE_COMP_THETA_DIET
#define RCEATTLE_REC_BETA
#define RCEATTLE_SEL_END_LOGIT
#define RCEATTLE_PROC_RECRUIT
void rceattle_apply_q_linkages(matrix< Type > &q_offset, int link_code, const LinkageTable< Type > <, int n_flt, int nyrs)
Add catchability offsets to q_offset[fleet, yr].
#define RCEATTLE_REC_R_INIT
#define RCEATTLE_PROC_GROWTH
#define RCEATTLE_N_GROWTH_PARAMS
#define RCEATTLE_REC_ALPHA
void rceattle_apply_sel_linkages(array< Type > &slp_offset, array< Type > &inf_offset, array< Type > &coff_offset, array< Type > &apical_offset, array< Type > &dn6_offset, int link_code, const LinkageTable< Type > <, int n_flt, int max_sex, int n_sel_bins, int nyrs)
Add selectivity offsets, by fleet, sex and year, to one of five arrays.
void rceattle_apply_recruitment_linkages(array< Type > &rec_offset, int link_code, const LinkageTable< Type > <, int nspp, int nyrs)
Add recruitment offsets to rec_offset[sp, param, yr].
#define RCEATTLE_COMP_THETA_COMP
#define RCEATTLE_LINK_IDENTITY
void rceattle_apply_growth_linkages(array< Type > &growth_offset, int link_code, const LinkageTable< Type > <, int nspp, const vector< int > &nsex, int nyrs)
Add growth offsets to growth_offset[sp, sex, yr, param].
#define RCEATTLE_SEL_SLP_ASC
void rceattle_re_group_nll(int structure, vector< Type > re, Type sigma, Type rho, Type &nll, Type &nll_unweighted)
Add the negative log density of one group's deviations to two accumulators.
#define RCEATTLE_PROC_COMP
void rceattle_apply_M_linkages(array< Type > &M_offset, int link_code, const LinkageTable< Type > <, int nspp, const vector< int > &nsex, const vector< int > &nages, int nyrs)
Add natural-mortality offsets to M_offset[sp, sex, age, yr].
#define RCEATTLE_LINK_LOG
#define RCEATTLE_SEL_INF_DESC
vector< int > rceattle_group_slots(const vector< int > &group_of_slot, int grp)
The random-effect slots of one group, in slot order, which is time order within a group (....
#define RCEATTLE_SEL_SLP_DESC
#define RCEATTLE_LINK_EXPONENTIAL
#define RCEATTLE_SEL_INF_ASC
#define RCEATTLE_COMP_THETA_CAAL
#define RCEATTLE_PROC_SEL
void calculate_msvpa_predation(array< Type > &avail_food, array< Type > &avail_food_dB0, array< Type > &avail_food_dBF, array< Type > &M2_at_age, array< Type > &M2_at_age_dB0, array< Type > &M2_at_age_dBF, array< Type > &M2_prop, array< Type > &B_eaten, array< Type > &B_eaten_as_prey, array< Type > &diet_prop_hat, array< Type > &other_diet_prop_hat, int nspp, int nyrs, const vector< int > &nsex, const vector< int > &nages, int msmMode, array< Type > &avgN_at_age, array< Type > &avgN_at_age_dB0, array< Type > &avgN_at_age_dBF, array< Type > &suitability, array< Type > &suit_other, array< Type > &weight_hat, array< Type > &ration, const vector< Type > &other_food)
Available food, predation mortality (M2), and consumed biomass (MSVPA).
void calculate_parametric_suitability(array< Type > &suitability, array< Type > &suit_other, int nspp, int nyrs, const vector< int > &nsex, const vector< int > &nages, const vector< int > &suitMode, array< Type > &length_hat, array< Type > &weight_hat, matrix< Type > &vulnerability, const vector< Type > &vulnerability_other, const vector< Type > &gam_a, const vector< Type > &gam_b)
Parametric suitability (Gamma, Lognormal, Normal) from size ratios.
void calculate_vulnerability(matrix< Type > &vulnerability, vector< Type > &vulnerability_other, int nspp, const vector< int > &suitMode, matrix< Type > &log_phi)
Transforms predator-prey preference parameters into vulnerability.
void calculate_msvpa_suitability(array< Type > &stom_div_bio, array< Type > &suitability, array< Type > &suit_other, int nspp, int nyrs, const vector< int > &suit_styr, const vector< int > &suit_endyr, const vector< int > &nyrs_suit, int msmMode, const vector< int > &nsex, const vector< int > &nages, const vector< int > &suitMode, array< Type > &diet_prop, array< Type > &avgN_at_age, array< Type > &weight_hat, array< Type > &other_food_diet_prop)
MSVPA/empirical suitability, from stomach content and prey biomass.
Type calculate_recruitment(int srr_fun, Type R0, Type ssb, Type srr_alpha, Type srr_beta, Type rec_dev, Type spr0)
Calculates the recruitment for a given species and year.
void calculate_selectivity(const int &nspp, const int &n_flt, const int &nyrs, const int &nyrs_hind, const int &styr, const vector< int > &nsex, const vector< int > &nages, const vector< int > &nlengths, matrix< Type > &lengths, const vector< int > &nlengths_pop, matrix< Type > &lengths_pop, const vector< int > &flt_spp, const vector< int > &flt_sel_type, const vector< int > &flt_varying_sel, const vector< int > &flt_sel_dim, const vector< int > &bin_first_selected, const vector< int > &flt_n_sel_bins, const vector< int > &flt_sel_cap_bin, const vector< int > &sel_norm_bin1, const vector< int > &sel_norm_bin2, const vector< int > &sel_norm_scope, const vector< int > &flt_sel_start_yr, matrix< Type > &emp_sel_obs, matrix< int > &emp_sel_ctl, array< Type > &log_sel_slp, array< Type > &log_sel_slp_dev, array< Type > &sel_inf, array< Type > &sel_inf_dev, array< Type > &sel_coff, array< Type > &sel_coff_dev, array< Type > &avg_sel, array< Type > &non_par_sel, array< Type > &log_non_par_sel, array< Type > &sel_at_length, array< Type > &sel_at_age, array< Type > &growth_matrix, array< Type > &sel_slp_off, array< Type > &sel_slp_off_nat, array< Type > &sel_inf_off, array< Type > &sel_inf_off_nat, array< Type > &sel_coff_off, array< Type > &sel_coff_off_nat, const int &sel_apical_on, array< Type > &log_sel_apical, array< Type > &sel_apical_off, array< Type > &sel_apical_off_nat, array< Type > &sel_dn6, array< Type > &sel_dn6_off, array< Type > &sel_dn6_off_nat, matrix< int > &sel_dn6_ends)
Calculates selectivity for every fleet, sex, bin (age or length) and year.
Spawning biomass per recruit, for the Amendment-56 SPR proxies.
Type spawning_biomass_per_recruit(const vector< Type > &n, const vector< Type > &Z, const vector< Type > &weight, const vector< Type > &mature_female, Type spawn_month)
Female spawning biomass per recruit, given a survivor schedule.
vector< Type > per_recruit_survivors(const vector< Type > &Z)
Survivors at age from one recruit under a fixed mortality schedule.
The linkage table: one entry per row, and the shared design matrix.