Skip to content

scipy.stats.distribution: problem with self.a, self.b if they depend on parameters (Trac #793) #1320

@scipy-gitbot

Description

@scipy-gitbot

Original ticket http://projects.scipy.org/scipy/ticket/793 on 2008-11-18 by @josef-pkt, assigned to unknown.

I obtain an error if I evaluate genextreme.ppf with multiple parameters (tuples)
at the same time, for traceback see below.

The direct reason for this is that genextreme._argcheck sets self.a to the same dimension as c (i.e. number of parameter tuples), which breaks reshaping using valarray in the generic ppf of rv_continuous.

(Similar genpareto._argcheck sets self.b as function of the parameters)

I don't think the module can handle correctly cases where multiple parameters tuples are used and the support of the distribution is parameter dependent. This needs further checking and some documentation.

For now, it is better to get some exception than incorrect or unintended results.
But I didn't test whether all generic methods that use the parameter dependent support actually fail.

I think, the current tests only verify cases with one parameter tuple at a time.

>>> c=2.62;stats.genextreme.ppf(0.5,np.array([[c],[c+0.5]]))
Traceback (most recent call last):
  File "<pyshell#427>", line 1, in <module>
    c=2.62;stats.genextreme.ppf(0.5,np.array([[c],[c+0.5]]))
  File "C:\Josef\_progs\building\scipy\scipy-trunk-new\dist\Programs\Python25\Lib\site-packages\scipy\stats\distributions.py", line 610, in ppf
    cond = cond0 & cond1
  File "C:\Josef\_progs\building\scipy\scipy-trunk-new\dist\Programs\Python25\Lib\site-packages\scipy\stats\distributions.py", line 229, in valarray
    out = reshape(repeat([value],product(shape,axis=0),axis=0),shape)
  File "C:\Programs\Python25\lib\site-packages\numpy\core\fromnumeric.py", line 145, in reshape
    return reshape(newshape, order=order)
ValueError: total size of new array must be unchanged

__ addition: __

Currently there is no easy or feasible way to allow multiple parameters for setting the support of a distribution (self.a, self.b). For example checking valid range of parameters for all public methods, and integration limits assume that self.a and self.b are scalars.
Methods that don't go through the valid argument check and don't require numerical integration don't raise the exception, e.g.

>>> c=2.62;stats.genextreme._ppf(0.5,np.array([c,c+0.5]))
array([ 0.23557562,  0.21836694])

calling numerical integration raises also an exception:

>>> c=2.62;stats.genextreme._mom0_sc(2,np.array([c,c+0.5]))
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
  File "C:\Josef\eclipsegworkspace\scipybranch2\dist\Programs\Python25\Lib\site-packages\scipy\stats\distributions.py", line 513, in _mom0_sc
    self.b, args=(m,)+args)[0]
  File "C:\Josef\eclipsegworkspace\scipybranch2\dist\Programs\Python25\Lib\site-packages\scipy\integrate\quadpack.py", line 185, in quad
    retval = _quad(func,a,b,args,full_output,epsabs,epsrel,limit,points)
  File "C:\Josef\eclipsegworkspace\scipybranch2\dist\Programs\Python25\Lib\site-packages\scipy\integrate\quadpack.py", line 251, in _quad
    return _quadpack._qagie(func,bound,infbounds,args,full_output,epsabs,epsrel,limit)
error: Supplied function does not return a valid float.

There are different problems for this case of multiple support parameters for higher order moments, see gh-1461 for missing argcheck in moment:

>>> c=2.62;stats.genextreme.moment(2,np.array([c,c+0.5]))
array([  25.50105963,  115.11191437])
>>> c=2.62;stats.genextreme.moment(5,np.array([c,c+0.5]))
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
  File "C:\Josef\eclipsegworkspace\scipybranch2\dist\Programs\Python25\Lib\site-packages\scipy\stats\distributions.py", line 937, in moment
    return self._munp(n,*args)
  File "C:\Josef\eclipsegworkspace\scipybranch2\dist\Programs\Python25\Lib\site-packages\scipy\stats\distributions.py", line 1991, in _munp
    vals = 1.0/c**n * sum(comb(n,k) * (-1)**k * special.gamma(c*k + 1),axis=0)
ValueError: shape mismatch: objects cannot be broadcast to a single shape

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions