TransformedDistribution
DistributionTransformedDistribution(base_distribution: Distribution, transforms: Transform | list[Transform], validate_args: bool | None = None)Pushforward of a base distribution through a (composite) bijector.
Constructs a new Distribution whose samples are obtained by
pushing samples from base_distribution through the supplied
chain of Transform instances, with log_prob
accounting for the Jacobian correction via the change-of-variable
formula. This is the canonical way to build normalising flows in
Lucid: stack any number of bijections on top of a tractable base
(typically a Normal) to obtain expressive densities while retaining
exact log-likelihood evaluation and reparameterised sampling.
Parameters
base_distributionDistributiontransforms.transformsTransform or list[Transform]validate_argsbool= NoneDistribution.Notes
Sampling (with the composite bijector):
Reparameterised sampling is available iff the base distribution
supports it (has_rsample is forwarded).
Density (change of variables):
where and . The implementation walks the transforms in reverse, inverting one step at a time and accumulating the Jacobian correction.
Examples
>>> import lucid
>>> from lucid.distributions import Normal
>>> from lucid.distributions.transforms import (
... ExpTransform, TransformedDistribution)
>>> # LogNormal = ExpTransform(Normal(0, 1))
>>> log_normal = TransformedDistribution(Normal(loc=0.0, scale=1.0), [ExpTransform()])
>>> log_normal.rsample((4,))
Tensor([...])
>>> log_normal.log_prob(lucid.tensor(1.0))
Tensor(...)Methods (5)
__init__
→None__init__(base_distribution: Distribution, transforms: Transform | list[Transform], validate_args: bool | None = None)Construct a transformed distribution.
Parameters
base_distributionDistributiontransforms.transformsTransform | list[Transform]validate_argsbool | None= NoneDistribution.has_rsample
→boolhas_rsample: boolWhether reparameterised sampling is available — inherited from the base distribution.
rsample
→Tensorrsample(sample_shape: tuple[int, ...] = ())Push a reparameterised base sample through the transform chain.
sample
→Tensorsample(sample_shape: tuple[int, ...] = ())Push a (non-reparameterised) base sample through the transform chain.
log_prob
→Tensorlog_prob(value: Tensor)Evaluate the log-density of value under the transformed distribution.
Uses the change-of-variable formula:
with the chain unwound by walking the transforms in reverse.