Abstract bijection between two measurable spaces.
A Transform represents an invertible map
together with its
log-absolute-determinant Jacobian, used to push a base distribution
through a measurable bijection. Composed with a base distribution
via TransformedDistribution, it implements normalising flows,
coupling layers, and standard change-of-variable arguments.
The change-of-variable formula for densities is
so the per-transform Jacobian determinant must be tractable.
Subclasses must override:
_call— forward map ._inverse— inverse map .log_abs_det_jacobian— , broadcast over the batch dimensions of the input.
Attributes
bijectiveboolTrue if the transform is invertible (most are; notable
exception: AbsTransform).signint or TensorAffineTransform whose scale is).
TransformedDistribution reads it to orient its CDF. A
transform with no meaningful sign (AbsTransform, the
vector-valued transforms) raises NotImplementedError on
access, so a missing sign is never mistaken for +1.event_ dimint0 for element-wise maps,
for vector / matrix transforms (e.g.
SoftmaxTransform has event_dim = 1,
LowerCholeskyTransform has event_dim = 2).Notes
Composition and inversion are provided structurally:
ComposeTransform— .~transform/inv— lazy_InverseTransformview.
so users can build complex bijectors without manually tracking Jacobian terms.
Examples
>>> import lucid
>>> from lucid.distributions.transforms import ExpTransform, AffineTransform, ComposeTransform
>>> # y = exp(2*x + 1) — a log-normal-like transform
>>> T = ComposeTransform([AffineTransform(loc=1.0, scale=2.0), ExpTransform()])
>>> x = lucid.tensor(0.0)
>>> y = T(x)
>>> T.log_abs_det_jacobian(x, y) # log(2) + (2x + 1) at x = 0
tensor(1.693)Used by 3
Constructors
2Properties
4Constraint describing valid outputs of this transform.
Constraint describing valid inputs to this transform.
Lazy inverse — caches an _InverseTransform view.
Orientation of the map: +1 increasing, -1 decreasing.
Only meaningful for a monotone scalar bijection. A subclass states its own (a class attribute for a fixed one, a property for one that depends on parameters); the base refuses, so a transform that never declared a sign cannot be silently read as increasing.
Raises
NotImplementedErrorInstance methods
3Infer the output shape from input shape (defaults to identity).
Infer the input shape from output shape (defaults to identity).
Log-absolute-determinant of the Jacobian .
Subclasses must override and return broadcast over the input batch dimensions.
Parameters
Returns
TensorElement-wise log-absolute-Jacobian-determinant, broadcastable
to x.shape.