diff --git a/stan/primarycensored_8stan.html b/stan/primarycensored_8stan.html index 197f0b9..1316e35 100644 --- a/stan/primarycensored_8stan.html +++ b/stan/primarycensored_8stan.html @@ -274,9 +274,9 @@

real log_cdf = primarycensored_lcdf(
d, dist_id, params, pwindow, D, primary_id, primary_params
);
-
real primarycensored_lcdf(data real d, int dist_id, array[] real params, data real pwindow, data real D, int primary_id, array[] real primary_params)
+
real primarycensored_lcdf(data real d, int dist_id, array[] real params, data real pwindow, data real D, int primary_id, array[] real primary_params)
-

Definition at line 84 of file primarycensored.stan.

+

Definition at line 86 of file primarycensored.stan.

@@ -368,9 +368,9 @@

real log_pmf = primarycensored_lpmf(
d, dist_id, params, pwindow, d_upper, D, primary_id, primary_params
);
-
real primarycensored_lpmf(data int d, int dist_id, array[] real params, data real pwindow, data real d_upper, data real D, int primary_id, array[] real primary_params)
+
real primarycensored_lpmf(data int d, int dist_id, array[] real params, data real pwindow, data real d_upper, data real D, int primary_id, array[] real primary_params)
-

Definition at line 150 of file primarycensored.stan.

+

Definition at line 152 of file primarycensored.stan.

@@ -461,9 +461,9 @@

int primary_id = 1; // Uniform
array[0] real primary_params = {};
real pmf = primarycensored_pmf(d, dist_id, params, pwindow, swindow, D, primary_id, primary_params);
-
real primarycensored_pmf(data int d, int dist_id, array[] real params, data real pwindow, data real d_upper, data real D, int primary_id, array[] real primary_params)
+
real primarycensored_pmf(data int d, int dist_id, array[] real params, data real pwindow, data real d_upper, data real D, int primary_id, array[] real primary_params)
-

Definition at line 212 of file primarycensored.stan.

+

Definition at line 214 of file primarycensored.stan.

@@ -555,9 +555,9 @@

max_delay, D, dist_id, params, pwindow, primary_id,
primary_params
);
-
vector primarycensored_sone_lpmf_vectorized(int max_delay, data real D, int dist_id, array[] real params, data real pwindow, int primary_id, array[] real primary_params)
+
vector primarycensored_sone_lpmf_vectorized(int max_delay, data real D, int dist_id, array[] real params, data real pwindow, int primary_id, array[] real primary_params)
-

Definition at line 261 of file primarycensored.stan.

+

Definition at line 263 of file primarycensored.stan.

@@ -648,7 +648,7 @@

max_delay, D, dist_id, params, pwindow, primary_id, primary_params
);
-

Definition at line 343 of file primarycensored.stan.

+

Definition at line 345 of file primarycensored.stan.

