Internals
Types for various transformations
These are not part of the API, use the as constructor or one of the predefined constants.
Scalar transformations
TransformVariables.Identity — Typestruct Identity <: TransformVariables.ScalarTransformIdentity $x ↦ x$.
Aggregating transformations
TransformVariables.ArrayTransformation — Typestruct ArrayTransformation{T<:TransformVariables.AbstractTransform, M} <: TransformVariables.VectorTransformApply transformation repeatedly to create an array with given dims.
TransformVariables.TransformTuple — Typestruct TransformTuple{T} <: TransformVariables.VectorTransformTransform consecutive groups of real numbers to a tuple, using the given transformations.
Wrapper for inverse
TransformVariables.CallableInverse — Typestruct Fix1{typeof(inverse), T<:TransformVariables.AbstractTransform} <: FunctionPartial application of inverse(t, y), callable with y. Use inverse(t) to construct.
Types and type aliases
TransformVariables.AbstractTransform — Typeabstract type AbstractTransformSupertype for all transformations in this package.
Interface
The user interface consists of
TransformVariables.ScalarTransform — Typeabstract type ScalarTransform <: TransformVariables.AbstractTransformTransform a scalar (real number) to another scalar.
Subtypes must define transform, transform_and_logjac, and inverse. Other methods of of the interface should have the right defaults.
This type is for code organization within the package, and is not part of the public API.
TransformVariables.VectorTransform — Typeabstract type VectorTransform <: TransformVariables.AbstractTransformTransformation that transforms <: AbstractVectors to other values.
Implementation
Implements transform and transform_and_logjac via transform_with, and inverse via inverse!.
Conditional calculation of log Jacobian determinant
TransformVariables.LogJacFlag — Typeabstract type LogJacFlagFlag used internally by the implementation of transformations, as explained below.
When calculating the log jacobian determinant for a matrix, initialize with
logjac_zero(flag, x)and then accumulate with log jacobians as needed with +.
When flag is LogJac, methods should return the log Jacobian as the second argument, otherwise NoLogJac, which simply combines to itself with +, serving as an empty placeholder. This allows methods to share code of the two implementations.
TransformVariables.LogJac — Typestruct LogJac <: TransformVariables.LogJacFlagCalculate log Jacobian as the second value.
TransformVariables.NoLogJac — Typestruct NoLogJac <: TransformVariables.LogJacFlagDon't calculate log Jacobian, return NOLOGJAC as the second value.
TransformVariables.logjac_zero — Functionlogjac_zero(_, _)
Initial value for log Jacobian calculations.
Helper functions
TransformVariables.transform_with — Functiontransform_with(flag::LogJacFlag, transformation, x::AbstractVector, index)
Transform elements of x from index, using transformation.
Return (y, logjac), index′, where
yis the result of the transformation,logjacis the the log Jacobian determinant or a placeholder, depending onflag,index′is the next index inxafter the elements used for the transformation
Internal function. Implementations
can assume that
xhas enough elements fortransformation(ie@inboundscan be used),should work with generalized indexing on
x.
TransformVariables._transform_tuple — Function_transform_tuple(flag, x, index, _)
Helper function for transforming tuples. Used internally, to help type inference. Use via transfom_tuple.
TransformVariables._inverse!_tuple — Function_inverse!_tuple(x, index, ts, ys)
Helper function for inverting tuples of transformations. Used internally.
Performs no argument validation, caller should do this.
TransformVariables._inverse_eltype_tuple — Function_inverse_eltype_tuple(ts, ys)
Helper function determining element type of inverses from tuples. Used internally.
Performs no argument validation, caller should do this.
TransformVariables.unit_triangular_dimension — Functionunit_triangular_dimension(n)
Number of elements (strictly) above the diagonal in an $n×n$ matrix.
Building blocks for transformations
TransformVariables.l2_remainder_transform — Function(y, log_r, ℓ) = l2_remainder_transform(flag, x, log_r)Given $x ∈ ℝ$ and $0 ≤ r ≤ 1$, we define (y, r′) such that
$y² + (r′)² = r²$,
$y: |y| ≤ r$ is mapped with a bijection from
x, with the sign depending onx,
but use log(r) for actual calculations so that large ys still give nonsingular results.
ℓ is the log Jacobian (whether it is evaluated depends on flag).
TransformVariables.l2_remainder_inverse — Function(x, r′) = l2_remainder_inverse(y, log_r)Inverse of l2_remainder_transform in x and y.