Transform (CADETProcess.transform)#

This module provides functionality for transforming data.

TransformerBase([lb_input, ub_input, ...])

Base class for parameter transformation.

NullTransformer([lb_input, ub_input, ...])

A transformer that performs no transformation.

NormLinearTransformer([lb_input, ub_input, ...])

A transformer that normalizes values linearly to the range [0, 1].

NormLogTransformer([lb_input, ub_input, ...])

A transformer that normalizes values logarithmically to the range [0, 1].

AutoTransformer(*args[, threshold])

A transformer that automatically selects between linear and logarithmic transformations.

class CADETProcess.transform.AutoTransformer(*args: Any, threshold: int = 100, **kwargs: Any)[source]#

A transformer that automatically selects between linear and logarithmic transformations.

Transforms the input value to the range [0, 1] using either the NormLinearTransformer or the NormLogTransformer based on the input parameter space.

Attributes:
linearNormLinearTransformer

Instance of the linear normalization transform.

logNormLogTransformer

Instance of the logarithmic normalization transform.

thresholdint

The maximum threshold to switch from linear to logarithmic transformation.

Methods

plot([use_log_scale, ax, setup_figure_kwargs])

Plot the transformed space against the input space.

transform(x)

Transform the input parameter space to the output parameter space.

untransform(x[, significant_digits])

Transform the output parameter space back to the input parameter space.

property is_linear: bool#

Return True if linear transformation is used, otherwise False.

property lb: float#

Return the lower bound of the output parameter space (0).

property lb_input: float | ndarray#

Return the lower bounds of the input parameter space.

property ub: float#

Return the upper bound of the output parameter space (1).

property ub_input: float | ndarray#

Return the upper bounds of the input parameter space.

property use_linear: bool#

Determine whether linear transformation should be used.

property use_log: bool#

Return True if logarithmic transformation is used, otherwise False.

class CADETProcess.transform.NormLinearTransformer(lb_input: float | ndarray = -inf, ub_input: float | ndarray = inf, allow_extended_input: bool | None = False, allow_extended_output: bool | None = False)[source]#

A transformer that normalizes values linearly to the range [0, 1].

This transformation scales the input value between the given lower and upper bounds into a normalized range of [0,1].

Attributes:
is_linear

Return True, as this is a linear transformation.

lb

Return the lower bound of the output space (0).

lb_input

Return the lower bounds of the input parameter space.

ub

Return the upper bound of the output space (1).

ub_input

Return the upper bounds of the input parameter space.

Methods

plot([use_log_scale, ax, setup_figure_kwargs])

Plot the transformed space against the input space.

transform(x)

Transform the input parameter space to the output parameter space.

untransform(x[, significant_digits])

Transform the output parameter space back to the input parameter space.

See also

TransformerBase

The base class for parameter transformation.

property is_linear: bool#

Return True, as this is a linear transformation.

property lb: float#

Return the lower bound of the output space (0).

property ub: float#

Return the upper bound of the output space (1).

class CADETProcess.transform.NormLogTransformer(lb_input: float | ndarray = -inf, ub_input: float | ndarray = inf, allow_extended_input: bool | None = False, allow_extended_output: bool | None = False)[source]#

A transformer that normalizes values logarithmically to the range [0, 1].

This transformation scales input values logarithmically between the given lower and upper bounds into a normalized range of [0,1].

Attributes:
is_linear

Return False, as this is a non-linear transformation.

lb

Return the lower bound of the output space (0).

lb_input

Return the lower bounds of the input parameter space.

ub

Return the upper bound of the output space (1).

ub_input

Return the upper bounds of the input parameter space.

Methods

plot([use_log_scale, ax, setup_figure_kwargs])

Plot the transformed space against the input space.

transform(x)

Transform the input parameter space to the output parameter space.

untransform(x[, significant_digits])

Transform the output parameter space back to the input parameter space.

See also

TransformerBase

The base class for parameter transformation.

property is_linear: bool#

Return False, as this is a non-linear transformation.

property lb: float#

Return the lower bound of the output space (0).

property ub: float#

Return the upper bound of the output space (1).

class CADETProcess.transform.NullTransformer(lb_input: float | ndarray = -inf, ub_input: float | ndarray = inf, allow_extended_input: bool | None = False, allow_extended_output: bool | None = False)[source]#

