epinowcast
Loading...
Searching...
No Matches
expected_obs_from.stan
Go to the documentation of this file.
1
33 int i, array[] vector imp_obs,
34 array[,] int rdlurd, vector srdlh,
35 matrix refp_lh, array[] int dpmfs, int ref_p,
36 int rep_h, int ref_as_p, int g, int t, int l,
37 vector refnp_lh, int ref_np, int p,
38 int rep_agg_p,
39 array[,,] int rep_agg_n_selected,
40 array[,,,] int rep_agg_selected_idx
41) {
42 // Combine logit hazards from reference and reporting time effects
43 vector[l] lh;
44 profile("model_likelihood_hazard_allocations") {
46 i, rdlurd, srdlh, refp_lh, dpmfs, ref_p, rep_h, g, t, l, refnp_lh, ref_np, p
47 );
48 }
49 // Only allocate aggregation index buffers when reporting-probability
50 // aggregation is active. The l x l int array can dominate per-snapshot
51 // allocation otherwise.
52 array[rep_agg_p ? l : 0] int n_sel;
53 array[rep_agg_p ? l : 0, rep_agg_p ? l : 0] int sel_idx;
54 if (rep_agg_p == 1) {
55 n_sel = rep_agg_n_selected[g, t, 1:l];
56 sel_idx = rep_agg_selected_idx[g, t, 1:l, 1:l];
57 }
58 // Combine expected final obs and time effects to get expected obs
59 return expected_obs(imp_obs[g][t], lh, l, ref_as_p, rep_agg_p, n_sel, sel_idx);
60}
61
90 int start, int end, array[] vector imp_obs,
91 array[,] int rdlurd, vector srdlh,
92 matrix refp_lh, array[] int dpmfs,
93 int ref_p, int rep_h, int ref_as_p,
94 array[] int sl, array[] int csl,
95 array[] int sg, array[] int st, int n,
96 vector refnp_lh, int ref_np, array[] int sdmax,
97 array[] int csdmax, int rep_agg_p,
98 array[,,] int rep_agg_n_selected,
99 array[,,,] int rep_agg_selected_idx
100) {
101 vector[n] log_exp_obs;
102 int ssnap = 1;
103 int esnap = 0;
104 int l;
105
106 // Retrospective mode: no delay or report effects. The delay distribution
107 // is a point mass on slot 0, so expected observations equal the latent
108 // count directly. R-side guards ensure this path is only reachable with
109 // max_delay = 1, so sl[i] == 1 for every snapshot and log_exp_obs has
110 // length end - start + 1.
111 if (ref_p == 0 && ref_np == 0 && rep_h == 0) {
112 for (i in start:end) {
113 log_exp_obs[i - start + 1] = imp_obs[sg[i], st[i]];
114 }
115 return(log_exp_obs);
116 }
117
118 for (i in start:end) {
119 l = sl[i];
120 profile("expected_obs_from_index") {
121 if (l) {
122 esnap += l;
123 log_exp_obs[ssnap:esnap] = expected_obs_from_index(
124 i, imp_obs, rdlurd, srdlh, refp_lh, dpmfs, ref_p, rep_h, ref_as_p,
125 sg[i], st[i], l, refnp_lh, ref_np, csdmax[i] - sdmax[i] + 1,
126 rep_agg_p, rep_agg_n_selected, rep_agg_selected_idx
127 );
128 ssnap += l;
129 }
130 }
131 }
132 return(log_exp_obs);
133}
vector combine_logit_hazards(int i, array[,] int rdlurd, vector srdlh, matrix refp_lh, array[] int dpmfs, int ref_p, int rep_h, int g, int t, int l, vector refnp_lh, int refnp_p, int p)
vector expected_obs(real tar_obs, vector lh, int l, int ref_as_p, int rep_agg_p, array[] int n_selected, array[,] int selected_idx)
vector expected_obs_from_index(int i, array[] vector imp_obs, array[,] int rdlurd, vector srdlh, matrix refp_lh, array[] int dpmfs, int ref_p, int rep_h, int ref_as_p, int g, int t, int l, vector refnp_lh, int ref_np, int p, int rep_agg_p, array[,,] int rep_agg_n_selected, array[,,,] int rep_agg_selected_idx)
vector expected_obs_from_snaps(int start, int end, array[] vector imp_obs, array[,] int rdlurd, vector srdlh, matrix refp_lh, array[] int dpmfs, int ref_p, int rep_h, int ref_as_p, array[] int sl, array[] int csl, array[] int sg, array[] int st, int n, vector refnp_lh, int ref_np, array[] int sdmax, array[] int csdmax, int rep_agg_p, array[,,] int rep_agg_n_selected, array[,,,] int rep_agg_selected_idx)