-
-
Notifications
You must be signed in to change notification settings - Fork 198
Feature/issue 2966 add 7 parameter ddm cdf and ccdf #3042
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Franzi2114
wants to merge
106
commits into
stan-dev:develop
Choose a base branch
from
Franzi2114:feature/issue-2966-Add-7-parameter-DDM-CDF-and-CCDF
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
106 commits
Select commit
Hold shift + click to select a range
26ed582
Merge branch 'develop' into issue-2966-Add-7-parameter-DDM-CDF-and-CCDF
Franzi2114 a080ab8
CDF and CCDF function files
Franzi2114 eee7267
unit prim prob tests
Franzi2114 8483c39
mix tests
Franzi2114 5ecf546
header and clang format
Franzi2114 8f085b8
include
Franzi2114 f274c18
include
Franzi2114 f68fe16
include
Franzi2114 10feb1f
correct includes
Franzi2114 9758d68
uncomment tests
Franzi2114 363eb42
minor changes tests
Franzi2114 2e1febf
correct wiener5
Franzi2114 287472c
merge PDF branch
Franzi2114 1138571
merge pdf
Franzi2114 4fc8fdb
Merge branch 'issue-2682-Add-7-parameter-DDM-PDF' into issue-2966-Add…
Franzi2114 721f181
PDF style
Franzi2114 bcc361e
cdf in pdf style
Franzi2114 d14a5d8
delete obsolete initializers
Franzi2114 cda2f6e
all tests pass
Franzi2114 22146d7
Merge branch 'develop' into issue-2966-Add-7-parameter-DDM-CDF-and-CCDF
Franzi2114 22bbb18
ccdf umbauen
Franzi2114 466b2d2
lccdf prim test pass
Franzi2114 b5bcb06
ret_t
Franzi2114 71e7825
linhart cite
Franzi2114 401c7a7
Merge commit '35d6d53545bf382b1bf8e5ea7a04469310892a2a' into HEAD
yashikno f597049
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot b65af9c
add brace
Franzi2114 1b14f78
add whitespaces
Franzi2114 6cd53f2
add params to docu
Franzi2114 d6c54c8
resolve some header errors
Franzi2114 142e017
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot 72617b1
add include to wiener4_lccdf
Franzi2114 601e4e1
Merge commit '1f94ed312376f726feb820bea90ed8df27974c17' into HEAD
yashikno 20d9689
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot 59ea8bc
add two includes to wiener4_lccdf
Franzi2114 80d4962
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot 98756a6
add includes in wieener_full_lccdf
Franzi2114 aa93836
correct include
Franzi2114 3e607c6
include in wiener_full_lcdf
Franzi2114 dba1b36
another include
Franzi2114 ae909ae
another include
Franzi2114 632a0b8
restore hypergemoetric files
Franzi2114 30f6c85
less includes
Franzi2114 8a44586
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot 13e4fbf
reduce and inline some functions
Franzi2114 1bb3bd5
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot d756c4a
whitespace error
Franzi2114 f105313
correct braces
Franzi2114 6862514
some minor changes
Franzi2114 a4549f2
more inlines
Franzi2114 70bc628
Merge commit '1830097a0de00b5322277b923fd6fb913050a90f' into HEAD
yashikno 44ebbcf
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot 037cca3
delete one ret_t
Franzi2114 c14459b
using ret_t
Franzi2114 49a14eb
Merge branch 'develop' into issue-2966-Add-7-parameter-DDM-CDF-and-CCDF
Franzi2114 4293e45
use std_normal_log, _lcdf, slice derive_y, shorter ifs
Franzi2114 979b17c
Merge commit 'af63738e6a62b9090188fd79592bfdfadf594705' into HEAD
yashikno 46c7a1e
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot e5f5048
early returns some ifs
Franzi2114 a4d1895
delete rexp
Franzi2114 572dcd4
merge develog
Franzi2114 00a930e
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot b9b1839
correct ifs in ccdf_grad_w
Franzi2114 443e25b
Merge commit '2fdd3ed700d48c0bfea46091be885d4bc787b7b8' into HEAD
yashikno afd9330
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot 20cba0c
fmin instead of min
Franzi2114 6c8688f
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot 97ab7a9
change prob_deriv *= prob
Franzi2114 f53cda6
some ret_t types
Franzi2114 cbd2c80
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot be67633
small code cleanup
SteveBronder cc70169
small code cleanup
SteveBronder b09bd1b
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot a280b12
error corrected
Franzi2114 bdd000e
Merge commit '7ada875b1a3a20fd78ce4eabd29664dc0d1fc42e' into HEAD
yashikno 0d05c83
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot 44a6c2b
deleted wildcards
Franzi2114 2489d88
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot ca6e23e
Merge branch 'develop' into feature/issue-2966-Add-7-parameter-DDM-CD…
Franzi2114 2fdfe8f
first bunch of changes for Bob
Franzi2114 398a56f
Merge commit 'b9167895dbb574acd40c2d3f8dd4b5ca6fb3d418' into HEAD
yashikno 5b0fb36
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot 79ae69a
first correction
Franzi2114 02f03aa
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot 38846da
second correction
Franzi2114 4a58f7b
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot 859d6c0
third correction
Franzi2114 17373b8
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot 783e9a5
without static constexpr
Franzi2114 a38bf2b
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot 965091e
const double log_four instead of static constexpr double
Franzi2114 c8aa4b9
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot 7b3ce8d
fourth correction
Franzi2114 1535b2f
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot 5504f82
changes for wiener4_lcdf
Franzi2114 e324b67
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot f8c103a
More changes for Bob
Franzi2114 4cb2e8c
Merge commit 'b82d68ced2e73c8188f3bbf287c1321033103986' into HEAD
yashikno 83956ed
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot ecf092a
corrected the error
Franzi2114 c7a7762
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot ea8ae10
new line
Franzi2114 7a204da
ret_t in wiener4_lccdf for type derivation error
Franzi2114 9f4c4c7
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot d957b6c
Merge branch 'develop' into 3042-merge-fix
WardBrian 0a2f7fd
Revert "first correction" merge errors
WardBrian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,372 @@ | ||
| #ifndef STAN_MATH_PRIM_PROB_WIENER4_LCCDF_HPP | ||
| #define STAN_MATH_PRIM_PROB_WIENER4_LCCDF_HPP | ||
|
|
||
| #include <stan/math/prim/prob/wiener4_lcdf.hpp> | ||
|
|
||
| namespace stan { | ||
| namespace math { | ||
| namespace internal { | ||
|
|
||
| /** | ||
| * Log of probability of reaching the upper bound in diffusion process | ||
| * | ||
| * @tparam T_a type of boundary | ||
| * @tparam T_w type of relative starting point | ||
| * @tparam T_v type of drift rate | ||
| * | ||
| * @param a The boundary separation | ||
| * @param w The relative starting point | ||
| * @param v The drift rate | ||
| * @return log probability to reach the upper bound | ||
| */ | ||
| template <typename T_a, typename T_w, typename T_v> | ||
| inline auto log_wiener_prob_hit_upper(const T_a& a, const T_v& v, | ||
| const T_w& w) { | ||
| using ret_t = return_type_t<T_a, T_w, T_v>; | ||
| const auto neg_v = -v; | ||
| const auto one_m_w = 1.0 - w; | ||
| if (fabs(v) == 0.0) { | ||
| return ret_t(log1m(one_m_w)); | ||
| } | ||
| const auto exponent = 2.0 * v * a * w; | ||
| // This branch is for numeric stability | ||
| if (exponent < 0) { | ||
| return ret_t(log1m_exp(exponent) | ||
| - log_diff_exp(2.0 * neg_v * a * one_m_w, exponent)); | ||
| } else { | ||
| return ret_t(log1m_exp(-exponent) - log1m_exp(2.0 * neg_v * a)); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Calculate parts of the partial derivatives for wiener_prob_grad_a and | ||
| * wiener_prob_grad_v (on log-scale) | ||
| * | ||
| * @tparam T_a type of boundary | ||
| * @tparam T_w type of relative starting point | ||
| * @tparam T_v type of drift rate | ||
| * | ||
| * @param a The boundary separation | ||
| * @param w The relative starting point | ||
| * @param v The drift rate | ||
| * @return 'ans' term | ||
| */ | ||
| template <typename T_a, typename T_w, typename T_v> | ||
| inline auto wiener_prob_derivative_term(const T_a& a, const T_v& v, | ||
| const T_w& w) noexcept { | ||
| using ret_t = return_type_t<T_a, T_w, T_v>; | ||
| const auto exponent_m1 = log1m(1.1 * 1.0e-8); | ||
| const auto neg_v = -v; | ||
| const auto one_m_w = 1 - w; | ||
| int sign_v = neg_v < 0 ? 1 : -1; | ||
| const auto two_a_neg_v = 2.0 * a * neg_v; | ||
| const auto exponent_with_1mw = sign_v * two_a_neg_v * w; | ||
| const auto exponent = sign_v * two_a_neg_v; | ||
| const auto exponent_with_w = two_a_neg_v * one_m_w; | ||
| // truncating longer calculations, for numerical stability | ||
| if (unlikely((exponent_with_1mw >= exponent_m1) | ||
Franzi2114 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| || ((exponent_with_w >= exponent_m1) && (sign_v == 1)) | ||
| || (exponent >= exponent_m1) || neg_v == 0)) { | ||
| return ret_t(-one_m_w); | ||
| } | ||
| ret_t ans; | ||
| ret_t diff_term; | ||
| const auto log_w = log(one_m_w); | ||
| if (neg_v < 0) { | ||
| ans = LOG_TWO + exponent_with_1mw - log1m_exp(exponent_with_1mw); | ||
| diff_term = log1m_exp(exponent_with_w) - log1m_exp(exponent); | ||
| } else if (neg_v > 0) { | ||
| ans = LOG_TWO - log1m_exp(exponent_with_1mw); | ||
| diff_term = log_diff_exp(exponent_with_1mw, exponent) - log1m_exp(exponent); | ||
| } | ||
| if (log_w > diff_term) { | ||
| ans = sign_v * exp(ans + log_diff_exp(log_w, diff_term)); | ||
| } else { | ||
| ans = -sign_v * exp(ans + log_diff_exp(diff_term, log_w)); | ||
| } | ||
| if (unlikely(!is_scal_finite(ans))) { | ||
| return ret_t(NEGATIVE_INFTY); | ||
| } | ||
| return ans; | ||
| } | ||
|
|
||
| /** | ||
| * Calculate wiener4 ccdf (natural-scale) | ||
| * | ||
| * @param y The reaction time in seconds | ||
| * @param a The boundary separation | ||
| * @param v The relative starting point | ||
| * @param w The drift rate | ||
| * @param log_err The log error tolerance in the computation of the number | ||
| * of terms for the infinite sums | ||
| * @return ccdf | ||
| */ | ||
| template <typename T_y, typename T_a, typename T_w, typename T_v, | ||
| typename T_err> | ||
| inline auto wiener4_ccdf(const T_y& y, const T_a& a, const T_v& v, const T_w& w, | ||
| T_err log_err = log(1e-12)) noexcept { | ||
| const auto prob_hit_upper = exp(log_wiener_prob_hit_upper(a, v, w)); | ||
| const auto cdf | ||
| = internal::wiener4_distribution<GradientCalc::ON>(y, a, v, w, log_err); | ||
| return prob_hit_upper - cdf; | ||
| } | ||
|
|
||
| /** | ||
| * Calculate derivative of the wiener4 ccdf w.r.t. 'a' (natural-scale) | ||
| * | ||
| * @param y The reaction time in seconds | ||
| * @param a The boundary separation | ||
| * @param v The relative starting point | ||
| * @param w The drift rate | ||
| * @param cdf The CDF value | ||
| * @param log_err The log error tolerance in the computation of the number | ||
| * of terms for the infinite sums | ||
| * @return Gradient with respect to a | ||
| */ | ||
| template <typename T_y, typename T_a, typename T_w, typename T_v, | ||
| typename T_cdf, typename T_err> | ||
| inline auto wiener4_ccdf_grad_a(const T_y& y, const T_a& a, const T_v& v, | ||
| const T_w& w, T_cdf&& cdf, | ||
| T_err log_err = log(1e-12)) noexcept { | ||
| using ret_t = return_type_t<T_a, T_w, T_v>; | ||
|
|
||
| // derivative of the wiener probability w.r.t. 'a' (on log-scale) | ||
| auto prob_grad_a = -wiener_prob_derivative_term(a, v, w) * v; | ||
| if (!is_scal_finite(prob_grad_a)) { | ||
| prob_grad_a = ret_t(NEGATIVE_INFTY); | ||
| } | ||
| const auto log_prob_hit_upper = log_wiener_prob_hit_upper(a, v, w); | ||
| const auto cdf_grad_a = wiener4_cdf_grad_a(y, a, v, w, cdf, log_err); | ||
| return prob_grad_a * exp(log_prob_hit_upper) - cdf_grad_a; | ||
| } | ||
|
|
||
| /** | ||
| * Calculate derivative of the wiener4 ccdf w.r.t. 'v' (natural-scale) | ||
| * | ||
| * @param y The reaction time in seconds | ||
| * @param a The boundary separation | ||
| * @param v The relative starting point | ||
| * @param w The drift rate | ||
| * @param cdf The CDF value | ||
| * @param log_err The log error tolerance in the computation of the number | ||
| * of terms for the infinite sums | ||
| * @return Gradient with respect to v | ||
| */ | ||
| template <typename T_y, typename T_a, typename T_w, typename T_v, | ||
| typename T_cdf, typename T_err> | ||
| inline auto wiener4_ccdf_grad_v(const T_y& y, const T_a& a, const T_v& v, | ||
| const T_w& w, T_cdf&& cdf, | ||
| T_err log_err = log(1e-12)) noexcept { | ||
| using ret_t = return_type_t<T_a, T_w, T_v>; | ||
| const auto log_prob_hit_upper = log_wiener_prob_hit_upper(a, v, w); | ||
| // derivative of the wiener probability w.r.t. 'v' (on log-scale) | ||
| auto prob_grad_v = -wiener_prob_derivative_term(a, v, w) * a; | ||
| if (!is_scal_finite(fabs(prob_grad_v))) { | ||
| prob_grad_v = ret_t(NEGATIVE_INFTY); | ||
| } | ||
|
|
||
| const auto cdf_grad_v = wiener4_cdf_grad_v(y, a, v, w, cdf, log_err); | ||
| return prob_grad_v * exp(log_prob_hit_upper) - cdf_grad_v; | ||
| } | ||
|
|
||
| /** | ||
| * Calculate derivative of the wiener4 ccdf w.r.t. 'w' (natural-scale) | ||
| * | ||
| * @param y The reaction time in seconds | ||
| * @param a The boundary separation | ||
| * @param v The relative starting point | ||
| * @param w The drift rate | ||
| * @param cdf The CDF value | ||
| * @param log_err The log error tolerance in the computation of the number | ||
| * of terms for the infinite sums | ||
| * @return Gradient with respect to w | ||
| */ | ||
| template <typename T_y, typename T_a, typename T_w, typename T_v, | ||
| typename T_cdf, typename T_err> | ||
| inline auto wiener4_ccdf_grad_w(const T_y& y, const T_a& a, const T_v& v, | ||
| const T_w& w, T_cdf&& cdf, | ||
| T_err log_err = log(1e-12)) noexcept { | ||
| using ret_t = return_type_t<T_a, T_w, T_v>; | ||
| const auto log_prob_hit_upper = log_wiener_prob_hit_upper(a, v, w); | ||
| // derivative of the wiener probability w.r.t. 'v' (on log-scale) | ||
| const auto exponent = -sign(v) * 2.0 * v * a * w; | ||
| auto prob_grad_w | ||
| = (v != 0) ? exp(LOG_TWO + log(fabs(v)) + log(a) - log1m_exp(exponent)) | ||
| : ret_t(1 / w); | ||
bob-carpenter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (v > 0) { | ||
| prob_grad_w *= exp(exponent); | ||
| } | ||
|
|
||
| const auto cdf_grad_w = wiener4_cdf_grad_w(y, a, v, w, cdf, log_err); | ||
| return prob_grad_w * exp(log_prob_hit_upper) - cdf_grad_w; | ||
| } | ||
|
|
||
| } // namespace internal | ||
|
|
||
| /** | ||
| * Log-CCDF for the 4-parameter Wiener distribution. | ||
| * See 'wiener_full_lpdf' for more comprehensive documentation. | ||
| * | ||
| * @tparam T_y type of reaction time | ||
| * @tparam T_a type of boundary | ||
| * @tparam T_t0 type of non-decision time | ||
| * @tparam T_w type of relative starting point | ||
| * @tparam T_v type of drift rate | ||
| * | ||
| * @param y The reaction time in seconds | ||
| * @param a The boundary separation | ||
| * @param t0 The non-decision time | ||
| * @param w The relative starting point | ||
| * @param v The drift rate | ||
| * @param precision_derivatives Level of precision in estimation | ||
| * @return The log of the Wiener first passage time distribution with | ||
| * the specified arguments for upper boundary responses | ||
| */ | ||
| template <bool propto = false, typename T_y, typename T_a, typename T_t0, | ||
| typename T_w, typename T_v> | ||
| inline auto wiener_lccdf(const T_y& y, const T_a& a, const T_t0& t0, | ||
| const T_w& w, const T_v& v, | ||
| const double& precision_derivatives) { | ||
| using T_partials_return = partials_return_t<T_y, T_a, T_t0, T_w, T_v>; | ||
| using ret_t = return_type_t<T_y, T_a, T_t0, T_w, T_v>; | ||
| using T_y_ref = ref_type_if_t<!is_constant<T_y>::value, T_y>; | ||
| using T_a_ref = ref_type_if_t<!is_constant<T_a>::value, T_a>; | ||
| using T_t0_ref = ref_type_if_t<!is_constant<T_t0>::value, T_t0>; | ||
| using T_w_ref = ref_type_if_t<!is_constant<T_w>::value, T_w>; | ||
| using T_v_ref = ref_type_if_t<!is_constant<T_v>::value, T_v>; | ||
| using internal::GradientCalc; | ||
|
|
||
| T_y_ref y_ref = y; | ||
| T_a_ref a_ref = a; | ||
| T_t0_ref t0_ref = t0; | ||
| T_w_ref w_ref = w; | ||
| T_v_ref v_ref = v; | ||
|
|
||
| auto y_val = to_ref(as_value_column_array_or_scalar(y_ref)); | ||
| auto a_val = to_ref(as_value_column_array_or_scalar(a_ref)); | ||
| auto v_val = to_ref(as_value_column_array_or_scalar(v_ref)); | ||
| auto w_val = to_ref(as_value_column_array_or_scalar(w_ref)); | ||
| auto t0_val = to_ref(as_value_column_array_or_scalar(t0_ref)); | ||
|
|
||
| static constexpr const char* function_name = "wiener4_lccdf"; | ||
Franzi2114 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (size_zero(y, a, t0, w, v)) { | ||
| return ret_t(0.0); | ||
| } | ||
|
|
||
| if (!include_summand<propto, T_y, T_a, T_t0, T_w, T_v>::value) { | ||
| return ret_t(0.0); | ||
| } | ||
|
|
||
| check_consistent_sizes(function_name, "Random variable", y, | ||
| "Boundary separation", a, "Drift rate", v, | ||
| "A-priori bias", w, "Nondecision time", t0); | ||
| check_positive_finite(function_name, "Random variable", y_val); | ||
| check_positive_finite(function_name, "Boundary separation", a_val); | ||
| check_finite(function_name, "Drift rate", v_val); | ||
| check_less(function_name, "A-priori bias", w_val, 1); | ||
| check_greater(function_name, "A-priori bias", w_val, 0); | ||
| check_nonnegative(function_name, "Nondecision time", t0_val); | ||
| check_finite(function_name, "Nondecision time", t0_val); | ||
|
|
||
| const size_t N = max_size(y, a, t0, w, v); | ||
|
|
||
| scalar_seq_view<T_y_ref> y_vec(y_ref); | ||
| scalar_seq_view<T_a_ref> a_vec(a_ref); | ||
| scalar_seq_view<T_t0_ref> t0_vec(t0_ref); | ||
| scalar_seq_view<T_w_ref> w_vec(w_ref); | ||
| scalar_seq_view<T_v_ref> v_vec(v_ref); | ||
| const size_t N_y_t0 = max_size(y, t0); | ||
|
|
||
| for (size_t i = 0; i < N_y_t0; ++i) { | ||
| if (y_vec[i] <= t0_vec[i]) { | ||
| std::stringstream msg; | ||
| msg << ", but must be greater than nondecision time = " << t0_vec[i]; | ||
| std::string msg_str(msg.str()); | ||
| throw_domain_error(function_name, "Random variable", y_vec[i], " = ", | ||
| msg_str.c_str()); | ||
| } | ||
| } | ||
|
|
||
| // for precs. 1e-6, 1e-12, see Hartmann et al. (2021), Henrich et al. (2023) | ||
| const auto log_error_cdf = log(1e-6); | ||
| const auto log_error_derivative = log(precision_derivatives); | ||
| const T_partials_return log_error_absolute = log(1e-12); | ||
Franzi2114 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| T_partials_return lccdf = 0.0; | ||
| auto ops_partials | ||
| = make_partials_propagator(y_ref, a_ref, t0_ref, w_ref, v_ref); | ||
|
|
||
| const double LOG_FOUR = std::log(4.0); | ||
|
|
||
| // calculate distribution and partials | ||
| for (size_t i = 0; i < N; i++) { | ||
| const auto y_value = y_vec.val(i); | ||
| const auto a_value = a_vec.val(i); | ||
| const auto t0_value = t0_vec.val(i); | ||
| const auto w_value = w_vec.val(i); | ||
| const auto v_value = v_vec.val(i); | ||
|
|
||
| const T_partials_return cdf | ||
| = internal::estimate_with_err_check<4, 0, GradientCalc::OFF, | ||
| GradientCalc::OFF>( | ||
| [](auto&&... args) { | ||
bob-carpenter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return internal::wiener4_distribution<GradientCalc::ON>(args...); | ||
| }, | ||
| log_error_cdf - LOG_TWO, y_value - t0_value, a_value, v_value, | ||
| w_value, log_error_absolute); | ||
|
|
||
| const auto prob_hit_upper | ||
| = exp(internal::log_wiener_prob_hit_upper(a_value, v_value, w_value)); | ||
| const auto ccdf = prob_hit_upper - cdf; | ||
| const auto log_ccdf_single_value = log(ccdf); | ||
|
|
||
| lccdf += log_ccdf_single_value; | ||
|
|
||
bob-carpenter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const auto new_est_err | ||
| = log_ccdf_single_value + log_error_derivative - LOG_FOUR; | ||
|
|
||
| if (!is_constant_all<T_y>::value || !is_constant_all<T_t0>::value) { | ||
| const auto deriv_y = internal::estimate_with_err_check<5, 0>( | ||
| [](auto&&... args) { | ||
| return internal::wiener5_density<GradientCalc::ON>(args...); | ||
| }, | ||
| new_est_err, y_value - t0_value, a_value, v_value, w_value, 0.0, | ||
| log_error_absolute); | ||
| if (!is_constant_all<T_y>::value) { | ||
| partials<0>(ops_partials)[i] = -deriv_y / ccdf; | ||
| } | ||
| if (!is_constant_all<T_t0>::value) { | ||
| partials<2>(ops_partials)[i] = deriv_y / ccdf; | ||
| } | ||
| } | ||
| if (!is_constant_all<T_a>::value) { | ||
| partials<1>(ops_partials)[i] | ||
| = internal::estimate_with_err_check<5, 0>( | ||
| [](auto&&... args) { | ||
| return internal::wiener4_ccdf_grad_a(args...); | ||
| }, | ||
| new_est_err, y_value - t0_value, a_value, v_value, w_value, cdf, | ||
| log_error_absolute) | ||
| / ccdf; | ||
| } | ||
| if (!is_constant_all<T_w>::value) { | ||
| partials<3>(ops_partials)[i] | ||
| = internal::estimate_with_err_check<5, 0>( | ||
| [](auto&&... args) { | ||
| return internal::wiener4_ccdf_grad_w(args...); | ||
| }, | ||
| new_est_err, y_value - t0_value, a_value, v_value, w_value, cdf, | ||
| log_error_absolute) | ||
| / ccdf; | ||
| } | ||
| if (!is_constant_all<T_v>::value) { | ||
| partials<4>(ops_partials)[i] | ||
| = internal::wiener4_ccdf_grad_v(y_value - t0_value, a_value, v_value, | ||
| w_value, cdf, log_error_absolute) | ||
| / ccdf; | ||
| } | ||
| } // for loop | ||
| return ops_partials.build(lccdf); | ||
| } | ||
| } // namespace math | ||
| } // namespace stan | ||
| #endif | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should just be
log(w)becauselog1m(1 - w) = log(1 - (1 - w)) = log(w).