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

Different results in expon.cdf and a derived class cdf (with the same pdf as expon). #6185

Closed
yashu-seth opened this issue May 23, 2016 · 3 comments

Comments

@yashu-seth
Copy link

>>> from scipy.stats import expon
>>> r1 = expon()
>>> r1.cdf(4.34)
0.9869634717965623
>>> from scipy.stats import rv_continuous
>>> class custom_expon(rv_continuous):
    def _pdf(self, x):
        return r1.pdf(x)

>>> r2 = custom_expon()
>>> r2.cdf(4.34)
0.98031897805159673
>>> r1.cdf

I think r1.cdf(4.34) and r2.cdf(4.34) should return the exact values. I cannot figure the reason behind the significant difference.
Also, r2.cdf(4.33) < r2.cdf(4.35)
but,

>>> r2.cdf(4.35)
0.98709318767881626
>>> r2.cdf(4.33)
0.99017134757679626
@yashu-seth yashu-seth changed the title Different results in expon.cdf and derived class (with the sam pdf as expon) cdf. Different results in expon.cdf and a derived class (with the same pdf as expon) cdf. May 23, 2016
@yashu-seth yashu-seth changed the title Different results in expon.cdf and a derived class (with the same pdf as expon) cdf. Different results in expon.cdf and a derived class cdf (with the same pdf as expon). May 23, 2016
@argriffing
Copy link
Contributor

Maybe the stats framework assumes that your pdf integrates to 1 over (-infinity, infinity) and is therefore returning a garbage cdf value because it's not sophisticated enough to detect that its assumptions are violated. You could work around that problem by specifying that the support is (0, infinity) using something like the following code.

from __future__ import print_function, division

from scipy.stats import rv_continuous, expon

r1 = expon()

class custom_expon(rv_continuous):
    def _pdf(self, x):
        return r1.pdf(x)
ce = custom_expon(a=0.0, name='custom_expon')

r2 = ce()
x = 4.34
print(r2.cdf(x))

0.986963471797

@yashu-seth
Copy link
Author

@argriffing Thanks. I think this should fix the problem.

@ewmoore
Copy link
Member

ewmoore commented May 23, 2016

If you're actually doing what your example code does, it is worth noting
that using the generic cdf routine uses numerical quadrature to find the
cdf value. Many of the built in distributions (expon) for instance also
include a _cdf routine that uses the analytical CDF. If you have an
analytical CDF, you're liable to be better off including it rather than
counting on integration of the pdf.

On Mon, May 23, 2016 at 2:41 PM, argriffing notifications@github.com
wrote:

Closed #6185 #6185.


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#6185 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants