pangolin.functional.tforms#

Provide standard backend-independent Transform combinators and factories.

pangolin.functional.tforms.exp: Final[Transform] = Transform(<function exp_forward>, <function exp_inverse>, <function exp_log_det_jac>, sign=<function positive_sign>)#

Map real scalars to positive scalars with the exponential Transform.

Parameters:

fun (Callable[P, ir.RV])

Return type:

Callable[P, ir.RV]

pangolin.functional.tforms.log: Final[Transform] = Transform(<function exp_inverse>, <function exp_forward>, <function Transform.reverse.<locals>.reversed_log_det>, sign=<function positive_sign>)#

Map positive scalars to real scalars with the logarithm Transform.

Parameters:

fun (Callable[P, ir.RV])

Return type:

Callable[P, ir.RV]

pangolin.functional.tforms.logit: Final[Transform] = Transform(<function logit_forward>, <function logit_inverse>, <function logit_log_det_jac>, sign=<function positive_sign>)#

Map the open unit interval to the real line with the logit Transform.

Parameters:

fun (Callable[P, ir.RV])

Return type:

Callable[P, ir.RV]

pangolin.functional.tforms.inv_logit: Final[Transform] = Transform(<function logit_inverse>, <function logit_forward>, <function Transform.reverse.<locals>.reversed_log_det>, sign=<function positive_sign>)#

Map the real line to the open unit interval with the inverse-logit Transform.

Parameters:

fun (Callable[P, ir.RV])

Return type:

Callable[P, ir.RV]

pangolin.functional.tforms.stick_breaking: Final[Transform] = Transform(<function stick_breaking_forward>, <function stick_breaking_inverse>, <function stick_breaking_log_det_jac>)#

Map a simplex of length K to K - 1 stick-breaking coordinates.

Parameters:

fun (Callable[P, ir.RV])

Return type:

Callable[P, ir.RV]

pangolin.functional.tforms.softmax_centered: Final[Transform] = Transform(<function softmax_centered_forward>, <function softmax_centered_inverse>, <function softmax_centered_log_det_jac>)#

Map a simplex of length K to K - 1 centered log coordinates.

Parameters:

fun (Callable[P, ir.RV])

Return type:

Callable[P, ir.RV]

pangolin.functional.tforms.softmax_centered_ilr: Final[Transform] = Transform(<function softmax_centered_ilr_forward>, <function softmax_centered_ilr_inverse>, <function softmax_centered_ilr_log_det_jac>)#

Map a simplex of length K to K - 1 orthonormal ILR coordinates.

Parameters:

fun (Callable[P, ir.RV])

Return type:

Callable[P, ir.RV]

pangolin.functional.tforms.scaled_logit(lower, upper)[source]#

Create the scalar Transform from (lower, upper) to the real line.

scaled_logit is a Transform factory. The returned Transform’s functions capture the exact lower and upper RVs in their closures, so applying the Transform makes the bounds parents in the resulting graph.

Parameters:
  • lower (RV) – Finite scalar lower endpoint captured as a Transform parameter.

  • upper (RV) – Finite scalar upper endpoint, strictly greater than lower, captured as a parameter.

Returns:

transform – Scalar scaled-logit Transform whose functions close over lower and upper.

Raises:
  • TypeError – If either endpoint is not an ir.RV.

  • ValueError – If either endpoint or the transformed value is nonscalar.

Return type:

Transform

Examples

>>> lower = ir.RV(ir.Constant(1))
>>> upper = ir.RV(ir.Constant(5))
>>> x = ir.RV(ir.Constant(3))
>>> scaled_logit(lower, upper).forward(x).shape
()
pangolin.functional.tforms.scale_by(factor)[source]#

Create the scalar Transform y = factor * x.

scale_by is a Transform factory. The returned Transform’s functions capture the exact factor RV in their closures, so applying the Transform makes factor a parent in the resulting graph.

Parameters:

factor (RV) – Scalar IR RV captured as a Transform parameter; its value must be finite and nonzero.

Returns:

transform – Scalar scaling Transform whose functions close over factor.

Raises:
  • TypeError – If factor is not an ir.RV.

  • ValueError – If factor is not scalar, or the Transform is applied to a nonscalar RV.

Return type:

Transform

Examples

>>> factor = ir.RV(ir.Constant(2))
>>> transform = scale_by(factor)
>>> x = ir.RV(ir.Constant(3))
>>> transform.forward(x).parents == (x, factor)
True
pangolin.functional.tforms.shift_by(offset)[source]#

Create the elementwise Transform y = x + offset.

shift_by is a Transform factory. The returned Transform’s functions capture the exact offset RV in their closures, so applying the Transform makes offset a parent in the resulting graph.

x and offset must have identical shapes; this function performs no broadcasting.

Parameters:

offset (RV) – IR RV captured as a Transform parameter; its values must be finite.

Returns:

transform – Elementwise shift Transform whose functions close over offset.

Raises:
  • TypeError – If offset is not an ir.RV.

  • ValueError – If the Transform is applied to an RV with a different shape.

Return type:

Transform

Examples

>>> offset = ir.RV(ir.Constant([1, 2]))
>>> x = ir.RV(ir.Constant([3, 4]))
>>> shift_by(offset).forward(x).shape
(2,)
pangolin.functional.tforms.cholesky: Final[Transform] = Transform(<function cholesky_forward>, <function cholesky_inverse>, <function cholesky_log_det_jac>)#

Map positive-definite matrices to lower-triangular Cholesky factors.

Parameters:

fun (Callable[P, ir.RV])

Return type:

Callable[P, ir.RV]

pangolin.functional.tforms.fill_tril: Final[Transform] = Transform(<function fill_tril_forward>, <function extract_tril_forward>, <function zero_log_det_jac>)#

Map vectors to lower-triangular matrices by filling entries row by row.

Parameters:

fun (Callable[P, ir.RV])

Return type:

Callable[P, ir.RV]

pangolin.functional.tforms.extract_tril: Final[Transform] = Transform(<function extract_tril_forward>, <function fill_tril_forward>, <function Transform.reverse.<locals>.reversed_log_det>)#

Map lower-triangular matrices to vectors by extracting entries row by row.

Parameters:

fun (Callable[P, ir.RV])

Return type:

Callable[P, ir.RV]

pangolin.functional.tforms.exp_diagonal: Final[Transform] = Transform(<function exp_diagonal_forward>, <function exp_diagonal_inverse>, <function exp_diagonal_log_det_jac>)#

Exponentiate a matrix diagonal while preserving other entries.

Parameters:

fun (Callable[P, ir.RV])

Return type:

Callable[P, ir.RV]

pangolin.functional.tforms.log_diagonal: Final[Transform] = Transform(<function exp_diagonal_inverse>, <function exp_diagonal_forward>, <function Transform.reverse.<locals>.reversed_log_det>)#

Take the logarithm of a matrix diagonal while preserving other entries.

Parameters:

fun (Callable[P, ir.RV])

Return type:

Callable[P, ir.RV]

pangolin.functional.tforms.unconstrain_spd: Final[Transform] = Transform(<function compose_transforms.<locals>.forward>, <function compose_transforms.<locals>.inverse>, <function compose_transforms.<locals>.forward_log_det>)#

Map positive-definite matrices to unconstrained vectors.

Parameters:

fun (Callable[P, ir.RV])

Return type:

Callable[P, ir.RV]