ModuleSpace.clip#
- ModuleSpace.clip(val, *, low=None, high=None, space=None, normalized=None)[source]#
Clip a value into a lower and upper bound.
The lower and upper bound are defined by the keyword argument
low,high,normalized, andspace.If
lowandhighare passed,valis clipped to the range[low, high].Otherwise, if
spaceis passed,val is clipped to the range ``[space.low, space.high].Otherwise, if normalized is passed:
If
normalized == True, ``val is clipped to the range
[space.normalized.low, space.normalized.high]If
normalized == False,val is clipped to the range ``[space.unnormalized.low, space.unnormalized.high]
Parameters#
- valnp.ndarray or dict[str, list[np.ndarray]]
Value to clip. Numpy array if
isinstance(self, :class:`.ModuleSpace`)and a dict ifisinstance(self, :class:`.MicrogridSpace`).- lownp.ndarray, dict[str, list[np.ndarray]] or None, default None
Value to define lower bound or None.
- highnp.ndarray, dict[str, list[np.ndarray]] or None, default None
Value to define upper bound or None.
- spacegym.Space or None, default None
Space from which to select lower and upper bounds.
- normalizedbool or None, default None
Whether to select bounds from
self.normalizedorself.unnormalized.
Returns#
- clipped_valnp.ndarray or dict[str, list[np.ndarray]]
Value clipped to lower and upper bounds.