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

pdf(MvNormal([1 0.4; 0.4 1]), [-Inf, -Inf]) is NaN while should be 0 #1937

Open
lrnv opened this issue Jan 9, 2025 · 3 comments
Open

pdf(MvNormal([1 0.4; 0.4 1]), [-Inf, -Inf]) is NaN while should be 0 #1937

lrnv opened this issue Jan 9, 2025 · 3 comments

Comments

@lrnv
Copy link

lrnv commented Jan 9, 2025

Everything is in the title. I do not really know what to do about it, is that expected ? easily fixable ?

@andreasnoack
Copy link
Member

I think we might need to add a branch for this case. While the quadratic form will always go to infinity as one of more elements diverge when the matrix is positive definite, this will not be possible to track from the individual vector elements of the intermediate values

julia> A = [1 0.4; 0.4 1]
2×2 Matrix{Float64}:
 1.0  0.4
 0.4  1.0

julia> A\[Inf, Inf]
2-element Vector{Float64}:
 NaN
 NaN

The fix should probably be in the invquad defintion in PDMats

@lrnv
Copy link
Author

lrnv commented Jan 17, 2025

@andreasnoack Thanks for pointing down the place where the issue might lie. Any chance you'll explain to me what exactly needs to happen for this to get fixed ? I could propose a PR

@andreasnoack
Copy link
Member

In the method I linked to, I think we'd have to check if the vector argument in the quadratic form for any non-finite elements. I think we can assume that the matrix doesn't have any non-finite values if the Cholesky factorization is successful. So if the vector has any Inf or -Inf values then the quadratic form should return Inf (appropriately promoted). A question is what should happen if there is a NaN. I think people interpret NaNs in two slightly different ways. Either as an undetermined limit value (which I prefer) or just as something that should always propagate. If we use the former definition then I think (but I'm not completely sure) that it would be safe to return Inf if the is an Inf even if there is also one or more NaNs in the vector since even if we don't which value the NaN should have been, it would always be dominated by the Inf in the quadratic form.

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