|
Rceattle C++ template
The CEATTLE likelihood: src/TMB/ceattle.cpp and its headers
|
Likelihood math for section 13 of ceattle.cpp: the composition row density and linkage prior families that several terms share, and the composition plus-group fold. More...
Go to the source code of this file.
Functions | |
| template<class Type> | |
| void | fold_comp_tails (vector< Type > &obs, vector< Type > &hat, int &n_comp, int nbins_blk, int nblk, int yng, int old) |
| Composition tail accumulation (AFSC ac_yng / ac_old). | |
| template<class Type> | |
| void | comp_row_nll (int ll_type, int osa_mode, vector< Type > obs_prop, vector< Type > hat_prop, Type offset, Type n_samp, Type weight, Type dm_theta, vector< Type > &obsvec, data_indicator< vector< Type >, Type > &keep, int osa_start, const char *type_name, Type &nll, Type &unweighted_nll) |
| Negative log-likelihood of one composition row: an age or length composition, or one length bin of conditional age-at-length (CAAL). | |
| template<class Type> | |
| Type | linkage_log_prior (int family, Type value, bool value_is_log, Type p1, Type p2, Type bias_adjust_proc) |
| Log density of a linkage prior on the natural scale. | |
Likelihood math for section 13 of ceattle.cpp: the composition row density and linkage prior families that several terms share, and the composition plus-group fold.
The loops over observations, and the SIMULATE draws beside each density, stay in ceattle.cpp.
Definition in file likelihood.hpp.
| void comp_row_nll | ( | int | ll_type, |
| int | osa_mode, | ||
| vector< Type > | obs_prop, | ||
| vector< Type > | hat_prop, | ||
| Type | offset, | ||
| Type | n_samp, | ||
| Type | weight, | ||
| Type | dm_theta, | ||
| vector< Type > & | obsvec, | ||
| data_indicator< vector< Type >, Type > & | keep, | ||
| int | osa_start, | ||
| const char * | type_name, | ||
| Type & | nll, | ||
| Type & | unweighted_nll ) |
Negative log-likelihood of one composition row: an age or length composition, or one length bin of conditional age-at-length (CAAL).
Likelihood types:
The data weight multiplies the multinomial log-likelihood (types -1 and 0); the Dirichlet-multinomial carries its weight as theta instead. unweighted_nll gets the row without either, in ordinary fitting only.
| ll_type | Likelihood type, -1, 0 or 1. |
| osa_mode | 0 = ordinary fitting; 1 or 2 = OSA build (2 adds the CDF terms). |
| obs_prop,hat_prop | Observed and expected proportions, after any tail fold. |
| offset | Constant c added to both, to keep log(0) out (comp_offset). |
| n_samp | Input sample size N. |
| weight | Data weight on the multinomial log-likelihood. |
| dm_theta | Dirichlet-multinomial theta, exp() of the log weight. |
| obsvec,keep,osa_start | OSA observation vector, its keep indicator, and this row's first position in them (< 0 = row not in obsvec). |
| type_name | Data column named in the error for an unknown type. |
| nll,unweighted_nll | Cells of jnll_comp and unweighted_jnll_comp to add to. |
Definition at line 80 of file likelihood.hpp.
References ddirmultinom(), ddirmultinom_osa(), and dmultinom_osa().
| void fold_comp_tails | ( | vector< Type > & | obs, |
| vector< Type > & | hat, | ||
| int & | n_comp, | ||
| int | nbins_blk, | ||
| int | nblk, | ||
| int | yng, | ||
| int | old ) |
Composition tail accumulation (AFSC ac_yng / ac_old).
Bins below yng are added into yng and bins above old into old, and only bins yng..old are kept. Joint-sex rows are folded per sex block, so a fold never crosses from females into males. yng = 1 with old >= nbins is a no-op.
| obs,hat | Observed and expected proportions; replaced by the folded vectors. |
| n_comp | Number of bins in the row; replaced by the folded count. |
| nbins_blk | Bins per sex block (ages or lengths). |
| nblk | Sex blocks in the row: 2 for joint-sex comps, else 1. |
| yng,old | First and last bin kept, 1-based ordinals on the fleet's comp dimension. |
Definition at line 27 of file likelihood.hpp.
| Type linkage_log_prior | ( | int | family, |
| Type | value, | ||
| bool | value_is_log, | ||
| Type | p1, | ||
| Type | p2, | ||
| Type | bias_adjust_proc ) |
Log density of a linkage prior on the natural scale.
Families: 1 = normal(p1, p2); 2 = lognormal, log x ~ normal(p1 - b * p2^2 / 2, p2), so exp(p1) is the mean when bias_adjust_proc b = 1 and the median when 0; 3 = gamma(shape p1, rate p2); 4 = beta(p1, p2). Any other code returns 0.
| family | Prior family code, from linkage_spec(priors = ). |
| value | The parameter, on the scale it is stored. |
| value_is_log | True if value is a log, so the prior reads exp(value). |
| p1,p2 | The family's two parameters, as listed above. |
| bias_adjust_proc | 1 to centre the lognormal on its mean, 0 on its median. |
Definition at line 156 of file likelihood.hpp.
References square().