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_categorical(self): """Test categorical distribution is assigned categorical gibbs metropolis method""" with Model() as model: Categorical('x', np.array([0.25, 0.75])) steps = assign_step_methods(model, []) self.assertIsInstance(steps, BinaryGibbsMetropolis) with Model() as model: Categorical('y', np.array([0.25, 0.70, 0.05])) steps = assign_step_methods(model, []) self.assertIsInstance(steps, CategoricalGibbsMetropolis)
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))