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
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
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
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
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
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)"
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]))
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]
def test_inclusive_intervals(self): """Test that discretized bounds are valid""" dim = Integer("yolo", "uniform", -3, 5.5) assert dim.interval() == (-3, 3)
def dim3(): """Create an example of integer `Dimension`.""" return Integer("yolo3", "uniform", 3, 7)
def logintdim(): """Create an log integer example of `Dimension`.""" dim = Integer("yolo5", "reciprocal", 1, 10, shape=(3, 2)) return dim
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]
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]
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]
def dim3(): """Create an example of integer `orion.algo.space.Dimension`.""" return Integer("yolo3", "uniform", 3, 7)
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)
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
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
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]))
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]