A transformer that performs no transformation.

This class simply returns the input values as output without modification.

Attributes:
is_linear

Return True, as this is a linear transformation.

lb

Return the lower bound of the output space (same as input lower bound).

lb_input

Return the lower bounds of the input parameter space.

ub

Return the upper bound of the output space (same as input upper bound).

ub_input

Return the upper bounds of the input parameter space.

Methods

plot([use_log_scale, ax, setup_figure_kwargs])

Plot the transformed space against the input space.

transform(x)

Transform the input parameter space to the output parameter space.

untransform(x[, significant_digits])

Transform the output parameter space back to the input parameter space.

See also

TransformerBase

The base class for parameter transformation.

property is_linear: bool#

Return True, as this is a linear transformation.

property lb: float | ndarray#

Return the lower bound of the output space (same as input lower bound).

property ub: float | ndarray#

Return the upper bound of the output space (same as input upper bound).

class CADETProcess.transform.TransformerBase(lb_input: float | ndarray = -inf, ub_input: float | ndarray = inf, allow_extended_input: bool | None = False, allow_extended_output: bool | None = False)[source]#

Base class for parameter transformation.

This class provides an interface for transforming an input parameter space to some output parameter space.

Attributes:
lb_inputfloat or np.ndarray

Return the lower bounds of the input parameter space.

ub_inputfloat or np.ndarray

Return the upper bounds of the input parameter space.

lbfloat or np.ndarray

Return the lower bounds of the output parameter space.

ubfloat or np.ndarray

Return the upper bounds of the output parameter space.

allow_extended_inputbool

If True, the input value may exceed the lower/upper bounds. Else, an exception is thrown.

allow_extended_outputbool

If True, the output value may exceed the lower/upper bounds. Else, an exception is thrown.

Methods

plot([use_log_scale, ax, setup_figure_kwargs])

Plot the transformed space against the input space.

transform(x)

Transform the input parameter space to the output parameter space.

untransform(x[, significant_digits])

Transform the output parameter space back to the input parameter space.

Raises:
ValueError

If lb_input and ub_input have different shapes.

Notes

  • This is an abstract base class and cannot be instantiated directly.

  • The transform method must be implemented by a subclass.

Examples

>>> class MyTransformer(TransformerBase):
...     def transform(self, x: float) -> float:
...         return x ** 2
...
>>> t = MyTransformer(lb_input=0, ub_input=10, lb=-100, ub=100)
>>> t.transform(3)
9
abstract property is_linear: bool#

Return whether the transformation is linear.

abstract property lb: float | ndarray#

Return the lower bounds of the output parameter space.

property lb_input: float | ndarray#

Return the lower bounds of the input parameter space.

plot(use_log_scale: bool = False, ax: Axes | None = None, setup_figure_kwargs: dict | None = None) tuple[Figure, Axes][source]#

Plot the transformed space against the input space.

Parameters:
use_log_scalebool, optional

If True, use a logarithmic scale for the x-axis.

axOptional[plt.Axes], default=None

Optional Matplotlib Axes. If not provided, a new figure is created.

setup_figure_kwargsOptional[dict], default=None

Additional options to setup the figure.

Returns:
tuple[plt.Figure, plt.Axes]

The Matplotlib Figure and Axes.

transform(x: float | ndarray) float | ndarray[source]#

Transform the input parameter space to the output parameter space.

Applies the transformation function _transform to x after performing input bounds checking. If the transformed value exceeds the output bounds, an error is raised.

Parameters:
xfloat or np.ndarray

Input parameter values.

Returns:
float or np.ndarray

Transformed parameter values.

Raises:
ValueError

If x exceeds input or output bounds and allow_extended_* is False.

abstract property ub: float | ndarray#

Return the upper bounds of the output parameter space.

property ub_input: float | ndarray#

Return the upper bounds of the input parameter space.

untransform(x: float | ndarray, significant_digits: int | None = None) float | ndarray[source]#

Transform the output parameter space back to the input parameter space.

Parameters:
xfloat or np.ndarray

Output parameter values.

significant_digitsint, optional

float | np.ndarray of significant figures to which variable can be rounded. If None, variable is not rounded.

Returns:
float or np.ndarray

Transformed parameter values.