[SciPy-User] deterministic random variable

josef.pktd at gmail.com josef.pktd at gmail.com
Mon May 3 09:16:54 EDT 2010


On Mon, May 3, 2010 at 6:04 AM, nicky van foreest <vanforeest at gmail.com> wrote:
> Hi,
>
> As far as I can see scipy.stats does not support the deterministic
> distribution. Would it be a good idea to implement this also? In my
> opinion this distribution is very useful to use as a test case, for
> debugging purposes for instance.

You mean something like http://en.wikipedia.org/wiki/Degenerate_distribution
(I never heard the term deterministic distribution before).

If the support is an integer, then rv_discrete might work, looks good see below

Are there any useful operations, that we could do with it?
I think I can see a case for debugging programs that use the
distributions in scipy.stats, but almost degenerate might also work
for debugging.

What I would like to have is a discrete distribution on the real line,
instead of the integers, like rv_discrete but with support on
arbitrary floats. This could use the machinery of rv_discrete but
would need a generalizing rewrite.


this looks good

>>> stats.rv_discrete(values=([0],[1]), name='degenerate')
<scipy.stats.distributions.rv_discrete object at 0x013BA5B0>
>>> deg=stats.rv_discrete(values=([0],[1]), name='degenerate')
>>> deg.rvs(size=10)
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
>>> deg.pmf(np.arange(-5,6))
array([ 0.,  0.,  0.,  0.,  0.,  1.,  0.,  0.,  0.,  0.,  0.])
>>> deg.cdf(np.arange(-5,6))
array([ 0.,  0.,  0.,  0.,  0.,  1.,  1.,  1.,  1.,  1.,  1.])
>>> deg.sf(np.arange(-5,6))
array([ 1.,  1.,  1.,  1.,  1.,  0.,  0.,  0.,  0.,  0.,  0.])
>>> deg.ppf(np.linspace(0,1,11))
array([-1.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.])
>>> deg.stats()
(array(0.0), array(0.0))
>>> deg.stats(moments='mvsk')
(array(0.0), array(0.0), array(-1.#IND), array(-1.#IND))


degenerate Bernoulli has a nan problem in pmf

>>> stats.bernoulli.rvs(0,size=10)
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
>>> stats.bernoulli.pmf(np.arange(-5,6),0.)
array([  0.,   0.,   0.,   0.,   0.,  NaN,   0.,   0.,   0.,   0.,   0.])
>>> stats.bernoulli.cdf(np.arange(-5,6),0.)
array([ 0.,  0.,  0.,  0.,  0.,  1.,  1.,  1.,  1.,  1.,  1.])
>>> stats.bernoulli.pmf(np.arange(-5,6),1.)
array([  0.,   0.,   0.,   0.,   0.,   0.,  NaN,   0.,   0.,   0.,   0.])
>>> stats.bernoulli.ppf(np.linspace(0,1,11),0.)
array([-1.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  1.])
>>> stats.bernoulli.ppf(np.linspace(0,1,11),1.)
array([-1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.])
>>> stats.bernoulli.stats(0., moments='mvsk')
(array(0.0), array(0.0), array(1.#INF), array(1.#INF))


and almost degenerate Bernoulli

>>> stats.bernoulli.pmf(np.arange(-5,6),1e-16)
array([  0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
         0.00000000e+00,   0.00000000e+00,   1.00000000e+00,
         1.00000000e-16,   0.00000000e+00,   0.00000000e+00,
         0.00000000e+00,   0.00000000e+00])
>>> stats.bernoulli.pmf(np.arange(-5,6),1-1e-16)
array([  0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
         0.00000000e+00,   0.00000000e+00,   1.11022302e-16,
         1.00000000e+00,   0.00000000e+00,   0.00000000e+00,
         0.00000000e+00,   0.00000000e+00])
>>> stats.bernoulli.ppf(np.linspace(0,1,11),1-1e-16)
array([-1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.])

Josef

>
> bye
>
> Nicky
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>



More information about the SciPy-User mailing list