question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Negative binomial sampling bug when p=0

See original GitHub issue

Negative binomial sample when p=0:

np.random.negative_binomial(1, 0)

Screen Shot 2020-04-05 at 6 43 43 PM

I believe the output should be 0 in this case.

1.18.2 3.7.3 (default, Mar 31 2019, 11:50:42) [Clang 10.0.1 (clang-1001.0.46.3)]

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
WarrenWeckessercommented, Apr 6, 2020

P.S. @adamgayoso, thanks for reporting the issue!

0reactions
WarrenWeckessercommented, Apr 8, 2020

@adamgayoso, the pull request gh-15914, in which the negative_binomial method of numpy.random.Generator is changed to disallow p=0, has been merged. With the master branch of numpy (and using the new numpy.random API), we have:

In [1]: import numpy as np

In [2]: np.__version__
Out[2]: '1.19.0.dev0+e78d076'

In [3]: rng = np.random.default_rng()

In [4]: rng.negative_binomial(1, 0)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-4-d61ac7f10aa5> in <module>
----> 1 rng.negative_binomial(1, 0)

_generator.pyx in numpy.random._generator.Generator.negative_binomial()

_common.pyx in numpy.random._common.disc()

_common.pyx in numpy.random._common.check_constraint()

ValueError: p <= 0, p > 1 or p contains NaNs

Note, however, that the function numpy.random.negative_binomial has not also been updated. That function is part of the “legacy” random API. The legacy code is usually only updated if a bug causes Python to crash. If you are writing new code, you should use the new API.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sampling Theory of the Negative Binomial and Logarithmic ...
If colonies or groups of individuals are distributed randomly over an area (or in time) so that the number of colonies observed in...
Read more >
Fitting the Negative Binomial Distribution to Biological Data
Since the expected variance of a Poisson distribution is equal ... Po = 1/qk, and if P0 is replaced by the proportion observed...
Read more >
Error in wp.logistic: 'p0' must be numeric in (0,1)? What to do ...
p0 and p1 are probabilities, and can't be negative. Share. Share a link to this answer.
Read more >
Using the negative binomial distribution to model ...
Scenarios for how sampling error, flocking, and environmental stochasticity might cause overdispersion in daily bird migration count data. Each ...
Read more >
The Negative Binomial Distribution
When sampling without replacement from a finite sample of size n from a dichotomous (S–F) population with the population size N, the hypergeometric...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found