@@ -22,6 +22,13 @@ Base.propertynames(d::AffineTransform{N}) where {N} = N
2222(f:: AffineTransform{(:μ,:σ)} )(x) = f. σ * x + f. μ
2323(f:: AffineTransform{(:μ,:ω)} )(x) = f. ω \ x + f. μ
2424
25+ # TODO : `log` doesn't work for the multivariate case, we need the log absolute determinant
26+ logjac (f:: AffineTransform{(:μ,:σ)} ) = log (f. σ)
27+ logjac (f:: AffineTransform{(:μ,:ω)} ) = - log (f. ω)
28+ logjac (f:: AffineTransform{(:σ,)} ) = log (f. σ)
29+ logjac (f:: AffineTransform{(:ω,)} ) = - log (f. ω)
30+ logjac (f:: AffineTransform{(:μ,)} ) = 0.0
31+
2532# ##############################################################################
2633
2734struct Affine{N,M,T} <: AbstractMeasure
@@ -61,8 +68,6 @@ Base.propertynames(d::Affine{N}) where {N} = N ∪ (:parent,)
6168 end
6269end
6370
64-
65-
6671# Note: We could also write
6772# logdensity(d::Affine, x) = logdensity(inv(getfield(d, :f)), x)
6873
@@ -74,16 +79,12 @@ logdensity(d::Affine{(:μ,)}, x) = logdensity(d.parent, x - d.μ)
7479
7580basemeasure (d:: Affine ) = Affine (getfield (d, :f ), basemeasure (d. parent))
7681
77- basemeasure (d:: Affine{N,L} ) where {N, L<: Lebesgue } = d. parent
82+ # We can't do this until we know we're working with Lebesgue measure, since for
83+ # example it wouldn't make sense to apply a log-Jacobian to a point measure
84+ basemeasure (d:: Affine{N,L} ) where {N, L<: Lebesgue } = WeightedMeasure (- logjac (d), d. parent)
7885
79- logdensity (d:: Affine{N,L} , x) where {N,L <: Lebesgue } = logjac (getfield (d, :f ))
86+ logjac (d:: Affine ) = logjac (getfield (d, :f ))
8087
81- # TODO : `log` doesn't work for the multivariate case, we need the log absolute determinant
82- logjac (:: AffineTransform{(:μ,:σ)} ) = - log (d. σ)
83- logjac (:: AffineTransform{(:μ,:ω)} ) = log (d. ω)
84- logjac (:: AffineTransform{(:σ,)} ) = - log (d. σ)
85- logjac (:: AffineTransform{(:ω,)} ) = log (d. ω)
86- logjac (:: AffineTransform{(:μ,)} ) = 0.0
8788
8889function Base. rand (rng:: Random.AbstractRNG , :: Type{T} , d:: Affine ) where {T}
8990 z = rand (rng, T, parent (d))
0 commit comments