CADETProcess.transform.TransformerBase#
- 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]#
Bases:
ABCBase 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.ndarrayLower bounds of the input parameter space.
ub_inputfloat or np.ndarrayUpper bounds of the input parameter space.
lbfloat or np.ndarrayLower bounds of the output parameter space.
ubfloat or np.ndarrayUpper 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.
- 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.