def test_competence(self, variable, has_grad, outcome): with Model() as pmodel: Normal('n', 0, 2, shape=(3, )) Binomial('b', n=2, p=0.3) assert DEMetropolisZ.competence(pmodel[variable], has_grad=has_grad) == outcome pass
def test_assign_step_methods(): with Model() as model: x = Bernoulli('x', 0.5) steps = assign_step_methods(model, []) assert isinstance(steps, BinaryMetropolis) with Model() as model: x = Normal('x', 0, 1) steps = assign_step_methods(model, []) assert isinstance(steps, NUTS) with Model() as model: x = Categorical('x', np.array([0.25, 0.75])) steps = assign_step_methods(model, []) assert isinstance(steps, BinaryMetropolis) with Model() as model: x = Categorical('x', np.array([0.25, 0.70, 0.05])) steps = assign_step_methods(model, []) assert isinstance(steps, Metropolis) with Model() as model: x = Binomial('x', 10, 0.5) steps = assign_step_methods(model, []) assert isinstance(steps, Metropolis)
def test_competence(self, variable, has_grad, outcome): """Test if competence function returns expected results for different models""" with Model() as pmodel: Normal("n", 0, 2, shape=(3, )) Binomial("b", n=2, p=0.3) assert MLDA.competence(pmodel[variable], has_grad=has_grad) == outcome
def test_multiple_samplers(self, caplog): with Model(): prob = Beta("prob", alpha=5.0, beta=3.0) Binomial("outcome", n=1, p=prob) caplog.clear() sample(3, tune=2, discard_tuned_samples=False, n_init=None, chains=1) messages = [msg.msg for msg in caplog.records] assert all("boolean index did not" not in msg for msg in messages)
def test_multiple_samplers(self): with Model(): prob = Beta('prob', alpha=5, beta=3) Binomial('outcome', n=1, p=prob) with warnings.catch_warnings(record=True) as warns: sample(3, tune=2, discard_tuned_samples=False, n_init=None) messages = [warn.message.args[0] for warn in warns] assert any("contains only 3" in msg for msg in messages) assert all('boolean index did not' not in msg for msg in messages)
def test_multiple_samplers(self): with Model(): prob = Beta('prob', alpha=5., beta=3.) Binomial('outcome', n=1, p=prob) # Catching warnings through multiprocessing doesn't work, # so we have to use single threaded sampling. with pytest.warns(None) as warns: sample(3, tune=2, discard_tuned_samples=False, n_init=None, chains=1) messages = [warn.message.args[0] for warn in warns] assert any("contains only 3" in msg for msg in messages) assert all('boolean index did not' not in msg for msg in messages)
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, []) self.assertIsInstance(steps, Metropolis)