CADETProcess.dataStructure.parameter.Ranged

CADETProcess.dataStructure.parameter.Ranged#

class CADETProcess.dataStructure.parameter.Ranged(*args: Any, lb: float = -inf, lb_op: Callable = <built-in function lt>, ub: float = inf, ub_op: Callable = <built-in function gt>, **kwargs: Any)[source]#

Bases: ParameterBase

Descriptor for parameters within specified bounds.

Allows setting values constrained by provided lower and upper bounds. The actual comparisons against the bounds can be customized using the lb_op and ub_op comparison functions.

Attributes:
lbnumeric

The lower bound of the parameter. Default is negative infinity.

lb_opcallable

A callable that defines the comparison operation against the lower bound. Default is less than (<).

ubnumeric

The upper bound of the parameter. Default is positive infinity.

ub_opcallable

A callable that defines the comparison operation against the upper bound. Default is greater than (>).

See also

ParameterBase

Notes

  • By default, values are checked to be strictly within the bounds (exclusive). To change this behavior, use the lb_op and ub_op parameters.

  • The check_range method can be overridden for custom range validation logic, especially if the data structure isn’t a simple scalar value (e.g. for np.ndarrays).

Examples

Constraining a parameter between 0 and 10:

>>> class MyClass:
...     value = Ranged(lb=0, ub=10)
>>> obj = MyClass()
>>> obj.value = 5  # This is valid
>>> obj.value = -5  # Raises an error
check_range(value: Any) None[source]#

Validate if the value is within the defined range.

Override this method if other methods for checking ranges are required (e.g. for np.ndarrays).

Parameters:
valueAny

Value to check against the range.

Raises:
ValueError

If the value is outside the specified bounds.