Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with affine transform and MvNormal #188

Closed
ptiede opened this issue Apr 17, 2022 · 2 comments · Fixed by #189
Closed

Issue with affine transform and MvNormal #188

ptiede opened this issue Apr 17, 2022 · 2 comments · Fixed by #189

Comments

@ptiede
Copy link

ptiede commented Apr 17, 2022

Hi Chad,

I was just checking out the new version and noticed I was getting an inconsistent answer. Here is an MWE

using MeasureTheory
import Distributions as Dists
using LinearAlgebra

μ = zeros(2)
Σ = [1.0 0.0; 0.0 2.0]
Ω = [1.0 0.0; 0.0 0.5]

σC = cholesky(Σ)
ωC = cholesky(Ω)

dd = Dists.MvNormal(μ, Σ)

d1 = MvNormal{(:μ, :σ)}((μ=μ, σ=σC.L))
d2 = MvNormal{(:μ, :ω)}((μ=μ, ω=ωC.L))
d3 = Affine(AffineTransform((;μ, σ=σC.L)), Normal()^2)

# I expect this to give -0.5 log((2π)^2 * 2) ≈ -2.1845

logdensityof(dd, zeros(2)) # ≈ -2.1845
logdensityof(d1, zeros(2)) # ≈ -3.676
logdensityof(d2, zeros(2)) # ≈ -3.676
logdensityof(d3, zeros(2)) # ≈ -3.676

From my poking around, it looks like the log jacobian of the affine transform isn't being included in the density calculation, and inv(2pi) is being included twice: once in the basemeasure density and a second time in the proxy call.

@cscherrer
Copy link
Collaborator

Ouch, that's a big one - thanks for catching it. I should be able to fix this today (high priority, obviously). Here's an easy test to add

julia> v = diagm(rand(2))
2×2 Matrix{Float64}:
 0.341486  0.0
 0.0       0.569916

julia> z = zeros(2)
2-element Vector{Float64}:
 0.0
 0.0

julia> logdensityof(MvNormal=z,σ=v), z)  logdensityof(MvNormal=v), z)
false

@cscherrer
Copy link
Collaborator

Thanks again @ptiede , this should be fixed in 0.15.1. Please reopen if you still see an issue :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants