예제 #1
0
 def test_u_error(self):
     dist = StandardNormal()
     rng = NumericalInversePolynomial(dist, u_resolution=1e-10)
     max_error, mae = rng.u_error()
     assert max_error < 1e-10
     assert mae <= max_error
     rng = NumericalInversePolynomial(dist, u_resolution=1e-14)
     max_error, mae = rng.u_error()
     assert max_error < 1e-14
     assert mae <= max_error
예제 #2
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()