JuliaStats / Distributions.jl

A Julia package for probability distributions and associated functions.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

rand gives wrong results for MvNormal with PSDMat covariance

knuesel opened this issue · comments

As mentioned in #1602, #1596 and #791 a naive MvNormal([0 0; 0 1]) fails with

ERROR: PosDefException: matrix is not positive definite; Cholesky factorization failed.

The proposed workaround for rand is to use PSDMat but that gives wrong results. Here's a MWE with Distribution 0.25.100 and PDMatsExtras 2.6.3:

julia> using Distributions, PDMatsExtras

julia> x = MvNormal([0, 0], PSDMat([0. 0; 0 1]))
MvNormal{Float64, PSDMat{Float64, Matrix{Float64}}, Vector{Float64}}(
dim: 2
μ: [0.0, 0.0]
Σ: [0.0 0.0; 0.0 1.0]
)

julia> rand(x)
2-element Vector{Float64}:
 -1.045836214782949
  0.0

It looks like the output values are swapped.

I believe this can now be closed as fixed in PDMatsExtras

Thanks for the quick fix!