Standard transforms#
Provide the standard library of Transform objects and factories.
The ready-made Transforms are:
stick_breaking,softmax_centered, andsoftmax_centered_ilrfor simplex coordinates;choleskyfor positive-definite matrices;fill_trilandextract_trilbetween vectors and lower-triangular matrices;exp_diagonalandlog_diagonalfor lower-triangular matrices; andunconstrain_spd, which composes Cholesky decomposition, diagonal logarithms, and lower-triangle extraction.
The parameterized factories are scaled_logit(), scale_by(), and shift_by(). They return Transforms
whose parameters are captured as RVs.
Examples#
>>> from pangolin import interface as pi
>>> positive = pi.tforms.exp(pi.normal)(0, 1)
>>> unit_interval = pi.tforms.inv_logit(pi.normal)(0, 1)
>>> positive.shape == unit_interval.shape == ()
True
- TransformLibrary.scale_by(factor)[source]#
Return the scalar bijection
y = factor * x.factoris coerced to an RV when the Transform is created and becomes a captured bijector parameter.Coercion uses the interface owning this library; the returned Transform is a generic combinator, not bound to that interface.
- Parameters:
factor (RVLike) – Scalar scale factor. It is coerced into an
ir.RVimmediately.- Returns:
transform – Scalar
pangolin.functional.Transformthat multiplies byfactorin its forward direction.- Raises:
ValueError – If
factoris not scalar or the Transform is later applied to a non-scalar RV.- Return type:
Examples
>>> from pangolin import interface as pi >>> y = pi.tforms.scale_by(2)(pi.normal)(0, 1) >>> y.shape ()
- TransformLibrary.shift_by(offset)[source]#
Return the bijection
y = x + offset.offsetis coerced to an RV when the Transform is created and becomes a captured bijector parameter.Coercion uses the interface owning this library; the returned Transform is a generic combinator, not bound to that interface.
The value and offset must have identical shapes; no broadcasting is performed.
- Parameters:
offset (RVLike) – Offset to add in the forward direction. It is coerced into an
ir.RVimmediately.- Returns:
transform –
pangolin.functional.Transformthat addsoffsetin its forward direction.- Return type:
Examples
>>> from pangolin import interface as pi >>> y = pi.tforms.shift_by(3)(pi.normal)(0, 1) >>> y.shape ()
- TransformLibrary.scaled_logit(lower, upper)[source]#
Return the scalar bijection from
(lower, upper)to the real line.The forward mapping is
logit((x - lower) / (upper - lower)). Both bounds are coerced to RVs when the Transform is created and become captured bijector parameters.Coercion uses the interface owning this library; the returned Transform is a generic combinator, not bound to that interface.
- Parameters:
- Returns:
transform – Scalar
pangolin.functional.Transformmapping(lower, upper)to the real line.- Raises:
ValueError – If either endpoint is not scalar or the Transform is later applied to a non-scalar RV.
- Return type:
Examples
>>> from pangolin import interface as pi >>> unconstrained = pi.tforms.scaled_logit(1, 5)(pi.uniform)(1, 5) >>> unconstrained.shape ()
Fixed transforms are shared with pangolin.functional.tforms. See
pangolin.functional.tforms for their definitions, directions, and shape requirements.