Dimension transformations

Perform transformations on Dimensions

Provide functions and classes to build a Space which an algorithm can operate on.

class orion.core.worker.transformer.Compose(transformers, base_domain_type=None)[source]

Initialize composite transformer with a list of Transformer objects and domain type on which it will be applied.

Attributes
domain_type

Return base domain type.

target_type

Infer type of the tranformation target.

Methods

infer_target_shape(shape)

Return the shape of the dimension after transformation.

interval([alpha])

Return interval of composed transformation.

repr_format(what)

Format a string for calling __repr__ in TransformedDimension.

reverse(transformed_point[, index])

Reverse transformation by reversing in the opposite order of the transformers list.

transform(point)

Apply transformers in the increasing order of the transformers list.

property domain_type

Return base domain type.

infer_target_shape(shape)[source]

Return the shape of the dimension after transformation.

interval(alpha=1.0)[source]

Return interval of composed transformation.

repr_format(what)[source]

Format a string for calling __repr__ in TransformedDimension.

reverse(transformed_point, index=None)[source]

Reverse transformation by reversing in the opposite order of the transformers list.

property target_type

Infer type of the tranformation target.

transform(point)[source]

Apply transformers in the increasing order of the transformers list.

class orion.core.worker.transformer.Enumerate(categories)[source]

Enumerate categories.

Effectively transform from a list of objects to a range of integers.

Methods

interval([alpha])

Return the interval for the enumerated choices.

reverse(transformed_point[, index])

Return categories corresponding to their positions inside transformed_point.

transform(point)

Return integers corresponding uniquely to the categories in point.

interval(alpha=1.0)[source]

Return the interval for the enumerated choices.

reverse(transformed_point, index=None)[source]

Return categories corresponding to their positions inside transformed_point.

transform(point)[source]

Return integers corresponding uniquely to the categories in point.

class orion.core.worker.transformer.Identity(domain_type=None)[source]

Implement an identity transformation. Everything as it is.

Attributes
domain_type

Return declared domain type on initialization.

first

Signals to ReshapedSpace whether this dimension should be used for reverse

target_type

Return domain type as this will be the target in a identity transformation.

Methods

repr_format(what)

Format a string for calling __repr__ in TransformedDimension.

reverse(transformed_point[, index])

Return transformed_point as it is.

transform(point)

Return point as it is.

property domain_type

Return declared domain type on initialization.

property first

Signals to ReshapedSpace whether this dimension should be used for reverse

repr_format(what)[source]

Format a string for calling __repr__ in TransformedDimension.

reverse(transformed_point, index=None)[source]

Return transformed_point as it is.

property target_type

Return domain type as this will be the target in a identity transformation.

transform(point)[source]

Return point as it is.

class orion.core.worker.transformer.Linearize[source]

Transform real numbers from loguniform to linear.

Methods

reverse(transformed_point[, index])

Turn linear distribution to logarithmic distribution.

transform(point)

Linearize logarithmic distribution.

reverse(transformed_point, index=None)[source]

Turn linear distribution to logarithmic distribution.

transform(point)[source]

Linearize logarithmic distribution.

class orion.core.worker.transformer.OneHotEncode(bound: int)[source]

Encode categories to a 1-hot integer space representation.

Methods

infer_target_shape(shape)

Infer that transformed points will have one more tensor dimension, if the number of supported integers to transform is larger than 2.

interval([alpha])

Return the interval for the one-hot encoding in proper shape.

reverse(transformed_point[, index])

Match real vector representations to integers using an argmax function.

transform(point)

Match a point containing integers to real vector representations of them.

infer_target_shape(shape)[source]

Infer that transformed points will have one more tensor dimension, if the number of supported integers to transform is larger than 2.

interval(alpha=1.0)[source]

Return the interval for the one-hot encoding in proper shape.

reverse(transformed_point, index=None)[source]

Match real vector representations to integers using an argmax function.

If the number of dimensions is exactly 2, then use 0.5 as a decision boundary, and convert representation to integers 0 or 1.

If the number of dimensions is exactly 1, then return zeros.

Note

This reverse transformation possibly removes the last tensor dimension from transformed_point.

transform(point)[source]

Match a point containing integers to real vector representations of them.

If the upper bound of integers supported by an instance of OneHotEncode is less or equal to 2, then cast them to floats.

Note

This transformation possibly appends one more tensor dimension to point.

class orion.core.worker.transformer.Precision(precision=4)[source]

Round real numbers to requested precision.

Methods

repr_format(what)

Format a string for calling __repr__ in TransformedDimension.

reverse(transformed_point[, index])

Cast transformed_point to floats, as numpy arrays.

transform(point)

Round point to the requested precision, as numpy arrays.

repr_format(what)[source]

Format a string for calling __repr__ in TransformedDimension.

reverse(transformed_point, index=None)[source]

Cast transformed_point to floats, as numpy arrays.

transform(point)[source]

Round point to the requested precision, as numpy arrays.

class orion.core.worker.transformer.Quantize[source]

Transform real numbers to integers, violating injection.

Methods

reverse(transformed_point[, index])

Cast transformed_point to floats, as numpy arrays.

