[Scipy-tickets] [SciPy] #745: scipy.stats.distribution - tests and bugfixes

SciPy scipy-tickets@scipy....
Fri Oct 3 12:43:51 CDT 2008


#745: scipy.stats.distribution - tests and bugfixes
-------------------------+--------------------------------------------------
 Reporter:  josefpktd    |        Owner:  somebody
     Type:  defect       |       Status:  new     
 Priority:  normal       |    Milestone:          
Component:  scipy.stats  |      Version:  devel   
 Severity:  normal       |   Resolution:          
 Keywords:               |  
-------------------------+--------------------------------------------------
Comment (by josefpktd):

 One more, what I think is a casting error

 In for example rv_discrete ppf:

 current:
 {{{
 output = valarray(shape(cond),value=self.a-1)
 place(output,(1-cond0)*(cond1==cond1), self.badvalue)
 }}}

 versus
 {{{
 output = valarray(shape(cond),value=self.a-1,typecode='d')
 place(output,(1-cond0)*(cond1==cond1), self.badvalue)
 }}}

 note: self.badvalue is nan, valarray is a function in
 scipy.stats.distributions

 I think in the first version, the nan's get cast to zero, because in the
 cases where the arguments are not correct, the final result shows zeros
 instead of nan's.

 After adding the typecode='d', I obtain NaN's in the output at the right
 places instead of zeros.

 But I am not a numpy casting expert.

 test case:
 {{{
 >>> stats.bernoulli.ppf([[0],[0.5],[0.8],[2]],[0.3,2])
 before change:
 array([[-1,  0],
        [ 0,  0],
        [ 1,  0],
        [-1,  0]])

 after change:
 [[ -1.  NaN]
  [  0.  NaN]
  [  1.  NaN]
  [ -1.  NaN]]
 }}}
 change that I propose:
 {{{
 >>> stats.bernoulli.ppf([[-1],[0],[0.5],[0.8],[2]],[0.3,2])
 array([[ NaN,  NaN],
        [ -1.,  NaN],
        [  0.,  NaN],
        [  1.,  NaN],
        [ NaN,  NaN]])
 }}}
 i.e. return nan if distribution parameters are invalid, and return nan's
 when the probability q is not in closed interval [0,1]

 {{{
 e.g this does what I want but is not cute:
         output = valarray(shape(cond),value=self.a-1,typecode='d')
         place(output,(1-cond0)*(cond1==cond1), self.badvalue)
         place(output,(q>1)*(cond==cond), self.badvalue)
         place(output,(q<0)*(cond==cond), self.badvalue)

 >python -c "from scipy import stats;print 'result1:\n',stats.bernoulli.ppf
 ([[-1],[0],[0.5],[0.8],[2]],[0.3,2]);print
 'result2:',stats.bernoulli.ppf(0.5,2)"

 result1:
 [[ NaN  NaN]
  [ -1.  NaN]
  [  0.  NaN]
  [  1.  NaN]
  [ NaN  NaN]]
 result2: -1.#IND
 }}}

 I haven't checked if this applies also to other methods, it is the same
 story for isf

 current version of isf  boundary and out-of bounds handling doesn't look
 too good
 {{{
 >python -c "from scipy import stats;print 'result1:\n',stats.bernoulli.isf
 ([[-1],[0],[0.5],[0.8],[2]],[0.3,2]);print
 'result2:',stats.bernoulli.isf(0.5,2)
 ,stats.bernoulli.isf(2,2)"
 result1:
 [[1 0]
  [1 0]
  [0 0]
  [1 0]
  [1 0]]
 result2: 0 0
 }}}

 Josef

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


More information about the Scipy-tickets mailing list