You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
test internal math functions F32, gradF32, grad2F1, gradRegIncBeta for infinite loops #27
changed the title [-]test remaining src/stan/prob/internal_math.hpp functions[/-][+]test internal math functions F32, gradF32, grad2F1, gradRegIncBeta for infinite loops[/+]on Aug 17, 2016
Maybe I just haven't read the functions correctly but I was trying to find consequences to this issue in the user-facing functions and it turns out this test (that I just wrote) fails with a nan for our function.
TEST(ProbBetaBinomial, lcdf_matches_emdbook_lcdf) {
int n = 8;
int N = 10;
double alpha = 3.0;
double beta = 1.0;
EXPECT_FLOAT_EQ(-1.849329, (stan::math::beta_binomial_lcdf(n, N, alpha, beta)));
}
With this output:
Running main() from gtest_main.cc
[==========] Running 2 tests from 1 test case.
[----------] Global test environment set-up.
[----------] 2 tests from ProbBetaBinomial
[ RUN ] ProbBetaBinomial.cdf_log_matches_lcdf
[ OK ] ProbBetaBinomial.cdf_log_matches_lcdf (0 ms)
[ RUN ] ProbBetaBinomial.lcdf_matches_emdbook_lcdf
test/unit/math/prim/scal/prob/beta_binomial_cdf_log_test.cpp:23: Failure
Value of: (stan::math::beta_binomial_lcdf(n, N, alpha, beta))
Actual: nan
Expected: -1.849329
[ FAILED ] ProbBetaBinomial.lcdf_matches_emdbook_lcdf (0 ms)
[----------] 2 tests from ProbBetaBinomial (0 ms total)
Turns out F32 also needs to terminate when the denominator for the rising factorial bits goes to 0. Once I push it will match mathematica results and have tests for that condition. Also, sign needs to be applied after exp, also fixing that. I'm not sure it was ever right except for a limited number of arguments (?)
Sounds good. I don't even know what this function is or where it's used, but might as well fix it if it's getting called from elsewhere. If it's not getting called anywhere, we can get rid of it unless it's there pending being exposed to the Stan language.
It gets called by the beta-binomial CDF and it's related to some functions that make my delay-time models hang so I'm just going to plow through all these if I can. I am setting up some tests against results from Mathematica so if you have any suggestions about how to do that better I appreciate suggestions. It's one of the less common instances of the generalized hypergeometric function
I have a problem with grad_reg_inc_beta function.
void grad_reg_inc_beta(T& g1, T& g2, const T& a, const T& b,
const T& z, const T& digammaA, const T& digammaB,
const T& digammaSum, const T& betaAB)
For example, when z = 1, I would expect that g1 is 0.
I also compare different value for z and find that it is not close to the value in the "Derivatives of the Incomplete Beta Function" (https://www.jstatsoft.org/article/view/v003i01). I dont know this function is the same with this one or not. Thanks.
Thanks for pointing out the additional test case, I've been working on
these but I don't think I've touched this one in any meaningful way yet. I
will look at this test case but not before finishing the other issue
related to these. If you're trying to use this function the best way to
get help now is to ask on the users mailing list (yes, even for C++ math
lib questions).
On Tue, Mar 28, 2017 at 5:42 AM hoanguc3m ***@***.***> wrote:
For example, in the grad_reg_inc_beta_test.cpp
`#include <stan/math/prim/scal.hpp>
#include <gtest/gtest.h>
TEST(grad_reg_inc_beta, 1) {
double alpha = 1.0;
double beta = 1.0;
double y = 1.0;
double digamma_alpha = stan::math::digamma(alpha);
double digamma_beta = stan::math::digamma(beta);
double digamma_sum = stan::math::digamma(alpha + beta);
double betafunc = std::exp(stan::math::lbeta(alpha, beta));
double g1 = 0;
double g2 = 0;
stan::math::grad_reg_inc_beta(g1, g2, alpha, beta, y,
digamma_alpha, digamma_beta, digamma_sum,
betafunc);
EXPECT_FLOAT_EQ(0, g1);
EXPECT_FLOAT_EQ(-std::numeric_limits::infinity(), g2);
}
`
If I change alpha = 2.5, beta = 0.5. I would expect the same g1 = 0.
—
You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub
<#27 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAfA6aiPHe30jNEMT_XR4OIrYwFT8_Ozks5rqNYGgaJpZM4FTDej>
.
Basically all the boxes in this issue are checked, including for grad_reg_inc_beta that relies on a hypergeometric function deep down on the inside (like most of us).
Activity
bob-carpenter commentedon Aug 17, 2016
What tests do these function need? If anyone knows, please edit the issue to add a list of tests.
[-]test remaining src/stan/prob/internal_math.hpp functions[/-][+]test internal math functions F32, gradF32, grad2F1, gradRegIncBeta for infinite loops[/+]syclik commentedon Sep 11, 2016
I started working on
F32, but I'm having lots of trouble. Here's the branch:feature/issue-27-internal_math_tests
The first problem I run into is
F32()isn't returning the correct results for:This is in the unit test on the branch:
./runTests.py test/unit/math/prim/scal/fun/F32_test.cppIf there's something wrong with the input, we really need to doc the function.
syclik commentedon Dec 1, 2016
Bump. I've gotten a first test up and it doesn't look good.
Check out branch
feature/issue-27-internal_math_testsRun:
sakrejda commentedon Feb 9, 2017
I started working on this branch.
sakrejda commentedon Feb 9, 2017
Maybe I just haven't read the functions correctly but I was trying to find consequences to this issue in the user-facing functions and it turns out this test (that I just wrote) fails with a
nanfor our function.With this output:
sakrejda commentedon Feb 9, 2017
Turns out F32 also needs to terminate when the denominator for the rising factorial bits goes to 0. Once I push it will match mathematica results and have tests for that condition. Also, sign needs to be applied after exp, also fixing that. I'm not sure it was ever right except for a limited number of arguments (?)
bob-carpenter commentedon Feb 9, 2017
sakrejda commentedon Feb 9, 2017
It gets called by the beta-binomial CDF and it's related to some functions that make my delay-time models hang so I'm just going to plow through all these if I can. I am setting up some tests against results from Mathematica so if you have any suggestions about how to do that better I appreciate suggestions. It's one of the less common instances of the generalized hypergeometric function
sakrejda commentedon Feb 10, 2017
I think this just became a meta-issue after I dug through these and figured out what they needed. I'll open and fix smaller ones as I go.
Currently, check as fixed some issues in these functions produce wrong results or infinite loops.
nanrather than terminating when denominator hits zero.nanrather than terminating when denominator hits zero.Design across these functions:
Some issues are maintenance-related
Some issues are cosmetic but it makes it hard to figure out errors and write tests:
hoanguc3m commentedon Mar 15, 2017
I have a problem with grad_reg_inc_beta function.
void grad_reg_inc_beta(T& g1, T& g2, const T& a, const T& b,
const T& z, const T& digammaA, const T& digammaB,
const T& digammaSum, const T& betaAB)
For example, when z = 1, I would expect that g1 is 0.
I also compare different value for z and find that it is not close to the value in the "Derivatives of the Incomplete Beta Function" (https://www.jstatsoft.org/article/view/v003i01). I dont know this function is the same with this one or not. Thanks.
hoanguc3m commentedon Mar 28, 2017
For example, in the grad_reg_inc_beta_test.cpp
If I change alpha = 2.5, beta = 0.5. I would expect the same g1 = 0.
sakrejda commentedon Mar 28, 2017
Merge pull request #27 from charlesm93/issue-26-ode-tuning
sakrejda commentedon Apr 7, 2018
Basically all the boxes in this issue are checked, including for grad_reg_inc_beta that relies on a hypergeometric function deep down on the inside (like most of us).