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.ShiftedExpType
struct 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ˣ.

source

Aggregating transformations

TransformVariables.ArrayTransformationType
struct ArrayTransformation{T<:TransformVariables.AbstractTransform, M} <: TransformVariables.VectorTransform

Apply transformation repeatedly to create an array with given dims.

source
TransformVariables.TransformTupleType
struct TransformTuple{T} <: TransformVariables.VectorTransform

Transform consecutive groups of real numbers to a tuple, using the given transformations.

source

Wrapper for inverse

Types and type aliases

TransformVariables.ScalarTransformType
abstract 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.

source

Conditional calculation of log Jacobian determinant

TransformVariables.LogJacFlagType
abstract 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.

source

Helper functions

TransformVariables.transform_withFunction

transform_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 on flag,

  • index′ is the next index in x after the elements used for the transformation

Internal function. Implementations

  1. can assume that x has enough elements for transformation (ie @inbounds can be

used),

  1. should work with generalized indexing on x.
source
TransformVariables._inverse!_tupleFunction
_inverse!_tuple(x, index, ts, ys)

Helper function for inverting tuples of transformations. Used internally.

Performs no argument validation, caller should do this.

source

Building blocks for transformations

TransformVariables.l2_remainder_transformFunction
(y, log_r, ℓ) =
l2_remainder_transform(flag, x, log_r)

Given $x ∈ ℝ$ and $0 ≤ r ≤ 1$, we define (y, r′) such that

  1. $y² + (r′)² = r²$,

  2. $y: |y| ≤ r$ is mapped with a bijection from x, with the sign depending on x,

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).

source