JuliaMath / MeasureTheory.jl

"Distributions" that might not add to one.
MIT License
385 stars 32 forks source link

Support ChangesOfVariables.with_logabsdet_jacobian for transformations #203

Open oschulz opened 2 years ago

oschulz commented 2 years ago

With ChangesOfVariables.jl we now have a standard for how to express transforms with log-abs-det-jacbian values, supported by central packages like LogExpFunctions.jl, as well as TransformVariables.jl, Bijectors.jl and others.

Transforms like AffineTransform ideally use ChangesOfVariables.with_logabsdet_jacobian as their primary LADJ-handling mechanism. This could also gradually reduce dependencies on TransformVariables.jl in the code.

Pushforward (should move into MeasureBase, see cscherrer/MeasureBase.jl#54) wouldn't need the logjac::L field anymore (with_logabsdet_jacobian now can test if an LADJ-definition exists).

cscherrer commented 2 years ago

We do need to be careful, because the transform alone isn't enough, this can depend on the base measure and the geometry of the space.

Say you have a uniform distribution on a unit 2-sphere in $\mathbb{R}^3$, and transform $(x,y,z) \mapsto (x, y, 2z)$. The logabsdet_jacobian for the ambient space is constant, 2. But this is only correct when $z=0$. And when $(x,y) = (0,0)$, the transform has no effect on the density.

oschulz commented 2 years ago

How do you handle this in MeasureBase.Pushforward currently?

cscherrer commented 2 years ago

I don't yet in Pushforward. In Affine, I think of it as a composition of an invertible square matrix and an orthogonal embedding. Then the embedding doesn't affect the log-density.

cscherrer commented 2 years ago

So you can work with the QR or LQ factorizations to start, and then find something equivalent that's as efficient as possible

cscherrer commented 2 years ago

I think for the more general case we should do (something equivalent to) logjac on the tangent space

oschulz commented 2 years ago

I think for the more general case we should do (something equivalent to) logjac on the tangent space

Hm but is there an efficient way to calculate logabsdet(J) via AD in higher dimensions?