Пример #1
0
    def test_register_and_contain(self):
        """Register bunch of dimensions, check if points/name are in space."""
        space = Space()

        assert "yolo" not in space
        assert (("asdfa", 2), 0, 3.5) not in space

        categories = {"asdfa": 0.1, 2: 0.2, 3: 0.3, 4: 0.4}
        dim = Categorical("yolo", categories, shape=2)
        space.register(dim)
        dim = Integer("yolo2", "uniform", -3, 6)
        space.register(dim)
        dim = Real("yolo3", "norm", 0.9)
        space.register(dim)

        assert "yolo" in space
        assert "yolo2" in space
        assert "yolo3" in space

        assert (("asdfa", 2), 0, 3.5) in space
        assert (("asdfa", 2), 7, 3.5) not in space
Пример #2
0
    def test_register_and_contain(self):
        """Register bunch of dimensions, check if points/name are in space."""
        space = Space()

        assert 'yolo' not in space
        assert (('asdfa', 2), 0, 3.5) not in space

        categories = {'asdfa': 0.1, 2: 0.2, 3: 0.3, 4: 0.4}
        dim = Categorical('yolo', categories, shape=2)
        space.register(dim)
        dim = Integer('yolo2', 'uniform', -3, 6)
        space.register(dim)
        dim = Real('yolo3', 'norm', 0.9)
        space.register(dim)

        assert 'yolo' in space
        assert 'yolo2' in space
        assert 'yolo3' in space

        assert (('asdfa', 2), 0, 3.5) in space
        assert (('asdfa', 2), 7, 3.5) not in space
Пример #3
0
    def test_register_and_contain(self):
        """Register bunch of dimensions, check if points/name are in space."""
        space = Space()

        trial = Trial(params=[{"name": "no", "value": 0, "type": "integer"}])

        assert "yolo" not in space
        assert trial not in space

        categories = {"asdfa": 0.1, 2: 0.2, 3: 0.3, 4: 0.4}
        dim = Categorical("yolo", categories, shape=2)
        space.register(dim)
        dim = Integer("yolo2", "uniform", -3, 6)
        space.register(dim)
        dim = Real("yolo3", "norm", 0.9)
        space.register(dim)

        assert "yolo" in space
        assert "yolo2" in space
        assert "yolo3" in space

        assert format_trials.tuple_to_trial((("asdfa", 2), 0, 3.5), space) in space
        assert format_trials.tuple_to_trial((("asdfa", 2), 7, 3.5), space) not in space
Пример #4
0
    def test_init_with_default_value(self):
        """Make sure the type of the default value is int"""
        dim = Integer('yolo', 'uniform', -3, 10, default_value=2)

        assert type(dim.default_value) is int
Пример #5
0
 def test_interval_with_infs(self):
     """Regression test: Interval handles correctly extreme bounds."""
     dim = Integer('yolo', 'poisson', 5)
     # XXX: Complete this on both end of interval when scipy bug is fixed
     assert dim.interval()[1] == np.inf
Пример #6
0
 def test_get_prior_string_discrete(self):
     """Test that discrete is included."""
     dim = Integer("yolo", "uniform", 1, 2)
     assert dim.get_prior_string() == "uniform(1, 3, discrete=True)"
Пример #7
0
 def test_cast_array(self):
     """Make sure array are cast to int and returned as array of values"""
     dim = Integer("yolo", "uniform", -3, 5)
     assert np.all(dim.cast(np.array(["1", "2"])) == np.array([1, 2]))
Пример #8
0
 def test_cast_list(self):
     """Make sure list are cast to int and returned as list of values"""
     dim = Integer('yolo', 'uniform', -3, 4)
     assert dim.cast(['1', '2']) == [1, 2]
Пример #9
0
 def test_inclusive_intervals(self):
     """Test that discretized bounds are valid"""
     dim = Integer("yolo", "uniform", -3, 5.5)
     assert dim.interval() == (-3, 3)
Пример #10
0
def dim3():
    """Create an example of integer `Dimension`."""
    return Integer("yolo3", "uniform", 3, 7)
Пример #11
0
def logintdim():
    """Create an log integer example of `Dimension`."""
    dim = Integer("yolo5", "reciprocal", 1, 10, shape=(3, 2))
    return dim
Пример #12
0
def test_log_discrete_grid():
    """Test log discrete grid"""
    dim = Integer("yolo", "reciprocal", 1, 1000)
    assert discrete_grid(dim, 4) == [1, 10, 100, 1000]
    assert discrete_grid(dim, 6) == [1, 4, 16, 63, 251, 1000]
Пример #13
0
def test_too_small_distrete_grid():
    """Test that small discrete grid does not lead to duplicates"""
    dim = Integer("yolo", "uniform", -2, 4)
    assert discrete_grid(dim, 3) == [-2, 0, 2]
    assert discrete_grid(dim, 5) == [-2, -1, 0, 1, 2]
    assert discrete_grid(dim, 50) == [-2, -1, 0, 1, 2]
Пример #14
0
def test_discrete_grid():
    """Test discrete grid"""
    dim = Integer("yolo", "uniform", -5, 10)
    assert discrete_grid(dim, 6) == [-5, -3, -1, 1, 3, 5]
    assert discrete_grid(dim, 7) == [-5, -3, -2, 0, 2, 3, 5]
Пример #15
0
def dim3():
    """Create an example of integer `orion.algo.space.Dimension`."""
    return Integer("yolo3", "uniform", 3, 7)
Пример #16
0
 def test_set_outside_bounds_default_value(self):
     """Make sure the default value is inside the bounds of the dimensions"""
     with pytest.raises(ValueError):
         Integer('yolo', 'uniform', -3, 2, default_value=4)
Пример #17
0
 def test_no_default_value(self):
     """Make sure the default value is None"""
     dim = Integer('yolo', 'uniform', -3, 4)
     assert dim.default_value is None
Пример #18
0
 def test_cast_borders(self):
     """Make sure cast to int returns correct borders"""
     dim = Integer("yolo", "uniform", -3, 5)
     assert dim.cast(-3.0) == -3
     assert dim.cast(2.0) == 2
Пример #19
0
 def test_cast_array(self):
     """Make sure array are cast to int and returned as array of values"""
     dim = Integer('yolo', 'uniform', -3, 4)
     assert np.all(dim.cast(np.array(['1', '2'])) == np.array([1, 2]))
Пример #20
0
 def test_cast_list(self):
     """Make sure list are cast to int and returned as list of values"""
     dim = Integer("yolo", "uniform", -3, 5)
     assert dim.cast(["1", "2"]) == [1, 2]