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

rand gives wrong results for MvNormal with PSDMat covariance #1776

Closed
knuesel opened this issue Sep 15, 2023 · 3 comments
Closed

rand gives wrong results for MvNormal with PSDMat covariance #1776

knuesel opened this issue Sep 15, 2023 · 3 comments

Comments

@knuesel
Copy link
Contributor

knuesel commented Sep 15, 2023

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.

@knuesel
Copy link
Contributor Author

knuesel commented Sep 15, 2023

Should be fixed by invenia/PDMatsExtras.jl#33

@oxinabox
Copy link
Contributor

I believe this can now be closed as fixed in PDMatsExtras

@knuesel knuesel closed this as completed Sep 15, 2023
@knuesel
Copy link
Contributor Author

knuesel commented Sep 15, 2023

Thanks for the quick fix!

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

No branches or pull requests

2 participants