138 data real d, vector boundaries, vector pmf,
139 int primary_id, array[] real primary_params, data real pwindow
141 int K = num_elements(pmf);
146 real u_min = d - pwindow;
154 if (u_max <= boundaries[2])
return negative_infinity();
157 vector[K] lo = fmax(u_min, head(boundaries, K));
158 vector[K] hi = fmin(u_max, tail(boundaries, K));
163 vector[K] cum_before;
165 if (K > 1) cum_before[2:K] = head(cumulative_sum(pmf), K - 1);
170 for (k in 1:K) active[k] = hi[k] > lo[k] ? 1 : 0;
178 vector[K] f_diff = (exp(f_lo) - exp(f_hi)) .* active;
180 real integral = dot_product(cum_before, f_diff);
184 real tail_start = fmax(boundaries[K + 1], u_min);
185 if (tail_start < u_max) {
186 real fp_tail = exp(
primary_lcdf(d - tail_start | primary_id,
187 primary_params, pwindow));
189 primary_params, pwindow));
190 integral += fp_tail - fp_end;
193 return log(integral);
212 data real d, vector boundaries, vector hazards,
213 int primary_id, array[] real primary_params, data real pwindow
216 d | boundaries,
hazards_to_pmf(hazards), primary_id, primary_params,
real discretestep_lcdf(data real d, vector boundaries, vector pmf, int primary_id, array[] real primary_params, data real pwindow)
real discretehazard_lcdf(data real d, vector boundaries, vector hazards, int primary_id, array[] real primary_params, data real pwindow)