Double Sigmoid¶
- class pumas.desirability.double_sigmoid.DoubleSigmoid(params: Dict[str, Any] | None = None)[source]¶
- compute_numeric(x: int | float) float[source]¶
Compute the double sigmoid 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 double sigmoid 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] = 'double_sigmoid'¶
Double Sigmoid desirability function implementation.
This class implements a double sigmoid desirability function with adjustable parameters. It provides methods to compute the desirability for both numeric and uncertain float inputs.
The double sigmoid function combines two sigmoid functions to create a plateau of high desirability between low and high, with smooth transitions on both sides.
Mathematical Definition:
The double sigmoid function is defined as:
\[\begin{split}F(x) = \begin{cases} S_1(x) & \text{if } x < x_{center} \\ 1 - S_2(x) & \text{if } x \geq x_{center} \end{cases}\end{split}\]where:
\[ \begin{align}\begin{aligned}S_1(x) = \frac{1}{1 + base^{-\frac{10 \cdot coef_{si}}{coef_{div}} \cdot (x - low)}}\\S_2(x) = \frac{1}{1 + base^{-\frac{10 \cdot coef_{se}}{coef_{div}} \cdot (x - high)}}\\x_{center} = \frac{high + low}{2}\end{aligned}\end{align} \]If invert is True, the function becomes:
\[D_{inverted}(x) = 1 - D(x)\]Finally, the shift is applied:
\[D_{final}(x) = D(x) \cdot (1 - shift) + shift\]- Parameters:
params (Optional[Dict[str, Any]]) – Initial parameters for the double sigmoid function. Defaults to None.
- low¶
The lower bound of the sigmoid range.
- Type:
float
- high¶
The upper bound of the sigmoid range.
- Type:
float
- coef_div¶
The divisor coefficient for slope adjustment, range [0.0, inf), default 1.0.
- Type:
float
- coef_si¶
The slope coefficient for the increasing part, range [0.0, inf), default 1.0.
- Type:
float
- coef_se¶
The slope coefficient for the decreasing part, range [0.0, inf), default 1.0.
- Type:
float
- base¶
The base of the exponential function, range (1.0, inf), default 10.0.
- Type:
float
- invert¶
Whether to invert the result, default False.
- Type:
bool
- shift¶
The vertical shift of the sigmoid, range [0.0, 1.0], default 0.0.
- Type:
float
- Raises:
InvalidBoundaryError – If base is less than or equal to 1, or if high is less than low.
InvalidParameterTypeError – If any parameter is of an invalid type.
ParameterValueNotSet – If any required parameter is not set.
Implementation Details: The double sigmoid function uses two different implementations based on the input parameters:
Hard Sigmoid: When coef_div is 0, a hard sigmoid function is used.
Stable Sigmoid: For all other cases, a numerically stable sigmoid implementation is used.
The choice between these implementations is made automatically based on the input parameters, ensuring accurate and stable results across a wide range of inputs.
Usage Example:
>>> from pumas.desirability import desirability_catalogue
>>> desirability_class = desirability_catalogue.get("double_sigmoid")
>>> params = {'low': 3.0, 'high': 7.0, 'coef_div': 1.0, 'coef_si': 2.0, 'coef_se': 2.0, 'base': 10.0, 'invert': False, 'shift': 0.0} >>> desirability = desirability_class(params=params) >>> print(desirability.get_parameters_values()) {'low': 3.0, 'high': 7.0, 'coef_div': 1.0, 'coef_si': 2.0, 'coef_se': 2.0, 'base': 10.0, 'invert': False, 'shift': 0.0}
>>> result = desirability.compute_numeric(x=5.0) >>> print(f"{result:.2f}") 1.00
>>> result = desirability(x=5.0) # Same as compute_numeric >>> print(f"{result:.2f}") 1.00
>>> from uncertainties import ufloat >>> result = desirability.compute_ufloat(x=ufloat(5.0, 1.0)) >>> print(result) 0.9999+/-0.0005
- class pumas.desirability.double_sigmoid.double_sigmoid(x: float, low: float, high: float, coef_div: float, coef_si: float, coef_se: float, base: float = 10.0, invert: bool = False, shift: float = 0.0, math_module: ~types.ModuleType = <module 'math' from '/home/docs/.asdf/installs/python/3.12.10/lib/python3.12/lib-dynload/math.cpython-312-x86_64-linux-gnu.so'>)[source]¶
Compute the double sigmoid function with adjustable parameters. :param x: The input value. :type x: float :param low: The lower bound of the sigmoid range. :type low: float :param high: The upper bound of the sigmoid range. :type high: float :param coef_div: The divisor coefficient for slope adjustment. :type coef_div: float :param coef_si: The slope coefficient for the increasing part. :type coef_si: float :param coef_se: The slope coefficient for the decreasing part. :type coef_se: float :param base: The base of the exponential function. Defaults to 10.0. :type base: float, opional :param invert: Whether to invert the result. Defaults to False. :type invert: bool, optional :param shift: The vertical shift of the sigmoid. Defaults to 0.0. :type shift: float, optional :param math_module: The math module to use. Defaults to math. :type math_module: ModuleType, optional
- Returns:
The result of the double sigmoid function.
- Return type:
Union[float, UFloat]
Parameter Analysis¶
(Source code, png, hires.png, pdf)