[Scipy-tickets] [SciPy] #835: nan propagation in stats.distribution

SciPy Trac scipy-tickets@scipy....
Tue Oct 11 20:18:40 CDT 2011


#835: nan propagation in stats.distribution
-------------------------+--------------------------------------------------
 Reporter:  josefpktd    |       Owner:  somebody    
     Type:  defect       |      Status:  needs_review
 Priority:  normal       |   Milestone:  Unscheduled 
Component:  scipy.stats  |     Version:  devel       
 Keywords:               |  
-------------------------+--------------------------------------------------
Changes (by pbrod):

  * status:  new => needs_review


Comment:

 I think NaN is what we want for out of domain inputs, because very often
 one set up a vectorized call to the distributions and each value
 calculated may be independent of eachother. (It is not like a cholesky
 factorization where the matrix must be positive semi-definit in order to
 be able calculate anything.) If the distributions raise an exception for
 out of domain inputs, you have to do the checking on the outside and I
 think it will be inconvenient for many use cases.

 Matlab's statistics toolbox also propagate nans like this ticket suggests.
 A patch for the propagation of nans in distributions.py is attached. This
 patch also fixes this issue for logcdf, logsf as well as logpdf.  A simple
 test is also provided here:


 {{{
 def test_nan_arguments_ticket835():
     assert_(np.isnan(stats.t.logcdf(np.nan)))
     assert_(np.isnan(stats.t.cdf(np.nan)))
     assert_(np.isnan(stats.t.logsf(np.nan)))
     assert_(np.isnan(stats.t.sf(np.nan)))
     assert_(np.isnan(stats.t.pdf(np.nan)))
     assert_(np.isnan(stats.t.logpdf(np.nan)))
     assert_(np.isnan(stats.t.ppf(np.nan)))
     assert_(np.isnan(stats.t.isf(np.nan)))

     assert_(np.isnan(stats.bernoulli.logcdf(np.nan)))
     assert_(np.isnan(stats.bernoulli.cdf(np.nan)))
     assert_(np.isnan(stats.bernoulli.logsf(np.nan)))
     assert_(np.isnan(stats.bernoulli.sf(np.nan)))
     assert_(np.isnan(stats.bernoulli.pdf(np.nan)))
     assert_(np.isnan(stats.bernoulli.logpdf(np.nan)))
     assert_(np.isnan(stats.bernoulli.ppf(np.nan)))
     assert_(np.isnan(stats.bernoulli.isf(np.nan)))
 }}}

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


More information about the Scipy-tickets mailing list