47 const vector<int>& nlengths_pop,
48 matrix<Type>& lengths_pop,
49 matrix<Type>& weight_length_pars,
50 const vector<int>& mat_len_use,
51 matrix<Type>& mat_len_pars,
52 array<Type>& growth_matrix,
53 array<Type>& weight_hat,
54 array<Type>& mat_weight_hat) {
55 int np = nlengths_pop(sp);
59 for(
int lp = 0; lp < np; lp++) growth_matrix(wtind, sex, age, lp, yr) = Type(0.0);
61 Type expected_weight = 0.0;
62 Type expected_mat_weight = 0.0;
63 for(
int lp = 0; lp < np; lp++) {
70 prob = pnorm((lengths_pop(sp, 1) - mu) / sd);
71 }
else if(lp == (np - 1)) {
72 prob = 1.0 - pnorm((lengths_pop(sp, np - 1) - mu) / sd);
74 prob = pnorm((lengths_pop(sp, lp + 1) - mu) / sd) - pnorm((lengths_pop(sp, lp) - mu) / sd);
76 growth_matrix(wtind, sex, age, lp, yr) = prob;
83 lenmid = (lengths_pop(sp, lp) + lengths_pop(sp, lp + 1)) / Type(2.0);
85 lenmid = lengths_pop(sp, np - 1);
87 lenmid = lengths_pop(sp, np - 1) + (lengths_pop(sp, np - 1) - lengths_pop(sp, np - 2)) / Type(2.0);
89 Type wt_len = weight_length_pars(sp, 0) * pow(lenmid, weight_length_pars(sp, 1));
90 expected_weight += prob * wt_len;
91 if(mat_len_use(sp) == 1) {
92 expected_mat_weight += prob * wt_len / (Type(1.0) + exp(-mat_len_pars(sp, 1) * (lenmid - mat_len_pars(sp, 0))));
95 weight_hat(wtind, sex, age, yr) = expected_weight;
96 if(mat_len_use(sp) == 1) mat_weight_hat(wtind, sex, age, yr) = expected_mat_weight;
137 const vector<int>& nsex,
138 const vector<int>& nages,
139 const vector<int>& nlengths,
140 const vector<int>& minage,
141 const vector<Type>& growth_age_L1,
142 const vector<int>& growth_model,
143 const vector<int>& growth_sd_style,
144 const vector<int>& growth_sd_form,
145 const vector<int>& growth_plus_length,
147 const vector<Type>& plus_group_decay,
148 matrix<Type>& lengths,
149 const vector<int>& nlengths_pop,
150 matrix<Type>& lengths_pop,
151 array<Type>& growth_parameters,
152 array<Type>& growth_log_sd,
153 matrix<Type>& weight_length_pars,
154 const vector<int>& mat_len_use,
155 matrix<Type>& mat_len_pars,
157 array<Type> &length_hat,
158 array<Type> &growth_matrix,
159 array<Type> &weight_hat,
160 array<Type> &mat_weight_hat
163 Type b_len, last_linear, current_age;
167 Type Lmin_sp = lengths_pop(sp, 0);
170 Type age_L1 = growth_age_L1(sp);
174 Type age_L1_safe = age_L1;
175 if (age_L1 <= Type(0)) age_L1_safe = Type(1);
177 for(
int sex = 0; sex < nsex(sp); sex++) {
178 for(
int yr = 0; yr < nyrs; yr++) {
179 for(
int age = 0; age < nages(sp); age++) {
182 Type kappa = growth_parameters(sp, sex, yr, 0);
183 Type l1 = growth_parameters(sp, sex, yr, 1);
184 Type linf = growth_parameters(sp, sex, yr, 2);
185 Type m = growth_parameters(sp, sex, yr, 3);
189 current_age = Type(age) + Type(minage(sp));
192 switch(growth_model(sp)) {
196 b_len = (l1 - Lmin_sp) / age_L1_safe;
199 if((current_age) <= age_L1){
200 length_hat(wtind, sex, age, yr) = Lmin_sp + b_len * (current_age);
203 length_hat(wtind, sex, age, yr) = linf + (l1 - linf) * exp(-kappa * (current_age - age_L1));
208 if(current_age - Type(1) < age_L1_safe || age == 0) {
209 last_linear = Lmin_sp + b_len * age_L1_safe;
210 length_hat(wtind, sex, age, yr) = last_linear + (last_linear - linf) * (exp(-kappa * (current_age - age_L1)) - 1.0);
213 Type lagkappa = growth_parameters(sp, sex, yr - 1, 0);
214 Type laglinf = growth_parameters(sp, sex, yr - 1, 2);
215 length_hat(wtind, sex, age, yr) = length_hat(wtind, sex, age - 1, yr - 1) + (length_hat(wtind, sex, age - 1, yr - 1) - laglinf) * (exp(-lagkappa) - 1.0);
224 b_len = (l1 - Lmin_sp) / age_L1_safe;
227 if((current_age) <= age_L1) {
228 length_hat(wtind, sex, age, yr) = Lmin_sp + b_len * (current_age);
231 length_hat(wtind, sex, age, yr) = pow(pow(linf, m) + (pow(l1, m) - pow(linf, m)) * exp(-kappa * (current_age - age_L1)), 1 / m);
234 if(current_age - Type(1) < age_L1_safe || age == 0) {
235 last_linear = Lmin_sp + b_len * age_L1_safe;
236 length_hat(wtind, sex, age, yr) = pow(pow(last_linear, m) + (pow(last_linear, m) - pow(linf, m)) * (exp(-kappa * (current_age - age_L1)) - 1.0), 1 / m);
239 Type lagkappa = growth_parameters(sp, sex, yr - 1, 0);
240 Type laglinf = growth_parameters(sp, sex, yr - 1, 2);
241 Type lagm = growth_parameters(sp, sex, yr - 1, 3);
242 length_hat(wtind, sex, age, yr) = pow(pow(length_hat(wtind, sex, age - 1, yr - 1), lagm) + (pow(length_hat(wtind, sex, age - 1, yr - 1), lagm) - pow(laglinf, lagm)) * (exp(-lagkappa) - 1.0), 1 / lagm);
249 error(
"Non-parametric growth not yet implemented");
253 error(
"Invalid 'growth_model");
261 if(growth_model(sp) < 3 && age == (nages(sp) - 1)) {
262 Type current_size = length_hat(wtind, sex, age, yr);
263 Type diff = linf - current_size;
264 int oldest_age = minage(sp) + nages(sp) - 1;
265 if(growth_plus_length(sp) == 1) {
266 Type temp_n = 0, temp_sum = 0, weight_a = 1.0;
267 Type surv = exp(-exp(log_M1(sp, sex, nages(sp) - 1)));
268 for(
int a = 0; a <= nages(sp); a++) {
269 temp_sum += weight_a * (current_size + (Type(a) / Type(nages(sp))) * diff);
273 length_hat(wtind, sex, age, yr) = temp_sum / temp_n;
274 }
else if(growth_plus_length(sp) == 3) {
275 Type temp_n = 0, temp_sum = 0;
278 for(
int a = 0; a <= oldest_age; a++) {
279 Type weight_a = exp(Type(-0.2) * Type(a));
280 temp_sum += weight_a * (current_size + (Type(a) / Type(oldest_age)) * diff);
283 length_hat(wtind, sex, age, yr) = temp_sum / temp_n;
284 }
else if(growth_plus_length(sp) == 4) {
285 Type size = current_size, temp_sum = current_size, temp_n = 1.0, weight_a = 1.0;
289 for(
int a = 1; a <= 2 * oldest_age; a++) {
290 weight_a *= exp(-plus_group_decay(sp));
291 size += (linf - size) * (Type(1.0) - exp(-kappa));
292 temp_sum += weight_a * size;
295 length_hat(wtind, sex, age, yr) = temp_sum / temp_n;
300 if(growth_model(sp) < 3) {
301 Type len = length_hat(wtind, sex, age, yr);
303 growth_sd_style(sp), growth_sd_form(sp), l1, linf, len,
304 growth_log_sd(sp, sex, 0), growth_log_sd(sp, sex, 1));
306 lengths_pop, weight_length_pars,
307 mat_len_use, mat_len_pars, growth_matrix, weight_hat, mat_weight_hat);
351 const vector<int>& nsex,
352 const vector<int>& nages,
353 const vector<int>& nlengths,
354 const vector<int>& minage,
355 const vector<Type>& growth_age_L1,
356 const vector<int>& growth_model,
357 const vector<int>& growth_sd_style,
358 const vector<int>& growth_sd_form,
359 const vector<int>& growth_plus_length,
360 matrix<Type>& lengths,
361 const vector<int>& nlengths_pop,
362 matrix<Type>& lengths_pop,
363 array<Type>& growth_parameters,
364 array<Type>& growth_log_sd,
365 matrix<Type>& weight_length_pars,
366 const vector<int>& mat_len_use,
367 matrix<Type>& mat_len_pars,
368 array<Type> &length_hat,
369 array<Type> &growth_matrix,
370 array<Type> &weight_hat,
371 array<Type> &mat_weight_hat
374 Type b_len, current_age, last_linear;
378 Type Lmin_sp = lengths_pop(sp, 0);
379 Type age_L1 = growth_age_L1(sp);
384 Type age_L1_safe = age_L1;
385 if (age_L1 <= Type(0)) age_L1_safe = Type(1);
387 for(
int sex = 0; sex < nsex(sp); sex++) {
388 for(
int yr = 0; yr < nyrs; yr++) {
389 for(
int age = 0; age < nages(sp); age++) {
392 Type kappa = growth_parameters(sp, sex, yr, 0);
393 Type l1 = growth_parameters(sp, sex, yr, 1);
394 Type linf = growth_parameters(sp, sex, yr, 2);
395 Type m = growth_parameters(sp, sex, yr, 3);
398 current_age = Type(age) + Type(minage(sp)) + fracyr;
401 switch(growth_model(sp)) {
405 b_len = (l1 - Lmin_sp) / age_L1_safe;
408 if((current_age) <= age_L1){
409 length_hat(wtind, sex, age, yr) = Lmin_sp + b_len * (current_age);
414 }
else if(age + 1.0 == nages(sp) && growth_plus_length(sp) == 1) {
415 length_hat(wtind, sex, age, yr) = length_hat(id_pop, sex, age, yr);
421 }
else if(age + Type(minage(sp)) < age_L1){
422 last_linear = Lmin_sp + b_len * age_L1;
423 length_hat(wtind, sex, age, yr) = last_linear + (last_linear - linf) * (exp(-kappa * (current_age - age_L1)) - 1.0);
425 length_hat(wtind, sex, age, yr) = length_hat(id_pop, sex, age, yr) + (length_hat(id_pop, sex, age, yr) - linf) * (exp(-kappa * fracyr) - 1.0);
432 b_len = (l1 - Lmin_sp) / age_L1_safe;
437 if((current_age) <= age_L1){
438 length_hat(wtind, sex, age, yr) = Lmin_sp + b_len * (current_age);
441 }
else if(age + 1.0 == nages(sp) && growth_plus_length(sp) == 1) {
442 length_hat(wtind, sex, age, yr) = length_hat(id_pop, sex, age, yr);
446 }
else if(age + Type(minage(sp)) < age_L1){
447 last_linear = Lmin_sp + b_len * age_L1;
448 length_hat(wtind, sex, age, yr) = pow(pow(last_linear, m) + (pow(last_linear, m) - pow(linf, m)) * (exp(-kappa * (current_age - age_L1)) - 1.0), 1 / m);
450 length_hat(wtind, sex, age, yr) = pow(pow(length_hat(id_pop, sex, age, yr), m) + (pow(length_hat(id_pop, sex, age, yr), m) - pow(linf, m)) * (exp(-kappa * fracyr) - 1.0), 1 / m);
455 error(
"Non-parametric growth not yet implemented");
459 error(
"Invalid 'growth_model");
463 if(growth_model(sp) < 3) {
464 Type len = length_hat(wtind, sex, age, yr);
466 growth_sd_style(sp), growth_sd_form(sp), l1, linf, len,
467 growth_log_sd(sp, sex, 0), growth_log_sd(sp, sex, 1));
469 lengths_pop, weight_length_pars,
470 mat_len_use, mat_len_pars, growth_matrix, weight_hat, mat_weight_hat);
505 array<Type> &weight_hat,
506 array<Type> &length_hat,
507 array<Type> &growth_matrix,
508 array<Type> &mat_weight_hat,
509 array<Type>& weight_obs,
510 const vector<int>& growth_model,
511 const vector<int>& growth_sd_style,
512 const vector<int>& growth_sd_form,
513 const vector<int>& growth_plus_length,
514 const vector<Type>& plus_group_decay,
517 const int& nyrs_hind,
519 const vector<int>& flt_spp,
520 vector<Type> flt_month,
521 const vector<int>& nsex,
522 const vector<int>& minage,
523 const vector<Type>& growth_age_L1,
524 const vector<int>& nages,
525 const vector<int>& nlengths,
526 const vector<int>& pop_wt_index,
527 const vector<int>& ssb_wt_index,
528 const vector<int>& flt_wt_index,
529 vector<Type> spawn_month,
530 matrix<Type>& lengths,
531 const vector<int>& nlengths_pop,
532 matrix<Type>& lengths_pop,
533 array<Type>& growth_parameters,
534 array<Type>& growth_log_sd,
535 matrix<Type> weight_length_pars,
536 const vector<int>& mat_len_use,
537 matrix<Type>& mat_len_pars,
546 for (
int sp = 0; sp < nspp; sp++) {
549 wt_idx_ssb = 2 * sp + 1;
552 if (growth_model(sp) == 0) {
553 for (
int sex = 0; sex < nsex(sp); sex++) {
554 for (
int age = 0; age < nages(sp); age++) {
555 for (
int yr = 0; yr < nyrs; yr++) {
558 yr_ind = (yr < nyrs_hind) ? yr : (nyrs_hind - 1);
561 weight_hat(wt_idx_pop, sex, age, yr) = weight_obs(pop_wt_index(sp), sex, age, yr_ind);
564 weight_hat(wt_idx_ssb, sex, age, yr) = weight_obs(ssb_wt_index(sp), sex, age, yr_ind);
571 if (growth_model(sp) > 0) {
608 spawn_month(sp) / Type(12.0),
637 for (
int flt = 0; flt < n_flt; flt++) {
638 int sp = flt_spp(flt);
639 Type mo = flt_month(flt);
641 wt_idx_flt = nspp * 2 + flt;
644 if (growth_model(sp) == 0) {
645 for (
int sex = 0; sex < nsex(sp); sex++) {
646 for (
int age = 0; age < nages(sp); age++) {
647 for (
int yr = 0; yr < nyrs; yr++) {
649 yr_ind = (yr < nyrs_hind) ? yr : (nyrs_hind - 1);
650 weight_hat(wt_idx_flt, sex, age, yr) = weight_obs(flt_wt_index(flt), sex, age, yr_ind);
657 if (growth_model(sp) > 0) {
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.
void estimate_growth(int wtind, int sp, int nspp, int nyrs, const vector< int > &nsex, const vector< int > &nages, const vector< int > &nlengths, const vector< int > &minage, const vector< Type > &growth_age_L1, 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, 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, array< Type > &length_hat, array< Type > &growth_matrix, array< Type > &weight_hat, array< Type > &mat_weight_hat)
Jan-1 (month 0) mean length, age-length key and weight-at-age for one species.
void estimate_growth_within_yr(int wtind, int id_pop, int sp, Type fracyr, int nspp, int nyrs, const vector< int > &nsex, const vector< int > &nages, const vector< int > &nlengths, const vector< int > &minage, const vector< Type > &growth_age_L1, const vector< int > &growth_model, const vector< int > &growth_sd_style, const vector< int > &growth_sd_form, const vector< int > &growth_plus_length, 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 > &length_hat, array< Type > &growth_matrix, array< Type > &weight_hat, array< Type > &mat_weight_hat)
Mean length-at-age, age-length key and weight-at-age fracyr into the year.