How to use the orion.algo.space.Dimension 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_get_prior_string(self):
        """Test that prior string can be rebuilt."""
        dim = Dimension('yolo', 'alpha', 1, 2, 3, some='args', plus='fluff', n=4)
        assert dim.get_prior_string() == 'alpha(1, 2, 3, some=\'args\', plus=\'fluff\', n=4)'
github Epistimio / orion / tests / unittests / core / evc / test_resolutions.py View on Github external
def test_adapters_without_default(self, missing_dimension_conflict):
        """Verify adapters without default value"""
        param = {'name': 'missing', 'type': 'real', 'value': Dimension.NO_DEFAULT_VALUE}
        resolution = missing_dimension_conflict.RemoveDimensionResolution(
            missing_dimension_conflict)
        resolution_adapters = resolution.get_adapters()
        assert len(resolution_adapters) == 1
        assert (resolution_adapters[0].configuration ==
                adapters.DimensionDeletion(param).configuration)
github Epistimio / orion / tests / unittests / core / test_transformer.py View on Github external
def test_mimics_Dimension(self, tdim):
        """Mimic `Dimension`.
        Set of `Dimension`'s methods are subset of `TransformedDimension`.
        """
        transformed_dimension_keys = set(TransformedDimension.__dict__.keys())
        # For some reason running all tests have the side-effect of adding an attribute
        # __slotnames__ to TransformedDimension. This attribute is not present when running
        # tests found in test_transformer.py only.
        transformed_dimension_keys.discard('__slotnames__')
        assert ((transformed_dimension_keys ^ set(Dimension.__dict__.keys())) ==
                set(['transform', 'reverse']))
github Epistimio / orion / tests / unittests / algo / test_space.py View on Github external
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)
github Epistimio / orion / tests / unittests / algo / test_space.py View on Github external
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
github Epistimio / orion / tests / unittests / algo / test_space.py View on Github external
def test_get_prior_string_default_values(self, monkeypatch):
        """Test that default_value are included."""
        def contains(self, value):
            return True
        monkeypatch.setattr(Dimension, '__contains__', contains)
        dim = Dimension('yolo', 'alpha', 1, 2, default_value=1)
        assert dim.get_prior_string() == 'alpha(1, 2, default_value=1)'
github Epistimio / orion / tests / unittests / algo / test_space.py View on Github external
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)
github Epistimio / orion / src / orion / core / worker / transformer.py View on Github external
if the number of supported integers to transform is larger than 2.
        """
        return tuple(list(shape) + [self.num_cats]) if self.num_cats > 2 else shape

    def _get_hashable_members(self):
        return super(OneHotEncode, self)._get_hashable_members() + (self.num_cats, )


# pylint:disable=too-many-public-methods
class TransformedDimension(object):
    """Duck-type `Dimension` to mimic its functionality,
    while transform automatically and appropriately an underlying `Dimension` object
    according to a `Transformer` object.
    """

    NO_DEFAULT_VALUE = Dimension.NO_DEFAULT_VALUE

    def __init__(self, transformer: Transformer, original_dimension: Dimension):
        """Initialize a `TransformedDimension` with an `original_dimension` object
        and the `transformer` that will be used.
        """
        self.original_dimension = original_dimension
        self.transformer = transformer

    def transform(self, point):
        """Expose `Transformer.transform` interface from underlying instance."""
        return self.transformer.transform(point)

    def reverse(self, transformed_point):
        """Expose `Transformer.reverse` interface from underlying instance."""
        return self.transformer.reverse(transformed_point)
github Epistimio / orion / src / orion / core / worker / transformer.py View on Github external
if the number of supported integers to transform is larger than 2.
        """
        return tuple(list(shape) + [self.num_cats]) if self.num_cats > 2 else shape

    def _get_hashable_members(self):
        return super(OneHotEncode, self)._get_hashable_members() + (self.num_cats, )


# pylint:disable=too-many-public-methods
class TransformedDimension(object):
    """Duck-type `Dimension` to mimic its functionality,
    while transform automatically and appropriately an underlying `Dimension` object
    according to a `Transformer` object.
    """

    NO_DEFAULT_VALUE = Dimension.NO_DEFAULT_VALUE

    def __init__(self, transformer: Transformer, original_dimension: Dimension):
        """Initialize a `TransformedDimension` with an `original_dimension` object
        and the `transformer` that will be used.
        """
        self.original_dimension = original_dimension
        self.transformer = transformer

    def transform(self, point):
        """Expose `Transformer.transform` interface from underlying instance."""
        return self.transformer.transform(point)

    def reverse(self, transformed_point):
        """Expose `Transformer.reverse` interface from underlying instance."""
        return self.transformer.reverse(transformed_point)