NegSoftplusT#
- class brainstate.nn.NegSoftplusT(upper)#
Negative softplus transformation mapping unbounded values to negative semi-infinite interval.
This transformation uses the negative softplus function to map any real value to the interval (-∞, upper]. It is the reflection of the softplus function and is useful for constraining parameters to be negative, such as log-probabilities or negative rate constants.
The transformation is defined by:
\[\text{forward}(x) = -\log(1 + e^{-x}) + \text{upper}\]which is equivalent to:
\[\text{forward}(x) = \text{upper} - \text{softplus}(-x)\]The inverse transformation is:
\[\text{inverse}(y) = -\log(e^{\text{upper} - y} - 1)\]- Parameters:
upper (
Array|ndarray|bool|number|bool|int|float|complex|Quantity) – Upper bound of the target interval.
- lower#
Stores the upper bound (inherited from parent class).
- Type:
array_like
- unit#
Physical unit of the upper bound.
- Type:
brainunit.Unit
Notes
This transformation is implemented by negating the input and output of the standard softplus transformation. For large positive x, the output approaches the upper bound, while for large negative x, the output approaches -∞.
Examples
>>> # Map to negative reals (-∞, 0] >>> transform = NegSoftplusT(0.0) >>> x = jnp.array([-5.0, 0.0, 5.0]) >>> y = transform.forward(x) >>> # y ≈ [-5.007, -0.693, -0.007]
>>> # Map to interval (-∞, -2] for negative-definite parameters >>> transform = NegSoftplusT(-2.0) >>> x = jnp.array([0.0]) >>> y = transform.forward(x) >>> # y ≈ [-2.693]
- forward(x)[source]#
Transform unbounded input to negative semi-infinite interval.
- Parameters:
x (
Array|ndarray|bool|number|bool|int|float|complex|Quantity) – Input values in unbounded domain (-∞, ∞).- Returns:
Transformed values in interval (-∞, upper].
- Return type:
Array
Notes
Implemented as: upper - softplus(-x).
- inverse(y)[source]#
Transform negative semi-infinite input back to unbounded domain.
- Parameters:
y (
Array|ndarray|bool|number|bool|int|float|complex|Quantity) – Input values in interval (-∞, upper].- Returns:
Transformed values in unbounded domain (-∞, ∞).
- Return type:
Array
Notes
Inverts: y = upper - softplus(-x) => x = -softplus^{-1}(upper - y).