-
-
Notifications
You must be signed in to change notification settings - Fork 197
Add quantile function for Student-T distribution #3211
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
base: develop
Are you sure you want to change the base?
Conversation
Jenkins Console Log Machine informationNo LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04.3 LTS Release: 20.04 Codename: focalCPU: G++: Clang: |
Thanks @andrjohns for tackling this! Do you happen to know any particular ranges which are problematic for the current implementation? |
I haven't done any proper testing at this point, it was more just getting an initial implementation in to be refined. Because it's just directly estimating, I'd say that the problematic ranges for both the values and gradients are going to mostly match those for boost's incomplete beta inverse Definitely want to move to more stable approximations for both the gradient and value at some point though! |
@spinkney on a semi-related note - after being annoyed by the need to compile c++ whenever I'm validating against Boost's Math functions, I've started exposing them in an R package: https://github.com/andrjohns/boostmath Just an FYI in case it helps with any of your validation/testing as well! |
That's great! |
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.
Sorry this took so long for me to look at. Looks good imo!
Should we have a higher order function to be able to call this with vectors?
template <typename T_p, typename T_nu, typename T_mu, typename T_sigma, | ||
typename T_container = common_container_t<T_p, T_nu, T_mu, T_sigma>, | ||
require_any_vector_t<T_p, T_nu, T_mu, T_sigma>* = nullptr, | ||
require_not_t<std::is_void<T_container>>* = nullptr> |
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.
What is this line doing?
template <typename T_p, typename T_nu, typename T_mu, typename T_sigma, | ||
require_all_stan_scalar_t<T_p, T_mu, T_sigma, T_nu>* = nullptr, | ||
require_any_var_t<T_p, T_mu, T_sigma, T_nu>* = nullptr> | ||
var student_t_qf(const T_p& p, const T_nu& nu, const T_mu& mu, |
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.
var student_t_qf(const T_p& p, const T_nu& nu, const T_mu& mu, | |
inline var student_t_qf(const T_p& p, const T_nu& nu, const T_mu& mu, |
Eigen::VectorXd hyper_arg_a(3); | ||
hyper_arg_a << 0.5, half_nu, half_nu; | ||
Eigen::VectorXd hyper_arg_b(2); | ||
hyper_arg_b << 1 + half_nu, 1 + half_nu; |
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.
Eigen::VectorXd hyper_arg_a(3); | |
hyper_arg_a << 0.5, half_nu, half_nu; | |
Eigen::VectorXd hyper_arg_b(2); | |
hyper_arg_b << 1 + half_nu, 1 + half_nu; | |
Eigen::VectorXd hyper_arg_a{{0.5, half_nu, half_nu}}; | |
Eigen::VectorXd hyper_arg_b{{1 + half_nu, 1 + half_nu}}; |
typename T_container = common_container_t<T_p, T_nu, T_mu, T_sigma>, | ||
require_any_vector_t<T_p, T_nu, T_mu, T_sigma>* = nullptr, | ||
require_not_t<std::is_void<T_container>>* = nullptr> | ||
auto student_t_qf(const T_p& p, const T_nu& nu, const T_mu& mu, |
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.
inline for functions so we can have multiple definitions of the same function across compilation units
auto student_t_qf(const T_p& p, const T_nu& nu, const T_mu& mu, | |
inline auto student_t_qf(const T_p& p, const T_nu& nu, const T_mu& mu, |
Summary
This PR adds the (vectorised) student-t quantile function with signature:
The current implementation directly estimates the quantile using the inverse of the incomplete beta, but implementing approximations (like those used by R) are a planned future improvement
Tests
Both
prim
andmix
tests (using the AD framework) are addedSide Effects
An additional utility type has been added:
common_container_type
to detect the right container type to return for vectorised inputs.Release notes
Added quantile function for student-t distribution
Checklist
Copyright holder: Andrew Johnson
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