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
Vonmisesfix #4649
Vonmisesfix #4649
Conversation
Thanks, merged! |
@@ -30,7 +30,7 @@ cdef double von_mises_cdf_series(double k,double x,unsigned int p): | |||
return 0.5 + x / (2 * NPY_PI) + V / NPY_PI | |||
|
|||
cdef von_mises_cdf_normalapprox(k, x): | |||
b = sqrt(NPY_2_PI) * np.exp(k) / i0(k) | |||
b = sqrt(NPY_2_PI) / i0e(k) # Check for negative k |
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's this comment mean?
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.
I think the idea is that the new code is not equivalent to the old code when k
is negative, because an absolute value is taken. But for the Von-Mises distribution k
must be non-negative anyway so it's OK.
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.
I guess this is checked somewhere else in the stats infrastructure then.
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.
Actually the comment can go - you only get to this branch if k>50. But in fact the von Mises distribution does make sense for k<0 (same as that for -k but shifted by pi), and this is not really implemented in scipy.
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.
Should it be? That seems like a relatively straightforward change.
docstrings would be nice to know what k and x are kappa is the dispersion shape parameter for vonmises, AFAIR, and should be > 0 by default argument checking in the distribution |
The von Mises distribution CDF doesn't work properly for narrow distributions because the exponential and the Bessel function it is divided by both underflow; scipy.special.i0e exists for this very reason. Wrote a test and fixed the problem.