Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion scipy/stats/distributions.py
Expand Up @@ -2705,24 +2705,33 @@ class erlang_gen(rv_continuous):
""" """
def _rvs(self, n): def _rvs(self, n):
return gamma.rvs(n,size=self._size) return gamma.rvs(n,size=self._size)
def _arg_check(self, n):
def _argcheck(self, n):
return (n > 0) & (floor(n)==n) return (n > 0) & (floor(n)==n)

def _pdf(self, x, n): def _pdf(self, x, n):
Px = (x)**(n-1.0)*exp(-x)/special.gamma(n) Px = (x)**(n-1.0)*exp(-x)/special.gamma(n)
return Px return Px

def _logpdf(self, x, n): def _logpdf(self, x, n):
return (n-1.0)*log(x) - x - gamln(n) return (n-1.0)*log(x) - x - gamln(n)

def _cdf(self, x, n): def _cdf(self, x, n):
return special.gdtr(1.0,n,x) return special.gdtr(1.0,n,x)

def _sf(self, x, n): def _sf(self, x, n):
return special.gdtrc(1.0,n,x) return special.gdtrc(1.0,n,x)

def _ppf(self, q, n): def _ppf(self, q, n):
return special.gdtrix(1.0, n, q) return special.gdtrix(1.0, n, q)

def _stats(self, n): def _stats(self, n):
n = n*1.0 n = n*1.0
return n, n, 2/sqrt(n), 6/n return n, n, 2/sqrt(n), 6/n

def _entropy(self, n): def _entropy(self, n):
return special.psi(n)*(1-n) + 1 + gamln(n) return special.psi(n)*(1-n) + 1 + gamln(n)

erlang = erlang_gen(a=0.0, name='erlang', shapes='n') erlang = erlang_gen(a=0.0, name='erlang', shapes='n')




Expand Down
12 changes: 11 additions & 1 deletion scipy/stats/tests/test_distributions.py
Expand Up @@ -4,7 +4,7 @@


from numpy.testing import TestCase, run_module_suite, assert_equal, \ from numpy.testing import TestCase, run_module_suite, assert_equal, \
assert_array_equal, assert_almost_equal, assert_array_almost_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 import numpy
Expand Down Expand Up @@ -876,5 +876,15 @@ def test_powerlaw_stats():
assert_array_almost_equal(mvsk, exact_mvsk) 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__": if __name__ == "__main__":
run_module_suite() run_module_suite()