[Scipy-tickets] [SciPy] #1326: chi2.pdf erroneous value at x=0.0 df=2

SciPy Trac scipy-tickets@scipy....
Wed Nov 10 07:40:16 CST 2010

#1326: chi2.pdf erroneous value at x=0.0 df=2
 Reporter:  tpikonen     |       Owner:  somebody    
     Type:  defect       |      Status:  needs_review
 Priority:  normal       |   Milestone:  0.9.0       
Component:  scipy.stats  |     Version:  devel       
 Keywords:  chi2 pdf     |  
Changes (by josefpktd):

  * status:  new => needs_review


 Thank you for finding and reporting this. It looks like another case of
 0*log(0) when switching to logs and expanding the expression.

 >>> np.log(0**0)
 >>> 0*np.log(0)

 In general, we want the equations to be able to handle array arguments,
 (although there are still problems for some parameters in some
 distributions) e.g.
 >>> stats.chi2._pdf(1e-15, np.array([1,1.99,2,2.0001,3]))
 array([  1.26156626e+07,   5.94583420e-01,   5.00000000e-01,
          4.99134381e-01,   1.26156626e-08])

 (note: multiple df need to be in an array for the private method, _pdf, a
 list doesn't work. similar for t, f,)

 The fix could either include a np.where as in other distributions for your
 special case x==0&df==2, or treat the 0*log(0) problem.

 Also, adding a test for this special case will be useful.



 stats.chi hasn't been switch to log yet, it doesn't have the 0log(0)
 problem, but the precision looks low at the boundary, x=0, or has a bug

 >>> stats.chi._pdf(0., 1.000001)
 >>> stats.chi._pdf(1e-15, 1.000001)
 >>> stats.chi._pdf(0., 1.00000)


 >>> stats.chi._pdf(1e-15, np.array([0.999, 1, 1.0001,1.99,2,2.0001,3]))
 array([  8.25398999e-01,   7.97884561e-01,   7.95184021e-01,
          1.41332744e-15,   1.00000000e-15,   9.96546302e-16,
 >>> stats.chi._pdf(0., np.array([0.999, 1, 1.0001,1.99,2,2.0001,3]))
 array([        Inf,  0.79788456,  0.        ,  0.        ,  0.        ,
         0.        ,  0.        ])

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

More information about the Scipy-tickets mailing list