Dimension transformations

orion.core.worker.transformer – Perform transformations on Dimensions

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) Reverse transformation by reversing in the opposite order of the transformers list.
transform(point) Apply transformers in the increasing order of the transformers list.
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)[source]

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

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

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) Return categories corresponding to their positions inside transformed_point.
transform(point) Return integers corresponding uniquely to the categories in point.
reverse(transformed_point)[source]

Return categories corresponding to their positions inside transformed_point.

Return type:numpy.ndarray, numpy.object
transform(point)[source]

Return integers corresponding uniquely to the categories in point.

Return type:numpy.ndarray, integer
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.

target_type

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

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) Return transformed_point as it is.
transform(point) Return point as it is.
domain_type

Return declared domain type on initialization.

repr_format(what)[source]

Format a string for calling __repr__ in TransformedDimension.

reverse(transformed_point)[source]

Return transformed_point as it is.

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.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.
repr_format(what) Format a string for calling __repr__ in TransformedDimension.
reverse(transformed_point) 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)[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

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) 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)[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

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) Cast transformed_point to floats, as numpy arrays.
transform(point) Cast point to the floor and then to integers, as numpy arrays.
reverse(transformed_point)[source]

Cast transformed_point to floats, as numpy arrays.

transform(point)[source]

Cast point to the floor and then to integers, as numpy arrays.

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

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) Use transform of composed transformer.
transform(point) Use reserve of composed transformer.
domain_type

Return target_type of composed transformer.

repr_format(what)[source]

Format a string for calling __repr__ in TransformedDimension.

reverse(transformed_point)[source]

Use transform of composed transformer.

target_type

Return domain_type of composed transformer.

transform(point)[source]

Use reserve of composed transformer.

class orion.core.worker.transformer.TransformedDimension(transformer: orion.core.worker.transformer.Transformer, original_dimension: orion.algo.space.Dimension)[source]

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

Attributes:
NO_DEFAULT_VALUE
cardinality

Wrap original Dimension capacity

default_value

Wrap original default value.

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

cast(point) Cast a point according to original_dimension and then transform it
get_prior_string() Do not change the prior string of original dimension.
get_string() Do not change the string of original dimension.
interval([alpha]) Map the interval bounds to the transformed ones.
reverse(transformed_point) Expose Transformer.reverse interface from underlying instance.
sample([n_samples, seed]) Sample from the original dimension and forward transform them.
transform(point) Expose Transformer.transform interface from underlying instance.
validate() Validate original_dimension
cardinality

Wrap original Dimension capacity

cast(point)[source]

Cast a point according to original_dimension and then transform it

default_value

Wrap original default value.

get_prior_string()[source]

Do not change the prior string of original dimension.

get_string()[source]

Do not change the string of original dimension.

interval(alpha=1.0)[source]

Map the interval bounds to the transformed ones.

name

Do not change the name of the original dimension.

prior_name

Do not change the prior name of the original dimension.

reverse(transformed_point)[source]

Expose Transformer.reverse interface from underlying instance.

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

Sample from the original dimension and forward transform them.

shape

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

transform(point)[source]

Expose Transformer.transform interface from underlying instance.

type

Ask transformer which is its target class.

validate()[source]

Validate original_dimension

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

Wrap the Space to support transformation methods.

Attributes:
cardinality

Return the number of all all possible sets of samples in the space

configuration

Return a dictionary of priors.

Methods

clear()
contains alias of TransformedDimension
copy()
fromkeys(iterable[, value]) Create a new dictionary with keys from iterable and values set to value.
get(key[, default]) Return the value for key if key is in the dictionary, else default.
interval([alpha]) Return a list with the intervals for each contained dimension.
items() Return items sorted according to keys
keys() Return sorted keys
pop(k[,d]) If key is not found, d is returned if given, otherwise KeyError is raised
popitem() 2-tuple; but raise KeyError if D is empty.
register(dimension) Register a new dimension to Space.
reverse(transformed_point) Reverses transformation so that a point from this TransformedSpace to be in the original one.
sample([n_samples, seed]) Draw random samples from this space.
setdefault(key[, default]) Insert key with a value of default if key is not in the dictionary.
transform(point) Transform a point that was in the original space to be in this one.
update([E, ]**F) If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
values() Return values sorted according to keys
contains

alias of TransformedDimension

reverse(transformed_point)[source]

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

transform(point)[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.

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

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

Attributes:
domain_type
target_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) 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.

reverse(transformed_point)[source]

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

transform(point)[source]

Transform a point from domain dimension to the target dimension.

orion.core.worker.transformer.build_required_space(requirements, original_space)[source]

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

It uses appropriate cascade of Transformer objects per Dimension contained in original_space.

Parameters:
requirements : list of str or str

Describes requirements that an algorithm needs a parameter space to have in order to be able to operate on it. In case it is a list, the infered transformations are going to be applied from the first item in the list to the last.

original_space : orion.algo.space.Space

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