SigmoidT#
- class brainstate.nn.SigmoidT(lower, upper)#
Sigmoid transformation mapping unbounded values to a bounded interval.
This transformation uses the logistic sigmoid function to map any real value to a bounded interval [lower, upper]. It is particularly useful for constraining parameters that must lie within specific bounds, such as probabilities or correlation coefficients.
The transformation is defined by:
\[\text{forward}(x) = \text{lower} + (\text{upper} - \text{lower}) \cdot \sigma(x)\]where \(\sigma(x) = \frac{1}{1 + e^{-x}}\) is the standard sigmoid function.
The inverse transformation is:
\[\text{inverse}(y) = \log\left(\frac{y - \text{lower}}{\text{upper} - y}\right)\]- Parameters:
- lower#
Lower bound of the interval.
- Type:
array_like
- width#
Width of the interval (upper - lower).
- Type:
array_like
- unit#
Physical unit of the bounds.
- Type:
brainunit.Unit
Notes
The sigmoid function provides a smooth, differentiable mapping with asymptotes at the specified bounds. The transformation is bijective from ℝ to (lower, upper), though numerical precision may limit the effective range near the boundaries.
Examples
>>> # Map to probability range [0, 1] >>> transform = SigmoidT(0.0, 1.0) >>> x = jnp.array([-2.0, 0.0, 2.0]) >>> y = transform.forward(x) >>> # y ≈ [0.12, 0.5, 0.88]
>>> # Map to correlation range [-1, 1] >>> transform = SigmoidT(-1.0, 1.0) >>> x = jnp.array([0.0]) >>> y = transform.forward(x) >>> # y ≈ [0.0]
- forward(x)[source]#
Transform unbounded input to bounded interval using sigmoid function.
- Parameters:
x (
Array|ndarray|bool|number|bool|int|float|complex|Quantity) – Input values in unbounded domain \((-\infty, \infty)\).- Returns:
Transformed values in interval [lower, upper].
- Return type:
Array
Notes
Uses numerically stable exponential to prevent overflow for large |x|.
- inverse(y)[source]#
Transform bounded input back to unbounded domain using logit function.
- Parameters:
y (
Array|ndarray|bool|number|bool|int|float|complex|Quantity) – Input values in bounded interval [lower, upper].- Returns:
Transformed values in unbounded domain (-∞, ∞).
- Return type:
Array
Notes
For numerical stability, input should be strictly within (lower, upper). Values at the boundaries will result in infinite outputs.