Skip to content

Commit ecf092a

Browse files
committed
corrected the error
1 parent 83956ed commit ecf092a

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

stan/math/prim/prob/wiener4_lccdf.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,20 @@ inline auto wiener_prob_derivative_term(const T_a& a, const T_v& v,
5656
const T_w& w) noexcept {
5757
using ret_t = return_type_t<T_a, T_w, T_v>;
5858
const auto exponent_m1 = log1m(1.1 * 1.0e-8);
59-
ret_t ans;
6059
const auto neg_v = -v;
6160
const auto one_m_w = 1 - w;
6261
int sign_v = neg_v < 0 ? 1 : -1;
6362
const auto two_a_neg_v = 2.0 * a * neg_v;
6463
const auto exponent_with_1mw = sign_v * two_a_neg_v * w;
65-
const auto exponent = (sign_v * two_a_neg_v);
64+
const auto exponent = sign_v * two_a_neg_v;
6665
const auto exponent_with_w = two_a_neg_v * one_m_w;
6766
// truncating longer calculations, for numerical stability
6867
if (unlikely((exponent_with_1mw >= exponent_m1)
6968
|| ((exponent_with_w >= exponent_m1) && (sign_v == 1))
7069
|| (exponent >= exponent_m1) || neg_v == 0)) {
7170
return ret_t(-one_m_w);
7271
}
72+
ret_t ans;
7373
ret_t diff_term;
7474
const auto log_w = log(one_m_w);
7575
if (neg_v < 0) {
@@ -133,7 +133,7 @@ inline auto wiener4_ccdf_grad_a(const T_y& y, const T_a& a, const T_v& v,
133133
// derivative of the wiener probability w.r.t. 'a' (on log-scale)
134134
auto prob_grad_a = -wiener_prob_derivative_term(a, v, w) * v;
135135
if (!is_scal_finite(prob_grad_a)) {
136-
prob_grad_a = ret_t(NEGATIVE_INFTY);
136+
return ret_t(NEGATIVE_INFTY);
137137
}
138138
const auto log_prob_hit_upper = log_wiener_prob_hit_upper(a, v, w);
139139
const auto cdf_grad_a = wiener4_cdf_grad_a(y, a, v, w, cdf, log_err);

stan/math/prim/prob/wiener4_lcdf.hpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ namespace internal {
99

1010
/**
1111
* Make the expression finite
12+
*
13+
* @param x Expression to test
14+
* @return Expression or limited to maximum numeric_limit
1215
*/
1316
template <typename T_x>
1417
inline auto make_finite(const T_x& x) {
@@ -18,6 +21,7 @@ inline auto make_finite(const T_x& x) {
1821
return std::numeric_limits<T_x>::max();
1922
}
2023
}
24+
2125
/**
2226
* Calculate the probability term 'P' on log scale for distribution
2327
*
@@ -106,9 +110,9 @@ inline auto log_probability_GradAV(const T_a& a, const T_v& v, const T_w& w) {
106110
log_quotient = NEGATIVE_INFTY;
107111
}
108112
if (log(w) > log_quotient) {
109-
return -exp(log_prob) * (w - exp(log_quotient));
110-
} else {
111-
return exp(log_prob) * (exp(log_quotient) - w);
113+
return -exp(log_prob + log_diff_exp(log(w), log_quotient));
114+
} else {
115+
return exp(log_prob + log_diff_exp(log_quotient, log(w)));
112116
}
113117
}
114118
}
@@ -728,4 +732,4 @@ inline auto wiener_lcdf(const T_y& y, const T_a& a, const T_t0& t0,
728732
}
729733
} // namespace math
730734
} // namespace stan
731-
#endif
735+
#endif

0 commit comments

Comments
 (0)