I am refactoring TransformVariables.jl. I have a conceptual question which I think this package solves (I think), so I want to ask for advice.
For those unfamiliar with the package, it encodes uni- and multivariate domain transformations, mostly for use in Bayesian estimation with samplers that work on an unconstrained Euclidean space. When calculating a log likelihood, this requires a correction by the log of the absolute value of the determinant of the Jacobian.
The current API is
y, lj = transform_and_logjac(transformation, x)
mapping x to y, with lj as the log abs det J.
This is cumbersome, as the user has to keep and accumulate ljs. Since those statements are usually followed by a logpdf(some_distribution, y) somewhere, I thought of returning a
struct ValueWithLogjac{T,L}
y::T
lj::L
end
wrapper, defining
Base.logpdf(distribution, v::ValueWithLogjac) = logpdf(distribution, v.y) + v.lj
but that would require loading Distributions.jl, a heavy dependency. Now JuliaStats/Distributions.jl#1139 would solve that but it seems not to be going anywhere. However, I could just do
DensityInterface.logdensityof(object, v::ValueWithLogjac) = DensityInterface.logdensityof(distribution, v.y) + v.lj
which works automatically for types in Distributions.jl, and is lightweight.
Does this conform with the intended usage of this package? Or should I try factoring out a DistributionsCore.jl again? Thoughts are appreciated.
I am refactoring TransformVariables.jl. I have a conceptual question which I think this package solves (I think), so I want to ask for advice.
For those unfamiliar with the package, it encodes uni- and multivariate domain transformations, mostly for use in Bayesian estimation with samplers that work on an unconstrained Euclidean space. When calculating a log likelihood, this requires a correction by the log of the absolute value of the determinant of the Jacobian.
The current API is
mapping
xtoy, withljas the log abs det J.This is cumbersome, as the user has to keep and accumulate
ljs. Since those statements are usually followed by alogpdf(some_distribution, y)somewhere, I thought of returning awrapper, defining
but that would require loading Distributions.jl, a heavy dependency. Now JuliaStats/Distributions.jl#1139 would solve that but it seems not to be going anywhere. However, I could just do
which works automatically for types in Distributions.jl, and is lightweight.
Does this conform with the intended usage of this package? Or should I try factoring out a DistributionsCore.jl again? Thoughts are appreciated.