[Scipy-tickets] [SciPy] #1291: stats.discrete distributions hypergeom.sf exception

SciPy Trac scipy-tickets@scipy....
Fri Oct 22 12:53:23 CDT 2010


#1291: stats.discrete distributions hypergeom.sf exception
-------------------------+--------------------------------------------------
 Reporter:  josefpktd    |       Owner:  somebody    
     Type:  defect       |      Status:  needs_review
 Priority:  normal       |   Milestone:  0.9.0       
Component:  scipy.stats  |     Version:  0.7.0       
 Keywords:               |  
-------------------------+--------------------------------------------------

Comment(by jledoux):

 Ok, the any(cond) change seems to be working well; doesn't change any
 results except avoids the IndexError.

 Here's my testing script that avoided stateful behavior (by launching a
 new python each time):

 {{{
 #!/usr/bin/python

 from commands import getoutput

 def print_command_output(cmdline):
     print cmdline
     print getoutput(cmdline)
 import numpy
 for k in (3,2,1,0,-1, numpy.array([3,2,1,0,-1])):
     for fn in ('cdf', 'sf', 'pmf','ppf','isf'):
         # print fn, k
         print_command_output("ipython -c 'from scipy.stats import
 hypergeom ; from numpy import array; print hypergeom.%s(%r,10,2,5)'" %
 (fn,k))
 }}}

 Results from original script being tested:
 {{{
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.cdf(3,10,2,5)'
 1.0
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.sf(3,10,2,5)'
 ---------------------------------------------------------------------------
 IndexError                                Traceback (most recent call
 last)
 ...
 IndexError: invalid index
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.pmf(3,10,2,5)'
 0.0
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.ppf(3,10,2,5)'
 nan
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.isf(3,10,2,5)'
 nan
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.cdf(2,10,2,5)'
 1.0
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.sf(2,10,2,5)'
 -8.881784197e-16
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.pmf(2,10,2,5)'
 0.222222222222
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.ppf(2,10,2,5)'
 nan
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.isf(2,10,2,5)'
 nan
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.cdf(1,10,2,5)'
 0.777777777778
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.sf(1,10,2,5)'
 0.222222222222
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.pmf(1,10,2,5)'
 0.555555555556
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.ppf(1,10,2,5)'
 2.0
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.isf(1,10,2,5)'
 -4.0
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.cdf(0,10,2,5)'
 0.222222222222
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.sf(0,10,2,5)'
 0.777777777778
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.pmf(0,10,2,5)'
 0.222222222222
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.ppf(0,10,2,5)'
 -4.0
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.isf(0,10,2,5)'
 2.0
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.cdf(-1,10,2,5)'
 0.0
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.sf(-1,10,2,5)'
 1.0
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.pmf(-1,10,2,5)'
 0.0
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.ppf(-1,10,2,5)'
 nan
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.isf(-1,10,2,5)'
 nan
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.cdf(array([ 3,  2,  1,  0, -1]),10,2,5)'
 [ 1.          1.          0.77777778  0.22222222  0.        ]
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.sf(array([ 3,  2,  1,  0, -1]),10,2,5)'
 [  0.00000000e+00  -8.88178420e-16   2.22222222e-01   7.77777778e-01
    1.00000000e+00]
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.pmf(array([ 3,  2,  1,  0, -1]),10,2,5)'
 [ 0.          0.22222222  0.55555556  0.22222222  0.        ]
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.ppf(array([ 3,  2,  1,  0, -1]),10,2,5)'
 [ NaN  NaN   2.  -4.  NaN]
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.isf(array([ 3,  2,  1,  0, -1]),10,2,5)'
 [ NaN  NaN  -4.   2.  NaN]
 }}}

 Results after adding the any(cond) check above place in rv_discrete:

 {{{
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.cdf(3,10,2,5)'
 1.0
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.sf(3,10,2,5)'
 0.0
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.pmf(3,10,2,5)'
 0.0
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.ppf(3,10,2,5)'
 nan
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.isf(3,10,2,5)'
 nan
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.cdf(2,10,2,5)'
 1.0
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.sf(2,10,2,5)'
 -8.881784197e-16
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.pmf(2,10,2,5)'
 0.222222222222
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.ppf(2,10,2,5)'
 nan
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.isf(2,10,2,5)'
 nan
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.cdf(1,10,2,5)'
 0.777777777778
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.sf(1,10,2,5)'
 0.222222222222
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.pmf(1,10,2,5)'
 0.555555555556
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.ppf(1,10,2,5)'
 2.0
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.isf(1,10,2,5)'
 -4.0
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.cdf(0,10,2,5)'
 0.222222222222
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.sf(0,10,2,5)'
 0.777777777778
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.pmf(0,10,2,5)'
 0.222222222222
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.ppf(0,10,2,5)'
 -4.0
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.isf(0,10,2,5)'
 2.0
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.cdf(-1,10,2,5)'
 0.0
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.sf(-1,10,2,5)'
 1.0
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.pmf(-1,10,2,5)'
 0.0
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.ppf(-1,10,2,5)'
 nan
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.isf(-1,10,2,5)'
 nan
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.cdf(array([ 3,  2,  1,  0, -1]),10,2,5)'
 [ 1.          1.          0.77777778  0.22222222  0.        ]
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.sf(array([ 3,  2,  1,  0, -1]),10,2,5)'
 [  0.00000000e+00  -8.88178420e-16   2.22222222e-01   7.77777778e-01
    1.00000000e+00]
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.pmf(array([ 3,  2,  1,  0, -1]),10,2,5)'
 [ 0.          0.22222222  0.55555556  0.22222222  0.        ]
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.ppf(array([ 3,  2,  1,  0, -1]),10,2,5)'
 [ NaN  NaN   2.  -4.  NaN]
 ipython -c 'from scipy.stats import hypergeom ; from numpy import array;
 print hypergeom.isf(array([ 3,  2,  1,  0, -1]),10,2,5)'
 [ NaN  NaN  -4.   2.  NaN]
 }}}

-- 
Ticket URL: <http://projects.scipy.org/scipy/ticket/1291#comment:8>
SciPy <http://www.scipy.org>
SciPy is open-source software for mathematics, science, and engineering.


More information about the Scipy-tickets mailing list