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

Go to the source code of this file.

Classes

struct  LinkageTable< Type >
 The linkage table: one entry per row, and the shared design matrix. More...

Macros

#define RCEATTLE_PROC_RECRUIT   0
#define RCEATTLE_PROC_M   1
#define RCEATTLE_PROC_GROWTH   2
#define RCEATTLE_PROC_Q   3
#define RCEATTLE_PROC_SEL   4
#define RCEATTLE_PROC_COMP   5
#define RCEATTLE_N_GROWTH_PARAMS   4
#define RCEATTLE_N_REC_PARAMS   4
#define RCEATTLE_REC_R0   0
#define RCEATTLE_REC_ALPHA   1
#define RCEATTLE_REC_BETA   2
#define RCEATTLE_REC_R_INIT   3
#define RCEATTLE_LINK_IDENTITY   0
#define RCEATTLE_LINK_LOG   1
#define RCEATTLE_LINK_LOGIT   2
#define RCEATTLE_LINK_EXPONENTIAL   3
#define RCEATTLE_RE_IID   0
#define RCEATTLE_RE_RW   1
#define RCEATTLE_RE_AR1   2
#define RCEATTLE_SEL_SLP_ASC   0
#define RCEATTLE_SEL_SLP_DESC   1
#define RCEATTLE_SEL_INF_ASC   2
#define RCEATTLE_SEL_INF_DESC   3
#define RCEATTLE_SEL_COFF   4
#define RCEATTLE_SEL_APICAL   5
#define RCEATTLE_SEL_DN_PEAK   6
#define RCEATTLE_SEL_TOP_LOGIT   7
#define RCEATTLE_SEL_ASCEND_SE   8
#define RCEATTLE_SEL_DESCEND_SE   9
#define RCEATTLE_SEL_START_LOGIT   10
#define RCEATTLE_SEL_END_LOGIT   11
#define RCEATTLE_COMP_THETA_COMP   0
#define RCEATTLE_COMP_THETA_CAAL   1
#define RCEATTLE_COMP_THETA_DIET   2

Functions

void rceattle_stratum_range (int id, int n_levels, int &lo, int &hi)
 Expand a stratum id into the loop range [lo, hi).
template<class Type>
void rceattle_apply_growth_linkages (array< Type > &growth_offset, int link_code, const LinkageTable< Type > &lt, int nspp, const vector< int > &nsex, int nyrs)
 Add growth offsets to growth_offset[sp, sex, yr, param].
template<class Type>
void rceattle_apply_M_linkages (array< Type > &M_offset, int link_code, const LinkageTable< Type > &lt, int nspp, const vector< int > &nsex, const vector< int > &nages, int nyrs)
 Add natural-mortality offsets to M_offset[sp, sex, age, yr].
template<class Type>
void rceattle_apply_recruitment_linkages (array< Type > &rec_offset, int link_code, const LinkageTable< Type > &lt, int nspp, int nyrs)
 Add recruitment offsets to rec_offset[sp, param, yr].
template<class Type>
void rceattle_apply_q_linkages (matrix< Type > &q_offset, int link_code, const LinkageTable< Type > &lt, int n_flt, int nyrs)
 Add catchability offsets to q_offset[fleet, yr].
template<class Type>
void rceattle_apply_sel_linkages (array< Type > &slp_offset, array< Type > &inf_offset, array< Type > &coff_offset, array< Type > &apical_offset, array< Type > &dn6_offset, int link_code, const LinkageTable< Type > &lt, int n_flt, int max_sex, int n_sel_bins, int nyrs)
 Add selectivity offsets, by fleet, sex and year, to one of five arrays.
vector< int > rceattle_group_slots (const vector< int > &group_of_slot, int grp)
 The random-effect slots of one group, in slot order, which is time order within a group (.assign_re_registry()).
template<class Type>
void rceattle_re_group_nll (int structure, vector< Type > re, Type sigma, Type rho, Type &nll, Type &nll_unweighted)
 Add the negative log density of one group's deviations to two accumulators.

Macro Definition Documentation

◆ RCEATTLE_COMP_THETA_CAAL

#define RCEATTLE_COMP_THETA_CAAL   1

Definition at line 70 of file linkage.hpp.

◆ RCEATTLE_COMP_THETA_COMP

#define RCEATTLE_COMP_THETA_COMP   0

Definition at line 69 of file linkage.hpp.

◆ RCEATTLE_COMP_THETA_DIET

#define RCEATTLE_COMP_THETA_DIET   2

Definition at line 71 of file linkage.hpp.

◆ RCEATTLE_LINK_EXPONENTIAL

#define RCEATTLE_LINK_EXPONENTIAL   3

Definition at line 45 of file linkage.hpp.

◆ RCEATTLE_LINK_IDENTITY

#define RCEATTLE_LINK_IDENTITY   0

Definition at line 42 of file linkage.hpp.

◆ RCEATTLE_LINK_LOG

#define RCEATTLE_LINK_LOG   1

Definition at line 43 of file linkage.hpp.

◆ RCEATTLE_LINK_LOGIT

#define RCEATTLE_LINK_LOGIT   2

Definition at line 44 of file linkage.hpp.

◆ RCEATTLE_N_GROWTH_PARAMS

#define RCEATTLE_N_GROWTH_PARAMS   4

Definition at line 31 of file linkage.hpp.

Referenced by rceattle_apply_growth_linkages().

◆ RCEATTLE_N_REC_PARAMS

#define RCEATTLE_N_REC_PARAMS   4

Definition at line 35 of file linkage.hpp.

Referenced by rceattle_apply_recruitment_linkages().

◆ RCEATTLE_PROC_COMP

#define RCEATTLE_PROC_COMP   5

Definition at line 27 of file linkage.hpp.

◆ RCEATTLE_PROC_GROWTH

#define RCEATTLE_PROC_GROWTH   2

Definition at line 24 of file linkage.hpp.

Referenced by rceattle_apply_growth_linkages().

◆ RCEATTLE_PROC_M

#define RCEATTLE_PROC_M   1

Definition at line 23 of file linkage.hpp.

Referenced by rceattle_apply_M_linkages().

◆ RCEATTLE_PROC_Q

#define RCEATTLE_PROC_Q   3

Definition at line 25 of file linkage.hpp.

Referenced by rceattle_apply_q_linkages().

◆ RCEATTLE_PROC_RECRUIT

#define RCEATTLE_PROC_RECRUIT   0

Definition at line 22 of file linkage.hpp.

Referenced by rceattle_apply_recruitment_linkages().

◆ RCEATTLE_PROC_SEL

#define RCEATTLE_PROC_SEL   4

Definition at line 26 of file linkage.hpp.

Referenced by rceattle_apply_sel_linkages().

◆ RCEATTLE_RE_AR1

#define RCEATTLE_RE_AR1   2

Definition at line 51 of file linkage.hpp.

Referenced by rceattle_re_group_nll().

◆ RCEATTLE_RE_IID

#define RCEATTLE_RE_IID   0

Definition at line 49 of file linkage.hpp.

◆ RCEATTLE_RE_RW

#define RCEATTLE_RE_RW   1

Definition at line 50 of file linkage.hpp.

Referenced by rceattle_re_group_nll().

◆ RCEATTLE_REC_ALPHA

#define RCEATTLE_REC_ALPHA   1

Definition at line 37 of file linkage.hpp.

◆ RCEATTLE_REC_BETA

#define RCEATTLE_REC_BETA   2

Definition at line 38 of file linkage.hpp.

◆ RCEATTLE_REC_R0

#define RCEATTLE_REC_R0   0

Definition at line 36 of file linkage.hpp.

◆ RCEATTLE_REC_R_INIT

#define RCEATTLE_REC_R_INIT   3

Definition at line 39 of file linkage.hpp.

◆ RCEATTLE_SEL_APICAL

#define RCEATTLE_SEL_APICAL   5

Definition at line 60 of file linkage.hpp.

Referenced by rceattle_apply_sel_linkages().

◆ RCEATTLE_SEL_ASCEND_SE

#define RCEATTLE_SEL_ASCEND_SE   8

Definition at line 63 of file linkage.hpp.

◆ RCEATTLE_SEL_COFF

#define RCEATTLE_SEL_COFF   4

Definition at line 59 of file linkage.hpp.

Referenced by rceattle_apply_sel_linkages().

◆ RCEATTLE_SEL_DESCEND_SE

#define RCEATTLE_SEL_DESCEND_SE   9

Definition at line 64 of file linkage.hpp.

◆ RCEATTLE_SEL_DN_PEAK

#define RCEATTLE_SEL_DN_PEAK   6

Definition at line 61 of file linkage.hpp.

Referenced by rceattle_apply_sel_linkages().

◆ RCEATTLE_SEL_END_LOGIT

#define RCEATTLE_SEL_END_LOGIT   11

Definition at line 66 of file linkage.hpp.

Referenced by rceattle_apply_sel_linkages().

◆ RCEATTLE_SEL_INF_ASC

#define RCEATTLE_SEL_INF_ASC   2

Definition at line 57 of file linkage.hpp.

Referenced by rceattle_apply_sel_linkages().

◆ RCEATTLE_SEL_INF_DESC

#define RCEATTLE_SEL_INF_DESC   3

Definition at line 58 of file linkage.hpp.

Referenced by rceattle_apply_sel_linkages().

◆ RCEATTLE_SEL_SLP_ASC

#define RCEATTLE_SEL_SLP_ASC   0

Definition at line 55 of file linkage.hpp.

Referenced by rceattle_apply_sel_linkages().

◆ RCEATTLE_SEL_SLP_DESC

#define RCEATTLE_SEL_SLP_DESC   1

Definition at line 56 of file linkage.hpp.

Referenced by rceattle_apply_sel_linkages().

◆ RCEATTLE_SEL_START_LOGIT

#define RCEATTLE_SEL_START_LOGIT   10

Definition at line 65 of file linkage.hpp.

◆ RCEATTLE_SEL_TOP_LOGIT

#define RCEATTLE_SEL_TOP_LOGIT   7

Definition at line 62 of file linkage.hpp.

Function Documentation

◆ rceattle_apply_growth_linkages()

template<class Type>
void rceattle_apply_growth_linkages ( array< Type > & growth_offset,
int link_code,
const LinkageTable< Type > & lt,
int nspp,
const vector< int > & nsex,
int nyrs )

Add growth offsets to growth_offset[sp, sex, yr, param].

Growth is not age-specific, so the age-bin id is ignored. The SD codes (sd_L1 = 4, sd_Linf = 5) take intercept rows only and are skipped here.

Parameters
growth_offset[in,out] Offsets [nspp, max_sex, nyrs, n_growth_params].
link_code,ltSee the note above.

Definition at line 136 of file linkage.hpp.

References LinkageTable< Type >::beta, LinkageTable< Type >::link, LinkageTable< Type >::param, LinkageTable< Type >::process, RCEATTLE_N_GROWTH_PARAMS, RCEATTLE_PROC_GROWTH, rceattle_stratum_range(), LinkageTable< Type >::sex, LinkageTable< Type >::species, LinkageTable< Type >::X, and LinkageTable< Type >::X_col.

◆ rceattle_apply_M_linkages()

template<class Type>
void rceattle_apply_M_linkages ( array< Type > & M_offset,
int link_code,
const LinkageTable< Type > & lt,
int nspp,
const vector< int > & nsex,
const vector< int > & nages,
int nyrs )

Add natural-mortality offsets to M_offset[sp, sex, age, yr].

Age-specific, unlike growth. M1 (code 0) is the only parameter.

Parameters
M_offset[in,out] Offsets [nspp, max_sex, max_age, nyrs].
link_code,ltSee the note above.

Definition at line 185 of file linkage.hpp.

References LinkageTable< Type >::age_bin, LinkageTable< Type >::beta, LinkageTable< Type >::link, LinkageTable< Type >::process, RCEATTLE_PROC_M, rceattle_stratum_range(), LinkageTable< Type >::sex, LinkageTable< Type >::species, LinkageTable< Type >::X, and LinkageTable< Type >::X_col.

◆ rceattle_apply_q_linkages()

template<class Type>
void rceattle_apply_q_linkages ( matrix< Type > & q_offset,
int link_code,
const LinkageTable< Type > & lt,
int n_flt,
int nyrs )

Add catchability offsets to q_offset[fleet, yr].

By fleet, which already implies the species, so species, sex and age ids are ignored. q (code 0) is the only parameter.

Parameters
q_offset[in,out] Offsets [n_flt, nyrs].
link_code,ltSee the note above.

Definition at line 280 of file linkage.hpp.

References LinkageTable< Type >::beta, LinkageTable< Type >::fleet, LinkageTable< Type >::link, LinkageTable< Type >::process, RCEATTLE_PROC_Q, rceattle_stratum_range(), LinkageTable< Type >::X, and LinkageTable< Type >::X_col.

◆ rceattle_apply_recruitment_linkages()

template<class Type>
void rceattle_apply_recruitment_linkages ( array< Type > & rec_offset,
int link_code,
const LinkageTable< Type > & lt,
int nspp,
int nyrs )

Add recruitment offsets to rec_offset[sp, param, yr].

Recruitment parameters are not sex- or age-specific (sex_ratio splits recruits later), so those ids are ignored. Parameters are RCEATTLE_REC_* (above).

Parameters
rec_offset[in,out] Offsets [nspp, n_rec_params, nyrs].
link_code,ltSee the note above.

Definition at line 236 of file linkage.hpp.

References LinkageTable< Type >::beta, LinkageTable< Type >::link, LinkageTable< Type >::param, LinkageTable< Type >::process, RCEATTLE_N_REC_PARAMS, RCEATTLE_PROC_RECRUIT, rceattle_stratum_range(), LinkageTable< Type >::species, LinkageTable< Type >::X, and LinkageTable< Type >::X_col.

