-
-
Notifications
You must be signed in to change notification settings - Fork 183
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
add 5-parameter diffusion drift; fixes #2584 #2585
add 5-parameter diffusion drift; fixes #2584 #2585
Conversation
…4.1 (tags/RELEASE_600/final)
Thanks for the PR! I don't understand these densities well enough to review myself. I'm afraid that everyone who might review this is scrambling to fix outstanding issues for the 2.28 code freeze this week. If someone doesn't review in the next few days, please ping again. |
Hi, thanks for the comment! As you suggested, I'm adding this comment to serve as a reminder for this PR. In the failed check, it looks as though there are 3 main types of error in the
The third type of error seems the most straightforward to me, but I can't figure out how only 6 arguments were provided to the function in question. If you could advise me on how to fix any of these errors, I'd really appreciate it! Thanks! |
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.
Lots of things to change. I'm gonna stop here for now.
I haven't looked at the math yet, but cleaning this up will help get to the math.
#include <stan/math/prim/err/throw_domain_error.hpp> | ||
#include <stan/math/prim/err/invalid_argument.hpp> | ||
|
||
// Open the Namespace |
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.
Please remove this comment; this information is assumed for C++.
|
||
/** | ||
* The log of the first passage time distribution function for a | ||
* (Ratcliff, 1978) drift diffusion model with intrinsic trial-trial variability |
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.
Could you include a full reference for the "(Ratcliff, 1978)" below? Maybe line 24.
#ifndef STAN_MATH_PRIM_PROB_DDM_LPDF_HPP | ||
#define STAN_MATH_PRIM_PROB_DDM_LPDF_HPP | ||
|
||
#define _USE_MATH_DEFINES |
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.
@kendalfoster What is this used for? This looks like it could cause unintended side effects.
static const int max_terms_large = 1; // heuristic for switching mechanism | ||
static const double ERR_TOL = 0.000001; // error tolerance for PDF approx | ||
static const double SV_THRESH = 0; // threshold for using variable drift rate | ||
static const double LOG_PI = log(M_PI); |
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.
There is already a declaration of LOG_PI
in the math library. Please:
- include this header at the top:
stan/math/prim/fun/constants.hpp
- remove this line.
LOG_PI
should be defined in this namespace and it should resolve ok.
static const double ERR_TOL = 0.000001; // error tolerance for PDF approx | ||
static const double SV_THRESH = 0; // threshold for using variable drift rate | ||
static const double LOG_PI = log(M_PI); | ||
static const double LOG_2PI_2 = 0.5 * log(2 * M_PI); |
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.
Please replace LOG_2PI_2
with the constant HALF_LOG_TWO_PI
found in the same constants.hpp
above.
if (Nt0 < 1) { // t0 | ||
return 0; | ||
} else { | ||
for (size_t i = 0; i < Nt0; i++) { |
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.
Please use check_positive_finite()
.
You'll have to include stan/math/prim/err/check_positive_finite.hpp
at the top.
if (Nw < 1) { // w | ||
return 0; | ||
} else { | ||
for (size_t i = 0; i < Nw; i++) { |
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.
Please use check_bounded()
with 0, 1.
if (Nsv < 1) { // sv | ||
return 0; | ||
} else { | ||
for (size_t i = 0; i < Nsv; i++) { |
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.
Please use check_positive()
.
} | ||
} | ||
|
||
if (!include_summand<propto, T_rt, T_response, T_a, T_v, T_t0, T_w, |
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.
After all the checks, this is where you'd put something like:
if (size_zero(rt, response, a, v, t0, w, ...)) {
return 0.0;
}
double t, a_i, v_i, w_i, sv_i; | ||
for (size_t i = 0; i < Nmax; i++) { | ||
// Check Parameter Values | ||
t = rt_vec[i % Nrt] |
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.
The pattern of indexing into rt_vec
isn't right.
The purpose of the view (scalar_seq_view<T_rt_ref> rt_vec(rt_ref)
) is to treat rt_vec
as if it were a vector even if it's a scalar.
So... this can be simplified to something like:
t = rt_vec[i] - t0_vec[i];
But... when you see that, you'll see the types are wrong now. t
isn't a double
, right? It could either be double
or var
(or fvar<T>
). I don't think this should work if you've tested this with rt
as var
and t0
as double
.
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.
Lots of things to change. I'm gonna stop here for now.
I haven't looked at the math yet, but cleaning this up will help get to the math.
Closed by #2822 |
Summary
This pull request implements the 5-parameter variant of the DDM by adding two new functions:
ddm_lpdf()
andddm_lcdf()
.This pull request addresses issue #2584: Adding 5-Parameter Drift Diffusion Model (DDM) PDF and CDF to Stan Math. This pull request has been discussed in this Discourse thread.
Tests
As recommended in the guidelines, I added the following tests to mirror that of the related
wiener_lpdf()
function that already exists in Stan Math:test/prob/ddm/ddm_cdf_log_test.hpp
test/prob/ddm/ddm_test.hpp
test/unit/math/prim/prob/ddm_cdf_log_test.cpp
test/unit/math/prim/prob/ddm_test.cpp
Side Effects
There should be no side effects.
Release notes
The 5-parameter variant of the DDM will become available in Stan Math.
Checklist
Math issue Adding 5-Parameter Drift Diffusion Model (DDM) PDF and CDF to Stan Math #2584
Copyright holder: Kendal Foster
The copyright holder is typically you or your assignee, such as a university or company. By submitting this pull request, the copyright holder is agreeing to the license the submitted work under the following licenses:
- Code: BSD 3-clause (https://opensource.org/licenses/BSD-3-Clause)
- Documentation: CC-BY 4.0 (https://creativecommons.org/licenses/by/4.0/)
the basic tests are passing
./runTests.py test/unit
)make test-headers
)make test-math-dependencies
)make doxygen
)make cpplint
)the code is written in idiomatic C++ and changes are documented in the doxygen
the new changes are tested