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;
134 const vector<int>& nsex,
135 const vector<int>& nages,
136 const vector<int>& nlengths,
137 const vector<int>& minage,
138 const vector<Type>& growth_age_L1,
139 const vector<int>& growth_model,
140 const vector<int>& growth_sd_style,
141 const vector<int>& growth_sd_form,
142 const vector<int>& growth_plus_length,
144 const vector<Type>& plus_group_decay,
145 matrix<Type>& lengths,
146 const vector<int>& nlengths_pop,
147 matrix<Type>& lengths_pop,
148 array<Type>& growth_parameters,
149 array<Type>& growth_log_sd,
150 matrix<Type>& weight_length_pars,
151 const vector<int>& mat_len_use,
152 matrix<Type>& mat_len_pars,
154 array<Type> &length_hat,
155 array<Type> &growth_matrix,
156 array<Type> &weight_hat,
157 array<Type> &mat_weight_hat
160 Type b_len, last_linear, current_age;
164 Type Lmin_sp = lengths_pop(sp, 0);
167 Type age_L1 = growth_age_L1(sp);
171 Type age_L1_safe = age_L1;
172 if (age_L1 <= Type(0)) age_L1_safe = Type(1);
174 for(
int sex = 0; sex < nsex(sp); sex++) {
175 for(
int yr = 0; yr < nyrs; yr++) {
176 for(
int age = 0; age < nages(sp); age++) {
179 Type kappa = growth_parameters(sp, sex, yr, 0);
180 Type l1 = growth_parameters(sp, sex, yr, 1);
181 Type linf = growth_parameters(sp, sex, yr, 2);
182 Type m = growth_parameters(sp, sex, yr, 3);
186 current_age = Type(age) + Type(minage(sp));
189 switch(growth_model(sp)) {
193 b_len = (l1 - Lmin_sp) / age_L1_safe;
196 if((current_age) <= age_L1){
197 length_hat(wtind, sex, age, yr) = Lmin_sp + b_len * (current_age);
200 length_hat(wtind, sex, age, yr) = linf + (l1 - linf) * exp(-kappa * (current_age - age_L1));
205 if(current_age - Type(1) < age_L1_safe || age == 0) {
206 last_linear = Lmin_sp + b_len * age_L1_safe;
207 length_hat(wtind, sex, age, yr) = last_linear + (last_linear - linf) * (exp(-kappa * (current_age - age_L1)) - 1.0);
210 Type lagkappa = growth_parameters(sp, sex, yr - 1, 0);
211 Type laglinf = growth_parameters(sp, sex, yr - 1, 2);
212 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);
221 b_len = (l1 - Lmin_sp) / age_L1_safe;
224 if((current_age) <= age_L1) {
225 length_hat(wtind, sex, age, yr) = Lmin_sp + b_len * (current_age);
228 length_hat(wtind, sex, age, yr) = pow(pow(linf, m) + (pow(l1, m) - pow(linf, m)) * exp(-kappa * (current_age - age_L1)), 1 / m);
231 if(current_age - Type(1) < age_L1_safe || age == 0) {
232 last_linear = Lmin_sp + b_len * age_L1_safe;
233 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);
236 Type lagkappa = growth_parameters(sp, sex, yr - 1, 0);
237 Type laglinf = growth_parameters(sp, sex, yr - 1, 2);
238 Type lagm = growth_parameters(sp, sex, yr - 1, 3);
239 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);
246 error(
"Non-parametric growth not yet implemented");
250 error(
"Invalid 'growth_model");
258 if(growth_model(sp) < 3 && age == (nages(sp) - 1)) {
259 Type current_size = length_hat(wtind, sex, age, yr);
260 Type diff = linf - current_size;
261 int oldest_age = minage(sp) + nages(sp) - 1;
262 if(growth_plus_length(sp) == 1) {
263 Type temp_n = 0, temp_sum = 0, weight_a = 1.0;
264 Type surv = exp(-exp(log_M1(sp, sex, nages(sp) - 1)));
265 for(
int a = 0; a <= nages(sp); a++) {
266 temp_sum += weight_a * (current_size + (Type(a) / Type(nages(sp))) * diff);
270 length_hat(wtind, sex, age, yr) = temp_sum / temp_n;
271 }
else if(growth_plus_length(sp) == 3) {
272 Type temp_n = 0, temp_sum = 0;
275 for(
int a = 0; a <= oldest_age; a++) {
276 Type weight_a = exp(Type(-0.2) * Type(a));
277 temp_sum += weight_a * (current_size + (Type(a) / Type(oldest_age)) * diff);
280 length_hat(wtind, sex, age, yr) = temp_sum / temp_n;
281 }
else if(growth_plus_length(sp) == 4) {
282 Type size = current_size, temp_sum = current_size, temp_n = 1.0, weight_a = 1.0;
286 for(
int a = 1; a <= 2 * oldest_age; a++) {
287 weight_a *= exp(-plus_group_decay(sp));
288 size += (linf - size) * (Type(1.0) - exp(-kappa));
289 temp_sum += weight_a * size;
292 length_hat(wtind, sex, age, yr) = temp_sum / temp_n;
297 if(growth_model(sp) < 3) {
298 Type len = length_hat(wtind, sex, age, yr);
300 growth_sd_style(sp), growth_sd_form(sp), l1, linf, len,
301 growth_log_sd(sp, sex, 0), growth_log_sd(sp, sex, 1));
303 lengths_pop, weight_length_pars,
304 mat_len_use, mat_len_pars, growth_matrix, weight_hat, mat_weight_hat);
345 const vector<int>& nsex,
346 const vector<int>& nages,
347 const vector<int>& nlengths,
348 const vector<int>& minage,
349 const vector<Type>& growth_age_L1,
350 const vector<int>& growth_model,
351 const vector<int>& growth_sd_style,
352 const vector<int>& growth_sd_form,
353 const vector<int>& growth_plus_length,
354 matrix<Type>& lengths,
355 const vector<int>& nlengths_pop,
356 matrix<Type>& lengths_pop,
357 array<Type>& growth_parameters,
358 array<Type>& growth_log_sd,
359 matrix<Type>& weight_length_pars,
360 const vector<int>& mat_len_use,
361 matrix<Type>& mat_len_pars,
362 array<Type> &length_hat,
363 array<Type> &growth_matrix,
364 array<Type> &weight_hat,
365 array<Type> &mat_weight_hat
368 Type b_len, current_age, last_linear;
372 Type Lmin_sp = lengths_pop(sp, 0);
373 Type age_L1 = growth_age_L1(sp);
378 Type age_L1_safe = age_L1;
379 if (age_L1 <= Type(0)) age_L1_safe = Type(1);
381 for(
int sex = 0; sex < nsex(sp); sex++) {
382 for(
int yr = 0; yr < nyrs; yr++) {
383 for(
int age = 0; age < nages(sp); age++) {
386 Type kappa = growth_parameters(sp, sex, yr, 0);
387 Type l1 = growth_parameters(sp, sex, yr, 1);
388 Type linf = growth_parameters(sp, sex, yr, 2);
389 Type m = growth_parameters(sp, sex, yr, 3);
392 current_age = Type(age) + Type(minage(sp)) + fracyr;
395 switch(growth_model(sp)) {
399 b_len = (l1 - Lmin_sp) / age_L1_safe;
402 if((current_age) <= age_L1){
403 length_hat(wtind, sex, age, yr) = Lmin_sp + b_len * (current_age);
408 }
else if(age + 1.0 == nages(sp) && growth_plus_length(sp) == 1) {
409 length_hat(wtind, sex, age, yr) = length_hat(id_pop, sex, age, yr);
415 }
else if(age + Type(minage(sp)) < age_L1){
416 last_linear = Lmin_sp + b_len * age_L1;
417 length_hat(wtind, sex, age, yr) = last_linear + (last_linear - linf) * (exp(-kappa * (current_age - age_L1)) - 1.0);
419 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);
426 b_len = (l1 - Lmin_sp) / age_L1_safe;
431 if((current_age) <= age_L1){
432 length_hat(wtind, sex, age, yr) = Lmin_sp + b_len * (current_age);
435 }
else if(age + 1.0 == nages(sp) && growth_plus_length(sp) == 1) {
436 length_hat(wtind, sex, age, yr) = length_hat(id_pop, sex, age, yr);
440 }
else if(age + Type(minage(sp)) < age_L1){
441 last_linear = Lmin_sp + b_len * age_L1;
442 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);
444 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);
449 error(
"Non-parametric growth not yet implemented");
453 error(
"Invalid 'growth_model");
457 if(growth_model(sp) < 3) {
458 Type len = length_hat(wtind, sex, age, yr);
460 growth_sd_style(sp), growth_sd_form(sp), l1, linf, len,
461 growth_log_sd(sp, sex, 0), growth_log_sd(sp, sex, 1));
463 lengths_pop, weight_length_pars,
464 mat_len_use, mat_len_pars, growth_matrix, weight_hat, mat_weight_hat);
499 array<Type> &weight_hat,
500 array<Type> &length_hat,
501 array<Type> &growth_matrix,
502 array<Type> &mat_weight_hat,
503 array<Type>& weight_obs,
504 const vector<int>& growth_model,
505 const vector<int>& growth_sd_style,
506 const vector<int>& growth_sd_form,
507 const vector<int>& growth_plus_length,
508 const vector<Type>& plus_group_decay,
511 const int& nyrs_hind,
513 const vector<int>& flt_spp,
514 vector<Type> flt_month,
515 const vector<int>& nsex,
516 const vector<int>& minage,
517 const vector<Type>& growth_age_L1,
518 const vector<int>& nages,
519 const vector<int>& nlengths,
520 const vector<int>& pop_wt_index,
521 const vector<int>& ssb_wt_index,
522 const vector<int>& flt_wt_index,
523 vector<Type> spawn_month,
524 matrix<Type>& lengths,
525 const vector<int>& nlengths_pop,
526 matrix<Type>& lengths_pop,
527 array<Type>& growth_parameters,
528 array<Type>& growth_log_sd,
529 matrix<Type> weight_length_pars,
530 const vector<int>& mat_len_use,
531 matrix<Type>& mat_len_pars,
540 for (
int sp = 0; sp < nspp; sp++) {
543 wt_idx_ssb = 2 * sp + 1;
546 if (growth_model(sp) == 0) {
547 for (
int sex = 0; sex < nsex(sp); sex++) {
548 for (
int age = 0; age < nages(sp); age++) {
549 for (
int yr = 0; yr < nyrs; yr++) {
552 yr_ind = (yr < nyrs_hind) ? yr : (nyrs_hind - 1);
555 weight_hat(wt_idx_pop, sex, age, yr) = weight_obs(pop_wt_index(sp), sex, age, yr_ind);
558 weight_hat(wt_idx_ssb, sex, age, yr) = weight_obs(ssb_wt_index(sp), sex, age, yr_ind);
565 if (growth_model(sp) > 0) {
602 spawn_month(sp) / Type(12.0),
631 for (
int flt = 0; flt < n_flt; flt++) {
632 int sp = flt_spp(flt);
633 Type mo = flt_month(flt);
635 wt_idx_flt = nspp * 2 + flt;
638 if (growth_model(sp) == 0) {
639 for (
int sex = 0; sex < nsex(sp); sex++) {
640 for (
int age = 0; age < nages(sp); age++) {
641 for (
int yr = 0; yr < nyrs; yr++) {
643 yr_ind = (yr < nyrs_hind) ? yr : (nyrs_hind - 1);
644 weight_hat(wt_idx_flt, sex, age, yr) = weight_obs(flt_wt_index(flt), sex, age, yr_ind);
651 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.