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.
- 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.
- 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.
- 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.
- 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
KtoK - 1stick-breaking coordinates.
- 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
KtoK - 1centered log coordinates.
- 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
KtoK - 1orthonormal ILR coordinates.
- pangolin.functional.tforms.scaled_logit(lower, upper)[source]#
Create the scalar Transform from
(lower, upper)to the real line.scaled_logitis a Transform factory. The returned Transform’s functions capture the exactlowerandupperRVs in their closures, so applying the Transform makes the bounds parents in the resulting graph.- Parameters:
- Returns:
transform – Scalar scaled-logit Transform whose functions close over
lowerandupper.- Raises:
TypeError – If either endpoint is not an
ir.RV.ValueError – If either endpoint or the transformed value is nonscalar.
- Return type:
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_byis a Transform factory. The returned Transform’s functions capture the exactfactorRV in their closures, so applying the Transform makesfactora 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
factoris not anir.RV.ValueError – If
factoris not scalar, or the Transform is applied to a nonscalar RV.
- Return type:
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_byis a Transform factory. The returned Transform’s functions capture the exactoffsetRV in their closures, so applying the Transform makesoffseta parent in the resulting graph.xandoffsetmust 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
offsetis not anir.RV.ValueError – If the Transform is applied to an RV with a different shape.
- Return type:
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.
- 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.
- 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.
- 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.
- 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.