Skip to content

Commit

Permalink
use broadcasting vs loop
Browse files Browse the repository at this point in the history
  • Loading branch information
seabbs committed Aug 14, 2024
1 parent 1da5231 commit 977a5ac
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions inst/stan/functions/observation_model.stan
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,9 @@
* @return A vector of reports adjusted for day of the week effects.
*/
vector day_of_week_effect(vector reports, array[] int day_of_week, vector effect) {
int t = num_elements(reports);
int wl = num_elements(effect);
// scale day of week effect
vector[wl] scaled_effect = wl * effect;
vector[t] scaled_reports;
for (s in 1:t) {
// add reporting effects (adjust for simplex scale)
scaled_reports[s] = reports[s] * scaled_effect[day_of_week[s]];
}
return(scaled_reports);
return reports .* scaled_effect[day_of_week];
}

/**
Expand Down

0 comments on commit 977a5ac

Please sign in to comment.