Multistep¶
- class pumas.desirability.multistep.MultiStep(params: Dict[str, Any] | None = None)[source]¶
- compute_numeric(x: int | float) float[source]¶
Compute the multistep desirability for a numeric input.
- Parameters:
x (Union[int, float]) – The numeric input value.
- Returns:
The computed desirability value.
- Return type:
float
- Raises:
InvalidParameterTypeError – If the input is not a float.
ParameterValueNotSet – If any required parameter is not set.
- compute_ufloat(x: AffineScalarFunc) AffineScalarFunc[source]¶
Compute the multistep desirability for an uncertain float input.
- Parameters:
x (UFloat) – The uncertain float input value.
- Returns:
The computed desirability value with uncertainty.
- Return type:
UFloat
- Raises:
InvalidParameterTypeError – If the input is not a UFloat.
ParameterValueNotSet – If any required parameter is not set.
- name: ClassVar[str] = 'multistep'¶
MultiStep desirability function implementation.
This class implements a multistep desirability function with linear interpolation between defined points. It provides methods to compute the desirability for both numeric and uncertain float inputs.
The multistep function is defined by a set of coordinates (x_i, y_i), where: - x_i represents the input values (independent variable) - y_i represents the corresonding desirability values (dependent variable) - The coordinates are ordered such that x_1 < x_2 < … < x_n - Each y_i must be in the range [0, 1]
Let (x_1, y_1) be the first point and (x_n, y_n) be the last point in the ordered set.
The multistep desirability function D(x) is defined as follows:
\[\begin{split}D(x) = \begin{cases} y_1 & \text{if } x \leq x_1 \\ y_n & \text{if } x \geq x_n \\ y_i + \frac{x - x_i}{x_{i+1} - x_i}(y_{i+1} - y_i) & \text{if } x_i < x < x_{i+1} \end{cases}\end{split}\]Where:
For x ≤ x_1, the function returns the desirability of the first point (y_1)
For x ≥ x_n, the function returns the desirability of the last point (y_n)
For x_i < x < x_{i+1}, linear interpolation is performed between the two closest points
The interpolation ensures a smooth transition between defined points while maintaining the step-like behavior at the specified coordinates.
Finally, the shift is applied:
\[D_{final}(x) = D(x) \cdot (1 - shift) + shift\]- Parameters:
params (Optional[Dict[str, Any]]) – Initial parameters for the multistep function.
- Content of params:
coordinates (Iterable[Tuple[float, float]]): The coordinates defining the multistep function. Each tuple contains (x, y) values. shift (float): Vertical shift of the function, range [0.0, 1.0], default 0.0.
- Raises:
InvalidCoordinateError – If the coordinates list is empty.
InvalidCoordinateError – If only one coordinate is provided (at least two are required).
InvalidCoordinateError – If any y-coordinate is not between 0 and 1.
InvalidCoordinateError – If any coordinate cannot be converted to a valid Point object (internal representation of coordinates).
Usage Example:
>>> from pumas.desirability import desirability_catalogue
>>> desirability_class = desirability_catalogue.get("multistep")
>>> coords = [(0, 0), (1, 0.5), (4, 1)] >>> params = {"coordinates": coords, "shift": 0.0} >>> desirability = desirability_class(params=params) >>> print(desirability.get_parameters_values()) {'coordinates': [(0, 0), (1, 0.5), (4, 1)], 'shift': 0.0}
>>> result = desirability.compute_numeric(x=-1.0) >>> print(f"{result:.2f}") 0.00
>>> result = desirability.compute_numeric(x=0.5) >>> print(f"{result:.2f}") 0.25
>>> result = desirability.compute_numeric(x=2.5) >>> print(f"{result:.2f}") 0.75
>>> result = desirability.compute_numeric(x=5.0) >>> print(f"{result:.2f}") 1.00
- class pumas.desirability.multistep.multistep(x: float | AffineScalarFunc, coordinates: List[Tuple[float, float]], shift: float = 0.0)[source]¶
Compute the multistep desirability value for a given input.
- Parameters:
x (Union[float, UFloat]) – The input value.
coordinates (Iterable[Tuple[float, float]]) – The coordinates defining the multistep function.
shift (float, optional) – Vertical shift of the function. Defaults to 0.0.
- Returns:
The computed desirability value.
- Return type:
Union[float, UFloat]
- class pumas.desirability.multistep.interpolate(x: float | AffineScalarFunc, p1: Point, p2: Point)[source]¶
Perform linear interpolation between two points.
- Parameters:
x (Union[float, UFloat]) – The x-value to interpolate.
p1 (Point) – The first point.
p2 (Point) – The second point.
- Returns:
The interpolated y-value.
- Return type:
Union[float, UFloat]
Parameter Analysis¶
(Source code, png, hires.png, pdf)