예제 #1
0
 def test_invalid_tune(self, tune_setting):
     with Model() as pmodel:
         Normal('n', 0, 2, shape=(3, ))
         with pytest.raises(ValueError):
             DEMetropolisZ(tune=tune_setting)
     pass
예제 #2
0
 def test_normal(self):
     """Test normal distribution is assigned NUTS method"""
     with Model() as model:
         Normal("x", 0, 1)
         steps = assign_step_methods(model, [])
     assert isinstance(steps, NUTS)
예제 #3
0
 def test_binomial(self):
     """Test binomial distribution is assigned metropolis method."""
     with Model() as model:
         Binomial("x", 10, 0.5)
         steps = assign_step_methods(model, [])
     assert isinstance(steps, Metropolis)
예제 #4
0
def test_discrete_uniform_negative():
    model = Model()
    with model:
        x = DiscreteUniform("x", lower=-10, upper=0)
    assert model.test_point["x"] == -5
예제 #5
0
def test_categorical_mode():
    model = Model()
    with model:
        x = Categorical("x", p=np.eye(4), shape=4)
    assert np.allclose(model.test_point["x"], np.arange(4))
예제 #6
0
파일: test_step.py 프로젝트: bedsDev/pymc3
 def test_categorical(self):
     """Test categorical distribution is assigned binary gibbs metropolis method"""
     with Model() as model:
         Categorical('x', np.array([0.25, 0.75]))
         steps = assign_step_methods(model, [])
     self.assertIsInstance(steps, BinaryGibbsMetropolis)
예제 #7
0
def test_default_discrete_uniform():
    with Model():
        x = DiscreteUniform("x", lower=1, upper=2)
        assert x.init_value == 1
예제 #8
0
def test_default_a():
    with Model():
        x = DistTest("x", 1, 2, defaults=["a"])
        assert x.tag.test_value == 1
예제 #9
0
def test_default_b():
    with Model():
        x = DistTest("x", np.nan, 2, defaults=["a", "b"])
        assert x.tag.test_value == 2
예제 #10
0
def test_default_testval():
    with Model():
        x = DistTest("x", 1, 2, testval=5, defaults=[])
        assert x.tag.test_value == 5
예제 #11
0
def test_default_testval_nan():
    with Model():
        x = DistTest("x", 1, 2, testval=np.nan, defaults=["a"])
        np.testing.assert_almost_equal(x.tag.test_value, np.nan)
예제 #12
0
def test_default_empty_fail():
    with Model(), pytest.raises(AttributeError):
        DistTest("x", 1, 2, defaults=[])
예제 #13
0
def test_default_nan_fail():
    with Model(), pytest.raises(AttributeError):
        DistTest("x", np.nan, 2, defaults=["a"])
예제 #14
0
 def test_bad_init(self):
     with Model():
         HalfNormal('a', sd=1, testval=-1, transform=None)
         with pytest.raises(ValueError) as error:
             sample(init=None)
         error.match('Bad initial')
예제 #15
0
 def test_bad_init_parallel(self):
     with Model():
         HalfNormal("a", sigma=1, testval=-1, transform=None)
         with pytest.raises(ParallelSamplingError) as error:
             sample(init=None, cores=2, random_seed=1)
         error.match("Bad initial")
예제 #16
0
def test_default_c():
    with Model():
        y = DistTest("y", 7, 8, testval=94)
        x = DistTest("x", y, 2, defaults=["a", "b"])
        assert x.tag.test_value == 94
예제 #17
0
 def test_bernoulli(self):
     """Test bernoulli distribution is assigned binary gibbs metropolis method"""
     with Model() as model:
         Bernoulli('x', 0.5)
         steps = assign_step_methods(model, [])
     assert isinstance(steps, BinaryGibbsMetropolis)
예제 #18
0
파일: test_step.py 프로젝트: bedsDev/pymc3
 def test_constant_step(self):
     with Model():
         x = Normal('x', 0, 1)
         start = {'x': -1}
         tr = sample(10, step=Constant([x]), start=start)
     assert_almost_equal(tr['x'], start['x'], decimal=10)