AffineT#
- class brainstate.nn.AffineT(scale, shift)#
Affine (linear) transformation with scaling and shifting.
This transformation applies a linear transformation of the form y = ax + b, where a is the scale factor and b is the shift. It is the most basic form of transformation and preserves the relative ordering of inputs while allowing for rescaling and translation.
The transformation is defined by:
\[\text{forward}(x) = a \cdot x + b\]The inverse transformation is:
\[\text{inverse}(y) = \frac{y - b}{a}\]- Parameters:
- a#
Scaling factor.
- Type:
array_like
- b#
Shift parameter.
- Type:
array_like
- Raises:
ValueError – If scale is zero or numerically close to zero, making the transformation non-invertible.
Notes
Affine transformations are the foundation of many statistical transformations. They preserve linearity and are particularly useful for:
Standardization: (x - μ) / σ
Normalization: (x - min) / (max - min)
Unit conversion: x * conversion_factor + offset
The Jacobian of this transformation is constant: |det(J)| = |a|.
Examples
>>> # Standardization transform (z-score) >>> mu, sigma = 5.0, 2.0 >>> transform = AffineT(1/sigma, -mu/sigma) >>> x = jnp.array([3.0, 5.0, 7.0]) >>> z = transform.forward(x) >>> # z ≈ [-1.0, 0.0, 1.0]
>>> # Temperature conversion: Celsius to Fahrenheit >>> transform = AffineT(9/5, 32) >>> celsius = jnp.array([0.0, 100.0]) >>> fahrenheit = transform.forward(celsius) >>> # fahrenheit ≈ [32.0, 212.0]