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 is not implemented.

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]#

Inverse transformation is not defined for clipping.

Raises:

NotImplementedError – Clipping is not bijective; inverse cannot be defined.

Return type:

Array