class

AffineTransform

extendsTransform
AffineTransform(loc: Tensor | float, scale: Tensor | float)
source

Element-wise affine bijection y=loc+scalexy = \mathrm{loc} + \mathrm{scale}\cdot x.

The fundamental location-scale transform. Composing with a standard Normal yields N(loc,scale2)\mathcal{N}(\mathrm{loc}, \mathrm{scale}^2); it underpins virtually every reparameterised sampler in the codebase. Bijective with sign matching sign(scale); the implementation fixes self.sign = +1, so the caller is responsible for ensuring scale > 0.

Parameters

locTensor or float
Additive offset bb.
scaleTensor or float
Multiplicative slope aa (assumed positive).

Notes

Forward: y=b+axy = b + a\,x.

Inverse: x=(yb)/ax = (y - b) / a.

Log Jacobian determinant (broadcast to x.shape):

log ⁣yx=loga\log\!\left|\frac{\partial y}{\partial x}\right| = \log|a|

For element-wise application (event_dim = 0) this is summed by IndependentTransform if the caller reinterprets trailing dims as event dims.

Examples

>>> import lucid
>>> from lucid.distributions.transforms import AffineTransform
>>> T = AffineTransform(loc=1.0, scale=2.0)
>>> T(lucid.tensor(3.0))
Tensor(7.0)

Methods (2)

dunder

__init__

None
__init__(loc: Tensor | float, scale: Tensor | float)
source

Store the affine offset loc and multiplier scale.

The caller is responsible for ensuring scale > 0; sign is fixed at +1 here so the transform is treated as increasing.

fn

log_abs_det_jacobian

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

Constant log-Jacobian logscale\log|\text{scale}|, broadcast to x's shape.