Skip to content

Commit 83956ed

Browse files
committed
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
1 parent 4cb2e8c commit 83956ed

3 files changed

Lines changed: 90 additions & 81 deletions

File tree

stan/math/prim/prob/wiener4_lcdf.hpp

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,16 @@ namespace stan {
77
namespace math {
88
namespace internal {
99

10-
11-
/**
10+
/**
1211
* Make the expression finite
1312
*/
1413
template <typename T_x>
1514
inline 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
*/
239240
template <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
*/
343346
template <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);

stan/math/prim/prob/wiener5_lpdf.hpp

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ enum GradientCalc { OFF = 0, ON = 1 };
2828
*/
2929
template <typename T_y, typename T_a, typename T_v, typename T_w, typename T_sv>
3030
inline auto wiener5_compute_log_error_term(T_y&& y, T_a&& a, T_v&& v, T_w&& w,
31-
T_sv&& sv) noexcept {
31+
T_sv&& sv) noexcept {
3232
const auto one_m_w = 1.0 - w;
3333
const auto neg_v = -v;
3434
const auto sv_sqr = square(sv);
@@ -361,11 +361,11 @@ inline auto wiener5_grad_t(const T_y& y, const T_a& a, const T_v& v,
361361
/ square(one_plus_svsqr_y);
362362
const auto log_error = (log_err - log_error_term) + two_log_a;
363363
const auto n_terms_small_t
364-
= wiener5_n_terms_small_t<GradientCalc::OFF, GradientCalc::OFF>(y, a, w,
365-
log_error);
364+
= wiener5_n_terms_small_t<GradientCalc::OFF, GradientCalc::OFF>(
365+
y, a, w, log_error);
366366
const auto n_terms_large_t
367-
= wiener5_gradient_large_reaction_time_terms<GradientCalc::OFF>(y, a, w,
368-
log_error);
367+
= wiener5_gradient_large_reaction_time_terms<GradientCalc::OFF>(
368+
y, a, w, log_error);
369369
auto wiener_res = wiener5_log_sum_exp<GradientCalc::OFF, GradientCalc::OFF>(
370370
y, a, w, n_terms_small_t, n_terms_large_t);
371371
auto&& result = wiener_res.first;
@@ -375,10 +375,11 @@ inline auto wiener5_grad_t(const T_y& y, const T_a& a, const T_v& v,
375375
const auto log_density = wiener5_density<GradientCalc::OFF>(
376376
y, a, v, w, sv, log_err - error_log_density);
377377
if (2.0 * n_terms_small_t < n_terms_large_t) {
378-
auto ans = density_part_one - 1.5 / y
379-
+ newsign
380-
* exp(log_error_term - two_log_a - 1.5 * LOG_TWO - LOG_SQRT_PI
381-
- 3.5 * log_y_asq + result - log_density);
378+
auto ans
379+
= density_part_one - 1.5 / y
380+
+ newsign
381+
* exp(log_error_term - two_log_a - 1.5 * LOG_TWO - LOG_SQRT_PI
382+
- 3.5 * log_y_asq + result - log_density);
382383
return WrtLog ? ans * exp(log_density) : ans;
383384
} else {
384385
auto ans = density_part_one
@@ -422,14 +423,15 @@ inline auto wiener5_grad_a(const T_y& y, const T_a& a, const T_v& v,
422423
const auto one_plus_svsqr_y = 1.0 + sv_sqr * y;
423424
const auto density_part_one
424425
= (v * one_m_w + sv_sqr * square(one_m_w) * a) / one_plus_svsqr_y;
425-
const auto log_error = log_err - log_error_term + 3.0 * log(a) - log(y) - LOG_TWO;
426+
const auto log_error
427+
= log_err - log_error_term + 3.0 * log(a) - log(y) - LOG_TWO;
426428

427429
const auto n_terms_small_t
428-
= wiener5_n_terms_small_t<GradientCalc::OFF, GradientCalc::OFF>(y, a, w,
429-
log_error);
430+
= wiener5_n_terms_small_t<GradientCalc::OFF, GradientCalc::OFF>(
431+
y, a, w, log_error);
430432
const auto n_terms_large_t
431-
= wiener5_gradient_large_reaction_time_terms<GradientCalc::OFF>(y, a, w,
432-
log_error);
433+
= wiener5_gradient_large_reaction_time_terms<GradientCalc::OFF>(
434+
y, a, w, log_error);
433435
auto wiener_res = wiener5_log_sum_exp<GradientCalc::OFF, GradientCalc::OFF>(
434436
y, a, w, n_terms_small_t, n_terms_large_t);
435437
auto&& result = wiener_res.first;
@@ -439,11 +441,11 @@ inline auto wiener5_grad_a(const T_y& y, const T_a& a, const T_v& v,
439441
const auto log_density = wiener5_density<GradientCalc::OFF>(
440442
y, a, v, w, sv, log_err - log_error_log_density);
441443
if (2.0 * n_terms_small_t < n_terms_large_t) {
442-
auto ans
443-
= density_part_one + 1.0 / a
444-
- newsign
445-
* exp(-0.5 * LOG_TWO - LOG_SQRT_PI - 2.5 * log(y)
446-
+ 2.0 * two_log_a + log_error_term + result - log_density);
444+
auto ans = density_part_one + 1.0 / a
445+
- newsign
446+
* exp(-0.5 * LOG_TWO - LOG_SQRT_PI - 2.5 * log(y)
447+
+ 2.0 * two_log_a + log_error_term + result
448+
- log_density);
447449
return WrtLog ? ans * exp(log_density) : ans;
448450
} else {
449451
auto ans = density_part_one - 2.0 / a
@@ -545,7 +547,8 @@ inline auto wiener5_grad_w(const T_y& y, const T_a& a, const T_v& v,
545547
} else {
546548
auto ans = -(
547549
density_part_one
548-
+ newsign * exp(result - (log_density - log_error_term) + 2.0 * LOG_PI));
550+
+ newsign
551+
* exp(result - (log_density - log_error_term) + 2.0 * LOG_PI));
549552
return WrtLog ? ans * exp(log_density) : ans;
550553
}
551554
}
@@ -645,8 +648,8 @@ inline auto estimate_with_err_check(F&& functor, T_err&& log_err,
645648
if (log_fabs_result < log_err) {
646649
log_fabs_result = is_inf(log_fabs_result) ? 0 : log_fabs_result;
647650
auto err_args_tuple = std::make_tuple(args_tuple...);
648-
const auto new_error
649-
= GradW7 ? log_err + log_fabs_result + LOG_TWO : log_err + log_fabs_result;
651+
const auto new_error = GradW7 ? log_err + log_fabs_result + LOG_TWO
652+
: log_err + log_fabs_result;
650653
if constexpr (NestedIndex != -1) {
651654
assign_err<NestedIndex>(std::get<ErrIndex>(err_args_tuple), new_error);
652655
}

stan/math/prim/prob/wiener_full_lcdf.hpp

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ namespace internal {
3131
template <typename T_y, typename T_a, typename T_v, typename T_w, typename T_sw,
3232
typename T_err>
3333
inline auto wiener7_cdf_grad_sw(const T_y& y, const T_a& a, const T_v& v,
34-
const T_w& w, const T_sw& sw,
35-
T_err log_error) {
34+
const T_w& w, const T_sw& sw, T_err log_error) {
3635
auto low = fmax(0.0, w - sw / 2.0);
3736
auto high = fmin(1.0, w + sw / 2.0);
3837
const auto lower_value
@@ -152,34 +151,36 @@ inline auto wiener7_integrate_cdf(const Wiener7FunctorT& wiener7_functor,
152151
const auto temp = (sv == 0) ? 0 : square(x_vec[0]);
153152
const auto factor = (sv == 0) ? 0 : x_vec[0] / (1 - temp);
154153
const auto new_v = (sv == 0) ? v : v + sv * factor;
155-
const auto new_w = (sw == 0) ? w : w + sw * (x_vec[sv == 0 ? 0 : 1] - 0.5);
156-
const auto idx = (sv == 0 && sw == 0) ? 0 : (sv != 0 && sw != 0) ? 2 : 1;
157-
const auto new_t0 = (st0 == 0) ? t0 : t0 + st0 * x_vec[idx];
154+
const auto new_w
155+
= (sw == 0) ? w : w + sw * (x_vec[sv == 0 ? 0 : 1] - 0.5);
156+
const auto idx
157+
= (sv == 0 && sw == 0) ? 0 : (sv != 0 && sw != 0) ? 2 : 1;
158+
const auto new_t0 = (st0 == 0) ? t0 : t0 + st0 * x_vec[idx];
158159
if (y - new_t0 <= 0) {
159160
return ret_t(0.0);
160161
}
161-
const auto dist = GradT ? 0
162-
: wiener4_distribution<true>(
163-
y - new_t0, a, new_v, new_w, lerr);
164-
const auto temp2 = (sv == 0) ? 0 : -0.5 * square(factor) - LOG_SQRT_PI
165-
- 0.5 * LOG_TWO + log1p(temp)
166-
- 2.0 * log1m(temp);
167-
const auto factor_sv = GradSV ? factor : 1;
168-
const auto factor_sw
169-
= GradSW ? ((sv == 0) ? (x_vec[0] - 0.5) : (x_vec[1] - 0.5))
170-
: 1;
171-
const auto integrand
172-
= Distribution ? dist
173-
: GradT ? conditionally_grad_sw_cdf<
174-
Conditionally_cdf>(
175-
wiener7_functor, y - new_t0, a, v, new_w,
176-
sv, sw, lerr)
177-
: factor_sv * factor_sw
178-
* conditionally_grad_sw_cdf<
179-
Conditionally_cdf>(
180-
wiener7_functor, y - new_t0, a,
181-
new_v, new_w, dist, sw, lerr);
182-
return ret_t(integrand * exp(temp2));
162+
const auto dist = GradT ? 0
163+
: wiener4_distribution<true>(
164+
y - new_t0, a, new_v, new_w, lerr);
165+
const auto temp2 = (sv == 0) ? 0
166+
: -0.5 * square(factor) - LOG_SQRT_PI
167+
- 0.5 * LOG_TWO + log1p(temp)
168+
- 2.0 * log1m(temp);
169+
const auto factor_sv = GradSV ? factor : 1;
170+
const auto factor_sw
171+
= GradSW ? ((sv == 0) ? (x_vec[0] - 0.5) : (x_vec[1] - 0.5)) : 1;
172+
const auto integrand
173+
= Distribution
174+
? dist
175+
: GradT
176+
? conditionally_grad_sw_cdf<Conditionally_cdf>(
177+
wiener7_functor, y - new_t0, a, v, new_w, sv, sw,
178+
lerr)
179+
: factor_sv * factor_sw
180+
* conditionally_grad_sw_cdf<Conditionally_cdf>(
181+
wiener7_functor, y - new_t0, a, new_v,
182+
new_w, dist, sw, lerr);
183+
return ret_t(integrand * exp(temp2));
183184
},
184185
integration_args...);
185186
};

0 commit comments

Comments
 (0)