Esempio n. 1
0
 def test_no_prior(self):
     """Test that giving a null prior defaults prior_name to `None`."""
     dim = Dimension('yolo', None)
     print(dim._prior_name)
     assert dim.prior is None
     assert dim._prior_name is 'None'
Esempio n. 2
0
 def test_init_with_default_value(self):
     """Make sure the __contains__ method does not work"""
     with pytest.raises(NotImplementedError):
         Dimension('yolo', 'uniform', -3, 4, default_value=4)
Esempio n. 3
0
 def test_no_default_value(self):
     """Test that no giving a default value assigns None"""
     dim = Dimension('yolo', 'uniform', -3, 4)
     assert dim.default_value is None
Esempio n. 4
0
    def test_contains_shape(self):
        """Test __contains__ for shape check."""
        dim = Dimension(None, 'uniform', -3, 4, shape=(4, 4))

        with pytest.raises(NotImplementedError):
            assert dists.uniform.rvs(-3, 4, size=(4, 4)) in dim
Esempio n. 5
0
 def test_set_bad_name(self):
     """Try setting a name other than str or None."""
     dim = Dimension('yolo', 'uniform', -3, 4, shape=(4, 4))
     with pytest.raises(TypeError):
         dim.name = 4
Esempio n. 6
0
 def test_interval(self):
     """Test that bounds on variable."""
     dim = Dimension('yolo', 'uniform', -3, 4)
     assert dim.interval(1.0) == (
         -3.0, 1.0)  # reminder that `scale` is not upper bound
Esempio n. 7
0
 def test_contains_bounds(self):
     """Test __contains__ for bounds."""
     dim = Dimension('yolo', 'uniform', -3, 4)
     with pytest.raises(NotImplementedError):
         assert -3 in dim
Esempio n. 8
0
 def test_ban_discrete_kwarg(self):
     """Do not allow use for 'discrete' kwarg, because now there's `_Discrete`."""
     with pytest.raises(ValueError) as exc:
         Dimension('yolo', 'uniform', -3, 4, shape=(4, 4), discrete=True)
     assert "pure `_Discrete`" in str(exc.value)
Esempio n. 9
0
 def test_many_samples(self, seed):
     """More than 1."""
     dim = Dimension('yolo', 'uniform', -3, 4, shape=(4, 4))
     samples = dim.sample(n_samples=4, seed=seed)
     assert len(samples) == 4
     assert_eq(dists.uniform.rvs(-3, 4, size=(4, 4)), samples[0])
Esempio n. 10
0
 def test_ban_rng_kwarg(self):
     """Should not be able to use 'random_state' kwarg."""
     with pytest.raises(ValueError):
         Dimension('yolo', 'norm', 0.9, random_state=8)
Esempio n. 11
0
 def test_with_predefined_dist(self, seed):
     """Use an already defined distribution object as prior arg."""
     dim = Dimension('yolo', dists.norm, 0.9)
     samples = dim.sample(seed=seed)
     assert len(samples) == 1
     assert dists.norm.rvs(0.9) == samples[0]
Esempio n. 12
0
 def test_ban_seed_kwarg(self):
     """Should not be able to use 'seed' kwarg."""
     with pytest.raises(ValueError):
         Dimension('yolo', 'norm', 0.9, seed=8)
Esempio n. 13
0
 def test_ban_size_kwarg(self):
     """Should not be able to use 'size' kwarg."""
     with pytest.raises(ValueError):
         Dimension('yolo', 'norm', 0.9, size=(3, 2))
Esempio n. 14
0
 def test_get_prior_string_loguniform(self):
     """Test that special loguniform prior name is replaced properly."""
     dim = Dimension("yolo", "reciprocal", 1e-10, 1)
     assert dim.get_prior_string() == "loguniform(1e-10, 1)"
Esempio n. 15
0
 def test_get_prior_string_shape(self):
     """Test that shape is included."""
     dim = Dimension("yolo", "alpha", 1, 2, shape=(2, 3))
     assert dim.get_prior_string() == "alpha(1, 2, shape=(2, 3))"
Esempio n. 16
0
 def test_get_prior_string_uniform(self):
     """Test special uniform args are handled properly."""
     dim = Dimension("yolo", "uniform", 1, 2)
     assert dim.get_prior_string() == "uniform(1, 3)"