Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
scipy-gitbot opened this issue Apr 25, 2013 · 3 comments · Fixed by #2847
Closed

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

scipy-gitbot opened this issue Apr 25, 2013 · 3 comments · Fixed by #2847
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected good first issue Good topic for first contributor pull requests, with a relatively straightforward solution Migrated from Trac scipy.stats
Milestone

Comments

@scipy-gitbot
Copy link

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
Copy link
Author

@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
Copy link
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
Copy link
Member

Done in gh-2847.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected good first issue Good topic for first contributor pull requests, with a relatively straightforward solution Migrated from Trac scipy.stats
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants