Hi, I am a new reader of this list, please forgive me if this issue has already discussed. I have been wanting to use the rician distribution (stats.rice) to analyze some data, but it seems that the implementation in scipy does not take the distribution's sigma parameter into account; rather, it has been set to 1.0. The wikipedia article shows the traditional formulation of the rician distribution [0]. I understand that some distributions, e.g. stats.norm, use the scale parameter to define std, but this does not seem to be the case with stats.rice. Any ideas on how to get around this, without actually modifying distribution.py? I have no experience with the internals of scipy, and wouldn't know how to modify it correctly. Cheers, Morten [0] http://en.wikipedia.org/wiki/Rice_distribution
On Wed, Apr 4, 2012 at 3:00 AM, Morten Kjeldgaard <mok@bioxray.dk> wrote:
Hi,
I am a new reader of this list, please forgive me if this issue has already discussed.
I have been wanting to use the rician distribution (stats.rice) to analyze some data, but it seems that the implementation in scipy does not take the distribution's sigma parameter into account; rather, it has been set to 1.0. The wikipedia article shows the traditional formulation of the rician distribution [0].
I understand that some distributions, e.g. stats.norm, use the scale parameter to define std, but this does not seem to be the case with stats.rice.
Any ideas on how to get around this, without actually modifying distribution.py? I have no experience with the internals of scipy, and wouldn't know how to modify it correctly.
Cheers, Morten
location loc and scale are handled generically for all distribution. you can add loc=some number and scale= some number to almost all methods of the distributions. This replaces x by (x-loc)/scale in the calculation in the function, e.g. the _pdf, (the pdf gets an additional 1/scale in front for the transformation) For example: from scipy import stats
x = np.linspace(0, 10, 100) import matplotlib.pyplot as plt
for s in [0.5, 1, 2, 5, 10]: plt.plot(x, stats.rice.pdf(x, 0.5 , scale=s)) ... [<matplotlib.lines.Line2D object at 0x04EB8170>] [<matplotlib.lines.Line2D object at 0x04EB8470>] [<matplotlib.lines.Line2D object at 0x04EB8790>] [<matplotlib.lines.Line2D object at 0x04EB8AB0>] [<matplotlib.lines.Line2D object at 0x04EB8DD0>] plt.show()
However, I don't see how the rice_gen._pdf matches up with the formula on the Wikipedia page. It looks to me that it uses a different parameterization for the shape parameter v. (Or I didn't have enough coffee yet) bugs in this case (only _pdf is defined) could be possible, because the tests only check for consistency across methods, but in most cases the distributions are not externally verified. Josef
_______________________________________________ SciPy-User mailing list SciPy-User@scipy.org http://mail.scipy.org/mailman/listinfo/scipy-user
On Wed, Apr 4, 2012 at 7:30 AM, <josef.pktd@gmail.com> wrote:
On Wed, Apr 4, 2012 at 3:00 AM, Morten Kjeldgaard <mok@bioxray.dk> wrote:
Hi,
I am a new reader of this list, please forgive me if this issue has already discussed.
I have been wanting to use the rician distribution (stats.rice) to analyze some data, but it seems that the implementation in scipy does not take the distribution's sigma parameter into account; rather, it has been set to 1.0. The wikipedia article shows the traditional formulation of the rician distribution [0].
I understand that some distributions, e.g. stats.norm, use the scale parameter to define std, but this does not seem to be the case with stats.rice.
Any ideas on how to get around this, without actually modifying distribution.py? I have no experience with the internals of scipy, and wouldn't know how to modify it correctly.
Cheers, Morten
location loc and scale are handled generically for all distribution.
you can add loc=some number and scale= some number to almost all methods of the distributions. This replaces x by (x-loc)/scale in the calculation in the function, e.g. the _pdf, (the pdf gets an additional 1/scale in front for the transformation)
For example: from scipy import stats
x = np.linspace(0, 10, 100) import matplotlib.pyplot as plt
for s in [0.5, 1, 2, 5, 10]: plt.plot(x, stats.rice.pdf(x, 0.5 , scale=s)) ... [<matplotlib.lines.Line2D object at 0x04EB8170>] [<matplotlib.lines.Line2D object at 0x04EB8470>] [<matplotlib.lines.Line2D object at 0x04EB8790>] [<matplotlib.lines.Line2D object at 0x04EB8AB0>] [<matplotlib.lines.Line2D object at 0x04EB8DD0>] plt.show()
However, I don't see how the rice_gen._pdf matches up with the formula on the Wikipedia page. It looks to me that it uses a different parameterization for the shape parameter v. (Or I didn't have enough coffee yet)
bugs in this case (only _pdf is defined) could be possible, because the tests only check for consistency across methods, but in most cases the distributions are not externally verified.
(after another coffee) the shape parameter in stats.rice corresponds to (v/sigma) in the Wikipedia page. This is a consequence of the generic treatment of location and scale. Josef
Josef
_______________________________________________ SciPy-User mailing list SciPy-User@scipy.org http://mail.scipy.org/mailman/listinfo/scipy-user
On Wed, Apr 4, 2012 at 2:00 AM, Morten Kjeldgaard <mok@bioxray.dk> wrote:
Hi,
I am a new reader of this list, please forgive me if this issue has already discussed.
I have been wanting to use the rician distribution (stats.rice) to analyze some data, but it seems that the implementation in scipy does not take the distribution's sigma parameter into account; rather, it has been set to 1.0. The wikipedia article shows the traditional formulation of the rician distribution [0].
I understand that some distributions, e.g. stats.norm, use the scale parameter to define std, but this does not seem to be the case with stats.rice.
Any ideas on how to get around this, without actually modifying distribution.py? I have no experience with the internals of scipy, and wouldn't know how to modify it correctly.
Cheers, Morten
Hi Morten, 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: ----- import numpy as np from scipy.special import i0 from scipy.stats import rice import matplotlib.pyplot as plt def rice_pdf(x, nu, sigma): s2 = sigma**2 f = x/s2 * np.exp(-(x**2 + nu**2)/(2*s2)) * i0(x*nu/s2) return f x = np.linspace(0, 8, 201) nu = 3.45 sigma = 0.35 my_pdf = rice_pdf(x, nu, sigma) sp_pdf = rice.pdf(x, nu / sigma, scale=sigma) np.testing.assert_allclose(my_pdf, sp_pdf) plt.plot(x, my_pdf, label="rice_pdf") plt.plot(x, sp_pdf, label="stats.rice.pdf") plt.legend(loc='best') plt.show() ----- Warren
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: 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
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 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
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 ?) 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
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
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
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. Could you add that comment to the ticket? ( http://projects.scipy.org/scipy/ticket/1639) 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
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. 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
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
On Wed, Apr 4, 2012 at 12: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 ?)
Josef
I created a ticket for this: http://projects.scipy.org/scipy/ticket/1639 Warren
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
participants (3)
-
josef.pktd@gmail.com -
Morten Kjeldgaard -
Warren Weckesser