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
Transformerobjects and domain type on which it will be applied.Attributes: domain_typeReturn base domain type.
target_typeInfer 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__inTransformedDimension.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.
-
repr_format(what)[source]¶ Format a string for calling
__repr__inTransformedDimension.
-
reverse(transformed_point)[source]¶ Reverse transformation by reversing in the opposite order of the transformers list.
-
target_type¶ Infer type of the tranformation target.
-
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__inTransformedDimension.reverse(transformed_point)Return categories corresponding to their positions inside transformed_point. transform(point)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_typeReturn declared domain type on initialization.
target_typeReturn 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__inTransformedDimension.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__inTransformedDimension.
-
target_type¶ Return domain type as this will be the target in a identity transformation.
-
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__inTransformedDimension.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.
-
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
OneHotEncodeis 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__inTransformedDimension.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__inTransformedDimension.
-
-
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__inTransformedDimension.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.
-
class
orion.core.worker.transformer.Reverse(transformer: orion.core.worker.transformer.Transformer)[source]¶ Apply the reverse transformation that another one would do.
Attributes: domain_typeReturn
target_typeof composed transformer.target_typeReturn
domain_typeof composed transformer.
Methods
infer_target_shape(shape)Return the shape of the dimension after transformation. repr_format(what)Format a string for calling __repr__inTransformedDimension.reverse(transformed_point)Use transformof composed transformer.transform(point)Use reserve of composed transformer. -
domain_type¶ Return
target_typeof composed transformer.
-
repr_format(what)[source]¶ Format a string for calling
__repr__inTransformedDimension.
-
target_type¶ Return
domain_typeof composed transformer.
-
class
orion.core.worker.transformer.TransformedDimension(transformer: orion.core.worker.transformer.Transformer, original_dimension: orion.algo.space.Dimension)[source]¶ Duck-type
Dimensionto mimic its functionality, while transform automatically and appropriately an underlyingDimensionobject according to aTransformerobject.Attributes: - NO_DEFAULT_VALUE
cardinalityWrap original
Dimensioncapacitydefault_valueWrap original default value.
nameDo not change the name of the original dimension.
prior_nameDo not change the prior name of the original dimension.
shapeWrap original shape with transformer, because it may have changed.
typeAsk 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.reverseinterface from underlying instance.sample([n_samples, seed])Sample from the original dimension and forward transform them. transform(point)Expose Transformer.transforminterface from underlying instance.validate()Validate original_dimension -
cardinality¶ Wrap original
Dimensioncapacity
-
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.
-
reverse(transformed_point)[source]¶ Expose
Transformer.reverseinterface 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.transforminterface from underlying instance.
-
type¶ Ask transformer which is its target class.
-
class
orion.core.worker.transformer.TransformedSpace[source]¶ Wrap the
Spaceto support transformation methods.Attributes: cardinalityReturn the number of all all possible sets of samples in the space
configurationReturn a dictionary of priors.
Methods
clear()containsalias of TransformedDimensioncopy()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 TransformedSpaceto 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
TransformedSpaceto be in the original one.
-
class
orion.core.worker.transformer.Transformer[source]¶ Define an (injective) function and its inverse. Base transformation class.
target_typedefines the type of the target space of the forward function. It can provide one of the values:['real', 'integer', 'categorical'].domain_typeis similar totarget_typebut it refers to the domain. If it isNone, 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__inTransformedDimension.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. -
repr_format(what)[source]¶ Format a string for calling
__repr__inTransformedDimension.
-
orion.core.worker.transformer.build_required_space(requirements, original_space)[source]¶ Build a
Spaceobject which agrees to the requirements imposed by the desired optimization algorithm.It uses appropriate cascade of
Transformerobjects perDimensioncontained 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.