Skip to content
class

AbsTransform

extendsTransform
AbsTransform()

Element-wise absolute value y=∣x∣y = |x| (folded, not bijective).

Maps R→[0,∞)\mathbb{R} \to [0, \infty) element-wise by folding the sign. Useful when composing with symmetric base distributions (e.g. a Normal) to produce a half-Normal or folded-Normal pushforward. bijective = False and it has no sign — a fold is neither increasing nor decreasing.

Because both xx and −x-x map to the same yy, the transform is non-invertible. The pseudo-inverse used here is the identity, under the convention that the preimage is assumed to lie on the non-negative half-line.

Notes

Forward: y=∣x∣y = |x|.

Pseudo-inverse: x=yx = y (assumes x≥0x \geq 0).

There is no log-determinant: the map folds the two half-lines onto one, so it is not a bijection and log_abs_det_jacobian raises NotImplementedError, as in the reference. Folding the sign halves the density (composing with a Normal(0,1) base gives the half-Normal p(y)=2ϕ(y)p(y) = 2 \phi(y), y≥0y \geq 0), which the standard change-of-variable formula cannot express.

Examples

>>> import lucid
>>> from lucid.distributions.transforms import AbsTransform
>>> T = AbsTransform()
>>> T(lucid.tensor(-3.0))
tensor(3.)

Used by 1