diff options
author | Kevin Sheppard <kevin.k.sheppard@gmail.com> | 2017-08-22 12:11:30 +0100 |
---|---|---|
committer | Kevin Sheppard <kevin.k.sheppard@gmail.com> | 2017-08-22 15:30:32 +0100 |
commit | 94dadea7e3fa338bad7fffce4751731501337781 (patch) | |
tree | 49bc8a69a14c591c75fba7dc600298da8bc1b735 /numpy/random | |
parent | 3c887aa5242857ef92870d2988de7c899c6415be (diff) | |
download | numpy-94dadea7e3fa338bad7fffce4751731501337781.tar.gz |
ENH: Remove unnecessary restriction in noncen-f
Set dfnum restriction to be > 0 as required by noncentral chisquare
closes #6638
Diffstat (limited to 'numpy/random')
-rw-r--r-- | numpy/random/mtrand/mtrand.pyx | 12 | ||||
-rw-r--r-- | numpy/random/tests/test_random.py | 8 |
2 files changed, 13 insertions, 7 deletions
diff --git a/numpy/random/mtrand/mtrand.pyx b/numpy/random/mtrand/mtrand.pyx index c4b4f7748..5da141b43 100644 --- a/numpy/random/mtrand/mtrand.pyx +++ b/numpy/random/mtrand/mtrand.pyx @@ -2110,9 +2110,9 @@ cdef class RandomState: Parameters ---------- dfnum : int or array_like of ints - Parameter, should be > 1. + Parameter, should be > 0. dfden : int or array_like of ints - Parameter, should be > 1. + Parameter, should be > 0. nonc : float or array_like of floats Parameter, should be >= 0. size : int or tuple of ints, optional @@ -2175,8 +2175,8 @@ cdef class RandomState: fdfden = PyFloat_AsDouble(dfden) fnonc = PyFloat_AsDouble(nonc) - if fdfnum <= 1: - raise ValueError("dfnum <= 1") + if fdfnum <= 0: + raise ValueError("dfnum <= 0") if fdfden <= 0: raise ValueError("dfden <= 0") if fnonc < 0: @@ -2184,8 +2184,8 @@ cdef class RandomState: return cont3_array_sc(self.internal_state, rk_noncentral_f, size, fdfnum, fdfden, fnonc, self.lock) - if np.any(np.less_equal(odfnum, 1.0)): - raise ValueError("dfnum <= 1") + if np.any(np.less_equal(odfnum, 0.0)): + raise ValueError("dfnum <= 0") if np.any(np.less_equal(odfden, 0.0)): raise ValueError("dfden <= 0") if np.any(np.less(ononc, 0.0)): diff --git a/numpy/random/tests/test_random.py b/numpy/random/tests/test_random.py index 39c45889f..a530b9e13 100644 --- a/numpy/random/tests/test_random.py +++ b/numpy/random/tests/test_random.py @@ -1106,7 +1106,13 @@ class TestBroadcast(object): assert_raises(ValueError, nonc_f, bad_dfnum, dfden, nonc * 3) assert_raises(ValueError, nonc_f, dfnum, bad_dfden, nonc * 3) assert_raises(ValueError, nonc_f, dfnum, dfden, bad_nonc * 3) - + + def test_noncentral_f_small_df(self): + self.setSeed() + desired = np.array([6.869638627492048, 0.785880199263955]) + actual = np.random.noncentral_f(0.9, 0.9, 2, size=2) + assert_array_almost_equal(actual, desired, decimal=14) + def test_chisquare(self): df = [1] bad_df = [-1] |