Beispiel #1
0
    def test_bad_args(self):
        dist = StandardNormal()
        rng = NumericalInversePolynomial(dist)
        msg = r"CDF is not available."
        with pytest.raises(ValueError, match=msg):
            rng.cdf([1, 2, 3])
        msg = r"`sample_size` must be greater than or equal to 1000."
        with pytest.raises(ValueError, match=msg):
            rng.u_error(10)

        class Distribution:
            def pdf(self, x):
                return np.exp(-0.5 * x * x)

        dist = Distribution()
        rng = NumericalInversePolynomial(dist)
        msg = r"Exact CDF required but not found."
        with pytest.raises(ValueError, match=msg):
            rng.u_error()
Beispiel #2
0
 def test_cdf(self, x):
     dist = StandardNormal()
     rng = NumericalInversePolynomial(dist,
                                      keep_cdf=True,
                                      u_resolution=1e-14)
     # Older versions of NumPy throw RuntimeWarnings for comparisons
     # with nan.
     with suppress_warnings() as sup:
         sup.filter(RuntimeWarning, "invalid value encountered in greater")
         sup.filter(RuntimeWarning, "invalid value encountered in "
                    "greater_equal")
         sup.filter(RuntimeWarning, "invalid value encountered in less")
         sup.filter(RuntimeWarning, "invalid value encountered in "
                    "less_equal")
         res = rng.cdf(x)
         expected = stats.norm.cdf(x)
     assert_allclose(res, expected, rtol=1e-11, atol=1e-11)
     assert res.shape == expected.shape