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
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)
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)
def test_discrete_uniform_negative(): model = Model() with model: x = DiscreteUniform("x", lower=-10, upper=0) assert model.test_point["x"] == -5
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))
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)
def test_default_discrete_uniform(): with Model(): x = DiscreteUniform("x", lower=1, upper=2) assert x.init_value == 1
def test_default_a(): with Model(): x = DistTest("x", 1, 2, defaults=["a"]) assert x.tag.test_value == 1
def test_default_b(): with Model(): x = DistTest("x", np.nan, 2, defaults=["a", "b"]) assert x.tag.test_value == 2
def test_default_testval(): with Model(): x = DistTest("x", 1, 2, testval=5, defaults=[]) assert x.tag.test_value == 5
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)
def test_default_empty_fail(): with Model(), pytest.raises(AttributeError): DistTest("x", 1, 2, defaults=[])
def test_default_nan_fail(): with Model(), pytest.raises(AttributeError): DistTest("x", np.nan, 2, defaults=["a"])
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')
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")
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
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)
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)