@@ -7,17 +7,16 @@ namespace stan {
77namespace math {
88namespace internal {
99
10-
11- /* *
10+ /* *
1211 * Make the expression finite
1312 */
1413template <typename T_x>
1514inline auto make_finite (const T_x& x) {
16- if (x < std::numeric_limits<T_x>::max ()) {
17- return x;
18- } else {
19- return std::numeric_limits<T_x>::max ();
20- }
15+ if (x < std::numeric_limits<T_x>::max ()) {
16+ return x;
17+ } else {
18+ return std::numeric_limits<T_x>::max ();
19+ }
2120}
2221/* *
2322 * Calculate the probability term 'P' on log scale for distribution
@@ -151,8 +150,8 @@ inline auto wiener4_distribution(const T_y& y, const T_a& a, const T_v& v,
151150
152151 const auto K1 = 0.5 * (fabs (neg_v) / a * y - one_m_w);
153152 const auto arg = fmax (
154- 0.0 ,
155- fmin ( 1.0 , exp (one_m_w_a_neg_v + square (neg_v) * y / 2.0 + log_err) / 2.0 ));
153+ 0.0 , fmin ( 1.0 , exp (one_m_w_a_neg_v + square (neg_v) * y / 2.0 + log_err)
154+ / 2.0 ));
156155 const auto K2 = (arg == 0 ) ? INFTY
157156 : (arg == 1 ) ? NEGATIVE_INFTY
158157 : -sqrt (y) / 2.0 / a * inv_Phi (arg);
@@ -161,10 +160,10 @@ inline auto wiener4_distribution(const T_y& y, const T_a& a, const T_v& v,
161160 const auto api = a / pi ();
162161 const auto v_square = square (neg_v);
163162 const auto sqrtL1 = sqrt (1.0 / y) * api;
164- const auto sqrtL2 = sqrt (
165- fmax ( 1.0 , -2.0 / y * square (api)
166- * (log_err + log (pi () * y / 2.0 * (v_square + square (pi () / a)))
167- + one_m_w_a_neg_v + v_square * y / 2.0 )));
163+ const auto sqrtL2 = sqrt (fmax (
164+ 1.0 , -2.0 / y * square (api)
165+ * (log_err + log (pi () * y / 2.0 * (v_square + square (pi () / a)))
166+ + one_m_w_a_neg_v + v_square * y / 2.0 )));
168167 const auto K_large_value = ceil (fmax (sqrtL1, sqrtL2));
169168
170169 auto lg = LOG_TWO + LOG_PI - 2.0 * log (a);
@@ -187,7 +186,8 @@ inline auto wiener4_distribution(const T_y& y, const T_a& a, const T_v& v,
187186 fminus = log_sum_exp (fminus, log_sum_exp (neg1, neg2));
188187 }
189188 auto ans = ret_t (0.0 );
190- ans = fplus > fminus ? log_diff_exp (fplus, fminus) : log_diff_exp (fminus, fplus);
189+ ans = fplus > fminus ? log_diff_exp (fplus, fminus)
190+ : log_diff_exp (fminus, fplus);
191191 ret_t log_distribution = ans - one_m_w_a_neg_v - square (neg_v) * y / 2 ;
192192 return NaturalScale ? exp (log_distribution) : log_distribution;
193193 }
@@ -212,7 +212,8 @@ inline auto wiener4_distribution(const T_y& y, const T_a& a, const T_v& v,
212212 }
213213 }
214214 ret_t ans = NEGATIVE_INFTY;
215- ans = fplus > fminus ? log_diff_exp (fplus, fminus) : log_diff_exp (fminus, fplus);
215+ ans = fplus > fminus ? log_diff_exp (fplus, fminus)
216+ : log_diff_exp (fminus, fplus);
216217 auto summand_1 = log_probability_distribution (a, neg_v, one_m_w);
217218 auto summand_2 = lg + (ans - one_m_w_a_neg_v - 0.5 * square (neg_v) * y);
218219 ret_t log_distribution = NEGATIVE_INFTY;
@@ -233,7 +234,7 @@ inline auto wiener4_distribution(const T_y& y, const T_a& a, const T_v& v,
233234 * @param w The drift rate
234235 * @param cdf The value of the distribution
235236 * @param log_err The log error tolerance in the computation of the number
236- * of terms for the infinite sums
237+ * of terms for the infinite sums
237238 * @return Gradient with respect to a
238239 */
239240template <typename T_y, typename T_a, typename T_v, typename T_w,
@@ -268,8 +269,8 @@ inline auto wiener4_cdf_grad_a(const T_y& y, const T_a& a, const T_v& v,
268269 const auto K_large = sqrt_y / a - wdash;
269270 const auto K_small_value = ceil (fmax (fmax (K_small, K_large), ret_t (1.0 )));
270271
271- // Depending on the Ks use formula for small reaction times or large
272- // reaction times (see Navarro & Fuss, 2009)
272+ // Depending on the Ks use formula for small reaction times or large
273+ // reaction times (see Navarro & Fuss, 2009)
273274 if (K_large_value > 4 * K_small_value) {
274275 const auto neg_vy = neg_v * y;
275276 auto ans = ret_t (0.0 );
@@ -282,26 +283,27 @@ inline auto wiener4_cdf_grad_a(const T_y& y, const T_a& a, const T_v& v,
282283 auto temp_1 = make_finite (exp (d_k_1 + logMill (x_over_sqrt_y_1)));
283284 auto exp_d_k_1 = exp (d_k_1);
284285 auto ans_1 = -temp_1 * neg_vy - sqrt_y * exp_d_k_1;
285-
286+
286287 auto x_2 = r_k_1 + neg_vy;
287288 auto x_over_sqrt_y_2 = x_2 / sqrt_y;
288289 auto temp_2 = make_finite (exp (d_k_1 + logMill (x_over_sqrt_y_2)));
289290 auto ans_2 = temp_2 * neg_vy - sqrt_y * exp_d_k_1;
290291 auto r_k_2 = a * (2.0 * k + 1.0 + w);
291292 auto d_k_2 = std_normal_lpdf (r_k_2 / sqrt_y);
292-
293+
293294 auto x_3 = r_k_2 - neg_vy;
294295 auto x_over_sqrt_y_3 = x_3 / sqrt_y;
295296 auto temp_3 = make_finite (exp (d_k_2 + logMill (x_over_sqrt_y_3)));
296297 auto exp_d_k_2 = exp (d_k_2);
297298 auto ans_3 = -temp_3 * neg_vy - sqrt_y * exp_d_k_2;
298-
299+
299300 auto x_4 = r_k_2 + neg_vy;
300301 auto x_over_sqrt_y_4 = x_4 / sqrt_y;
301302 auto temp_4 = make_finite (exp (d_k_2 + logMill (x_over_sqrt_y_4)));
302303 auto ans_4 = temp_4 * neg_vy - sqrt_y * exp_d_k_2;
303304
304- ans += (ans_1 + ans_2 + ans_3 - ans_4) * (2.0 * k + one_m_w) + ans_3 * one_m_w;
305+ ans += (ans_1 + ans_2 + ans_3 - ans_4) * (2.0 * k + one_m_w)
306+ + ans_3 * one_m_w;
305307 }
306308 F_k = make_finite (exp (one_m_w_a_neg_v + 0.5 * square (neg_v) * y));
307309 const auto summands_small_y = ans / (y * F_k);
@@ -316,7 +318,8 @@ inline auto wiener4_cdf_grad_a(const T_y& y, const T_a& a, const T_v& v,
316318 * exp (-0.5 * kpia2 * y);
317319 ans -= last * sin (kpi * one_m_w);
318320 }
319- const ret_t prob = make_finite (exp (log_probability_distribution (a, neg_v, one_m_w)));
321+ const ret_t prob
322+ = make_finite (exp (log_probability_distribution (a, neg_v, one_m_w)));
320323 const auto dav = log_probability_GradAV (a, neg_v, one_m_w);
321324 auto dav_neg_v = dav * neg_v;
322325 auto prob_deriv = fabs (neg_v) == 0
@@ -337,7 +340,7 @@ inline auto wiener4_cdf_grad_a(const T_y& y, const T_a& a, const T_v& v,
337340 * @param w The drift rate
338341 * @param cdf The value of the distribution
339342 * @param log_err The log error tolerance in the computation of the number
340- * of terms for the infinite sums
343+ * of terms for the infinite sums
341344 * @return Gradient with respect to v
342345 */
343346template <typename T_y, typename T_a, typename T_v, typename T_w,
@@ -395,11 +398,11 @@ inline auto wiener4_cdf_grad_v(const T_y& y, const T_a& a, const T_v& v,
395398 auto ans_2 = make_finite (exp (d_k_1 + logMill (x_over_sqrt_y_2)));
396399 auto r_k_2 = a * (2.0 * k + 1.0 + w);
397400 auto d_k_2 = std_normal_lpdf (r_k_2 / sqrt_y);
398-
399- auto x_3 = r_k_2 - neg_vy;
401+
402+ auto x_3 = r_k_2 - neg_vy;
400403 auto x_over_sqrt_y_3 = x_3 / sqrt_y;
401404 auto ans_3 = make_finite (exp (d_k_2 + logMill (x_over_sqrt_y_3)));
402-
405+
403406 auto x_4 = r_k_2 + neg_vy;
404407 auto x_over_sqrt_y_4 = x_4 / sqrt_y;
405408 auto ans_4 = make_finite (exp (d_k_2 + logMill (x_over_sqrt_y_4)));
@@ -419,7 +422,8 @@ inline auto wiener4_cdf_grad_v(const T_y& y, const T_a& a, const T_v& v,
419422 auto last = denomk * ekpia2y / denom;
420423 ans -= last * sin (kpi * one_m_w);
421424 }
422- const ret_t prob = make_finite (exp (log_probability_distribution (a, neg_v, one_m_w)));
425+ const ret_t prob
426+ = make_finite (exp (log_probability_distribution (a, neg_v, one_m_w)));
423427 const auto dav = log_probability_GradAV (a, neg_v, one_m_w);
424428 auto dav_a = dav * a;
425429 auto prob_deriv = is_inf (dav_a) ? ret_t (NEGATIVE_INFTY) : dav_a * prob;
@@ -492,20 +496,20 @@ inline auto wiener4_cdf_grad_w(const T_y& y, const T_a& a, const T_v& v,
492496 auto temp_1 = make_finite (exp (d_k_1 + logMill (x_over_sqrt_y_1)));
493497 auto exp_d_k_1 = exp (d_k_1);
494498 auto ans_1 = -temp_1 * neg_vy - sqrt_y * exp_d_k_1;
495-
499+
496500 auto x_2 = r_k_1 + neg_vy;
497501 auto x_over_sqrt_y_2 = x_2 / sqrt_y;
498502 auto temp_2 = make_finite (exp (d_k_1 + logMill (x_over_sqrt_y_2)));
499503 auto ans_2 = temp_2 * neg_vy - sqrt_y * exp_d_k_1;
500504 auto r_k_2 = a * (2.0 * k + 1.0 + w);
501505 auto d_k_2 = std_normal_lpdf (r_k_2 / sqrt_y);
502-
506+
503507 auto x_3 = r_k_2 - neg_vy;
504508 auto x_over_sqrt_y_3 = x_3 / sqrt_y;
505509 auto temp_3 = make_finite (exp (d_k_2 + logMill (x_over_sqrt_y_3)));
506510 auto exp_d_k_2 = exp (d_k_2);
507511 auto ans_3 = -temp_3 * neg_vy - sqrt_y * exp_d_k_2;
508-
512+
509513 auto x_4 = r_k_2 + neg_vy;
510514 auto x_over_sqrt_y_4 = x_4 / sqrt_y;
511515 auto temp_4 = make_finite (exp (d_k_2 + logMill (x_over_sqrt_y_4)));
@@ -529,7 +533,8 @@ inline auto wiener4_cdf_grad_w(const T_y& y, const T_a& a, const T_v& v,
529533 ans -= last * cos (kpi * one_m_w);
530534 }
531535 const auto evaw = exp (-one_m_w_a_neg_v - 0.5 * square (neg_v) * y);
532- const ret_t prob = make_finite (exp (log_probability_distribution (a, neg_v, one_m_w)));
536+ const ret_t prob
537+ = make_finite (exp (log_probability_distribution (a, neg_v, one_m_w)));
533538
534539 // Calculate the probability term 'P' on log scale
535540 auto dav = ret_t (-1 / w);
0 commit comments