# scipy/scipy

### Subversion checkout URL

You can clone with HTTPS or Subversion.

# Rice distribution: extend to b=0, add an explicit rvs method.#2847

Merged
merged 3 commits into from
+38 −1

### 3 participants

Collaborator

closes gh-2164 and gh-2742.

As a bonus, rvs get a bit faster. With current master:

In [10]: scipy.__version__
Out[10]: '0.14.0.dev-efbde60'

In [11]: %timeit stats.rice.rvs(b=3.)
100 loops, best of 3: 4.18 ms per loop

In [12]: %timeit stats.rice.rvs(b=3., size=1000)
1 loops, best of 3: 4.13 s per loop


with this PR:

In [6]: scipy.__version__
Out[6]: '0.14.0.dev-bf7d8d9'

In [7]: %timeit stats.rice.rvs(b=3.)
10000 loops, best of 3: 45.5 µs per loop

In [8]: %timeit stats.rice.rvs(b=3., size=1000)
10000 loops, best of 3: 192 µs per loop

Collaborator

nice, ticket count is going down

looks good to me

scipy/stats/tests/test_continuous_extra.py
 ((7 lines not shown)) + npt.assert_(np.isfinite(stats.rice.pdf(x, b=0.)).all()) + npt.assert_(np.isfinite(stats.rice.logpdf(x, b=0.)).all()) + npt.assert_(np.isfinite(stats.rice.cdf(x, b=0.)).all()) + npt.assert_(np.isfinite(stats.rice.logcdf(x, b=0.)).all()) + + q = [0.1, 0.1, 0.5, 0.9] + npt.assert_(np.isfinite(stats.rice.ppf(q, b=0.)).all()) + + mvsk = stats.rice.stats(0, moments='mvsk') + npt.assert_(np.isfinite(mvsk).all()) + + # furthermore, pdf is continuous as b\to 0 + # rice.pdf(x, b\to 0) = x exp(-x^2/2) + O(b^2) + # see e.g. Abramovich & Stegun 9.6.7 & 9.6.10 + b = 1e-8 + np.allclose(stats.rice.pdf(x, 0), stats.rice.pdf(x, b),
 Owner rgommers added a note Sep 15, 2013 I think you meant to use assert_allclose here? to join this conversation on GitHub. Already have an account? Sign in to comment
scipy/stats/tests/test_continuous_extra.py
 ((12 lines not shown)) + q = [0.1, 0.1, 0.5, 0.9] + npt.assert_(np.isfinite(stats.rice.ppf(q, b=0.)).all()) + + mvsk = stats.rice.stats(0, moments='mvsk') + npt.assert_(np.isfinite(mvsk).all()) + + # furthermore, pdf is continuous as b\to 0 + # rice.pdf(x, b\to 0) = x exp(-x^2/2) + O(b^2) + # see e.g. Abramovich & Stegun 9.6.7 & 9.6.10 + b = 1e-8 + np.allclose(stats.rice.pdf(x, 0), stats.rice.pdf(x, b), + atol = b, rtol=0) + + +def test_rice_rvs(): + # a supplement to the KS test (which is run separately)
 Owner rgommers added a note Sep 15, 2013 This test just checks that _rvs returns the right output shape. What does it have to do with a KS test? Owner rgommers added a note Sep 15, 2013 Ah, you meant check_distribution_rvs. Maybe remove the comment or be more explicit to join this conversation on GitHub. Already have an account? Sign in to comment
Owner

Looks good. One thing to add would be to remove 'rice' from the list of slow distributions in test_continuous_basic.py

Collaborator

made changed suggested by @rgommers, rebased on master, pushed the rebased version.

Owner

Slight git mishap here....

Collaborator

ouch.
I screwed it up.
any suggestion of how to fix this mess? Or is it easier to close this, apply the changes to the master, and send a fresh PR?

Owner

You can create a new branch from current master, cherry-pick the relevant commits and then force push to this PR (\$ git push origin newbranch:rice_enh).

 ev-br ENH: allow b=0 for rice distribution b7e0dec ev-br ENH: add an explicit rvs method to the Rice distribution cbc8e02 ev-br MAINT: remove rice from the list of slow distributions 305f7b4
Collaborator

@rgommers done just that, thanks a whole lot!
Just for me to understand (and avoid in the future): what was the error?
What I did was

• fetch upstream master and merge it to the local master
• rebased the feature branch on local master
• tried pushing to the origin, which failed
• pulled the feature branch from the origin, resolved merge conflicts,
• pushed the feature branch back to origin As there was no force-pushing involved, I thought it'd to the right thing. Apparently not...
Collaborator

after rebase you need to force push to your github branch, to overwrite it

Owner

Yep. Step 1, 2 are correct, 3 needed -f.

merged commit f1b8578 into from
Owner

Merged, thanks!

This was referenced
Closed

Closed

### stats.rice.pdf(x, 0) returns nan (Trac #1639) #2164

deleted the branch