-
-
Notifications
You must be signed in to change notification settings - Fork 10
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
ishermitian
test's A[i,j] != ctranspose(A[j,i])
which causes problems with numerical accuracy
#182
Comments
I think the better solution here is to define |
Yes I do, but then I would need to construct the special matrix myself? If it isn’t changed a note in the documentation about the problem would probably be a good idea. |
You would only have to write |
When you know that is the trick, it is a good solution. On the other side a newcomer to the language could get really stumped by the fact |
The only reasonable thing I can think of doing here is to relax the exact inequality test to an approximate one with user-specifiable threshold. |
I don't think the two solutions exclude each other: having a floating point |
Sounds like a good idea to test for approximate equality for |
Note that Matlab's What would be the right criterion? |
If we can agree on something I would be happy to prepare a pull. As @stevengj pointed out Matlab do test for exact equallity for both Do this sound like a viable path of solving this issue? |
I think we should use a tolerance for matrices with floating point elements even though MATLAB has chosen a different solution. I don't see why you'd be interested in exact symmetry when working with floating point values. I asked @alanedelman and he is fine with such a change. So basically there should be two versions of It would be great if you could prepare a pull request with something like this. |
Should |
@andreasnoack, even if you accept that these tests should be approximate, it still seems to be an open question what those tests should be. (The test in JuliaLang/julia#10369 is clearly wrong.) As I mentioned above, possibly it should be something like |
I'm pretty sure we won't do this at this point. One thing we could consider is to remove the |
It is weird if |
I can see that but it will mainly throw in the cases people have complained about it returning |
Wouldn't we end up here then: A = [2. 1.; 0. 1.]
isposdef(A) # errors because A is not Hermitian, error message suggests using Hermitian(A)
isposdef(Hermitian(A)) # Success! But clearly A is not positive definite. |
Similarly, this error message is not very good either: julia> A = [2. 1.; 0. 1.];
julia> cholfact(A)
ERROR: ArgumentError: matrix is not symmetric/Hermitian. This error can be avoided by calling cholfact(Hermitian(A)) which will ignore either the upper or lower triangle of the matrix.
Stacktrace:
[1] cholfact(::Array{Float64,2}, ::Val{false}) at ./linalg/cholesky.jl:318 (repeats 2 times)
julia> cholfact(Hermitian(A))
Base.LinAlg.Cholesky{Float64,Array{Float64,2}} with factor:
[1.41421 0.707107; 0.0 0.707107]
successful: true
|
I think the first error message is pretty clear about what will happen if you wrap your matrix in The point regarding the
Could you explain what you mean here. I'm not sure I follow. |
There is also a more general meaning of "positive-definite" that applies to arbitrary matrices: whether the Hermitian part |
|
Exactly, we now treat bad input differently; for |
Okay, I get it. It makes sense now that we set the flag. This was also kind of a deprecation of the old behavior. Since it happened in 0.6 we could change to just setting the flag now. |
I don't there is anything left to do here. |
I think the behavior of |
I have a function where i determine the hessian with finite difference using the
hessian
function in the Calculus package. Then I test if the hessian is positive definite withisposdef
this always return false because,ishermitian
is called at: https://github.com/JuliaLang/julia/blob/5e2a6173eca65e78f787a3525bae18857d283229/base/linalg/dense.jl#L27-L28before the
LAPACK.potrf!
is called. Due to numerical inaccuracy willishermitian
always return false becauseA[i,j] != ctranspose(A[j,i])
in https://github.com/JuliaLang/julia/blob/5e2a6173eca65e78f787a3525bae18857d283229/base/linalg/generic.jl#L282, will return true for somei,j
due to numerical inaccuracy. If I change the line to!isapprox(A[i,j],ctranspose(Aj,i]))
theishermitian
returns true and hence also call theLAPACK.potrf!
to check if it is positive definite.So from my point of view, should
ishermitian
test approximately equality.The text was updated successfully, but these errors were encountered: