Transform
Transform()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).signintevent_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)
Tensor(...)Methods (5)
__init__
→None__init__()Initialise the transform with an empty inverse cache.
__call__
→Tensor__call__(x: Tensor)Apply the forward map T(x) by delegating to _call.
inv
→Transforminv: TransformLazy inverse — caches an _InverseTransform view.
log_abs_det_jacobian
→Tensorlog_abs_det_jacobian(x: Tensor, y: Tensor)Log-absolute-determinant of the Jacobian ∂T/∂x.
Subclasses must override and return broadcast over the input batch dimensions.
__repr__
→str__repr__()Return a developer-facing string representation of the instance.