[SciPy-dev] Problem with F distribution, or with me? - ticket 422 might apply for discrete distributions

josef.pktd at gmail.com josef.pktd at gmail.com
Thu Aug 28 17:17:16 EDT 2008


patch that works for me with scipy 0.6.0
follwing the pattern of Changeset 3797

in class rv_discrete add a line, adapted from Changeset 3797

    def _cdf(self, x, *args):     line 3456 in scipy 0.6.0, line 3473 in trunk
        k = floor(x)
+        self._cdfvec.nin = self.numargs+1  #JP
        return self._cdfvec(k,*args)

I could do this without recompile
now zipf works:

>>> stats.zipf._cdf(10,1.5)
array(0.7638016085053122)
>>> stats.zipf.cdf(10,1.5)
array(0.7638016085053122)

all test in scipy 0.6.0 stats still pass (but that's not very reliable)

stats.test()
  Found 73/73 tests for scipy.stats.tests.test_distributions
  Found 10/10 tests for scipy.stats.tests.test_morestats
  Found 107/107 tests for scipy.stats.tests.test_stats
...........................................................................Ties
preclude use of exact statistic.
..Ties preclude use of exact statistic.
.................................................................................................................
----------------------------------------------------------------------
Ran 190 tests in 0.469s

OK
<unittest._TextTestResult run=190 errors=0 failures=0>

Josef

On 8/28/08, josef.pktd at gmail.com <josef.pktd at gmail.com> wrote:
> I just saw the report by Alan McIntyre that this fails
> check_rvs (scipy.stats.tests.test_distributions.test_rv_discrete)
>
> Looking briefly at the current trunk source, I think now that the
> problem with the generic cdf for defined distributions such as zipf is
> in
>
> 3383 	        self._cdfvec = sgf(self._cdfsingle,otypes='d')
> which calls
> 3469 	    def _cdfsingle(self, k, *args):
>
> If the explanation in ticket 422 applies more generally, then all
> calls to vectorize, i.e. to sgf, would need to be checked in
> scipy.stats.distribution.
>
> I'm sorry if I'm barking up the wrong tree, I am just looking at the
> pattern without knowing the internals.
>
> Josef
>
> On 8/26/08, josef.pktd at gmail.com <josef.pktd at gmail.com> wrote:
>> On Tue, Aug 26, 2008 at 8:18 PM,  <josef.pktd at gmail.com> wrote:
>>
>>> Can somebody run:
>>>
>>> stats.zipf.pmf(range(10),1.5)
>>> stats.zipf.cdf(10,1.5)
>>> stats.zipf.cdf(range(10),1.5)
>>>
>>> I get
>>>>>> stats.zipf.cdf(10,1.5)
>>> Traceback (most recent call last):
>>>  File "<stdin>", line 1, in ?
>>>  File
>>> "C:\Josef\_progs\Subversion\scipy_trunk\dist\Programs\Python24\Lib\site-p
>>> ackages\scipy\stats\distributions.py", line 3549, in cdf
>>>    place(output,cond,self._cdf(*goodargs))
>>>  File
>>> "C:\Josef\_progs\Subversion\scipy_trunk\dist\Programs\Python24\Lib\site-p
>>> ackages\scipy\stats\distributions.py", line 3458, in _cdf
>>>    return self._cdfvec(k,*args)
>>>  File
>>> "C:\Programs\Python24\Lib\site-packages\numpy\lib\function_base.py",
>>> line
>>>  1092, in __call__
>>>    raise ValueError, "mismatch between python function inputs"\
>>> ValueError: mismatch between python function inputs and received
>>> arguments
>>>
>>> but this might be, because I am running either an older version of
>>> scipy or from my own faulty (?) build from subversion.
>>> If the current version still has this error, then I think it is
>>> related to the generic calculation of the cdf,
>>> similar to ticket 422, changeset 3797 for the moment calculation.
>>>
>>> In my tests I get many value errors, but again I don't know whether it
>>> is my version/setup, whether the parameters are not ruled out but
>>> don't make sense, or whether there is actually a bug somewhere.
>>>
>>> Josef
>>>
>>
>> in changeset 3797 this was added to the continuous random variable:
>> 315	        self.generic_moment.nin = self.numargs+1 # Because of the
>> *args argument
>> 316	        # of _mom0_sc, vectorize cannot count the number of
>> arguments correctly.
>> in current trunk these are lines 318 and 319
>>
>> I don't understand the details of numpy and vectorize, but I think
>> that the same problem with the number
>> of arguments also applies to the generic calculation for the discrete
>> distribution, i.e. lines
>>
>> 3401 	            self._ppf = new.instancemethod(sgf(_drv_ppf,otypes='d'),
>> 3402 	                                           self, rv_discrete)
>> 3403 	            self._pmf = new.instancemethod(sgf(_drv_pmf,otypes='d'),
>> 3404 	                                           self, rv_discrete)
>> 3405 	            self._cdf = new.instancemethod(sgf(_drv_cdf,otypes='d'),
>> 3406 	                                           self, rv_discrete)
>>
>> since all _drv_??? methods also use the *args argument and the
>> exception message I get looks the same as in ticket 422.
>>
>> Josef
>>
>



More information about the SciPy-Dev mailing list