Skip to content

Commit 11dc975

Browse files
committed
Replace _defective with _unnorm
1 parent a5f8022 commit 11dc975

49 files changed

Lines changed: 1090 additions & 1092 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

stan/math/prim/prob.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,11 @@
311311
#include <stan/math/prim/prob/weibull_rng.hpp>
312312
#include <stan/math/prim/prob/wiener5_lpdf.hpp>
313313
#include <stan/math/prim/prob/wiener_lpdf.hpp>
314-
#include <stan/math/prim/prob/wiener4_lcdf_defective.hpp>
315-
#include <stan/math/prim/prob/wiener4_lccdf_defective.hpp>
314+
#include <stan/math/prim/prob/wiener4_lcdf_unnorm.hpp>
315+
#include <stan/math/prim/prob/wiener4_lccdf_unnorm.hpp>
316316
#include <stan/math/prim/prob/wiener_full_lpdf.hpp>
317-
#include <stan/math/prim/prob/wiener_full_lcdf_defective.hpp>
318-
#include <stan/math/prim/prob/wiener_full_lccdf_defective.hpp>
317+
#include <stan/math/prim/prob/wiener_full_lcdf_unnorm.hpp>
318+
#include <stan/math/prim/prob/wiener_full_lccdf_unnorm.hpp>
319319
#include <stan/math/prim/prob/wishart_cholesky_lpdf.hpp>
320320
#include <stan/math/prim/prob/wishart_cholesky_rng.hpp>
321321
#include <stan/math/prim/prob/wishart_lpdf.hpp>

stan/math/prim/prob/wiener4_lccdf_defective.hpp renamed to stan/math/prim/prob/wiener4_lccdf_unnorm.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#ifndef STAN_MATH_PRIM_PROB_WIENER4_LCCDF_DEFECTIVE_HPP
2-
#define STAN_MATH_PRIM_PROB_WIENER4_LCCDF_DEFECTIVE_HPP
1+
#ifndef STAN_MATH_PRIM_PROB_WIENER4_LCCDF_UNNORM_HPP
2+
#define STAN_MATH_PRIM_PROB_WIENER4_LCCDF_UNNORM_HPP
33

4-
#include <stan/math/prim/prob/wiener4_lcdf_defective.hpp>
4+
#include <stan/math/prim/prob/wiener4_lcdf_unnorm.hpp>
55

