"Fancy" matrix variable transformations in TransformVariables.jl / DynamicHMC.jl

Lately I’ve been using @Tamas_Papp’s excellent DynamicHMC package (thank you, Tamas!) and it’s been a lot of fun, but was hoping someone could point me in the right direction with a few more esoteric variable transformations using TransformVariables.jl, e.g.

  • A matrix each column of which is L1 normalized (to be used with a Dirichlet prior)
  • A symmetric matrix

I realise that similar examples to these exist in the special_arrays.jl, namely UnitVector and CorrCholeskyFactor. Does the following seem like the right approach?

  • Declare a struct in each case, e.g.
TransformVariables.@calltrans struct UnitColumnMatrix <: TransformVariables.VectorTransform
  • Implement dimension, transform_with, inverse_eltype, and inverse! for each type.

I am happy to hear that you find the package useful.

You can use a stick-breaking transform to make L1-unit vectors, as described eg in the Stan docs. I am quite busy at the moment, but if you open an issue I am happy to add them in the medium rum.

As for symmetric matrices, just generate them from a vector of the upper or lower triangle. Since the transformation is trivially linear, there is no need for a Jacobian adjustment.

Thanks, Tamas! I’ll have a go at this and open an issue if I get stuck.

1 Like