Skip to content

Commit

Permalink
use inv_square instead of 1/pow(..., 2) (#603)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbfnk authored Mar 11, 2024
1 parent 45f0ed5 commit fc9e031
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion inst/stan/functions/generated_quantities.stan
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ array[] real R_to_growth(vector R, real gt_mean, real gt_var) {
int t = num_elements(R);
array[t] real r;
if (gt_var > 0) {
real k = gt_var / pow(gt_mean, 2);
real k = gt_var * inv_square(gt_mean);
for (s in 1:t) {
r[s] = (pow(R[s], k) - 1) / (k * gt_mean);
}
Expand Down
6 changes: 3 additions & 3 deletions inst/stan/functions/observation_model.stan
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void report_lp(array[] int cases, array[] int cases_time, vector reports,
obs_cases = cases;
}
if (model_type) {
real dispersion = 1 / pow(phi_sd > 0 ? rep_phi[model_type] : phi_mean, 2);
real dispersion = inv_square(phi_sd > 0 ? rep_phi[model_type] : phi_mean);
if (phi_sd > 0) {
rep_phi[model_type] ~ normal(phi_mean, phi_sd) T[0,];
}
Expand Down Expand Up @@ -108,7 +108,7 @@ vector report_log_lik(array[] int cases, vector reports,
log_lik[i] = poisson_lpmf(cases[i] | reports[i]) * weight;
}
} else {
real dispersion = 1 / pow(rep_phi[model_type], 2);
real dispersion = inv_square(rep_phi[model_type]);
for (i in 1:t) {
log_lik[i] = neg_binomial_2_lpmf(cases[i] | reports[i], dispersion) * weight;
}
Expand All @@ -121,7 +121,7 @@ array[] int report_rng(vector reports, array[] real rep_phi, int model_type) {
array[t] int sampled_reports;
real dispersion = 1e5;
if (model_type) {
dispersion = 1 / pow(rep_phi[model_type], 2);
dispersion = inv_square(rep_phi[model_type]);
}

for (s in 1:t) {
Expand Down

0 comments on commit fc9e031

Please sign in to comment.