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 transformation 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.
- property 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.
- property target_type¶
Infer type of the transformation target.
- 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.
- 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__
inTransformedDimension
.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.
- repr_format(what)[source]¶
Format a string for calling
__repr__
inTransformedDimension
.
- property 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
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.
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
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__
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
reverse
(transformed_point[, index])Cast transformed_point to floats, as numpy arrays.
transform
(point)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
- 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.- Parameters
- space: `orion.core.worker.TransformedSpace`
Transformed version of the orinigal problem’s definition of parameter space.
- Attributes
cardinality
Reshape does not affect cardinality
original
Original space without reshape or transformations
Methods
assert_contains
(trial)Check if the trial or key is contained inside the space, if not an exception is raised
alias of
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.
- assert_contains(trial)[source]¶
Check if the trial or key is contained inside the space, if not an exception is raised
- Raises
- TypeError when a dimension is not compatible with the space
- property cardinality¶
Reshape does not affect cardinality
- contains¶
alias of
ReshapedDimension
- property original¶
Original space without reshape or transformations
- reverse(transformed_trial: Trial) Trial [source]¶
Reverses transformation so that a point from this
ReshapedSpace
to be in the original one.
- class orion.core.worker.transformer.Reverse(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__
inTransformedDimension
.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__
inTransformedDimension
.
- property target_type¶
Return
domain_type
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 underlyingorion.algo.space.Dimension
object according to aTransformer
object.- Attributes
- NO_DEFAULT_VALUE
cardinality
Wrap original
orion.algo.space.Dimension
capacitydefault_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
- 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.
- class orion.core.worker.transformer.TransformedSpace(space, *args, **kwargs)[source]¶
Wrap the
orion.algo.space.Space
to support transformation methods.- Parameters
- space: `orion.algo.space.Space`
Original problem’s definition of parameter space.
Methods
alias of
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
TransformedDimension
- reverse(transformed_trial: Trial) Trial [source]¶
Reverses transformation so that a point from this
TransformedSpace
to be in the original 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 isNone
, 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__
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_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__
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
- property 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.
- property 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
orion.algo.space.Space
object which agrees to the requirements imposed by the desired optimization algorithm.It uses appropriate cascade of
Transformer
objects perorion.algo.space.Dimension
contained in original_space. ReshapedTransformer objects are used above theTransformer
if 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
orion.algo.space.Real
- ‘integer’, the dim should be transformed so type isorion.algo.space.Integer
- ‘numerical’, the dim should be transformed so type is eitherorion.algo.space.Integer
ororion.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
- original_space
- orion.core.worker.transformer.build_transform(dim, type_requirement, dist_requirement)[source]¶
- orion.core.worker.transformer.build_transform(dim: Categorical, type_requirement, dist_requirement)
- orion.core.worker.transformer.build_transform(dim: Fidelity, type_requirement, dist_requirement)
- orion.core.worker.transformer.build_transform(dim: Integer, type_requirement, dist_requirement)
- orion.core.worker.transformer.build_transform(dim: 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 isorion.algo.space.Integer
- ‘numerical’, the dim should be transformed so type is eitherorion.algo.space.Integer
ororion.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