24 int delay_types, array[]
int delay_types_p, array[]
int delay_types_id,
25 array[]
int delay_types_groups, array[]
int delay_max,
26 array[]
int delay_np_pmf_groups
28 array[delay_types]
int ret;
29 for (i in 1:delay_types) {
31 for (j in delay_types_groups[i]:(delay_types_groups[i + 1] - 1)) {
32 if (delay_types_p[j]) {
33 ret[i] += delay_max[delay_types_id[j]];
35 ret[i] += delay_np_pmf_groups[delay_types_id[j] + 1] -
36 delay_np_pmf_groups[delay_types_id[j]] - 1;
65 int delay_id,
int len, array[]
int delay_types_p, array[]
int delay_types_id,
66 array[]
int delay_types_groups, array[]
int delay_max,
67 vector delay_np_pmf, array[]
int delay_np_pmf_groups,
68 vector delay_params, array[]
int delay_params_groups, array[]
int delay_dist,
69 int left_truncate,
int reverse_pmf,
int cumulative
72 vector[len] pmf = rep_vector(0, len);
76 delay_types_groups[delay_id]:(delay_types_groups[delay_id + 1] - 1)) {
77 if (delay_types_p[i]) {
78 int start = delay_params_groups[delay_types_id[i]];
79 int end = delay_params_groups[delay_types_id[i] + 1] - 1;
80 vector[delay_max[delay_types_id[i]] + 1] new_variable_pmf =
82 delay_params[start:end],
83 delay_max[delay_types_id[i]] + 1,
84 delay_dist[delay_types_id[i]]
86 new_len = current_len + delay_max[delay_types_id[i]];
87 if (current_len == 1) {
88 pmf[1:new_len] = new_variable_pmf;
91 pmf[1:current_len], reverse(new_variable_pmf), new_len
95 int start = delay_np_pmf_groups[delay_types_id[i]];
96 int end = delay_np_pmf_groups[delay_types_id[i] + 1] - 1;
97 new_len = current_len + end - start;
98 if (current_len == 1) {
99 pmf[1:new_len] = delay_np_pmf[start:end];
102 pmf[1:current_len], reverse(delay_np_pmf[start:end]), new_len
106 current_len = new_len;
110 rep_vector(0, left_truncate),
111 pmf[(left_truncate + 1):len] / sum(pmf[(left_truncate + 1):len])
115 pmf = cumulative_sum(pmf);
136 vector delay_params_mean, vector delay_params_sd,
137 array[]
int delay_params_groups,
138 array[]
int delay_dist, array[]
int weight) {
139 int n_delays = num_elements(delay_params_groups) - 1;
143 for (d in 1:n_delays) {
144 int start = delay_params_groups[d];
145 int end = delay_params_groups[d + 1] - 1;
146 for (s in start:end) {
147 if (delay_params_sd[s] > 0) {
149 target += weight[d] *
151 delay_params[s] | delay_params_mean[s], delay_params_sd[s]
154 delay_params[s] ~ normal(delay_params_mean[s], delay_params_sd[s]);
172 int len = num_elements(mu);
175 real p = normal_cdf(lb[i] | mu[i], sigma[i]);
176 real u = uniform_rng(p, 1);
177 ret[i] = (sigma[i] * inv_Phi(u)) + mu[i];
array[] int get_delay_type_max(int delay_types, array[] int delay_types_p, array[] int delay_types_id, array[] int delay_types_groups, array[] int delay_max, array[] int delay_np_pmf_groups)
void delays_lp(vector delay_params, vector delay_params_mean, vector delay_params_sd, array[] int delay_params_groups, array[] int delay_dist, array[] int weight)
vector get_delay_rev_pmf(int delay_id, int len, array[] int delay_types_p, array[] int delay_types_id, array[] int delay_types_groups, array[] int delay_max, vector delay_np_pmf, array[] int delay_np_pmf_groups, vector delay_params, array[] int delay_params_groups, array[] int delay_dist, int left_truncate, int reverse_pmf, int cumulative)