-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Could random.hypergeometric() be made to match behavior of random.binomial() when sample or n = 0? #9237
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
Labels
Comments
See #8056 -- this is tagged for inclusion in 1.14. |
This seems reasonable, but I would think so, given that my implementation of
|
bashtage
added a commit
to bashtage/randomgen
that referenced
this issue
Apr 10, 2019
Enable Hypergeometric to work with 0 samples xref numpy/numpy#9237
This was referenced Apr 11, 2019
16 tasks
Closing. Verified that |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am trying to implement a multidimensional hypergeometric distribution. My algorithm would be made simpler if
np.random.hypergeometric()
returned zeros when sample=0, just like thenp.random.binomial()
does when n = 0 (instead of throwing an ValueError). Note that the binomial is often used as an approximation to the hypergeometric so getting the same behavior when swapping one for the other may be advantageous.In particular:
np.random.binomial(0,.5)
Returns
0
whereas:
np.random.hypergeometric(1,1,0)
Returns
... ValueError: nsample < 1
I think it would be a matter of 3 changes to the code base:
change Line 4254-5 of master/numpy/random/mtrand/mtrand.pyx to:
if lnsample < 0: raise ValueError("nsample < 0")
Move line 794 of master/numpy/random/mtrand/distributions.c to line 791.
Add
if(sample == 0) Z = 0
tork_hypergeometric_hrua
in master/numpy/random/mtrand/distributions.c --- though there might be another way to avoid anif
but I don't understand how the code works well enough.Also, as a new user, please let me know if there is a better way to ask for this change.
Thank you
-Will
The text was updated successfully, but these errors were encountered: