Standard transforms#

Provide the standard library of Transform objects and factories.

The ready-made Transforms are:

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.

factor is 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.RV immediately.

Returns:

transform – Scalar pangolin.functional.Transform that multiplies by factor in its forward direction.

Raises:

ValueError – If factor is not scalar or the Transform is later applied to a non-scalar RV.

Return type:

Transform

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.

offset is 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.RV immediately.

Returns:

transform – pangolin.functional.Transform that adds offset in its forward direction.

Return type:

Transform

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:
  • lower (RVLike) – Scalar lower endpoint of the open interval.

  • upper (RVLike) – Scalar upper endpoint of the open interval.

Returns:

transform – Scalar pangolin.functional.Transform mapping (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:

Transform

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.