epinowcast
Loading...
Searching...
No Matches
log_expected_latent_from_r.stan
Go to the documentation of this file.
1
50 matrix lexp_latent_int, vector r, array[] int r_g, int r_t,
51 int r_seed, int gt_n, vector lrgt, int t, int g
52) {
53 array[g] vector[t] exp_lobs;
54 vector[gt_n] rgt = exp(lrgt);
55
56 for (k in 1:g) {
57 vector[r_t] local_r = segment(r, r_g[k] + 1, r_t);
58 if (gt_n == 1) {
59 exp_lobs[k][1] = lexp_latent_int[1, k];
60 exp_lobs[k][(r_seed + 1):t] = exp_lobs[k][1] + cumulative_sum(local_r);
61 } else {
62 vector[t] exp_obs;
63 exp_obs[1:r_seed] = exp(lexp_latent_int[1:r_seed, k]);
64 vector[r_t] local_R = exp(local_r);
65 for (i in 1:r_t) {
66 exp_obs[r_seed + i] = local_R[i] * dot_product(
67 segment(exp_obs, r_seed + i - gt_n, gt_n), rgt
68 );
69 }
70 exp_lobs[k] = log(exp_obs);
71 }
72 }
73 return(exp_lobs);
74}
array[] vector log_expected_latent_from_r(matrix lexp_latent_int, vector r, array[] int r_g, int r_t, int r_seed, int gt_n, vector lrgt, int t, int g)