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

More Stable invquad(A::PDMat, z::AbstractVector) #94

Closed
bayesthm opened this issue May 9, 2019 · 3 comments
Closed

More Stable invquad(A::PDMat, z::AbstractVector) #94

bayesthm opened this issue May 9, 2019 · 3 comments

Comments

@bayesthm
Copy link
Contributor

bayesthm commented May 9, 2019

For A a PDMat and z a Vector, would it not be more numerically stable to compute invquad(A, z) as

zhalf  = A.chol.L \ z
q = dot(zhalf, zhalf)

rather than the current:

invquad(a::PDMat, x::AbstractVector) = dot(x, a \ x)

In some experiments my suggested way of computing invquad(A,z) more reliably gives positive values (as it always should!) when A and z contain very large values and A is close to singular. This is important when computing logpdf() of a multivariate normal distribution at fairly extreme values using the Distributions.jl package, which appears to use the PDMats invquad() function.

If I understand the source code correctly this is already how the computation is handled in the case of z being a matrix:

function Xt_invA_X(a::PDMat, x::StridedMatrix)

An analogous suggestion could also pertain to the computing of quad(A, z), though the numerical stability properties there are probably less of a problem. I'm running Julia 1.1.0 and PDMats 0.9.7.

@andreasnoack
Copy link
Member

It would be more stable and faster as well. Would you be able to prepare a PR?

@bayesthm
Copy link
Contributor Author

Yes, I will do so.

@devmotion
Copy link
Member

Fixed by #95.

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

3 participants