[SciPy-dev] Fwd: tests and partial patchforscipy.stats.distributions

Per.Brodtkorb at ffi.no Per.Brodtkorb at ffi.no
Mon Oct 6 10:47:28 EDT 2008


I have some suggestions for further improvement on distributions.py and is listed in the following:

When I import your scipy.stats.distributions into ipython, the doc-string for the distributions are not updated correctly.

To fix it I would also suggest to replace this part in .__init__ method of rv_discrete and rv_continous class:

if self.__doc__ is None:
	self.__doc__ = rv_discrete.__doc__
else:
	self.__doc__ = self.__doc__.replace("A Generic",longname)

with

if self.__doc__ is None:
	self.__doc__ = rv_discrete.__doc__
if self.__doc__ is None:
	self.__doc__ = self.__doc__.replace("A Generic",longname)


Replace
.... 
goodargs = argsreduce(cond, *((q,)+args+(loc,)))
loc, goodargs = goodargs[-1], goodargs[:-1]

if [1 for i in goodargs if any(i)]:
	place(output,cond,(self._ppf(*goodargs) + loc).tolist())  

with 

if any(cond):
	goodargs = argsreduce(cond, *((q,)+args+(loc,)))
	loc, goodargs = goodargs[-1], goodargs[:-1]
	place(output,cond,self._ppf(*goodargs) + loc)  


(I also think this fix could be applied to cdf, ppf......)

To fix the stats method of rv_frozen class, replace it with:
def stats(self,moments='mv'):
	kwds = self.kwds
      kwds.update({'moments':moments})
      return self.dist.stats(*self.args,**kwds)


In order to improve accuracy in calculation for small x values, I would also suggest to replace all calls to
log(1-x) and 1-exp(-x)
with 
log1p(-x) and -expm1(-x), respectively,


The _isf method of the rv_discrete class is never called.
In the isf method of the rv_discrete class replace

place(output,cond,self._ppf(*goodargs) + loc)
with
place(output,cond,self._isf(*goodargs) + loc)


Per A.

-----Opprinnelig melding-----
Fra: scipy-dev-bounces at scipy.org [mailto:scipy-dev-bounces at scipy.org] På vegne av josef.pktd at gmail.com
Sendt: 2. oktober 2008 15:30
Til: SciPy Developers List
Emne: Re: [SciPy-dev] Fwd: tests and partial patchforscipy.stats.distributions

I finally filed a ticket on this on scipy trac:
http://scipy.org/scipy/scipy/ticket/745

On Wed, Oct 1, 2008 at 7:14 AM,  <Per.Brodtkorb at ffi.no> wrote:
> I have looked into the bugs in the patch of the discrete distributions you sent. The error in _ppf method of dlaplace can be corrected by replacing it with:
>
> class dlaplace_gen(rv_discrete):
> .....
>    def _ppf(self, q, a):
>        const = 1.0/(1+exp(-a))
>        cons2 = 1+exp(a)
>        ind = q < const
>        return ceil(where(ind, log(q*cons2)/a-1, -log((1-q)*cons2)/a))
> ......
>

Thanks, I didn't see the misplaced bracket, I changed my corrections
to this. Do you have any idea or reference about the theoretical
second moment of dlaplace?


> The tests written for the generic moment, fails for those distributions that set the limits (self.a and/or self.b) for the support of the distribution in the self._argcheck method. I think the generic_moment method is meant to be private to the self._munp method, since it does only limited input checks.
> Perhaps better to rename generic_moment to _generic_moment

I aggree, I didn't check this systematically, but I guess
'vec_generic_moment', 'vecentropy' are also private methods.
>
> Per A.

I did not realize that some of my tests on private methods might fail
for some distributions by design.
To make it a bit clearer, I separated the tests into tests for public
methods, and tests for private methods. I still like the tests of
private methods, even if some are known failures, since they help to
narrow down what the source of an exception or test failure in the
public methods is.

Josef
_______________________________________________
Scipy-dev mailing list
Scipy-dev at scipy.org
http://projects.scipy.org/mailman/listinfo/scipy-dev



More information about the SciPy-Dev mailing list