Skip to content
class

ComposeTransform

extendsTransform
ComposeTransform(parts: list[Transform])

Function composition of a list of transforms — left-to-right.

Implements the composite map T=Tn∘Tn−1∘⋯∘T1T = T_n \circ T_{n-1} \circ \cdots \circ T_1 so that the first transform in parts is applied first. The composite Jacobian is the sum of the per-step Jacobians along the trajectory, by the chain rule. This is the workhorse for stacking normalising flows.

Parameters

partslist[Transform]
Ordered list of sub-transforms. Must be non-empty. Their event_dim values are reduced via max.

Raises

ValueError
If parts is empty.

Notes

Forward:

y=Tn(Tn−1(⋯T1(x)⋯ ))\mathbf{y} = T_n(T_{n-1}(\cdots T_1(\mathbf{x}) \cdots ))

Inverse (transforms run in reverse with each one inverted):

x=T1−1(T2−1(⋯Tn−1(y)⋯ ))\mathbf{x} = T_1^{-1}(T_2^{-1}(\cdots T_n^{-1}(\mathbf{y}) \cdots ))

Log Jacobian determinant (chain rule):

log⁡∣det⁡JT(x)∣=∑k=1nlog⁡∣det⁡JTk(x(k−1))∣\log|\det J_T(\mathbf{x})| = \sum_{k=1}^{n} \log|\det J_{T_k}(\mathbf{x}^{(k-1)})|

where x(0)=x\mathbf{x}^{(0)} = \mathbf{x} and x(k)=Tk(x(k−1))\mathbf{x}^{(k)} = T_k(\mathbf{x}^{(k-1)}). The implementation re-evaluates the forward chain to collect the intermediate states needed by each sub-Jacobian.

Examples

>>> import lucid
>>> from lucid.distributions.transforms import (
...     ExpTransform, AffineTransform, ComposeTransform)
>>> # Log-normal-like: y = exp(loc + scale * x)
>>> T = ComposeTransform([AffineTransform(loc=0.0, scale=1.0), ExpTransform()])
>>> T(lucid.tensor(0.0))
tensor(1.)

Used by 2

Constructors

1
dunder

__init__

→None
__init__(parts: list[Transform])

Store the ordered list of sub-transforms.

Raises

ValueError
If parts is empty.

Properties

3
prop

codomain

→Constraint
codomain: Constraint

Output codomain of the composite transform.

prop

domain

→Constraint
domain: Constraint

Input domain of the composite transform.

prop

sign

→int | Tensor
sign: int | Tensor

Product of the parts' signs.

Raises

NotImplementedError
If any part has no defined sign.

Instance methods

3
fn

forward_shape

→tuple[int, ...]
forward_shape(shape: tuple[int, ...])

Propagate shape forward through every sub-transform in order.

fn

inverse_shape

→tuple[int, ...]
inverse_shape(shape: tuple[int, ...])

Propagate shape backward through every sub-transform in reverse order.

fn

log_abs_det_jacobian

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

Cumulative log-Jacobian across the composition.

Re-evaluates the chain of forward maps to obtain the intermediate states needed by each sub-Jacobian, then sums the contributions.

Parameters

Input to the first transform in the chain.
Output of the last transform; ignored — the chain is re-evaluated from x.

Returns

Tensor

Element-wise sum of every sub-transform's log-Jacobian, broadcastable to x.shape.