class

Transform

Transform()
source

Abstract bijection between two measurable spaces.

A Transform represents an invertible map T:XYT : \mathcal{X} \to \mathcal{Y} 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

logpY(y)=logpX(x)logdetT(x)x,y=T(x)\log p_Y(\mathbf{y}) = \log p_X(\mathbf{x}) - \log \left|\det \frac{\partial T(\mathbf{x})}{\partial \mathbf{x}}\right|, \quad \mathbf{y} = T(\mathbf{x})

so the per-transform Jacobian determinant must be tractable.

Subclasses must override:

  • _call — forward map y=T(x)\mathbf{y} = T(\mathbf{x}).
  • _inverse — inverse map x=T1(y)\mathbf{x} = T^{-1}(\mathbf{y}).
  • log_abs_det_jacobianlogdetT/x\log \bigl|\det \partial T / \partial \mathbf{x}\bigr|, broadcast over the batch dimensions of the input.

Attributes

bijectivebool
True if the transform is invertible (most are; notable exception: AbsTransform).
signint
+1+1 for monotone-increasing scalar bijections, 1-1 for monotone-decreasing. Used by the change-of-variable machinery to track CDF orientation.
event_dimint
Number of trailing tensor dimensions that the transform treats as a single event. 0 for element-wise maps, 1\geq 1 for vector / matrix transforms (e.g. SoftmaxTransform has event_dim = 1, LowerCholeskyTransform has event_dim = 2).

Notes

Composition and inversion are provided structurally:

  • ComposeTransformT=TnT1T = T_n \circ \cdots \circ T_1.
  • ~transform / inv — lazy _InverseTransform view.

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)

dunder

__init__

None
__init__()
source

Initialise the transform with an empty inverse cache.

dunder

__call__

Tensor
__call__(x: Tensor)
source

Apply the forward map T(x) by delegating to _call.

prop

inv

Transform
inv: Transform
source

Lazy inverse — caches an _InverseTransform view.

fn

log_abs_det_jacobian

Tensor
log_abs_det_jacobian(x: Tensor, y: Tensor)
source

Log-absolute-determinant of the Jacobian ∂T/∂x.

Subclasses must override and return logdety/x\log|\det \partial y/\partial x| broadcast over the input batch dimensions.

dunder

__repr__

str
__repr__()
source

Return a developer-facing string representation of the instance.