How to use the orion.algo.space.Real function in orion

To help you get started, we’ve selected a few orion examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Epistimio / orion / tests / unittests / algo / test_space.py View on Github external
def test_order(self):
        """Test that the same space built twice will have the same ordering."""
        space1 = Space()
        space1.register(Integer('yolo1', 'uniform', -3, 6, shape=(2,)))
        space1.register(Integer('yolo2', 'uniform', -3, 6, shape=(2,)))
        space1.register(Real('yolo3', 'norm', 0.9))
        space1.register(Categorical('yolo4', ('asdfa', 2)))

        space2 = Space()
        space2.register(Integer('yolo1', 'uniform', -3, 6, shape=(2,)))
        space2.register(Real('yolo3', 'norm', 0.9))
        space2.register(Categorical('yolo4', ('asdfa', 2)))
        space2.register(Integer('yolo2', 'uniform', -3, 6, shape=(2,)))

        assert list(space1) == list(space1.keys())
        assert list(space2) == list(space2.keys())
        assert list(space1.values()) == list(space2.values())
        assert list(space1.items()) == list(space2.items())
        assert list(space1.keys()) == list(space2.keys())
        assert list(space1.values()) == list(space2.values())
        assert list(space1.items()) == list(space2.items())
github Epistimio / orion / tests / unittests / algo / test_space.py View on Github external
def test_getitem(self):
        """Test getting dimensions from space."""
        space = Space()
        probs = (0.1, 0.2, 0.3, 0.4)
        categories = ('asdfa', 2, 3, 4)
        dim = Categorical('yolo', OrderedDict(zip(categories, probs)), shape=2)
        space.register(dim)
        dim = Integer('yolo2', 'uniform', -3, 6)
        space.register(dim)
        dim = Real('yolo3', 'norm', 0.9)
        space.register(dim)

        assert space['yolo'].type == 'categorical'
        assert space[0].type == 'categorical'

        with pytest.raises(KeyError):
            space['asdf']

        with pytest.raises(IndexError):
            space[3]
github Epistimio / orion / tests / unittests / algo / test_space.py View on Github external
def test_sample_from_extra_bounds_good(self):
        """Randomized test **successful** sampling with the extra bounds."""
        dim = Real('yolo', 'norm', 0, 2, low=-5, high=+5, shape=(4, 4))
        for _ in range(8):
            samples = dim.sample(8)
            for sample in samples:
                assert sample in dim
github Epistimio / orion / tests / unittests / core / test_transformer.py View on Github external
def dim():
    """Create an example of `Dimension`."""
    dim = Real('yolo', 'norm', 0.9, shape=(3, 2))
    return dim
github Epistimio / orion / tests / unittests / core / io / test_space_builder.py View on Github external
def test_build_a_good_real(self, dimbuilder):
        """Check that non registered names are good, as long as they are in
        `scipy.stats.distributions`.
        """
        dim = dimbuilder.build('yolo2', 'alpha(0.9, low=0, high=10, shape=2)')
        assert isinstance(dim, Real)
        assert dim.name == 'yolo2'
        assert dim._prior_name == 'alpha'
        assert 3.3 not in dim
        assert (3.3, 11.1) not in dim
        assert (3.3, 6) in dim
        assert isinstance(dim.prior, dists.alpha_gen)
github Epistimio / orion / tests / unittests / algo / test_space.py View on Github external
def test_precision(self):
        """Test that precision is correctly handled."""
        space = Space()
        space.register(Real('yolo1', 'norm', 0.9, precision=6))
        space.register(Real('yolo2', 'norm', 0.9, precision=None))
        space.register(Real('yolo5', 'norm', 0.9))

        assert space['yolo1'].precision == 6
        assert space['yolo2'].precision is None
        assert space['yolo5'].precision == 4

        with pytest.raises(TypeError):
            space.register(Real('yolo3', 'norm', 0.9, precision=-12))

        with pytest.raises(TypeError):
            space.register(Real('yolo4', 'norm', 0.9, precision=0.6))
github Epistimio / orion / tests / unittests / algo / test_space.py View on Github external
def test_simple_instance(self, seed):
        """Test Real.__init__."""
        dim = Real('yolo', 'norm', 0.9)
        samples = dim.sample(seed=seed)
        assert len(samples) == 1
        assert dists.norm.rvs(0.9) == samples[0]

        assert dists.norm.interval(1.0, 0.9) == dim.interval()
        assert dists.norm.interval(0.5, 0.9) == dim.interval(0.5)

        assert 1.0 in dim

        assert str(dim) == "Real(name=yolo, prior={norm: (0.9,), {}}, shape=(), default value=None)"
        assert dim.name == 'yolo'
        assert dim.type == 'real'
        assert dim.shape == ()
github Epistimio / orion / tests / unittests / algo / test_tpe.py View on Github external
def test_1d_shape(self, tpe):
        """Test suggest with 1D shape dimensions"""
        space = Space()
        dim1 = Real('yolo1', 'uniform', -3, 6, shape=(2))
        space.register(dim1)
        dim2 = Real('yolo2', 'uniform', -2, 4)
        space.register(dim2)

        tpe.space = space

        tpe.n_initial_points = 10
        results = numpy.random.random(10)
        for i in range(10):
            point = tpe.suggest(1)
            assert len(point) == 1
            assert len(point[0]) == 2
            assert len(point[0][0]) == 2
            tpe.observe(point, [{'objective': results[i]}])

        point = tpe.suggest(1)
        assert len(point) == 1
        assert len(point[0]) == 2
github Epistimio / orion / tests / unittests / algo / test_asha.py View on Github external
def test_get_id_multidim(self, b_config):
        """Test valid id for points with dim of shape > 1"""
        space = Space()
        space.register(Fidelity('epoch', 1, 9, 3))
        space.register(Real('lr', 'uniform', 0, 1, shape=2))

        asha = ASHA(space, num_brackets=3)

        assert asha.get_id(['whatever', [1, 1]]) == asha.get_id(['is here', [1, 1]])
        assert asha.get_id(['whatever', [1, 1]]) != asha.get_id(['is here', [2, 2]])
github Epistimio / orion / src / orion / core / io / space_builder.py View on Github external
def _real_or_int(kwargs):
    return Integer if kwargs.pop('discrete', False) else Real