[Numpy-tickets] [NumPy] #921: numpy.random.hypergeometric: error for some cases
NumPy
numpy-tickets@scipy....
Thu Oct 2 11:19:39 CDT 2008
#921: numpy.random.hypergeometric: error for some cases
--------------------------+-------------------------------------------------
Reporter: josefpktd | Owner: somebody
Type: defect | Status: new
Priority: normal | Milestone:
Component: numpy.random | Version: none
Severity: normal | Keywords:
--------------------------+-------------------------------------------------
In my fuzz testing of scipy stats, I get sometimes a test failure. I think
there is something wrong, random numbers are outside of support of the
distribution, with numpy.random.hypergeometric for some cases:
{{{
>>> np.version.version
'1.2.0rc2'
}}}
signature:
hypergeometric(ngood, nbad, nsample, size=None)
when sample size (number of draws, nsample) is small then random numbers
look ok:
{{{
>>> np.random.hypergeometric(3,18,8,size=10)
array([2, 1, 0, 2, 1, 1, 2, 1, 0, 3])
>>> np.random.hypergeometric(3,18,9,size=10)
array([2, 2, 0, 0, 1, 0, 1, 1, 3, 1])
>>> np.random.hypergeometric(3,18,10,size=10)
array([0, 2, 2, 0, 2, 2, 2, 0, 0, 2])
}}}
for sample size larger than 11 the random number are larger than possible
(there are only 3 good balls in urn):
{{{
>>> np.random.hypergeometric(3,18,11,size=10)
array([18, 16, 16, 17, 18, 17, 18, 17, 17, 16])
>>> np.random.hypergeometric(3,18,12,size=10)
array([17, 16, 16, 18, 17, 17, 18, 17, 16, 17])
>>> np.random.hypergeometric(3,18,13,size=10)
array([18, 17, 17, 16, 17, 17, 16, 16, 18, 16])
>>> np.random.hypergeometric(3,18,14,size=10)
array([16, 17, 17, 17, 17, 18, 17, 16, 18, 17])
>>> np.random.hypergeometric(3,18,15,size=10)
array([18, 18, 17, 16, 17, 16, 17, 17, 18, 18])
}}}
reversing the number of good and bad balls -> ok for small sample size:
{{{
>>> np.random.hypergeometric(18,3,5,size=10) #ok
array([5, 4, 5, 5, 4, 4, 4, 4, 5, 5])
>>> np.random.hypergeometric(18,3,10,size=10) #ok
array([9, 8, 9, 7, 8, 8, 7, 8, 8, 9])
}}}
negative numbers for sample size >= 11:
{{{
>>> np.random.hypergeometric(18,3,11,size=10)
array([-5, -5, -5, -7, -4, -5, -5, -4, -6, -6])
>>> np.random.hypergeometric(18,3,13,size=10)
array([-3, -5, -5, -4, -4, -4, -5, -5, -3, -4])
>>> np.random.hypergeometric(18,3,14,size=10)
array([-4, -3, -4, -3, -2, -4, -3, -4, -2, -4])
>>> np.random.hypergeometric(18,3,15,size=10)
array([-2, -2, -1, -1, -3, -2, -2, -2, -1, -2])
>>> np.random.hypergeometric(18,3,16,size=10)
array([-1, -1, 0, -1, 0, -2, -1, -2, -1, -2])
}}}
--
Ticket URL: <http://scipy.org/scipy/numpy/ticket/921>
NumPy <http://projects.scipy.org/scipy/numpy>
The fundamental package needed for scientific computing with Python.
More information about the Numpy-tickets
mailing list