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[, 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. -
domain_type¶ Return base domain type.
-
repr_format(what)[source]¶ Format a string for calling
__repr__inTransformedDimension.
-
reverse(transformed_point, index=None)[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. interval([alpha])Return the interval for the enumerated choices. repr_format(what)Format a string for calling __repr__inTransformedDimension.reverse(transformed_point[, index])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.
firstSignals to ReshapedSpace whether this dimension should be used for
reversetarget_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[, index])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.Linearize[source]¶ Transform real numbers from loguniform to linear.
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[, index])Turn linear distribution to logarithmic distribution. transform(point)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. repr_format(what)Format a string for calling __repr__inTransformedDimension.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.
-
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
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[, 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__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[, index])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.ReshapedDimension(transformer, original_dimension, index, name=None)[source]¶ Duck-type
Dimensionto mimic its functionality.Attributes: - NO_DEFAULT_VALUE
cardinalityCompute cardinality
firstSignals to ReshapedSpace whether this dimension should be used for
reversenameName of the view
prior_nameDo not change the prior name of the original dimension.
shapeShape is fixed to ().
typeAsk transformer which is its target class.
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.reverseinterface from underlying instance.transform(point)Expose Transformer.transforminterface from underlying instance.validate()Validate original_dimension -
cardinality¶ Compute cardinality
-
name¶ Name of the view
-
reverse(transformed_point, index=None)[source]¶ Expose
Transformer.reverseinterface from underlying instance.
-
shape¶ Shape is fixed to ().
-
transform(point)[source]¶ Expose
Transformer.transforminterface from underlying instance.
-
class
orion.core.worker.transformer.ReshapedSpace(original_space, *args, **kwargs)[source]¶ Wrap the
TransformedSpaceto support reshape methods.Attributes: cardinalityReshape does not affect cardinality
configurationReturn a dictionary of priors.
originalOriginal space without reshape or transformations
Methods
clear()containsalias of ReshapedDimensioncopy()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.reshape(point)Reshape the point restore_shape(transformed_point)Restore shape reverse(transformed_point)Reverses transformation so that a point from this ReshapedSpaceto be in the original one.sample([n_samples, seed])Sample from the original dimension and forward transform them. 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 -
cardinality¶ Reshape does not affect cardinality
-
contains¶ alias of
ReshapedDimension
-
original¶ Original space without reshape or transformations
-
reverse(transformed_point)[source]¶ Reverses transformation so that a point from this
ReshapedSpaceto be in the original 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_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[, index])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, original_dimension)[source]¶ Duck-type
Dimensionto mimic its functionality, while transform automatically and appropriately an underlyingDimensionobject according to aTransformerobject.Attributes: - NO_DEFAULT_VALUE
cardinalityWrap original
DimensioncapacitynameDo 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
interval([alpha])Map the interval bounds to the transformed ones. reverse(transformed_point[, index])Expose Transformer.reverseinterface from underlying instance.transform(point)Expose Transformer.transforminterface from underlying instance.validate()Validate original_dimension -
cardinality¶ Wrap original
Dimensioncapacity
-
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, index=None)[source]¶ Expose
Transformer.reverseinterface from underlying instance.
-
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(space, *args, **kwargs)[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])Sample from the original dimension and forward transform them. 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[, index])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.
-
class
orion.core.worker.transformer.View(shape, index, domain_type=None)[source]¶ Look-up single index in a dimensions with shape > 1
Attributes: domain_typeReturn declared domain type on initialization.
firstSignals to ReshapedSpace whether this dimension should be used for
reversetarget_typeReturn domain type as this will be the target in flatten transformation.
Methods
infer_target_shape(shape)Return the shape of the dimension after transformation. interval(interval)Return corresponding view from interval repr_format(what)Format a string for calling __repr__inTransformedDimension.reverse(transformed_point[, index])Only return packend point if view of first element, otherwise drop. transform(point)Only return one element of the group -
domain_type¶ Return declared domain type on initialization.
-
repr_format(what)[source]¶ Format a string for calling
__repr__inTransformedDimension.
-
reverse(transformed_point, index=None)[source]¶ Only return packend point if view of first element, otherwise drop.
-
target_type¶ Return domain type as this will be the target in flatten transformation.
-
orion.core.worker.transformer.build_required_space(original_space, type_requirement=None, shape_requirement=None, dist_requirement=None)[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. ReshapedTransformer objects are used above theTransformerif the optimizatios algorithm requires flattened dimensions.Parameters: - original_space :
orion.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
Real- ‘integer’, the dim should be transformed so type isInteger- ‘numerical’, the dim should be transformed so type is eitherIntegerorReal- 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
- original_space :
-
orion.core.worker.transformer.build_transform(dim, type_requirement, dist_requirement)[source]¶ 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
Real- ‘integer’, the dim should be transformed so type isInteger- ‘numerical’, the dim should be transformed so type is eitherIntegerorReal- 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