ClipT#
- class brainstate.nn.ClipT(lower, upper)#
Transformation with clipping to specified bounds.
This transformation applies a clipping operation to the input values, constraining them within the specified lower and upper bounds. It is useful for enforcing hard limits on parameters that must remain within a certain range.
The transformation is defined by:
\[\text{forward}(x) = \min(\max(x, \text{lower}), \text{upper})\]The inverse transformation is not defined for clipping, as information is lost.
- Parameters:
- lower#
Lower bound for clipping.
- Type:
array_like
- upper#
Upper bound for clipping.
- Type:
array_like
Notes
Clipping is a non-bijective transformation since multiple input values can map to the same output value at the bounds. Therefore, the inverse method cannot recover the original input; it provides a best-effort pseudo-inverse that simply re-applies the clip (a passthrough for values already inside
[lower, upper]).Examples
>>> # Clip values to [0, 1] >>> transform = ClipT(0.0, 1.0) >>> x = jnp.array([-0.5, 0.5, 1.5]) >>> y = transform.forward(x) >>> # y = [0.0, 0.5, 1.0]
- inverse(y)[source]#
Best-effort inverse for the (non-bijective) clipping transform.
Clipping is not bijective, so a true inverse does not exist. As a best-effort pseudo-inverse this re-applies the clip, which acts as the identity for values already inside
[lower, upper]and projects out-of-range values back onto the nearest bound.