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 (Array | ndarray | bool | number | bool | int | float | complex | Quantity) – Lower bound for clipping.

  • upper (Array | ndarray | bool | number | bool | int | float | complex | Quantity) – Upper bound for clipping.

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]
forward(x)[source]#

Apply clipping to the input values.

Parameters:

x (Array | ndarray | bool | number | bool | int | float | complex | Quantity) – Input values to clip.

Returns:

Clipped values within [lower, upper].

Return type:

Array

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.

Parameters:

y (Array | ndarray | bool | number | bool | int | float | complex | Quantity) – Values in [lower, upper] (typically the output of forward).

Returns:

The values clipped to [lower, upper] (a passthrough for in-range inputs).

Return type:

Array