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.ScalarTransform
Identity $x ↦ x$.
TransformVariables.ScaledShiftedLogistic
— Typestruct ScaledShiftedLogistic{T<:Real} <: TransformVariables.ScalarTransform
Maps to (scale, shift + scale)
using logistic(x) * scale + shift
.
TransformVariables.ShiftedExp
— Typestruct ShiftedExp{D, T<:Real} <: TransformVariables.ScalarTransform
Shifted exponential. When D::Bool == true
, maps to (shift, ∞)
using x ↦ shift + eˣ
, otherwise to (-∞, shift)
using x ↦ shift - eˣ
.
Aggregating transformations
TransformVariables.ArrayTransformation
— Typestruct ArrayTransformation{T<:TransformVariables.AbstractTransform, M} <: TransformVariables.VectorTransform
Apply transformation
repeatedly to create an array with given dims
.
TransformVariables.TransformTuple
— Typestruct TransformTuple{T} <: TransformVariables.VectorTransform
Transform consecutive groups of real numbers to a tuple, using the given transformations.
Wrapper for inverse
TransformVariables.CallableInverse
— Typestruct CallableInverse{T}
Partial application of inverse(t, y)
, callable with y
. Use inverse(t)
to construct.
Types and type aliases
TransformVariables.AbstractTransform
— Typeabstract type AbstractTransform
Supertype for all transformations in this package.
Interface
The user interface consists of
dimension
transform
transform_and_logjac
- [
inverse
]@(ref),inverse!
inverse_eltype
.
TransformVariables.ScalarTransform
— Typeabstract type ScalarTransform <: TransformVariables.AbstractTransform
Transform a scalar (real number) to another scalar.
Subtypes mustdefine transform
, transform_and_logjac
, and inverse
; other methods of of the interface should have the right defaults.
TransformVariables.VectorTransform
— Typeabstract type VectorTransform <: TransformVariables.AbstractTransform
Transformation that transforms <: AbstractVector
s 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 LogJacFlag
Flag 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
— TypeCalculate log Jacobian as the second value.
TransformVariables.NoLogJac
— TypeDon'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
y
is the result of the transformation,logjac
is the the log Jacobian determinant or a placeholder, depending onflag
,index′
is the next index inx
after the elements used for the transformation
Internal function. Implementations
- can assume that
x
has enough elements fortransformation
(ie@inbounds
can 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 y
s still give nonsingular results.
ℓ
is the log Jacobian (whether it is evaluated depends on flag
).
TransformVariables.l2_remainder_inverse
— Function