EpiNow2 Stan Functions
Loading...
Searching...
No Matches
Parameter Handlers

Functions for parameter management. More...

+ Collaboration diagram for Parameter Handlers:

Functions

vector get_param (int id, array[] int params_fixed_lookup, array[] int params_variable_lookup, vector params_value, matrix params)
 
real get_param (int id, array[] int params_fixed_lookup, array[] int params_variable_lookup, vector params_value, vector params)
 
void params_lp (vector params, array[] int prior_dist, vector prior_dist_params, vector params_lower, vector params_upper)
 

Description

Functions for parameter management.

Functions from params.stan for accessing, manipulating, and applying priors to model parameters.

Function Documentation

◆ get_param() [1/2]

vector get_param ( int id,
array[]int params_fixed_lookup,
array[]int params_variable_lookup,
vector params_value,
matrix params )

#include </github/workspace/inst/stan/functions/params.stan>

Get a parameter value from either fixed or variable parameters (matrix version)

This function is an overloaded version of get_param that works with a matrix of parameter values, returning a vector of parameter values for multiple samples.

Parameters
idParameter ID
params_fixed_lookupArray of fixed parameter lookup indices
params_variable_lookupArray of variable parameter lookup indices
params_valueVector of fixed parameter values
paramsMatrix of variable parameter values (rows are samples)
Returns
A vector of parameter values across samples

Definition at line 52 of file params.stan.

55 {
56 int n_samples = rows(params);
57 if (id == 0) {
58 return rep_vector(0, n_samples) ; // parameter not used
59 } else if (params_fixed_lookup[id]) {
60 return rep_vector(params_value[params_fixed_lookup[id]], n_samples);
61 } else {
62 return params[, params_variable_lookup[id]];
63 }
64}

◆ get_param() [2/2]

real get_param ( int id,
array[]int params_fixed_lookup,
array[]int params_variable_lookup,
vector params_value,
vector params )

#include </github/workspace/inst/stan/functions/params.stan>

Parameter Handlers

This group of functions handles parameter access, retrieval, and prior specification in the model. Parameters can be either fixed (specified in advance) or variable (estimated during inference). Get a parameter value from either fixed or variable parameters

This function retrieves a parameter value based on its ID, checking first if it's a fixed parameter and then if it's a variable parameter.

Parameters
idParameter ID
params_fixed_lookupArray of fixed parameter lookup indices
params_variable_lookupArray of variable parameter lookup indices
params_valueVector of fixed parameter values
paramsVector of variable parameter values
Returns
The parameter value (scalar)

Definition at line 24 of file params.stan.

27 {
28 if (id == 0) {
29 return 0; // parameter not used
30 } else if (params_fixed_lookup[id]) {
31 return params_value[params_fixed_lookup[id]];
32 } else {
33 return params[params_variable_lookup[id]];
34 }
35}

◆ params_lp()

void params_lp ( vector params,
array[]int prior_dist,
vector prior_dist_params,
vector params_lower,
vector params_upper )

#include </github/workspace/inst/stan/functions/params.stan>

Update log density for parameter priors

This function adds the log density contributions from parameter priors to the target, supporting multiple prior distribution types.

Parameters
paramsVector of parameter values
prior_distArray of prior distribution types (0: lognormal, 1: gamma, 2: normal)
prior_dist_paramsVector of prior distribution parameters
params_lowerVector of lower bounds for parameters
params_upperVector of upper bounds for parameters

Definition at line 80 of file params.stan.

82 {
83 int params_id = 1;
84 int num_params = num_elements(params);
85 for (id in 1:num_params) {
86 if (prior_dist[id] == 0) { // lognormal
87 params[id] ~
88 lognormal(
89 prior_dist_params[params_id], prior_dist_params[params_id + 1]
90 )
91 T[params_lower[id], params_upper[id]];
92 params_id += 2;
93 } else if (prior_dist[id] == 1) {
94 params[id] ~
95 gamma(prior_dist_params[params_id], prior_dist_params[params_id + 1])
96 T[params_lower[id], params_upper[id]];
97 params_id += 2;
98 } else if (prior_dist[id] == 2) {
99 params[id] ~
100 normal(prior_dist_params[params_id], prior_dist_params[params_id + 1])
101 T[params_lower[id], params_upper[id]];
102 params_id += 2;
103 } else {
104 reject("dist must be <= 2");
105 }
106 }
107}