Rceattle C++ template
The CEATTLE likelihood: src/TMB/ceattle.cpp and its headers
Loading...
Searching...
No Matches
predation.hpp
Go to the documentation of this file.
1#ifndef PREDATION_HPP
2#define PREDATION_HPP
3
4
5/**
6 * @brief Transforms predator-prey preference parameters into vulnerability.
7 *
8 * Multinomial logistic transform: each predator's prey preferences and its vulnerability
9 * to "other food" sum to 1. Parametric suitability only (suitMode > 0). Adopted from
10 * Trijoulet et al. 2020
11 * (https://github.com/vtrijoulet/Multisp_model_JAE/blob/master/MS_SSM.cpp).
12 *
13 * @param vulnerability Bounded predator-prey vulnerability [nspp, nspp], updated.
14 * @param vulnerability_other Remaining vulnerability for "other food" [nspp], updated.
15 * @param nspp Number of species.
16 * @param suitMode Suitability/preference mode per species.
17 * @param log_phi Estimated log-preference parameters [nspp, nspp].
18 */
19template <class Type>
20void calculate_vulnerability(matrix<Type> &vulnerability,
21 vector<Type> &vulnerability_other,
22 int nspp,
23 const vector<int> &suitMode,
24 matrix<Type> &log_phi) {
25
26 vulnerability.setZero();
27 vulnerability_other.setZero();
28
29 for(int rsp = 0; rsp < nspp; rsp++) {
30 if(suitMode(rsp) > 0) {
31
32 Type sum_phi = 0;
33
34 for(int ksp = 0; ksp < nspp; ksp++) {
35 sum_phi += exp(log_phi(rsp, ksp));
36 }
37
38 for(int ksp = 0; ksp < nspp; ksp++) {
39 vulnerability(rsp, ksp) = exp(log_phi(rsp, ksp)) / (Type(1.0) + sum_phi);
40 }
41
42 vulnerability_other(rsp) = Type(1.0) - vulnerability.row(rsp).sum();
43 }
44 }
45}
46
47/**
48 * @brief Parametric suitability (Gamma, Lognormal, Normal) from size ratios.
49 *
50 * Evaluates the predator-to-prey size ratio against a density scaled to a peak of 1.
51 * `suitMode` sets both the density and the size metric:
52 * - Gamma: suitMode 1 (length-based) or 2 (weight-based)
53 * - Lognormal: suitMode 3 (length-based) or 4 (weight-based)
54 * - Normal: suitMode 5 (length-based) or 6 (weight-based)
55 * The length-based modes 1, 3 and 5 are NOT YET AVAILABLE: they need an active growth
56 * model, and data_check() blocks them until that validation is added.
57 *
58 * @param suitability Size-based suitability, updated
59 * [nspp*max_sex, nspp*max_sex, max_age, max_age, nyrs].
60 * @param suit_other Baseline vulnerability to "other food", updated;
61 * [nspp, max_sex, max_age, nyrs] -- species NOT collapsed,
62 * unlike suitability.
63 * @param nspp Number of species.
64 * @param nyrs Years, hindcast plus projection.
65 * @param nsex Sexes modelled per species: 1 = combined, 2 = both.
66 * @param nages Age bins per species.
67 * @param suitMode Parametric suitability mode per predator species.
68 * @param length_hat Lengths-at-age [nspp*2+n_flt, max_sex, max_age, nyrs].
69 * @param weight_hat Weights-at-age [nspp*2+n_flt, max_sex, max_age, nyrs].
70 * @param vulnerability Bounded predator-prey vulnerability [nspp, nspp].
71 * @param vulnerability_other Vulnerability preference for "other food" [nspp].
72 * @param gam_a Shape/mean parameter for predator size-selectivity [nspp].
73 * @param gam_b Scale/sd parameter for predator size-selectivity [nspp].
74 */
75template <class Type>
76void calculate_parametric_suitability(array<Type> &suitability,
77 array<Type> &suit_other,
78 int nspp, int nyrs,
79 const vector<int> &nsex,
80 const vector<int> &nages,
81 const vector<int> &suitMode,
82 array<Type> &length_hat,
83 array<Type> &weight_hat,
84 matrix<Type> &vulnerability,
85 const vector<Type> &vulnerability_other,
86 const vector<Type> &gam_a,
87 const vector<Type> &gam_b) {
88
89 for(int rsp = 0; rsp < nspp; rsp++) {
90 int smode = suitMode(rsp);
91 int wt_idx_rsp = 2 * rsp;
92
93 // Parametric suitability modes (1 through 6)
94 if(smode >= 1 && smode <= 6) {
95 for(int r_sex = 0; r_sex < nsex(rsp); r_sex++) {
96 int r_idx = rsp + (nspp * r_sex);
97
98 for(int r_age = 0; r_age < nages(rsp); r_age++) {
99 for(int ksp = 0; ksp < nspp; ksp++) {
100 int wt_idx_ksp = 2 * ksp;
101
102 for(int k_sex = 0; k_sex < nsex(ksp); k_sex++) {
103 int k_idx = ksp + (nspp * k_sex);
104
105 for(int k_age = 0; k_age < nages(ksp); k_age++) {
106 for(int yr = 0; yr < nyrs; yr++) {
107
108 suit_other(rsp, r_sex, r_age, yr) = vulnerability_other(rsp);
109 Type size_ratio = 0.0;
110
111 // Modes 1-4 use the log size ratio, 5 and 6 the raw ratio. A ratio of
112 // 0 or less leaves suitability at 0: on modes 1-4 that is prey at
113 // least as large as the predator.
114 if(smode == 1 || smode == 3) {
115 size_ratio = log(length_hat(rsp, r_sex, r_age, yr) / length_hat(ksp, k_sex, k_age, yr));
116 } else if (smode == 2 || smode == 4) {
117 size_ratio = log(weight_hat(wt_idx_rsp, r_sex, r_age, yr) / weight_hat(wt_idx_ksp, k_sex, k_age, yr));
118 } else if (smode == 5) {
119 size_ratio = length_hat(rsp, r_sex, r_age, yr) / length_hat(ksp, k_sex, k_age, yr);
120 } else if (smode == 6) {
121 size_ratio = weight_hat(wt_idx_rsp, r_sex, r_age, yr) / weight_hat(wt_idx_ksp, k_sex, k_age, yr);
122 }
123
124 if(size_ratio > 0) {
125 if(smode == 1 || smode == 2) {
126 // Divided by the density at the mode, (gam_a-1)*gam_b.
127 suitability(r_idx, k_idx, r_age, k_age, yr) = vulnerability(rsp, ksp) * dgamma(size_ratio, gam_a(rsp), gam_b(rsp)) /
128 dgamma((gam_a(rsp)-1) * gam_b(rsp), gam_a(rsp), gam_b(rsp));
129 } else if (smode >= 3 && smode <= 6) {
130 // Divided by the density at the mean, gam_a.
131 suitability(r_idx, k_idx, r_age, k_age, yr) = vulnerability(rsp, ksp) * dnorm(size_ratio, gam_a(rsp), gam_b(rsp)) /
132 dnorm(gam_a(rsp), gam_a(rsp), gam_b(rsp));
133 }
134 }
135 }
136 }
137 }
138 }
139 }
140 }
141 }
142 }
143}
144
145
146/**
147 * @brief MSVPA/empirical suitability, from stomach content and prey biomass.
148 *
149 * For predators with suitMode = 0. stom_div_bio is the observed diet proportion divided
150 * by prey biomass (numbers in thousands x weight in kg = mt; the prey term is squared
151 * under msmMode = 2, Type III). That ratio is normalized over the modeled prey and "other
152 * food", averaged over suit_styr..suit_endyr, and held constant across all years.
153 *
154 * A prey age whose average numbers approach zero with a positive diet proportion sends
155 * stom_div_bio, and so the prey term, to infinity: that one cell takes the whole
156 * normalized share, "other food" vanishes, available food collapses with it, so M2
157 * diverges. The other-food term is floored at a fixed fraction of the prey term, bounding
158 * suit_other below at floor/(1 + floor), leaving sum(suitability) + suit_other = 1 exact.
159 * .warn_suitability_floor() reports when it binds.
160 *
161 * @param stom_div_bio Ratio of diet proportion to biomass, updated;
162 * [nspp*max_sex, nspp*max_sex, max_age, max_age, nyrs].
163 * @param suitability Final calculated suitability, updated.
164 * @param suit_other Remaining suitability for "other food", updated.
165 * @param nspp Number of species.
166 * @param nyrs Years, hindcast plus projection.
167 * @param suit_styr Start year index of the suitability window, per predator.
168 * @param suit_endyr End year index of the suitability window, per predator.
169 * @param nyrs_suit Years in the suitability window, per predator.
170 * @param msmMode Predation mode; 2 (Type III) squares the prey numbers.
171 * @param nsex Sexes modelled per species: 1 = combined, 2 = both.
172 * @param nages Age bins per species.
173 * @param suitMode Suitability mode per predator species.
174 * @param diet_prop Observed diet proportions from organize_diet_obs().
175 * @param avgN_at_age Average numbers-at-age (thousands of fish).
176 * @param weight_hat Estimated weights-at-age (kg).
177 * @param other_food_diet_prop Residual diet proportion for "other food", per mt of it.
178 */
179template <class Type>
180void calculate_msvpa_suitability(array<Type> &stom_div_bio,
181 array<Type> &suitability,
182 array<Type> &suit_other,
183 int nspp, int nyrs,
184 const vector<int> &suit_styr, const vector<int> &suit_endyr, const vector<int> &nyrs_suit,
185 int msmMode,
186 const vector<int> &nsex,
187 const vector<int> &nages,
188 const vector<int> &suitMode,
189 array<Type> &diet_prop, // const
190 array<Type> &avgN_at_age,// const
191 array<Type> &weight_hat,// const
192 array<Type> &other_food_diet_prop) {// const
193
194 // Working sums per predator species/sex/age/year: stom_div_bio over prey,
195 // and diet proportion over prey.
196 int max_sex = imax(nsex);
197 int max_age = imax(nages);
198 array<Type> suma_suit(nspp, max_sex, max_age, nyrs);
199 suma_suit.setZero();
200
201 array<Type> diet_prop_sum(nspp, max_sex, max_age, nyrs);
202 diet_prop_sum.setZero();
203
204 stom_div_bio.setZero();
205
206
207 for(int rsp = 0; rsp < nspp; rsp++) {
208
209 if(suitMode(rsp) == 0) { // MSVPA based suitability
210
211 // Pass 1: diet proportion divided by prey biomass, and its per-predator-age sums.
212 for(int yr = 0; yr < nyrs; yr++) {
213 for(int ksp = 0; ksp < nspp; ksp++) {
214 int wt_idx_ksp = 2 * ksp;
215 for(int k_sex = 0; k_sex < nsex(ksp); k_sex++) {
216 int k_idx = ksp + (nspp * k_sex);
217
218 for(int k_age = 0; k_age < nages(ksp); k_age++) {
219
220 // prey_N is thousands of fish and prey_wt kg, so the product is mt.
221 // Type III MSVPA (msmMode 2) squares prey_N: prey_denom is not a biomass.
222 Type prey_wt = weight_hat(wt_idx_ksp, k_sex, k_age, yr);
223 Type prey_N = avgN_at_age(ksp, k_sex, k_age, yr);
224 if (msmMode == 2) { prey_N *= prey_N; }
225
226 Type prey_denom = prey_wt * prey_N;
227
228 if (prey_denom > Type(0.0)) {
229 Type inv_prey_denom = Type(1.0) / prey_denom;
230
231 for(int r_sex = 0; r_sex < nsex(rsp); r_sex++) {
232 int r_idx = rsp + (nspp * r_sex);
233 for(int r_age = 0; r_age < nages(rsp); r_age++) {
234
235 suitability(r_idx, k_idx, r_age, k_age, yr) = 0.0;
236 Type d_prop = diet_prop(r_idx, k_idx, r_age, k_age, yr);
237
238 if (d_prop > Type(0.0)) {
239 Type sdb = d_prop * inv_prey_denom;
240 stom_div_bio(r_idx, k_idx, r_age, k_age, yr) = sdb;
241 suma_suit(rsp, r_sex, r_age, yr) += sdb;
242 diet_prop_sum(rsp, r_sex, r_age, yr) += d_prop;
243 }
244 }
245 }
246 }
247 }
248 }
249 }
250 }
251
252 // Pass 2: normalize over the modeled prey plus "other food", then average the
253 // standardized ratio over the suitability window.
254 for(int r_sex = 0; r_sex < nsex(rsp); r_sex++) {
255 int r_idx = rsp + (nspp * r_sex);
256 for(int r_age = 0; r_age < nages(rsp); r_age++) {
257
258 vector<Type> inv_pred_denom(nyrs);
259 for(int yr = suit_styr(rsp); yr <= suit_endyr(rsp); yr++) {
260 Type prey_term = suma_suit(rsp, r_sex, r_age, yr);
261 // Other food is held at >= 1e-6 x the modelled-prey term, a unitless
262 // ratio, so suit_other cannot reach 0 when a prey age's biomass does.
263 Type other_term = max2(other_food_diet_prop(rsp, r_sex, r_age, yr),
264 Type(1.0e-6) * prey_term);
265 Type denom = prey_term + other_term;
266 // `diet_prop_sum` gates whether this predator age has diet data; `denom` is
267 // what we divide by and can reach 0 or go negative on its own, so floor it.
268 if (diet_prop_sum(rsp, r_sex, r_age, yr) > Type(0.0)) {
269 inv_pred_denom(yr) = Type(1.0) / max2(denom, Type(1.0e-10));
270 } else {
271 inv_pred_denom(yr) = Type(0.0);
272 }
273 }
274
275 Type total_suit_prey = Type(0.0); // Total suitability assigned to modeled prey
276
277 for(int ksp = 0; ksp < nspp; ksp++) {
278 for(int k_sex = 0; k_sex < nsex(ksp); k_sex++) {
279 int k_idx = ksp + (nspp * k_sex);
280 for(int k_age = 0; k_age < nages(ksp); k_age++) {
281
282 Type suit_sum_yrs = Type(0.0);
283
284 for(int yr = suit_styr(rsp); yr <= suit_endyr(rsp); yr++) {
285 suit_sum_yrs += stom_div_bio(r_idx, k_idx, r_age, k_age, yr) * inv_pred_denom(yr);
286 }
287
288 Type final_suit = suit_sum_yrs / Type(nyrs_suit(rsp));
289 total_suit_prey += final_suit;
290
291 for(int yr = 0; yr < nyrs; yr++) {
292 suitability(r_idx, k_idx, r_age, k_age, yr) = final_suit;
293 }
294 }
295 }
296 }
297
298 // "Other food" takes whatever suitability the modeled prey leave.
299 Type final_suit_other = Type(1.0) - total_suit_prey;
300 for(int yr = 0; yr < nyrs; yr++) {
301 suit_other(rsp, r_sex, r_age, yr) = final_suit_other;
302 }
303 }
304 }
305 }
306 }
307}
308
309
310/**
311 * @brief Available food, predation mortality (M2), and consumed biomass (MSVPA).
312 *
313 * Available food is suitability-weighted prey biomass plus "other food": prey numbers
314 * (thousands of fish) x weight (kg) = mt, and other_food is mt. Under msmMode = 2
315 * (Type III) the prey term is squared, so the denominator is not a biomass there. M2
316 * divides each predator's consumption (avgN x ration) by that denominator, so a LARGER
317 * available-food denominator gives LESS predation mortality. The dB0 (F = 0) and dBF
318 * (F = Ftarget) arrays repeat the calculation for the dynamic reference points. Prey
319 * biomass and the predator scalars are each computed once outside the deepest loop.
320 *
321 * @param avail_food Available food (mt) [nspp, max_sex, max_age, nyrs], updated.
322 * @param avail_food_dB0 Available food at F=0, updated.
323 * @param avail_food_dBF Available food at F=Ftarget, updated.
324 * @param M2_at_age Predation mortality (yr^-1), updated;
325 * [nspp, max_sex, max_age, nyrs].
326 * @param M2_at_age_dB0 Predation mortality at F=0, updated.
327 * @param M2_at_age_dBF Predation mortality at F=Ftarget, updated.
328 * @param M2_prop A predator age's contribution to prey M2, not a share of it.
329 * @param B_eaten Prey biomass eaten by a specific predator age (mt), updated.
330 * @param B_eaten_as_prey Prey biomass eaten by all predators (mt), updated.
331 * @param diet_prop_hat Predicted diet proportions, updated.
332 * @param other_diet_prop_hat Predicted proportion of "other food" in diet, updated.
333 * @param nspp Number of species.
334 * @param nyrs Years, hindcast plus projection.
335 * @param nsex Sexes modelled per species: 1 = combined, 2 = both.
336 * @param nages Age bins per species.
337 * @param msmMode Predation mode (1 = Type II MSVPA, Holsman et al. 2015;
338 * 2 = Type III MSVPA, which squares the prey term).
339 * @param avgN_at_age Average numbers-at-age (thousands of fish).
340 * @param avgN_at_age_dB0 Average numbers-at-age at F=0.
341 * @param avgN_at_age_dBF Average numbers-at-age at F=Ftarget.
342 * @param suitability Calculated suitability.
343 * @param suit_other Suitability for "other food".
344 * @param weight_hat Estimated weights-at-age (kg).
345 * @param ration Individual consumption (kg/predator/yr); consumption_at_age.
346 * @param other_food "Other food" biomass by predator (mt).
347 */
348template <class Type>
349void calculate_msvpa_predation(array<Type> &avail_food,
350 array<Type> &avail_food_dB0,
351 array<Type> &avail_food_dBF,
352 array<Type> &M2_at_age,
353 array<Type> &M2_at_age_dB0,
354 array<Type> &M2_at_age_dBF,
355 array<Type> &M2_prop,
356 array<Type> &B_eaten,
357 array<Type> &B_eaten_as_prey,
358 array<Type> &diet_prop_hat,
359 array<Type> &other_diet_prop_hat,
360 int nspp, int nyrs,
361 const vector<int> &nsex,
362 const vector<int> &nages,
363 int msmMode,
364 array<Type> &avgN_at_age, // const
365 array<Type> &avgN_at_age_dB0, // const
366 array<Type> &avgN_at_age_dBF, // const
367 array<Type> &suitability, // const
368 array<Type> &suit_other, // const
369 array<Type> &weight_hat, // const
370 array<Type> &ration,
371 const vector<Type> &other_food) {
372
373 // Predation is re-entered on every multispecies iteration (niter). M2, available food
374 // and B_eaten_as_prey accumulate with +=; the rest are written only where avail > 0.
375 avail_food.setZero();
376 avail_food_dB0.setZero();
377 avail_food_dBF.setZero();
378 M2_at_age.setZero();
379 M2_at_age_dB0.setZero();
380 M2_at_age_dBF.setZero();
381 M2_prop.setZero();
382 B_eaten.setZero();
383 B_eaten_as_prey.setZero();
384 diet_prop_hat.setZero();
385 other_diet_prop_hat.setZero();
386
387 // 1. Available food: suitability-weighted prey biomass (mt), then "other food".
388 for(int yr = 0; yr < nyrs; yr++) {
389 for(int ksp = 0; ksp < nspp; ksp++) {
390 int wt_idx_ksp = 2 * ksp;
391 for(int k_sex = 0; k_sex < nsex(ksp); k_sex++) {
392 int k_idx = ksp + (nspp * k_sex);
393 for(int k_age = 0; k_age < nages(ksp); k_age++) {
394
395 // msmMode 2 (Type III) squares the prey numbers; "other food" is never squared.
396 Type prey_N = avgN_at_age(ksp, k_sex, k_age, yr);
397 Type prey_N_adj = (msmMode == 1) ? prey_N : (prey_N * prey_N);
398
399 Type prey_N_dB0 = avgN_at_age_dB0(ksp, k_sex, k_age, yr);
400 Type prey_N_adj_dB0 = (msmMode == 1) ? prey_N_dB0 : (prey_N_dB0 * prey_N_dB0);
401
402 Type prey_N_dBF = avgN_at_age_dBF(ksp, k_sex, k_age, yr);
403 Type prey_N_adj_dBF = (msmMode == 1) ? prey_N_dBF : (prey_N_dBF * prey_N_dBF);
404
405 Type prey_wt = weight_hat(wt_idx_ksp, k_sex, k_age, yr);
406
407 Type bio_avail = prey_N_adj * prey_wt;
408 Type bio_avail_dB0 = prey_N_adj_dB0 * prey_wt; // dynamic B0, F = 0
409 Type bio_avail_dBF = prey_N_adj_dBF * prey_wt; // dynamic BF, F = Ftarget
410
411 for(int rsp = 0; rsp < nspp; rsp++) {
412 for(int r_sex = 0; r_sex < nsex(rsp); r_sex++) {
413 int r_idx = rsp + (nspp * r_sex);
414 for(int r_age = 0; r_age < nages(rsp); r_age++) {
415 Type suit = suitability(r_idx, k_idx, r_age, k_age, yr);
416 avail_food(rsp, r_sex, r_age, yr) += suit * bio_avail;
417 avail_food_dB0(rsp, r_sex, r_age, yr) += suit * bio_avail_dB0;
418 avail_food_dBF(rsp, r_sex, r_age, yr) += suit * bio_avail_dBF;
419 }
420 }
421 }
422 }
423 }
424 }
425
426 // "Other food" (mt) is prey outside the model, added once per predator age and year.
427 for(int rsp = 0; rsp < nspp; rsp++) {
428 for(int r_sex = 0; r_sex < nsex(rsp); r_sex++) {
429 for(int r_age = 0; r_age < nages(rsp); r_age++) {
430 Type other_f = other_food(rsp) * suit_other(rsp, r_sex, r_age, yr);
431 avail_food(rsp, r_sex, r_age, yr) += other_f;
432 avail_food_dB0(rsp, r_sex, r_age, yr) += other_f;
433 avail_food_dBF(rsp, r_sex, r_age, yr) += other_f;
434 }
435 }
436 }
437 }
438
439 // 2. Predation mortality (M2) and the prey biomass eaten.
440 for(int yr = 0; yr < nyrs; yr++) {
441 for(int rsp = 0; rsp < nspp; rsp++) {
442 for(int r_sex = 0; r_sex < nsex(rsp); r_sex++) {
443 int r_idx = rsp + (nspp * r_sex);
444 for(int r_age = 0; r_age < nages(rsp); r_age++) {
445
446 Type avail = avail_food(rsp, r_sex, r_age, yr);
447
448 if(avail > Type(0.0)) {
449 // avgN (thousands of fish) x ration (kg/predator/yr) is mt consumed, over
450 // available food in mt.
451 Type inv_avail = Type(1.0) / avail;
452 Type pred_rat = ration(rsp, r_sex, r_age, yr);
453 Type pred_mort_scalar = avgN_at_age(rsp, r_sex, r_age, yr) * pred_rat * inv_avail;
454
455 Type pred_mort_scalar_dB0 = Type(0.0);
456 Type avail_dB0 = avail_food_dB0(rsp, r_sex, r_age, yr);
457 if(avail_dB0 > Type(0.0)) {
458 pred_mort_scalar_dB0 = (avgN_at_age_dB0(rsp, r_sex, r_age, yr) * pred_rat) / avail_dB0;
459 }
460
461 Type pred_mort_scalar_dBF = Type(0.0);
462 Type avail_dBF = avail_food_dBF(rsp, r_sex, r_age, yr);
463 if(avail_dBF > Type(0.0)) {
464 pred_mort_scalar_dBF = (avgN_at_age_dBF(rsp, r_sex, r_age, yr) * pred_rat) / avail_dBF;
465 }
466
467 other_diet_prop_hat(rsp, r_sex, r_age, yr) = other_food(rsp) * suit_other(rsp, r_sex, r_age, yr) * inv_avail;
468
469 for(int ksp = 0; ksp < nspp; ksp++) {
470 int wt_idx_ksp = 2 * ksp;
471 for(int k_sex = 0; k_sex < nsex(ksp); k_sex++) {
472 int k_idx = ksp + (nspp * k_sex);
473 for(int k_age = 0; k_age < nages(ksp); k_age++) {
474
475 Type prey_N = avgN_at_age(ksp, k_sex, k_age, yr);
476 Type prey_wt = weight_hat(wt_idx_ksp, k_sex, k_age, yr);
477 Type suit = suitability(r_idx, k_idx, r_age, k_age, yr);
478
479 Type M2_frac = pred_mort_scalar * suit;
480 M2_at_age(ksp, k_sex, k_age, yr) += M2_frac;
481 M2_prop(r_idx, k_idx, r_age, k_age, yr) = M2_frac;
482
483 Type eaten = prey_N * prey_wt * M2_frac;
484 B_eaten(r_idx, k_idx, r_age, k_age, yr) = eaten;
485 B_eaten_as_prey(ksp, k_sex, k_age, yr) += eaten;
486
487 diet_prop_hat(r_idx, k_idx, r_age, k_age, yr) = prey_N * prey_wt * suit * inv_avail;
488
489 M2_at_age_dB0(ksp, k_sex, k_age, yr) += pred_mort_scalar_dB0 * suit;
490 M2_at_age_dBF(ksp, k_sex, k_age, yr) += pred_mort_scalar_dBF * suit;
491 }
492 }
493 }
494 }
495 }
496 }
497 }
498 }
499}
500
501
502
503#endif
Type imax(const vector< Type > &x)
Type max2(Type x, Type y)
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.
Definition predation.hpp:76
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.
Definition predation.hpp:20
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.