Skip to content

Loading…

BUG: stats: fix misnamed _argcheck method of the erlang distribution. #198

Closed
wants to merge 1 commit into from

4 participants

@WarrenWeckesser

Closes #1647 (http://projects.scipy.org/scipy/ticket/1647).

Reviewers: be sure to read the comments in the trac ticket.

@pv
SciPy member
pv commented

Seems correct to me.

@WarrenWeckesser

The code changes are pretty simple, but there is a discussion in the trac ticket about whether erlang should allow non-integer shape parameters. (This would make erlang an alias for gamma.) If you have an opinion on that, could you add a comment in the trac ticket?

@josef-pkt
SciPy member

As discussed on the ticket and mailing list, I'm pretty much against this change. It breaks the pattern of continuous parameter spaces without sufficient benefits that I can see.

The only reason to make this change is if we also create a fit method that restricts to discrete parameter spaces.

@rgommers rgommers added a commit to rgommers/scipy that referenced this pull request
@rgommers rgommers MAINT: stats: alias the erlang to the gamma distribution. Add gamma._…
…sf().

Closes gh-2172 and gh-198.  See discussion on gh-2172 for details.
1ae8bd5
@rgommers rgommers added a commit that referenced this pull request
@rgommers rgommers MAINT: stats: alias the erlang to the gamma distribution. Add gamma._…
…sf().

Closes gh-2172 and gh-198.  See discussion on gh-2172 for details.
8427a3a
@rgommers
SciPy member

Fixed by gh-2507.

@rgommers rgommers closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 22, 2012
Showing with 21 additions and 2 deletions.
  1. +10 −1 scipy/stats/distributions.py
  2. +11 −1 scipy/stats/tests/test_distributions.py
View
11 scipy/stats/distributions.py
@@ -2705,24 +2705,33 @@ class erlang_gen(rv_continuous):
"""
def _rvs(self, n):
return gamma.rvs(n,size=self._size)
- def _arg_check(self, n):
+
+ def _argcheck(self, n):
return (n > 0) & (floor(n)==n)
+
def _pdf(self, x, n):
Px = (x)**(n-1.0)*exp(-x)/special.gamma(n)
return Px
+
def _logpdf(self, x, n):
return (n-1.0)*log(x) - x - gamln(n)
+
def _cdf(self, x, n):
return special.gdtr(1.0,n,x)
+
def _sf(self, x, n):
return special.gdtrc(1.0,n,x)
+
def _ppf(self, q, n):
return special.gdtrix(1.0, n, q)
+
def _stats(self, n):
n = n*1.0
return n, n, 2/sqrt(n), 6/n
+
def _entropy(self, n):
return special.psi(n)*(1-n) + 1 + gamln(n)
+
erlang = erlang_gen(a=0.0, name='erlang', shapes='n')
View
12 scipy/stats/tests/test_distributions.py
@@ -4,7 +4,7 @@
from numpy.testing import TestCase, run_module_suite, assert_equal, \
assert_array_equal, assert_almost_equal, assert_array_almost_equal, \
- assert_allclose, assert_, rand, dec
+ assert_allclose, assert_, assert_raises, rand, dec
import numpy
@@ -876,5 +876,15 @@ def test_powerlaw_stats():
assert_array_almost_equal(mvsk, exact_mvsk)
+def test_erlang_noninteger_n():
+ """ erlang distribution requires an integer shape parameter.
+
+ Regression test for ticket #1647.
+ """
+ assert_array_equal(stats.erlang._argcheck([1.5, 2.0, 3.4]),
+ [False, True, False])
+ assert_raises(ValueError, stats.erlang.rvs, 1.5)
+
+
if __name__ == "__main__":
run_module_suite()
Something went wrong with that request. Please try again.