66
namespace stan {
77
namespace math {
@@ -224,9 +224,9 @@ inline auto wiener4_ccdf_grad_w(const T_y& y, const T_a& a, const T_v& v,
224224
*/
225225
template <bool propto = false, typename T_y, typename T_a, typename T_t0,
226226
typename T_w, typename T_v>
227-
inline auto wiener_lccdf_defective(const T_y& y, const T_a& a, const T_t0& t0,
228-
const T_w& w, const T_v& v,
229-
const double& precision_derivatives = 1e-4) {
227+
inline auto wiener_lccdf_unnorm(const T_y& y, const T_a& a, const T_t0& t0,
228+
const T_w& w, const T_v& v,
229+
const double& precision_derivatives = 1e-4) {
230230
using T_partials_return = partials_return_t<T_y, T_a, T_t0, T_w, T_v>;
231231
using ret_t = return_type_t<T_y, T_a, T_t0, T_w, T_v>;
232232
using T_y_ref = ref_type_t<T_y>;

stan/math/prim/prob/wiener4_lcdf_defective.hpp renamed to stan/math/prim/prob/wiener4_lcdf_unnorm.hpp

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef STAN_MATH_PRIM_PROB_WIENER4_LCDF_DEFECTIVE_HPP
2-
#define STAN_MATH_PRIM_PROB_WIENER4_LCDF_DEFECTIVE_HPP
1+
#ifndef STAN_MATH_PRIM_PROB_WIENER4_LCDF_UNNORM_HPP
2+
#define STAN_MATH_PRIM_PROB_WIENER4_LCDF_UNNORM_HPP
33

44
#include <stan/math/prim/prob/wiener5_lpdf.hpp>
55

@@ -156,9 +156,9 @@ inline auto wiener4_distribution(const T_y& y, const T_a& a, const T_v& v,
156156
const auto arg = fmax(
157157
0.0, fmin(1.0, exp(one_m_w_a_neg_v + square(neg_v) * y / 2.0 + log_err)
158158
/ 2.0));
159-
const auto K2 = (arg == 0) ? INFTY
160-
: (arg == 1) ? NEGATIVE_INFTY
161-
: -sqrt(y) / 2.0 / a * inv_Phi(arg);
159+
const auto K2 = (arg == 0) ? INFTY
160+
: (arg == 1) ? NEGATIVE_INFTY
161+
: -sqrt(y) / 2.0 / a * inv_Phi(arg);
162162
const auto K_small_value = ceil(fmax(K1, K1 + K2));
163163

164164
const auto api = a / pi();
@@ -326,9 +326,9 @@ inline auto wiener4_cdf_grad_a(const T_y& y, const T_a& a, const T_v& v,
326326
= make_finite(exp(log_probability_distribution(a, neg_v, one_m_w)));
327327
const auto dav = log_probability_GradAV(a, neg_v, one_m_w);
328328
auto dav_neg_v = dav * neg_v;
329-
auto prob_deriv = fabs(neg_v) == 0
330-
? ret_t(0.0)
331-
: is_inf(dav_neg_v) ? NEGATIVE_INFTY : dav_neg_v * prob;
329+
auto prob_deriv = fabs(neg_v) == 0 ? ret_t(0.0)
330+
: is_inf(dav_neg_v) ? NEGATIVE_INFTY
331+
: dav_neg_v * prob;
332332
ans = (-2.0 / a - one_m_w_neg_v) * (cdf - prob)
333333
+ ans * (2.0 * pi() / square(a))
334334
* exp(-one_m_w_a_neg_v - 0.5 * square(neg_v) * y);
@@ -371,10 +371,9 @@ inline auto wiener4_cdf_grad_v(const T_y& y, const T_a& a, const T_v& v,
371371
- 2.5 * LOG_TWO - 3 * log_a - log_v),
372372
1.0);
373373
K_large_value
374-
= fmax(ceil((alphK_large == 0)
375-
? ret_t(INFTY)
376-
: (alphK_large == 1) ? ret_t(NEGATIVE_INFTY)
377-
: temp * inv_Phi(alphK_large)),
374+
= fmax(ceil((alphK_large == 0) ? ret_t(INFTY)
375+
: (alphK_large == 1) ? ret_t(NEGATIVE_INFTY)
376+
: temp * inv_Phi(alphK_large)),
378377
ret_t(1.0));
379378
}
380379

@@ -469,10 +468,9 @@ inline auto wiener4_cdf_grad_w(const T_y& y, const T_a& a, const T_v& v,
469468
= fmin(exp(factor + 0.5 * (LOG_PI + log_y) - 1.5 * LOG_TWO - log_a), 1.0);
470469
alphK_large = fmax(0.0, alphK_large);
471470
const auto K_large_value
472-
= fmax(ceil((alphK_large == 0)
473-
? ret_t(INFTY)
474-
: (alphK_large == 1) ? ret_t(NEGATIVE_INFTY)
475-
: temp * inv_Phi(alphK_large)),
471+
= fmax(ceil((alphK_large == 0) ? ret_t(INFTY)
472+
: (alphK_large == 1) ? ret_t(NEGATIVE_INFTY)
473+
: temp * inv_Phi(alphK_large)),
476474
ret_t(1.0));
477475

478476
const auto sqrt_y = sqrt(y);
@@ -481,10 +479,9 @@ inline auto wiener4_cdf_grad_w(const T_y& y, const T_a& a, const T_v& v,
481479
const auto lv = log1p(square(neg_v) * y);
482480
const auto alphK_small = factor - LOG_TWO - lv;
483481
const auto arg = fmin(exp(alphK_small), 1.0);
484-
const auto K_small
485-
= (arg == 0)
486-
? INFTY
487-
: (arg == 1) ? NEGATIVE_INFTY : -sqrt_y / a * inv_Phi(arg) - wdash;
482+
const auto K_small = (arg == 0) ? INFTY
483+
: (arg == 1) ? NEGATIVE_INFTY
484+
: -sqrt_y / a * inv_Phi(arg) - wdash;
488485
const auto K_small_value = ceil(fmax(fmax(K_small, K_large), ret_t(1.0)));
489486

490487
if (K_large_value > 4 * K_small_value) {
@@ -586,9 +583,9 @@ inline auto wiener4_cdf_grad_w(const T_y& y, const T_a& a, const T_v& v,
586583
*/
587584
template <bool propto = false, typename T_y, typename T_a, typename T_t0,
588585
typename T_w, typename T_v>
589-
inline auto wiener_lcdf_defective(const T_y& y, const T_a& a, const T_t0& t0,
590-
const T_w& w, const T_v& v,
591-
const double& precision_derivatives = 1e-4) {
586+
inline auto wiener_lcdf_unnorm(const T_y& y, const T_a& a, const T_t0& t0,
587+
const T_w& w, const T_v& v,
588+
const double& precision_derivatives = 1e-4) {
592589
using T_partials_return = partials_return_t<T_y, T_a, T_t0, T_w, T_v>;
593590
using T_y_ref = ref_type_t<T_y>;
594591
using T_a_ref = ref_type_t<T_a>;

stan/math/prim/prob/wiener_full_lccdf_defective.hpp renamed to stan/math/prim/prob/wiener_full_lccdf_unnorm.hpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#ifndef STAN_MATH_PRIM_PROB_WIENER_FULL_LCCDF_DEFECTIVE_HPP
2-
#define STAN_MATH_PRIM_PROB_WIENER_FULL_LCCDF_DEFECTIVE_HPP
1+
#ifndef STAN_MATH_PRIM_PROB_WIENER_FULL_LCCDF_UNNORM_HPP
2+
#define STAN_MATH_PRIM_PROB_WIENER_FULL_LCCDF_UNNORM_HPP
33

4-
#include <stan/math/prim/prob/wiener4_lccdf_defective.hpp>
5-
#include <stan/math/prim/prob/wiener_full_lcdf_defective.hpp>
4+
#include <stan/math/prim/prob/wiener4_lccdf_unnorm.hpp>
5+
#include <stan/math/prim/prob/wiener_full_lcdf_unnorm.hpp>
66

77
namespace stan {
88
namespace math {
@@ -84,10 +84,10 @@ inline auto wiener7_ccdf_grad_sw(const T_y& y, const T_a& a, const T_v& v,
8484
template <bool propto = false, typename T_y, typename T_a, typename T_t0,
8585
typename T_w, typename T_v, typename T_sv, typename T_sw,
8686
typename T_st0>
87-
inline auto wiener_lccdf_defective(const T_y& y, const T_a& a, const T_t0& t0,
88-
const T_w& w, const T_v& v, const T_sv& sv,
89-
const T_sw& sw, const T_st0& st0,
90-
const double& precision_derivatives = 1e-8) {
87+
inline auto wiener_lccdf_unnorm(const T_y& y, const T_a& a, const T_t0& t0,
88+
const T_w& w, const T_v& v, const T_sv& sv,
89+
const T_sw& sw, const T_st0& st0,
90+
const double& precision_derivatives = 1e-8) {
9191
using ret_t = return_type_t<T_y, T_a, T_t0, T_w, T_v, T_sv, T_sw, T_st0>;
9292
using T_y_ref = ref_type_t<T_y>;
9393
using T_a_ref = ref_type_t<T_a>;
@@ -124,7 +124,7 @@ inline auto wiener_lccdf_defective(const T_y& y, const T_a& a, const T_t0& t0,
124124
return ret_t(0.0);
125125
}
126126

127-
static constexpr const char* function_name = "wiener_lccdf_defective";
127+
static constexpr const char* function_name = "wiener_lccdf_unnorm";
128128
check_consistent_sizes(function_name, "Random variable", y,
129129
"Boundary separation", a, "Drift rate", v,
130130
"A-priori bias", w, "Nondecision time", t0,
@@ -211,9 +211,9 @@ inline auto wiener_lccdf_defective(const T_y& y, const T_a& a, const T_t0& t0,
211211
// calculate density and partials
212212
for (size_t i = 0; i < N; i++) {
213213
if (sv_vec[i] == 0 && sw_vec[i] == 0 && st0_vec[i] == 0) {
214-
result += wiener_lccdf_defective<propto>(y_vec[i], a_vec[i], t0_vec[i],
215-
w_vec[i], v_vec[i],
216-
precision_derivatives);
214+
result += wiener_lccdf_unnorm<propto>(y_vec[i], a_vec[i], t0_vec[i],
215+
w_vec[i], v_vec[i],
216+
precision_derivatives);
217217
continue;
218218
}
219219
const T_partials_return y_value = y_vec.val(i);

stan/math/prim/prob/wiener_full_lcdf_defective.hpp renamed to stan/math/prim/prob/wiener_full_lcdf_unnorm.hpp

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#ifndef STAN_MATH_PRIM_PROB_WIENER_FULL_LCDF_DEFECTIVE_HPP
2-
#define STAN_MATH_PRIM_PROB_WIENER_FULL_LCDF_DEFECTIVE_HPP
1+
#ifndef STAN_MATH_PRIM_PROB_WIENER_FULL_LCDF_UNNORM_HPP
2+
#define STAN_MATH_PRIM_PROB_WIENER_FULL_LCDF_UNNORM_HPP
33

4-
#include <stan/math/prim/prob/wiener4_lcdf_defective.hpp>
4+
#include <stan/math/prim/prob/wiener4_lcdf_unnorm.hpp>
55
#include <stan/math/prim/prob/wiener_full_lpdf.hpp>
66

77
namespace stan {
@@ -153,15 +153,16 @@ inline auto wiener7_integrate_cdf(const Wiener7FunctorT& wiener7_functor,
153153
const auto new_v = (sv == 0) ? v : v + sv * factor;
154154
const auto new_w
155155
= (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;
156+
const auto idx = (sv == 0 && sw == 0) ? 0
157+
: (sv != 0 && sw != 0) ? 2
158+
: 1;
158159
const auto new_t0 = (st0 == 0) ? t0 : t0 + st0 * x_vec[idx];
159160
if (y - new_t0 <= 0) {
160161
return ret_t(0.0);
161162
}
162163
const auto dist = GradT ? 0
163164
: wiener4_distribution<true>(
164-
y - new_t0, a, new_v, new_w, lerr);
165+
y - new_t0, a, new_v, new_w, lerr);
165166
const auto temp2 = (sv == 0) ? 0
166167
: -0.5 * square(factor) - LOG_SQRT_PI
167168
- 0.5 * LOG_TWO + log1p(temp)
@@ -170,16 +171,14 @@ inline auto wiener7_integrate_cdf(const Wiener7FunctorT& wiener7_functor,
170171
const auto factor_sw
171172
= GradSW ? ((sv == 0) ? (x_vec[0] - 0.5) : (x_vec[1] - 0.5)) : 1;
172173
const auto integrand
173-
= Distribution
174-
? dist
175-
: GradT
176-
? conditionally_grad_sw_cdf<Conditionally_cdf>(
174+
= Distribution ? dist
175+
: GradT ? conditionally_grad_sw_cdf<Conditionally_cdf>(
177176
wiener7_functor, y - new_t0, a, v, new_w, sv, sw,
178177
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);
178+
: factor_sv * factor_sw
179+
* conditionally_grad_sw_cdf<Conditionally_cdf>(
180+
wiener7_functor, y - new_t0, a, new_v, new_w,
181+
dist, sw, lerr);
183182
return ret_t(integrand * exp(temp2));
184183
},
185184
integration_args...);
@@ -260,10 +259,10 @@ inline auto wiener7_integrate_cdf(const Wiener7FunctorT& wiener7_functor,
260259
template <bool propto = false, typename T_y, typename T_a, typename T_t0,
261260
typename T_w, typename T_v, typename T_sv, typename T_sw,
262261
typename T_st0>
263-
inline auto wiener_lcdf_defective(const T_y& y, const T_a& a, const T_t0& t0,
264-
const T_w& w, const T_v& v, const T_sv& sv,
265-
const T_sw& sw, const T_st0& st0,
266-
const double& precision_derivatives = 1e-8) {
262+
inline auto wiener_lcdf_unnorm(const T_y& y, const T_a& a, const T_t0& t0,
263+
const T_w& w, const T_v& v, const T_sv& sv,
264+
const T_sw& sw, const T_st0& st0,
265+
const double& precision_derivatives = 1e-8) {
267266
using ret_t = return_type_t<T_y, T_a, T_t0, T_w, T_v, T_sv, T_sw, T_st0>;
268267
using T_y_ref = ref_type_t<T_y>;
269268
using T_a_ref = ref_type_t<T_a>;
@@ -300,7 +299,7 @@ inline auto wiener_lcdf_defective(const T_y& y, const T_a& a, const T_t0& t0,
300299
return ret_t(0);
301300
}
302301

303-
static constexpr const char* function_name = "wiener_lcdf_defective";
302+
static constexpr const char* function_name = "wiener_lcdf_unnorm";
304303
check_consistent_sizes(function_name, "Random variable", y,
305304
"Boundary separation", a, "Drift rate", v,
306305
"A-priori bias", w, "Nondecision time", t0,
@@ -387,9 +386,9 @@ inline auto wiener_lcdf_defective(const T_y& y, const T_a& a, const T_t0& t0,
387386
// calculate density and partials
388387
for (size_t i = 0; i < N; i++) {
389388
if (sv_vec[i] == 0 && sw_vec[i] == 0 && st0_vec[i] == 0) {
390-
result += wiener_lcdf_defective<propto>(y_vec[i], a_vec[i], t0_vec[i],
391-
w_vec[i], v_vec[i],
392-
precision_derivatives);
389+
result
390+
+= wiener_lcdf_unnorm<propto>(y_vec[i], a_vec[i], t0_vec[i], w_vec[i],
391+
v_vec[i], precision_derivatives);
393392
continue;
394393
}
395394
const T_partials_return y_value = y_vec.val(i);

test/sig_utils.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def get_cpp_type(stan_type):
8181
"cov_matrix_constrain": [None, 1],
8282
"cholesky_decompose": [pos_definite, None],
8383
"cholesky_corr_constrain": [None, 2],
84-
"cholesky_factor_constrain": [None, 1,1],
84+
"cholesky_factor_constrain": [None, 1, 1],
8585
"csr_to_dense_matrix": [1, 1, None, [1], [1, 2]],
8686
"csr_matrix_times_vector": [1, 1, None, [1], [1, 2], None],
8787
"distance": [0.6, 0.4],
@@ -145,17 +145,17 @@ def get_cpp_type(stan_type):
145145
"uniform_lcdf": [None, 0.2, 0.9],
146146
"uniform_lpdf": [None, 0.2, 0.9],
147147
"uniform_rng": [0.2, 1.9, None],
148-
"wiener_lpdf": [0.8, None, 0.4, None, None, None, None, None, 1e-4],
149-
"wiener_lccdf_defective": [0.8, None, 0.4, None, None, None, None, None, 1e-4],
150-
"wiener_lcdf_defective": [0.8, None, 0.4, None, None, None, None, None, 1e-4],
148+
"wiener_lpdf": [0.8, None, 0.4, None, None, None, None, None, 1e-4],
149+
"wiener_lccdf_unnorm": [0.8, None, 0.4, None, None, None, None, None, 1e-4],
150+
"wiener_lcdf_unnorm": [0.8, None, 0.4, None, None, None, None, None, 1e-4],
151151
}
152152

153153
# list of functions we do not test. These are mainly functions implemented in compiler
154154
# (not in Stan Math).
155155
ignored = [
156-
"std_normal_qf", # synonym for inv_Phi
156+
"std_normal_qf", # synonym for inv_Phi
157157
"if_else",
158-
"hypergeometric_3F2", # requires arguments of specific lengths
158+
"hypergeometric_3F2", # requires arguments of specific lengths
159159
]
160160

161161
# these are all slight renames compared to stan math
@@ -183,8 +183,8 @@ def get_cpp_type(stan_type):
183183
"ode_bdf_tol": [4, 5, 6],
184184
"ode_rk45_tol": [4, 5, 6],
185185
"wiener_lpdf": [6, 8],
186-
"wiener_lccdf_defective": [5, 8],
187-
"wiener_lcdf_defective": [5, 8],
186+
"wiener_lccdf_unnorm": [5, 8],
187+
"wiener_lcdf_unnorm": [5, 8],
188188
}
189189

190190
# lists of functions that do not support fwd or rev autodiff
@@ -297,6 +297,7 @@ def get_signatures():
297297

298298
return res + internal_signatures
299299

300+
300301
def handle_rename(function_name):
301302
"""
302303
Replace certain function names with their stan math counterparts
@@ -306,6 +307,7 @@ def handle_rename(function_name):
306307
fname = fname.replace("_unconstrain", "_free")
307308
return fname
308309

310+
309311
def parse_signature(signature):
310312
"""
311313
Parses one signature

test/unit/math/mix/prob/wiener4_lccdf_defective_0_test.cpp renamed to test/unit/math/mix/prob/wiener4_lccdf_unnorm_0_test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ TEST(mathMixDouble, wiener4_lccdf) {
77
double t0 = 0.2;
88
double w = 0.5;
99
double v = 1.5;
10-
stan::math::wiener_lccdf_defective(y, a, t0, w, v, 1e-4);
10+
stan::math::wiener_lccdf_unnorm(y, a, t0, w, v, 1e-4);
1111
}
1212

1313
TEST(mathMixVar, wiener4_lccdf) {
@@ -17,7 +17,7 @@ TEST(mathMixVar, wiener4_lccdf) {
1717
var t0 = 0.2;
1818
var w = 0.5;
1919
var v = 1.5;
20-
stan::math::wiener_lccdf_defective(y, a, t0, w, v, 1e-4);
20+
stan::math::wiener_lccdf_unnorm(y, a, t0, w, v, 1e-4);
2121
}
2222

2323
TEST(mathMixFVar, wiener4_lccdf) {
@@ -29,5 +29,5 @@ TEST(mathMixFVar, wiener4_lccdf) {
2929
fvar<var> w = 0.5;
3030
fvar<var> v = 1.5;
3131
double error = 1e-4;
32-
stan::math::wiener_lccdf_defective(y, a, t0, w, v, error);
32+
stan::math::wiener_lccdf_unnorm(y, a, t0, w, v, error);
3333
}

0 commit comments

Comments
 (0)