-
-
Notifications
You must be signed in to change notification settings - Fork 12.1k
Description
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 the np.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 = 0tork_hypergeometric_hruain master/numpy/random/mtrand/distributions.c --- though there might be another way to avoid anifbut 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