[SciPy-User] problem with discrete rvs?
Robin
robince at gmail.com
Mon Aug 17 17:47:15 EDT 2009
Hi,
If I understand the scipy.stats package I should be able to create my
own arbitrary discrete distribution and generate samples from it... I
am trying this but am having the following problem. I define my
discrete distribution with the following:
vals = (array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]),
array([ 0.31518555, 0.08191701, 0.0817977 , 0.02212394, 0.08149974,
0.02204335, 0.02201125, 0.00595341, 0.0817977 , 0.02212394,
0.02209172, 0.00597518, 0.02201125, 0.00595341, 0.00594474,
0.00160788, 0.08161887, 0.02207557, 0.02204342, 0.00596212,
0.02196313, 0.0059404 , 0.00593175, 0.00160437, 0.02204342,
0.00596212, 0.00595343, 0.00161023, 0.00593175, 0.00160437,
0.00160203, 0.0004333 ]))
Then I do
rv = rv_discrete(name='test',values=vals)
and then try to generate samples. When I plot the results of this for
large number of samples, it seems to match pretty well but the last 4
or 5 values are never generated and have zero probability, even with
enough samples to really capture them.
In [742]: (te.rvs(size=1000000)==30).sum()
Out[742]: 0
In [743]: (te.rvs(size=1000000)==29).sum()
Out[743]: 0
In [744]: (te.rvs(size=1000000)==27).sum()
Out[744]: 0
In [745]: (te.rvs(size=1000000)==20).sum()
Out[745]: 21884
Does anyone have any ideas? Is this a bug in rv_discrete.rvs?
In [746]: scipy.__version__
Out[746]: '0.8.0.dev5825'
In [747]: numpy.__version__
Out[747]: '1.4.0.dev7039'
Cheers
Robin
More information about the SciPy-User
mailing list