Example #1
0
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)
Example #2
0
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)
Example #3
0
 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)
Example #4
0
 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, [])
     assert isinstance(steps, BinaryGibbsMetropolis)
     with Model() as model:
         Categorical('y', np.array([0.25, 0.70, 0.05]))
         steps = assign_step_methods(model, [])
     assert isinstance(steps, CategoricalGibbsMetropolis)
Example #5
0
    def test_normal_nograd_op(self):
        """Test normal distribution without an implemented gradient is assigned slice method"""
        with Model() as model:
            x = Normal('x', 0, 1)

            # a custom Theano Op that does not have a grad:
            is_64 = theano.config.floatX == "float64"
            itypes = [tt.dscalar] if is_64 else [tt.fscalar]
            otypes = [tt.dscalar] if is_64 else [tt.fscalar]
            @theano.as_op(itypes, otypes)
            def kill_grad(x):
                return x

            data = np.random.normal(size=(100,))
            Normal("y", mu=kill_grad(x), sd=1, observed=data.astype(theano.config.floatX))

            steps = assign_step_methods(model, [])
        assert isinstance(steps, Slice)
Example #6
0
    def test_normal_nograd_op(self):
        """Test normal distribution without an implemented gradient is assigned slice method"""
        with Model() as model:
            x = Normal('x', 0, 1)

            # a custom Theano Op that does not have a grad:
            is_64 = theano.config.floatX == "float64"
            itypes = [tt.dscalar] if is_64 else [tt.fscalar]
            otypes = [tt.dscalar] if is_64 else [tt.fscalar]
            @theano.as_op(itypes, otypes)
            def kill_grad(x):
                return x

            data = np.random.normal(size=(100,))
            Normal("y", mu=kill_grad(x), sd=1, observed=data.astype(theano.config.floatX))

            steps = assign_step_methods(model, [])
        assert isinstance(steps, Slice)
Example #7
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, [])
     self.assertIsInstance(steps, Metropolis)
Example #8
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, [])
     self.assertIsInstance(steps, NUTS)
Example #9
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, [])
     self.assertIsInstance(steps, BinaryGibbsMetropolis)
Example #10
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)
Example #11
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)
Example #12
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)