Transform (CADETProcess.transform)#
This module provides functionality for transforming data.
|
Base class for parameter transformation. |
|
A transformer that performs no transformation. |
|
A transformer that normalizes values linearly to the range [0, 1]. |
|
A transformer that normalizes values logarithmically to the range [0, 1]. |
|
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
NormLinearTransformeror theNormLogTransformerbased 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.
- 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:
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
TransformerBaseThe base class for parameter transformation.
- 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:
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
TransformerBaseThe base class for parameter transformation.
- 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_linearReturn True, as this is a linear transformation.
lbReturn the lower bound of the output space (same as input lower bound).
lb_inputReturn the lower bounds of the input parameter space.
ubReturn the upper bound of the output space (same as input upper bound).
ub_inputReturn 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
TransformerBaseThe base class for parameter transformation.
- 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.ndarrayReturn the lower bounds of the input parameter space.
ub_inputfloat or np.ndarrayReturn the upper bounds of the input parameter space.
lbfloat or np.ndarrayReturn the lower bounds of the output parameter space.
ubfloat or np.ndarrayReturn 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
- 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.
- 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.