diff --git a/stan/primarycensored_8stan_source.html b/stan/primarycensored_8stan_source.html index 16a6533..7101f95 100644 --- a/stan/primarycensored_8stan_source.html +++ b/stan/primarycensored_8stan_source.html @@ -128,181 +128,183 @@
37 } else {
38 // Use numerical integration for other cases
39 real lower_bound = max({d - pwindow, 1e-6});
-
40 array[num_elements(params) + num_elements(primary_params)] real theta = append_array(params, primary_params);
-
41 array[4] int ids = {dist_id, primary_id, num_elements(params), num_elements(primary_params)};
-
42
-
43 vector[1] y0 = rep_vector(0.0, 1);
-
44 result = ode_rk45(primarycensored_ode, y0, lower_bound, {d}, theta, {d, pwindow}, ids)[1, 1];
-
45
-
46 if (!is_inf(D)) {
-
47 real log_cdf_D = primarycensored_lcdf(
-
48 D | dist_id, params, pwindow, positive_infinity(), primary_id,primary_params
-
49 );
-
50 result = exp(log(result) - log_cdf_D);
-
51 }
-
52 }
-
53
-
54 return result;
-
55}
+
40 int n_params = size(params);
+
41 int n_primary_params = size(primary_params);
+
42 array[n_params + n_primary_params] real theta = append_array(params, primary_params);
+
43 array[4] int ids = {dist_id, primary_id, n_params, n_primary_params};
+
44
+
45 vector[1] y0 = rep_vector(0.0, 1);
+
46 result = ode_rk45(primarycensored_ode, y0, lower_bound, {d}, theta, {d, pwindow}, ids)[1, 1];
+
47
+
48 if (!is_inf(D)) {
+
49 real log_cdf_D = primarycensored_lcdf(
+
50 D | dist_id, params, pwindow, positive_infinity(), primary_id,primary_params
+
51 );
+
52 result = exp(log(result) - log_cdf_D);
+
53 }
+
54 }
+
55
+
56 return result;
+
57}
-
56
-
-
84real primarycensored_lcdf(data real d, int dist_id, array[] real params,
-
85 data real pwindow, data real D,
-
86 int primary_id,
-
87 array[] real primary_params) {
-
88 real result;
-
89
-
90 if (d <= 0) {
-
91 return negative_infinity();
-
92 }
-
93
-
94 if (d >= D) {
-
95 return 0;
-
96 }
-
97
-
98 // Check if an analytical solution exists
-
99 if (check_for_analytical(dist_id, primary_id)) {
- -
101 d | dist_id, params, pwindow, positive_infinity(), primary_id, primary_params
-
102 );
-
103 } else {
-
104 // Use numerical integration
-
105 result = log(primarycensored_cdf(
-
106 d | dist_id, params, pwindow, positive_infinity(), primary_id, primary_params
-
107 ));
-
108 }
-
109
-
110 // Handle truncation
-
111 if (!is_inf(D)) {
-
112 real log_cdf_D = primarycensored_lcdf(
-
113 D | dist_id, params, pwindow, positive_infinity(), primary_id, primary_params
-
114 );
-
115 result = result - log_cdf_D;
-
116 }
-
117
-
118 return result;
-
119}
+
58
+
+
86real primarycensored_lcdf(data real d, int dist_id, array[] real params,
+
87 data real pwindow, data real D,
+
88 int primary_id,
+
89 array[] real primary_params) {
+
90 real result;
+
91
+
92 if (d <= 0) {
+
93 return negative_infinity();
+
94 }
+
95
+
96 if (d >= D) {
+
97 return 0;
+
98 }
+
99
+
100 // Check if an analytical solution exists
+
101 if (check_for_analytical(dist_id, primary_id)) {
+ +
103 d | dist_id, params, pwindow, positive_infinity(), primary_id, primary_params
+
104 );
+
105 } else {
+
106 // Use numerical integration
+
107 result = log(primarycensored_cdf(
+
108 d | dist_id, params, pwindow, positive_infinity(), primary_id, primary_params
+
109 ));
+
110 }
+
111
+
112 // Handle truncation
+
113 if (!is_inf(D)) {
+
114 real log_cdf_D = primarycensored_lcdf(
+
115 D | dist_id, params, pwindow, positive_infinity(), primary_id, primary_params
+
116 );
+
117 result = result - log_cdf_D;
+
118 }
+
119
+
120 return result;
+
121}
-
120
-
-
150real primarycensored_lpmf(data int d, int dist_id, array[] real params,
-
151 data real pwindow, data real d_upper,
-
152 data real D, int primary_id,
-
153 array[] real primary_params) {
-
154 if (d_upper > D) {
-
155 reject("Upper truncation point is greater than D. It is ", d_upper,
-
156 " and D is ", D, ". Resolve this by increasing D to be greater or equal to d + swindow or decreasing swindow.");
-
157 }
-
158 if (d_upper <= d) {
-
159 reject("Upper truncation point is less than or equal to d. It is ", d_upper,
-
160 " and d is ", d, ". Resolve this by increasing d to be less than d_upper.");
-
161 }
-
162 real log_cdf_upper = primarycensored_lcdf(
-
163 d_upper | dist_id, params, pwindow, positive_infinity(), primary_id, primary_params
-
164 );
-
165 real log_cdf_lower = primarycensored_lcdf(
-
166 d | dist_id, params, pwindow, positive_infinity(), primary_id, primary_params
-
167 );
-
168 if (!is_inf(D)) {
-
169 real log_cdf_D;
-
170
-
171 if (d_upper == D) {
-
172 log_cdf_D = log_cdf_upper;
-
173 } else {
-
174 log_cdf_D = primarycensored_lcdf(
-
175 D | dist_id, params, pwindow, positive_infinity(), primary_id, primary_params
-
176 );
-
177 }
-
178 return log_diff_exp(log_cdf_upper, log_cdf_lower) - log_cdf_D;
-
179 } else {
-
180 return log_diff_exp(log_cdf_upper, log_cdf_lower);
-
181 }
-
182}
+
122
+
+
152real primarycensored_lpmf(data int d, int dist_id, array[] real params,
+
153 data real pwindow, data real d_upper,
+
154 data real D, int primary_id,
+
155 array[] real primary_params) {
+
156 if (d_upper > D) {
+
157 reject("Upper truncation point is greater than D. It is ", d_upper,
+
158 " and D is ", D, ". Resolve this by increasing D to be greater or equal to d + swindow or decreasing swindow.");
+
159 }
+
160 if (d_upper <= d) {
+
161 reject("Upper truncation point is less than or equal to d. It is ", d_upper,
+
162 " and d is ", d, ". Resolve this by increasing d to be less than d_upper.");
+
163 }
+
164 real log_cdf_upper = primarycensored_lcdf(
+
165 d_upper | dist_id, params, pwindow, positive_infinity(), primary_id, primary_params
+
166 );
+
167 real log_cdf_lower = primarycensored_lcdf(
+
168 d | dist_id, params, pwindow, positive_infinity(), primary_id, primary_params
+
169 );
+
170 if (!is_inf(D)) {
+
171 real log_cdf_D;
+
172
+
173 if (d_upper == D) {
+
174 log_cdf_D = log_cdf_upper;
+
175 } else {
+
176 log_cdf_D = primarycensored_lcdf(
+
177 D | dist_id, params, pwindow, positive_infinity(), primary_id, primary_params
+
178 );
+
179 }
+
180 return log_diff_exp(log_cdf_upper, log_cdf_lower) - log_cdf_D;
+
181 } else {
+
182 return log_diff_exp(log_cdf_upper, log_cdf_lower);
+
183 }
+
184}
-
183
-
-
212real primarycensored_pmf(data int d, int dist_id, array[] real params,
-
213 data real pwindow, data real d_upper,
-
214 data real D, int primary_id,
-
215 array[] real primary_params) {
-
216 return exp(
- -
218 d | dist_id, params, pwindow, d_upper, D, primary_id, primary_params
-
219 )
-
220 );
-
221}
+
185
+
+
214real primarycensored_pmf(data int d, int dist_id, array[] real params,
+
215 data real pwindow, data real d_upper,
+
216 data real D, int primary_id,
+
217 array[] real primary_params) {
+
218 return exp(
+ +
220 d | dist_id, params, pwindow, d_upper, D, primary_id, primary_params
+
221 )
+
222 );
+
223}
-
222
-
- -
262 int max_delay, data real D, int dist_id,
-
263 array[] real params, data real pwindow,
-
264 int primary_id, array[] real primary_params
-
265) {
-
266
-
267 int upper_interval = max_delay + 1;
-
268 vector[upper_interval] log_pmfs;
-
269 vector[upper_interval] log_cdfs;
-
270 real log_normalizer;
-
271
-
272 // Check if D is at least max_delay + 1
-
273 if (D < upper_interval) {
-
274 reject("D must be at least max_delay + 1");
-
275 }
-
276
-
277 // Compute log CDFs
-
278 for (d in 1:upper_interval) {
-
279 log_cdfs[d] = primarycensored_lcdf(
-
280 d | dist_id, params, pwindow, positive_infinity(), primary_id,
-
281 primary_params
-
282 );
-
283 }
-
284
-
285 // Compute log normalizer using upper_interval
-
286 if (D > upper_interval) {
-
287 if (is_inf(D)) {
-
288 log_normalizer = 0; // No normalization needed for infinite D
-
289 } else {
-
290 log_normalizer = primarycensored_lcdf(
-
291 D | dist_id, params, pwindow, positive_infinity(),
-
292 primary_id, primary_params
-
293 );
-
294 }
-
295 } else {
-
296 log_normalizer = log_cdfs[upper_interval];
-
297 }
-
298
-
299 // Compute log PMFs
-
300 log_pmfs[1] = log_cdfs[1] - log_normalizer;
-
301 for (d in 2:upper_interval) {
-
302 log_pmfs[d] = log_diff_exp(log_cdfs[d], log_cdfs[d-1]) - log_normalizer;
-
303 }
-
304
-
305 return log_pmfs;
-
306}
+
224
+
+ +
264 int max_delay, data real D, int dist_id,
+
265 array[] real params, data real pwindow,
+
266 int primary_id, array[] real primary_params
+
267) {
+
268
+
269 int upper_interval = max_delay + 1;
+
270 vector[upper_interval] log_pmfs;
+
271 vector[upper_interval] log_cdfs;
+
272 real log_normalizer;
+
273
+
274 // Check if D is at least max_delay + 1
+
275 if (D < upper_interval) {
+
276 reject("D must be at least max_delay + 1");
+
277 }
+
278
+
279 // Compute log CDFs
+
280 for (d in 1:upper_interval) {
+
281 log_cdfs[d] = primarycensored_lcdf(
+
282 d | dist_id, params, pwindow, positive_infinity(), primary_id,
+
283 primary_params
+
284 );
+
285 }
+
286
+
287 // Compute log normalizer using upper_interval
+
288 if (D > upper_interval) {
+
289 if (is_inf(D)) {
+
290 log_normalizer = 0; // No normalization needed for infinite D
+
291 } else {
+
292 log_normalizer = primarycensored_lcdf(
+
293 D | dist_id, params, pwindow, positive_infinity(),
+
294 primary_id, primary_params
+
295 );
+
296 }
+
297 } else {
+
298 log_normalizer = log_cdfs[upper_interval];
+
299 }
+
300
+
301 // Compute log PMFs
+
302 log_pmfs[1] = log_cdfs[1] - log_normalizer;
+
303 for (d in 2:upper_interval) {
+
304 log_pmfs[d] = log_diff_exp(log_cdfs[d], log_cdfs[d-1]) - log_normalizer;
+
305 }
+
306
+
307 return log_pmfs;
+
308}
-
307
-
- -
344 int max_delay, data real D, int dist_id,
-
345 array[] real params, data real pwindow,
-
346 int primary_id,
-
347 array[] real primary_params
-
348) {
-
349 return exp(
- -
351 max_delay, D, dist_id, params, pwindow, primary_id, primary_params
-
352 )
-
353 );
-
354}
+
309
+
+ +
346 int max_delay, data real D, int dist_id,
+
347 array[] real params, data real pwindow,
+
348 int primary_id,
+
349 array[] real primary_params
+
350) {
+
351 return exp(
+ +
353 max_delay, D, dist_id, params, pwindow, primary_id, primary_params
+
354 )
+
355 );
+
356}
real primarycensored_cdf(data real d, int dist_id, array[] real params, data real pwindow, data real D, int primary_id, array[] real primary_params)
-
vector primarycensored_sone_pmf_vectorized(int max_delay, data real D, int dist_id, array[] real params, data real pwindow, int primary_id, array[] real primary_params)
-
real primarycensored_lpmf(data int d, int dist_id, array[] real params, data real pwindow, data real d_upper, data real D, int primary_id, array[] real primary_params)
-
real primarycensored_lcdf(data real d, int dist_id, array[] real params, data real pwindow, data real D, int primary_id, array[] real primary_params)
-
real primarycensored_pmf(data int d, int dist_id, array[] real params, data real pwindow, data real d_upper, data real D, int primary_id, array[] real primary_params)
-
vector primarycensored_sone_lpmf_vectorized(int max_delay, data real D, int dist_id, array[] real params, data real pwindow, int primary_id, array[] real primary_params)
+
vector primarycensored_sone_pmf_vectorized(int max_delay, data real D, int dist_id, array[] real params, data real pwindow, int primary_id, array[] real primary_params)
+
real primarycensored_lpmf(data int d, int dist_id, array[] real params, data real pwindow, data real d_upper, data real D, int primary_id, array[] real primary_params)
+
real primarycensored_lcdf(data real d, int dist_id, array[] real params, data real pwindow, data real D, int primary_id, array[] real primary_params)
+
real primarycensored_pmf(data int d, int dist_id, array[] real params, data real pwindow, data real d_upper, data real D, int primary_id, array[] real primary_params)
+
vector primarycensored_sone_lpmf_vectorized(int max_delay, data real D, int dist_id, array[] real params, data real pwindow, int primary_id, array[] real primary_params)
real primarycensored_analytical_cdf(data real d, int dist_id, array[] real params, data real pwindow, data real D, int primary_id, array[] real primary_params)
real primarycensored_analytical_lcdf(data real d, int dist_id, array[] real params, data real pwindow, data real D, int primary_id, array[] real primary_params)
int check_for_analytical(int dist_id, int primary_id)
diff --git a/stan/primarycensored__analytical__cdf_8stan_source.html b/stan/primarycensored__analytical__cdf_8stan_source.html index c780b8f..cad8cdb 100644 --- a/stan/primarycensored__analytical__cdf_8stan_source.html +++ b/stan/primarycensored__analytical__cdf_8stan_source.html @@ -310,7 +310,7 @@
271 return exp(primarycensored_analytical_lcdf(d | dist_id, params, pwindow, D, primary_id, primary_params));
272}
-
real primarycensored_lcdf(data real d, int dist_id, array[] real params, data real pwindow, data real D, int primary_id, array[] real primary_params)
+
real primarycensored_lcdf(data real d, int dist_id, array[] real params, data real pwindow, data real D, int primary_id, array[] real primary_params)
real primarycensored_analytical_cdf(data real d, int dist_id, array[] real params, data real pwindow, data real D, int primary_id, array[] real primary_params)
real log_weibull_g(real t, real shape, real scale)
real primarycensored_weibull_uniform_lcdf(data real d, real q, array[] real params, data real pwindow)