Skip to content

stats.rice.pdf(x, 0) returns nan (Trac #1639) #2164

Closed
scipy-gitbot opened this Issue Apr 25, 2013 · 3 comments

3 participants

@scipy-gitbot

Original ticket http://projects.scipy.org/scipy/ticket/1639 on 2012-04-04 by @WarrenWeckesser, assigned to unknown.

stats.rice.pdf(x, 0) incorrectly returns nan:

In [15]: stats.rice.pdf(1.0, 0.0)
Out[15]: nan

In [16]: stats.rice.pdf([0.0, 1.0, 2.0], 0.0)
Out[16]: array([ nan,  nan,  nan])

But stats.rice._pdf works:

In [21]: x = array([0.0, 1.0, 2.0])

In [22]: stats.rice._pdf(x, 0.0)
Out[22]: array([ 0.        ,  0.60653066,  0.27067057])

This was pointed out on the scipy-user mailing list in the thread that starts here:
http://mail.scipy.org/pipermail/scipy-user/2012-April/031991.html

@scipy-gitbot

@josef-pkt wrote on 2012-04-04

I think the solution is to overwrite the default argcheck

something like the following
(but I didn't check yet which args _argcheck is supposed to have)

>>> def _argcheck(self, *args): return args >=0
...
>>> stats.rice._argcheck = _argcheck
>>> stats.rice.pdf(np.linspace(0,4,11),0.)

The default has >0

    def _argcheck(self, *args):
        # Default check for correct values on args and keywords.
        # Returns condition array of 1's where arguments are correct and
        #  0's where they are not.
        cond = 1
        for arg in args:
            cond = logical_and(cond,(arr(arg) > 0))
        return cond
@josef-pkt
SciPy member

This looks like a safe bet to extend to b=0
http://en.wikipedia.org/wiki/Rice_distribution shows it's not degenerate and moments exist.

def _argcheck(self, b)
    return b >= 0

maybe that's all

all three methods that are define in rice_gen seem to work without problems

>>> stats.rice._munp(1., 0)
1.2533141373155003
>>> stats.rice._munp(1., 1e-12)
1.2533141373155003
>>> stats.rice._munp(1., 1e-6)
1.2533141373158136

>>> stats.rice._munp(2., 1e-6)
2.0000000000010001
>>> stats.rice._munp(2., 0)
2.0

>>> stats.rice._logpdf(np.array([0.0, 1.0, 2.0]), -0.10)
array([       -inf, -0.50250156, -1.30187771])
>>> stats.rice._pdf(np.array([0.0, 1.0, 2.0]), -0.10)
array([ 0.        ,  0.60501528,  0.27202054])
@rgommers
SciPy member

Done in gh-2847.

@rgommers rgommers closed this Sep 15, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.