transform(point)

Round point and then cast to integers, as numpy arrays.

reverse(transformed_point, index=None)[source]

Cast transformed_point to floats, as numpy arrays.

transform(point)[source]

Round point and then cast to integers, as numpy arrays.

class orion.core.worker.transformer.ReshapedDimension(transformer, original_dimension, index, name=None)[source]

Duck-type orion.algo.space.Dimension to mimic its functionality.

Attributes
cardinality

Compute cardinality

first

Signals to ReshapedSpace whether this dimension should be used for reverse

name

Name of the view

shape

Shape is fixed to ().

Methods

cast(point)

Cast a point according to original_dimension and then transform it

interval([alpha])

Map the interval bounds to the transformed ones.

reverse(transformed_point[, index])

Expose Transformer.reverse interface from underlying instance.

transform(point)

Expose Transformer.transform interface from underlying instance.

property cardinality

Compute cardinality

cast(point)[source]

Cast a point according to original_dimension and then transform it

property first

Signals to ReshapedSpace whether this dimension should be used for reverse

interval(alpha=1.0)[source]

Map the interval bounds to the transformed ones.

property name

Name of the view

reverse(transformed_point, index=None)[source]

Expose Transformer.reverse interface from underlying instance.

property shape

Shape is fixed to ().

transform(point)[source]

Expose Transformer.transform interface from underlying instance.

class orion.core.worker.transformer.ReshapedSpace(original_space, *args, **kwargs)[source]

Wrap the TransformedSpace to support reshape methods.

Attributes
cardinality

Reshape does not affect cardinality

original

Original space without reshape or transformations

Methods

contains

alias of orion.core.worker.transformer.ReshapedDimension

reshape(trial)

Reshape the point

restore_shape(transformed_trial)

Restore shape.

reverse(transformed_trial)

Reverses transformation so that a point from this ReshapedSpace to be in the original one.

sample([n_samples, seed])

Sample from the original dimension and forward transform them.

transform(trial)

Transform a point that was in the original space to be in this one.

property cardinality

Reshape does not affect cardinality

contains

alias of orion.core.worker.transformer.ReshapedDimension

property original

Original space without reshape or transformations

reshape(trial)[source]

Reshape the point

restore_shape(transformed_trial)[source]

Restore shape.

reverse(transformed_trial)[source]

Reverses transformation so that a point from this ReshapedSpace to be in the original one.

sample(n_samples=1, seed=None)[source]

Sample from the original dimension and forward transform them.

transform(trial)[source]

Transform a point that was in the original space to be in this one.

class orion.core.worker.transformer.Reverse(transformer: orion.core.worker.transformer.Transformer)[source]

Apply the reverse transformation that another one would do.

Attributes
domain_type

Return target_type of composed transformer.

target_type

Return domain_type of composed transformer.

Methods

repr_format(what)

Format a string for calling __repr__ in TransformedDimension.

reverse(transformed_point[, index])

Use transform of composed transformer.

transform(point)

Use reserve of composed transformer.

property domain_type

Return target_type of composed transformer.

repr_format(what)[source]

Format a string for calling __repr__ in TransformedDimension.

reverse(transformed_point, index=None)[source]

Use transform of composed transformer.

property target_type

Return domain_type of composed transformer.

transform(point)[source]

Use reserve of composed transformer.

class orion.core.worker.transformer.TransformedDimension(transformer, original_dimension)[source]

Duck-type orion.algo.space.Dimension to mimic its functionality, while transform automatically and appropriately an underlying orion.algo.space.Dimension object according to a Transformer object.

Attributes
NO_DEFAULT_VALUE
cardinality

Wrap original orion.algo.space.Dimension capacity

default_value

Return the default value for this dimensions

name

Do not change the name of the original dimension.

prior_name

Do not change the prior name of the original dimension.

shape

Wrap original shape with transformer, because it may have changed.

type

Ask transformer which is its target class.

Methods

interval([alpha])

Map the interval bounds to the transformed ones.

reverse(transformed_point[, index])

Expose Transformer.reverse interface from underlying instance.

transform(point)

Expose Transformer.transform interface from underlying instance.

validate()

Validate original_dimension

property cardinality

Wrap original orion.algo.space.Dimension capacity

property default_value

Return the default value for this dimensions

interval(alpha=1.0)[source]

Map the interval bounds to the transformed ones.

property name

Do not change the name of the original dimension.

property prior_name

Do not change the prior name of the original dimension.

reverse(transformed_point, index=None)[source]

Expose Transformer.reverse interface from underlying instance.

property shape

Wrap original shape with transformer, because it may have changed.

transform(point)[source]

Expose Transformer.transform interface from underlying instance.

property type

Ask transformer which is its target class.

validate()[source]

Validate original_dimension

class orion.core.worker.transformer.TransformedSpace(space, *args, **kwargs)[source]

Wrap the orion.algo.space.Space to support transformation methods.

Methods

contains

alias of orion.core.worker.transformer.TransformedDimension

reverse(transformed_trial)

Reverses transformation so that a point from this TransformedSpace to be in the original one.

sample([n_samples, seed])

Sample from the original dimension and forward transform them.

