Rceattle C++ template
The CEATTLE likelihood: src/TMB/ceattle.cpp and its headers
Loading...
Searching...
No Matches
predation.hpp File Reference

Go to the source code of this file.

Functions

template<class Type>
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.
template<class Type>
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.
template<class Type>
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.
template<class Type>
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).

Function Documentation

◆ calculate_msvpa_predation()

template<class Type>
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).

Available food is suitability-weighted prey biomass plus "other food": prey numbers (thousands of fish) x weight (kg) = mt, and other_food is mt. Under msmMode = 2 (Type III) the prey term is squared, so the denominator is not a biomass there. M2 divides each predator's consumption (avgN x ration) by that denominator, so a LARGER available-food denominator gives LESS predation mortality. The dB0 (F = 0) and dBF (F = Ftarget) arrays repeat the calculation for the dynamic reference points. Prey biomass and the predator scalars are each computed once outside the deepest loop.

Parameters
avail_foodAvailable food (mt) [nspp, max_sex, max_age, nyrs], updated.
avail_food_dB0Available food at F=0, updated.
avail_food_dBFAvailable food at F=Ftarget, updated.
M2_at_agePredation mortality (yr^-1), updated; [nspp, max_sex, max_age, nyrs].
M2_at_age_dB0Predation mortality at F=0, updated.
M2_at_age_dBFPredation mortality at F=Ftarget, updated.
M2_propA predator age's contribution to prey M2, not a share of it.
B_eatenPrey biomass eaten by a specific predator age (mt), updated.
B_eaten_as_preyPrey biomass eaten by all predators (mt), updated.
diet_prop_hatPredicted diet proportions, updated.
other_diet_prop_hatPredicted proportion of "other food" in diet, updated.
nsppNumber of species.
nyrsYears, hindcast plus projection.
nsexSexes modelled per species: 1 = combined, 2 = both.
nagesAge bins per species.
msmModePredation mode (1 = Type II MSVPA, Holsman et al. 2015; 2 = Type III MSVPA, which squares the prey term).
avgN_at_ageAverage numbers-at-age (thousands of fish).
avgN_at_age_dB0Average numbers-at-age at F=0.
avgN_at_age_dBFAverage numbers-at-age at F=Ftarget.
suitabilityCalculated suitability.
suit_otherSuitability for "other food".
weight_hatEstimated weights-at-age (kg).
rationIndividual consumption (kg/predator/yr); consumption_at_age.
other_food"Other food" biomass by predator (mt).

Definition at line 349 of file predation.hpp.

◆ calculate_msvpa_suitability()

template<class Type>
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.

For predators with suitMode = 0. stom_div_bio is the observed diet proportion divided by prey biomass (numbers in thousands x weight in kg = mt; the prey term is squared under msmMode = 2, Type III). That ratio is normalized over the modeled prey and "other food", averaged over suit_styr..suit_endyr, and held constant across all years.

A prey age whose average numbers approach zero with a positive diet proportion sends stom_div_bio, and so the prey term, to infinity: that one cell takes the whole normalized share, "other food" vanishes, available food collapses with it, so M2 diverges. The other-food term is floored at a fixed fraction of the prey term, bounding suit_other below at floor/(1 + floor), leaving sum(suitability) + suit_other = 1 exact. .warn_suitability_floor() reports when it binds.

Parameters
stom_div_bioRatio of diet proportion to biomass, updated; [nspp*max_sex, nspp*max_sex, max_age, max_age, nyrs].
suitabilityFinal calculated suitability, updated.
suit_otherRemaining suitability for "other food", updated.
nsppNumber of species.
nyrsYears, hindcast plus projection.
suit_styrStart year index of the suitability window, per predator.
suit_endyrEnd year index of the suitability window, per predator.
nyrs_suitYears in the suitability window, per predator.
msmModePredation mode; 2 (Type III) squares the prey numbers.
nsexSexes modelled per species: 1 = combined, 2 = both.
nagesAge bins per species.
suitModeSuitability mode per predator species.
diet_propObserved diet proportions from organize_diet_obs().
avgN_at_ageAverage numbers-at-age (thousands of fish).
weight_hatEstimated weights-at-age (kg).
other_food_diet_propResidual diet proportion for "other food", per mt of it.

Definition at line 180 of file predation.hpp.

References imax(), and max2().

◆ calculate_parametric_suitability()

template<class Type>
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.

Evaluates the predator-to-prey size ratio against a density scaled to a peak of 1. suitMode sets both the density and the size metric:

  • Gamma: suitMode 1 (length-based) or 2 (weight-based)
  • Lognormal: suitMode 3 (length-based) or 4 (weight-based)
  • Normal: suitMode 5 (length-based) or 6 (weight-based) The length-based modes 1, 3 and 5 are NOT YET AVAILABLE: they need an active growth model, and data_check() blocks them until that validation is added.
Parameters
suitabilitySize-based suitability, updated [nspp*max_sex, nspp*max_sex, max_age, max_age, nyrs].
suit_otherBaseline vulnerability to "other food", updated; [nspp, max_sex, max_age, nyrs] – species NOT collapsed, unlike suitability.
nsppNumber of species.
nyrsYears, hindcast plus projection.
nsexSexes modelled per species: 1 = combined, 2 = both.
nagesAge bins per species.
suitModeParametric suitability mode per predator species.
length_hatLengths-at-age [nspp*2+n_flt, max_sex, max_age, nyrs].
weight_hatWeights-at-age [nspp*2+n_flt, max_sex, max_age, nyrs].
vulnerabilityBounded predator-prey vulnerability [nspp, nspp].
vulnerability_otherVulnerability preference for "other food" [nspp].
gam_aShape/mean parameter for predator size-selectivity [nspp].
gam_bScale/sd parameter for predator size-selectivity [nspp].

Definition at line 76 of file predation.hpp.

◆ calculate_vulnerability()

template<class Type>
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.

Multinomial logistic transform: each predator's prey preferences and its vulnerability to "other food" sum to 1. Parametric suitability only (suitMode > 0). Adopted from Trijoulet et al. 2020 (https://github.com/vtrijoulet/Multisp_model_JAE/blob/master/MS_SSM.cpp).

Parameters
vulnerabilityBounded predator-prey vulnerability [nspp, nspp], updated.
vulnerability_otherRemaining vulnerability for "other food" [nspp], updated.
nsppNumber of species.
suitModeSuitability/preference mode per species.
log_phiEstimated log-preference parameters [nspp, nspp].

Definition at line 20 of file predation.hpp.