tpapp / TransformVariables.jl

Transformations to contrained variables from ℝⁿ.
Other
66 stars 14 forks source link

Support ChangesOfVariables and InverseFunctions #85

Closed oschulz closed 2 years ago

oschulz commented 2 years ago

This PR adds support for JuliaMath/ChangesOfVariables and JuliaMath/InverseFunctions. Both are very lightweight, dependency-free, low-bias packages designed to enable composability of packages that provide/implement or use variable transformation capabilities.

Specifically, this PR adds support for ChangesOfVariables.test_with_logabsdet_jacobian and InverseFunctions.inverse. Package like StatsFuns and LogExpFunctions already support one or both of them (JuliaStats/LogExpFunctions.jl#29, JuliaStats/LogExpFunctions.jl#30, JuliaStats/StatsFuns.jl#130). I think it would be awesome if TransformVariables would join the club.

This PR has no impact on the load time of TransformVariables

# Current master branch:
julia> @time using TransformVariables
  1.104098 seconds (3.20 M allocations: 229.310 MiB, 2.51% gc time, 39.71% compilation time)
# This PR:
julia> @time using TransformVariables
1.105833 seconds (3.20 M allocations: 229.336 MiB, 2.15% gc time, 37.48% compilation time)

CC @devmotion

tpapp commented 2 years ago

@oschulz: Thanks for the nice PR. Should I tag a release, or are you planning more additions?

oschulz commented 2 years ago

Should I tag a release

That would be great, thanks!

or are you planning more additions?

No, I think this is complete (as far as I can see for now :-) ).

I thought about proposing that TransformVariables just adopts InverseFunctions.inverse as it's own inverse, but the semantics are a bit different - InverseFunctions.inverse is more restrictive, it expects that it's argument is a function (not a Function but callable).

Btw., input on ChangesOfVariables and InverseFunctions is very welcome of course - me and @devmotion created them, but they're really intended to be standards for and carried/evolved by the whole community.