[SciPy-Dev] [stats] discrete vs continuous distributions, arguments
Fri Jun 14 19:27:16 CDT 2013
On Fri, Jun 14, 2013 at 8:11 PM, Evgeni Burovski
> Dear experts,
> Could somebody comment on the way how continuous and discrete distributions
> handle their positional arguments --- especially where there are too many of
> them. For example:
>>>> from scipy.stats import poisson, norm
>>>> poisson.pmf(42, 41) # k=42, \mu=41
>>>> poisson.pmf(42, 41, -101) # gets shifted by -101?
>>>> poisson.pmf(42+101, 41) # indeed
>>>> norm.pdf(39, 41, 2) # N(41, 2) at x=39 ?
>>>> np.exp(-1./2)/np.sqrt(2.*np.pi*2**2) # indeed, it is
>>>> norm.pdf(39, 41, 2, -101) # is it N(41+101, 2) at x=39? or at x=39+101?
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> line 1212, in pdf
> args, loc, scale = self._fix_loc_scale(args, loc, scale)
> line 545, in _fix_loc_scale
> raise TypeError("Too many input arguments.")
> TypeError: Too many input arguments.
I assume you have a recent scipy. this was recently fixed.
with scipy 0.9 it's possible to get weird results with too many parameters
>>> stats.norm.pdf(5, 4,3,2,1)
does this raise an error ?
>>> stats.poisson.pmf(5, 4, 3, 2)
each continuous distribution requires shape parameter and optional loc and scale
loc and scale are keyword parameters, but can be given as positional parameters
numargs shows the number of shape parameters
so we need at least numargs distribution parameters and at most numargs + 2
For the discrete distribution there is no scale, so only loc is an
extra keyword, which means discrete distributions take either numargs
arguments with loc=0 as default, or numargs + 1 parameters when loc is
the normal distribution has numargs=0, so it can either take 0, 1 or 2
arguments, interpreted as loc and scale with defaults 0, 1.
3 arguments is too many and raises an exception.
Poisson should raise an exception if there are 3 or more parameters
given, and needs at least one for the shape parameter (loc=0 is
What I don't remember is whether the discrete distribution have been
fixed so they raise an exception if there are too many arguments.
> I understand what happens in the code (the `loc` parameter is free for
> `poisson` and is fixed at `mu` for norm), but I'm at loss whether this
> disparity is by design --- is it a feature or a bug or just my
> SciPy-Dev mailing list
More information about the SciPy-Dev