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

Go to the source code of this file.

Functions

template<class Type>
void normalize_and_project_selectivity (const int &flt, const int &nyrs_hind, const int &nyrs, const vector< int > &flt_spp, const vector< int > &flt_sel_type, const vector< int > &flt_sel_dim, const vector< int > &bin_first_selected, const vector< int > &nages, const vector< int > &nlengths_pop, const vector< int > &nsex, const vector< int > &sel_norm_bin1, const vector< int > &sel_norm_bin2, const vector< int > &sel_norm_scope, array< Type > &selectivity)
 Zeroes, normalizes and projects ONE fleet's selectivity (age or length based).
template<class Type>
void convert_length_selectivity (const int &flt, const int &sp, const int &sex, const int &yr, const int &wtind, const vector< int > &nages, const vector< int > &nlengths_pop, array< Type > &sel_length, array< Type > &growth_matrix, array< Type > &sel_at_age)
 Converts one fleet/sex/year of length-based selectivity to ages: the sum over population length bins of selectivity-at-length x Prob(length | age).
template<class Type>
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.

Function Documentation

◆ calculate_selectivity()

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

An age-based curve is evaluated at the bin number bin + 1, without minage, so an inflection or peak is on the bin scale; a length-based one at bin midpoints (cm).

Forms (fleet_control$Selectivity; R/0-switches.R is the authority):

  • 0 Fixed: read from emp_sel_obs; age-based.
  • 1 Logistic.
  • 2 NonParametric (Ianelli et al. 2018, AMAK): one log coefficient per bin, mean-centred.
  • 3 DoubleLogistic (Dorn and Methot 1990).
  • 4 DescendingLogistic.
  • 5 Hake (Taylor et al. 2014): exp of the cumulative sum of coefficients.
  • 6 2DAR1: inverse logit of coefficients with AR1 deviates by bin and year.
  • 7 3DAR1 (Cheng et al. 2024): as 6, with a cohort term.
  • 8 DoubleNormal: Gaussian dome with a right-tail floor.
  • 9 NonParametricPM (AMAK "pm"): random walk on the log curve, capped at Sel_cap_bin.
  • 11 LogisticPM (AMAK "pm" bottom-trawl survey): multiplicative deviates, free first bin.
  • 13 NonParametricIntegrable: form 2 with deviates random_sel can integrate.
  • 15 DoubleNormalSS3: Stock Synthesis size pattern 24 (age pattern 20).

Which linkage offsets a form accepts is checked in R, by .check_sel_linkage_support().

Definition at line 151 of file selectivity.hpp.

References convert_length_selectivity(), isNA(), log_mean_exp(), max2(), normalize_and_project_selectivity(), and square().

◆ convert_length_selectivity()

template<class Type>
void convert_length_selectivity ( const int & flt,
const int & sp,
const int & sex,
const int & yr,
const int & wtind,
const vector< int > & nages,
const vector< int > & nlengths_pop,
array< Type > & sel_length,
array< Type > & growth_matrix,
array< Type > & sel_at_age )

Converts one fleet/sex/year of length-based selectivity to ages: the sum over population length bins of selectivity-at-length x Prob(length | age).

Definition at line 106 of file selectivity.hpp.

Referenced by calculate_selectivity().

◆ normalize_and_project_selectivity()

template<class Type>
void normalize_and_project_selectivity ( const int & flt,
const int & nyrs_hind,
const int & nyrs,
const vector< int > & flt_spp,
const vector< int > & flt_sel_type,
const vector< int > & flt_sel_dim,
const vector< int > & bin_first_selected,
const vector< int > & nages,
const vector< int > & nlengths_pop,
const vector< int > & nsex,
const vector< int > & sel_norm_bin1,
const vector< int > & sel_norm_bin2,
const vector< int > & sel_norm_scope,
array< Type > & selectivity )

Zeroes, normalizes and projects ONE fleet's selectivity (age or length based).

Normalization never applies to Hake (5), LogisticPM (11) or DoubleNormalSS3 (15). Under Sel_norm_scope = AcrossSexes the less-selected sex peaks below 1.

Parameters
sel_norm_bin1Normalization bin, 0-based; -99 = the maximum, -999 = off.
sel_norm_bin2Upper bin for the mean over a range; negative = no range.
sel_norm_scope0 = WithinSex (a reference per sex), 1 = AcrossSexes (pooled).
selectivity[fleet, sex, age or length bin, year], modified in place.

Definition at line 16 of file selectivity.hpp.

References max2().

Referenced by calculate_selectivity().