transform(trial)

Transform a point that was in the original space to be in this one.

contains

alias of orion.core.worker.transformer.TransformedDimension

reverse(transformed_trial)[source]

Reverses transformation so that a point from this TransformedSpace to be in the original one.

sample(n_samples=1, seed=None)[source]

Sample from the original dimension and forward transform them.

transform(trial)[source]

Transform a point that was in the original space to be in this one.

class orion.core.worker.transformer.Transformer[source]

Define an (injective) function and its inverse. Base transformation class.

Attributes
target_type: str

Defines the type of the target space of the forward function. It can provide one of the values: ['real', 'integer', 'categorical'].

domain_type: str

Is similar to target_type but it refers to the domain. If it is None, then it can receive inputs of any type.

Methods

infer_target_shape(shape)

Return the shape of the dimension after transformation.

repr_format(what)

Format a string for calling __repr__ in TransformedDimension.

reverse(transformed_point[, index])

Reverse transform a point from target dimension to the domain dimension.

transform(point)

Transform a point from domain dimension to the target dimension.

infer_target_shape(shape)[source]

Return the shape of the dimension after transformation.

repr_format(what)[source]

Format a string for calling __repr__ in TransformedDimension.

abstract reverse(transformed_point, index=None)[source]

Reverse transform a point from target dimension to the domain dimension.

abstract transform(point)[source]

Transform a point from domain dimension to the target dimension.

class orion.core.worker.transformer.View(shape, index, domain_type=None)[source]

Look-up single index in a dimensions with shape > 1

Attributes
domain_type

Return declared domain type on initialization.

first

Signals to ReshapedSpace whether this dimension should be used for reverse

target_type

Return domain type as this will be the target in flatten transformation.

Methods

interval(interval)

Return corresponding view from interval

repr_format(what)

Format a string for calling __repr__ in TransformedDimension.

reverse(transformed_point[, index])

Only return packend point if view of first element, otherwise drop.

transform(point)

Only return one element of the group

property domain_type

Return declared domain type on initialization.

property first

Signals to ReshapedSpace whether this dimension should be used for reverse

interval(interval)[source]

Return corresponding view from interval

repr_format(what)[source]

Format a string for calling __repr__ in TransformedDimension.

reverse(transformed_point, index=None)[source]

Only return packend point if view of first element, otherwise drop.

property target_type

Return domain type as this will be the target in flatten transformation.

transform(point)[source]

Only return one element of the group

orion.core.worker.transformer.build_required_space(original_space, type_requirement=None, shape_requirement=None, dist_requirement=None)[source]

Build a orion.algo.space.Space object which agrees to the requirements imposed by the desired optimization algorithm.

It uses appropriate cascade of Transformer objects per orion.algo.space.Dimension contained in original_space. ReshapedTransformer objects are used above the Transformer if the optimizatios algorithm requires flattened dimensions.

Parameters
original_spaceorion.algo.space.Space

Original problem’s definition of parameter space given by the user to Oríon.

type_requirement: str, None

String defining the requirement of the algorithm. It can be one of the following - ‘real’, the dim should be transformed so type is orion.algo.space.Real - ‘integer’, the dim should be transformed so type is orion.algo.space.Integer - ‘numerical’, the dim should be transformed so type is either orion.algo.space.Integer or orion.algo.space.Real - None, no requirement

shape_requirement: str, None

String defining the shape requirement of the algorithm. - ‘flattened’, any dimension with shape > 1 will be flattened - None, no requirement

dist_requirement: str, None

String defining the distribution requirement of the algorithm. - ‘linear’, any dimension with logarithmic prior while be linearized - None, no requirement

orion.core.worker.transformer.build_transform(dim, type_requirement, dist_requirement)[source]
orion.core.worker.transformer.build_transform(dim: orion.algo.space.Categorical, type_requirement, dist_requirement)
orion.core.worker.transformer.build_transform(dim: orion.algo.space.Fidelity, type_requirement, dist_requirement)
orion.core.worker.transformer.build_transform(dim: orion.algo.space.Integer, type_requirement, dist_requirement)
orion.core.worker.transformer.build_transform(dim: orion.algo.space.Real, type_requirement, dist_requirement)

Base transformation factory

Parameters
dim: `orion.algo.space.Dimension`

A dimension object which may need transformations to match provided requirements.

type_requirement: str, None

String defining the requirement of the algorithm. It can be one of the following - ‘real’, the dim should be transformed so type is orion.algo.space.Real - ‘integer’, the dim should be transformed so type is orion.algo.space.Integer - ‘numerical’, the dim should be transformed so type is either orion.algo.space.Integer or orion.algo.space.Real - None, no requirement

dist_requirement: str, None

String defining the distribution requirement of the algorithm. - ‘linear’, any dimension with logarithmic prior while be linearized - None, no requirement

orion.core.worker.transformer.change_trial_params(trial, point, space)[source]

Convert params in Param objects and update trial

orion.core.worker.transformer.reshape(space, shape_requirement)[source]

Build a reshaped space

orion.core.worker.transformer.transform(original_space, type_requirement, dist_requirement)[source]

Build a transformed space