-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Silent overflow error in numpy.random.default_rng.negative_binomial
#18997
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
Comments
IIRC, there is probably a Making floating point error checking work here (so that |
I'm not surprised. There has not been systematic testing to determine the breakdown point of many of the algorithms. Many that aren't simple transformations of normals or uniforms probably will have incorrect distributions for parameters near these points as well. |
I don't agree with this. Both 0 and 1 are in the support of |
I'm no expert in probability theory and was merely citing my ressources (German wikipedia states p∈(0,1), my uni's ressources (0,1] - I just checked some more and English wikipedia states [0,1], wolfram alpha (0,1)). Just looking at the pmf I'd guess that allowing 0 would lead to the distribution not being normed since it'd be identically zero - but it's also very well possible that I'm missing something here. Allowing 1 seems fine to me. Maybe it's a formal thing that people like to ignore? Or it depends on which of the few alternative definitions one uses. |
p=0 cleanly limits to infinity. However here we have integer values and so 0 and parameters close to 0 should be excluded since infinity cannot be represented (p<=0 is excluded, but the real exclusion range should depend on both p and n). p=1 cleanly limits to 0 since there are always no failures before |
FWIW, I like to take a pragmatic approach for these domain endpoints. I rarely take any textbook's pronouncement of the open-/closed-ness of the domains as a given. Those are typically the most variable things between sources. Some sources like to exclude some endpoints because it would make the general formula (that otherwise applies cleanly to the interior) more complicated. And other sources will include them because their treatment of the resulting infinities is obvious from the context (or they just don't care). In most cases, there is no thought given at all to the pragmatic concerns of numerical computation in floating point or finite-integer arithmetic, and that's what really concerns me. I'm happy to modify the definition somewhat to handle these extreme cases somewhat felicitously. The The other approach is to permit that probability mass, but just reassign it to the last possible value. That is, if https://github.com/numpy/numpy/blob/main/numpy/random/src/distributions/distributions.c#L562 We could just clip the result of the |
Uh oh!
There was an error while loading. Please reload this page.
There still seem to be overflow/underflow problems for
negative_binomial
even in the "new" rng-API (see also issue 1494).I'd expect the behaviour to be similar to
poisson
:but there are no errors.
In particular the "tipover"-point after which it overflows depends on p. For
p=0.5
it's at9223372037481356287
(sodefault_rng(1).negative_binomial(9223372037481356287, 0.5) > 0
anddefault_rng(1).negative_binomial(9223372037481356287+1, 0.5) < 0
) which still works fine forp=0.9
. Forp=0
(which shouldn't even be allowed and raise an error) I've experienced it to be at exactly2**63
, but I can't reproduce that now; on my current machine it seems to be the case thatlambda n: np.random.default_rng(1).negative_binomial(n, 0)
is identically equal to-2**63
for alln
.Reproducing code example:
Error message:
The code samples don't raise an error regardless of
np.seterr(all="raise")
.NumPy/Python version information:
This has been verified on python 3.8.3, numpy version 1.18.5 and 1.17.4 running on linux mint 20 as well as python 3.8.5, numpy version 1.19.2 running on macOS Big Sur (Version 11.3).
The text was updated successfully, but these errors were encountered: