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.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(...)Used by 1
Constructors
1__init__
→None__init__(base_distribution: Distribution, transforms: Transform | list[Transform], validate_args: bool | None = None)Construct a transformed distribution.
Parameters
base_distributionDistributiontransforms.validate_argsbool | None= NoneDistribution.Properties
1Instance methods
3Evaluate 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.
Push a reparameterised base sample through the transform chain.
Push a (non-reparameterised) base sample through the transform chain.