◆ rceattle_apply_sel_linkages()

template<class Type>
void rceattle_apply_sel_linkages ( array< Type > & slp_offset,
array< Type > & inf_offset,
array< Type > & coff_offset,
array< Type > & apical_offset,
array< Type > & dn6_offset,
int link_code,
const LinkageTable< Type > & lt,
int n_flt,
int max_sex,
int n_sel_bins,
int nyrs )

Add selectivity offsets, by fleet, sex and year, to one of five arrays.

Offsets are per fleet; fleets sharing a Selectivity_index still share one parameter block through the map. The param code (RCEATTLE_SEL_*, above) picks the array: slopes slp_offset, inflections inf_offset, non-parametric coefficients coff_offset (every bin), apical height apical_offset, and DoubleNormalSS3 P1-P6 (SS3 pattern 24) dn6_offset.

Parameters
slp_offset[in,out] Slope offsets [2, n_flt, max_sex, nyrs].
inf_offset[in,out] Inflection offsets [2, n_flt, max_sex, nyrs].
coff_offset[in,out] Nonparametric offsets [n_flt, max_sex, n_sel_bins, nyrs].
apical_offset[in,out] Apical-height offsets [n_flt, max_sex, nyrs].
dn6_offset[in,out] DoubleNormalSS3 offsets [6, n_flt, max_sex, nyrs].
link_code,ltSee the note above.

Definition at line 328 of file linkage.hpp.

References LinkageTable< Type >::beta, LinkageTable< Type >::fleet, LinkageTable< Type >::link, LinkageTable< Type >::param, LinkageTable< Type >::process, RCEATTLE_PROC_SEL, RCEATTLE_SEL_APICAL, RCEATTLE_SEL_COFF, RCEATTLE_SEL_DN_PEAK, RCEATTLE_SEL_END_LOGIT, RCEATTLE_SEL_INF_ASC, RCEATTLE_SEL_INF_DESC, RCEATTLE_SEL_SLP_ASC, RCEATTLE_SEL_SLP_DESC, rceattle_stratum_range(), LinkageTable< Type >::sex, LinkageTable< Type >::X, and LinkageTable< Type >::X_col.

◆ rceattle_group_slots()

vector< int > rceattle_group_slots ( const vector< int > & group_of_slot,
int grp )
inline

The random-effect slots of one group, in slot order, which is time order within a group (.assign_re_registry()).

Parameters
group_of_slotEach slot's group (ceattle.cpp's linkage_re_sigma: an index, not an sd).
grpThe group.
Returns
The group's slot indices, ascending; empty if it has none.

Definition at line 389 of file linkage.hpp.

◆ rceattle_re_group_nll()

template<class Type>
void rceattle_re_group_nll ( int structure,
vector< Type > re,
Type sigma,
Type rho,
Type & nll,
Type & nll_unweighted )

Add the negative log density of one group's deviations to two accumulators.

RCEATTLE_RE_IID: sd sigma. RCEATTLE_RE_RW: sd sigma on first differences (the first deviation has no term of its own; build_map() holds it at its start, 0 by default, so the base parameter carries the level). RCEATTLE_RE_AR1: stationary, MARGINAL sd sigma and correlation rho (the glmmTMB / Rogers QAR1 convention).

Parameters
structureRCEATTLE_RE_IID, RCEATTLE_RE_RW or RCEATTLE_RE_AR1.
reThe group's deviations, in time order.
sigmaThe group's sd, natural scale (AR1: the marginal sd).
rhoThe AR1 correlation in (-1, 1); read only under RCEATTLE_RE_AR1.
nll,nll_unweightedCells of jnll_comp and unweighted_jnll_comp to add to.

Definition at line 414 of file linkage.hpp.

References RCEATTLE_RE_AR1, and RCEATTLE_RE_RW.

◆ rceattle_stratum_range()

void rceattle_stratum_range ( int id,
int n_levels,
int & lo,
int & hi )
inline

Expand a stratum id into the loop range [lo, hi).

Clamped to n_levels, so an id past the last level gives an empty range.

Parameters
id1-based stratum id, or 0 for "all levels".
n_levelsNumber of levels the caller loops over.
lo,hi[out] First level, and one past the last level.

Definition at line 82 of file linkage.hpp.

Referenced by rceattle_apply_growth_linkages(), rceattle_apply_M_linkages(), rceattle_apply_q_linkages(), rceattle_apply_recruitment_linkages(), and rceattle_apply_sel_linkages().