[SciPy-User] Rician distributions lacks sigma parameter

josef.pktd@gmai... josef.pktd@gmai...
Wed Apr 4 17:08:28 CDT 2012


On Wed, Apr 4, 2012 at 5:55 PM,  <josef.pktd@gmail.com> wrote:
> On Wed, Apr 4, 2012 at 5:04 PM, Warren Weckesser
> <warren.weckesser@enthought.com> wrote:
>>
>>
>> On Wed, Apr 4, 2012 at 3:57 PM, <josef.pktd@gmail.com> wrote:
>>>
>>> On Wed, Apr 4, 2012 at 1:59 PM,  <josef.pktd@gmail.com> wrote:
>>> > On Wed, Apr 4, 2012 at 1:53 PM,  <josef.pktd@gmail.com> wrote:
>>> >> On Wed, Apr 4, 2012 at 1:33 PM, Morten Kjeldgaard <mok@bioxray.dk>
>>> >> wrote:
>>> >>> Thanks for replies Josef and Warren!
>>> >>>
>>> >>> I think my current limitation is that I don't fully grasp how the
>>> >>> shape and scale parameters are propagated to the individual stats
>>> >>> distributions, and alas the autogenerated documentation isn't always
>>> >>> very helpful.
>>> >>>
>>> >>>> Given the parameters nu and sigma (as shown in the wikipedia
>>> >>>> article), you use scipy.stats.rice by setting the scale=sigma and
>>> >>>> the shape parameter b=nu/sigma.  You can use the following script to
>>> >>>> verify this:
>>> >>>
>>> >>> Like you write, the script works fine with parameters (nu, sigma) =
>>> >>> (3.45, 0.35), but it actually fails when I try to reproduce the plots
>>> >>> in the wikipedia article. When setting (nu, sigma) = (0, 1), I get the
>>> >>> following:
>>> >>
>>> >> the shape parameter nu has to be strictly positive, eg. nu=1e-10 works
>>> >> there is a problem with the calculation for nu equal to zero
>>> >
>>> > But the _pdf doesn't have a problem
>>> >>>> stats.rice._pdf(np.linspace(0,4,11),0.)
>>> > array([ 0.        ,  0.36924654,  0.58091923,  0.58410271,  0.44485968,
>>> >        0.27067057,  0.13472343,  0.05555507,  0.01912327,  0.00552172,
>>> >        0.00134185])
>>> >
>>> >>>> stats.rice.pdf(np.linspace(0,4,11),0.)
>>> > array([ nan,  nan,  nan,  nan,  nan,  nan,  nan,  nan,  nan,  nan,
>>> >  nan])
>>> >>>>
>>> >
>>> > so it should be possible to fix it for the nu=0 case, (define a>= 0 ?)
>>>
>>> should be a ticket: define _argcheck for rice
>>>
>>> something like the following (but I didn't check which args _argcheck
>>> is supposed to have)
>>>
>>> >>> def _argcheck(self, *args): return args >=0
>>> ...
>>> >>> stats.rice._argcheck = _argcheck
>>> >>> stats.rice.pdf(np.linspace(0,4,11),0.)
>>> array([ 0.        ,  0.36924654,  0.58091923,  0.58410271,  0.44485968,
>>>        0.27067057,  0.13472343,  0.05555507,  0.01912327,  0.00552172,
>>>        0.00134185])
>>> >>> stats.rice._pdf(np.linspace(0,4,11),0.)
>>> array([ 0.        ,  0.36924654,  0.58091923,  0.58410271,  0.44485968,
>>>        0.27067057,  0.13472343,  0.05555507,  0.01912327,  0.00552172,
>>>        0.00134185])
>>>
>>> Josef
>>>
>>
>>
>>
>> Once again, your post arrived just as I was finishing mine.  Kinda spooky.
>
> Better 2 than 0.
>
>>
>> Could you add that comment to the ticket?
>> (http://projects.scipy.org/scipy/ticket/1639)
>
> Done,
> I didn't check the source file for distributions (just pulling up
> source of functions of 0.9 that I have installed),
> but it should be just 2-3 lines to fix this.

Planning for the future:

I think we could start to switch to personalized docstrings for
distributions as the show up on the mailing list or in tickets.

For example in the case of rice it would be good to have the
difference in the parameterization in the doc string, so we don't have
to do a search to find it again, or figure out the same thing each
time again.

Morten, thanks for finding the corner case. It's always difficult to
figure out the limits for which the distributions are supposed to
work.

Josef


>
> Josef
>
>>
>> Warren
>>
>>
>>>
>>> >
>>> > Josef
>>> >
>>> >
>>> >>
>>> >> Josef
>>> >>
>>> >>>
>>> >>> AssertionError:
>>> >>> Not equal to tolerance rtol=1e-07, atol=0
>>> >>>
>>> >>> x and y nan location mismatch:
>>> >>>  x: array([  0.00000000e+00,   3.99680128e-02,   7.97444092e-02,
>>> >>>          1.19139103e-01,   1.57965051e-01,   1.96039735e-01,
>>> >>>          2.33186584e-01,   2.69236346e-01,   3.04028363e-01,...
>>> >>>  y: array([ nan,  nan,  nan,  nan,  nan,  nan,  nan,  nan,  nan,
>>> >>> nan,  nan,
>>> >>>         nan,  nan,  nan,  nan,  nan,  nan,  nan,  nan,  nan,  nan,
>>> >>> nan,
>>> >>>         nan,  nan,  nan,  nan,  nan,  nan,  nan,  nan,  nan,  nan,
>>> >>> nan,...
>>> >>>
>>> >>> In other words, your defined function rice_pdf works, but stats.rice
>>> >>> does not.
>>> >>>
>>> >>> Cheers,
>>> >>> Morten
>>> >>>
>>> >>> _______________________________________________
>>> >>> SciPy-User mailing list
>>> >>> SciPy-User@scipy.org
>>> >>> http://mail.scipy.org/mailman/listinfo/scipy-user
>>> _______________________________________________
>>> SciPy-User mailing list
>>> SciPy-User@scipy.org
>>> http://mail.scipy.org/mailman/listinfo/scipy-user
>>
>>
>>
>> _______________________________________________
>> SciPy-User mailing list
>> SciPy-User@scipy.org
>> http://mail.scipy.org/mailman/listinfo/scipy-user
>>


More information about the SciPy-User mailing list