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

Eigenvalues not sorted for almost perfectly symmetric matrix #343

Closed
jeff-regier opened this issue Jun 24, 2016 · 6 comments
Closed

Eigenvalues not sorted for almost perfectly symmetric matrix #343

jeff-regier opened this issue Jun 24, 2016 · 6 comments
Labels
breaking This change will break code design Design of APIs or of the language itself

Comments

@jeff-regier
Copy link

I'm not sure whether this qualifies as a bug, though the behavior seems undesirable. Below A is a matrix that is almost exactly symmetric. eigvals(A) returns the singular values without sorting them. For perfectly symmetric matrices (e.g., B below), the eigenvalues are always sorted. It seems like eigvals(A) should sort them too, since due to numerical issues, even symmetric matrices are often not exactly symmetric.

julia> A = [2.319564160285209 20.613046913136856 -0.5068584177942504
            20.613046913136856 201.80977596527438 -1.2031203195074227
            -0.5068584177942503 -1.203120319507423 11.188307566885028];

julia> eigvals(A)  # these singular values are not sorted
3-element Array{Float64,1}:
 203.926   
   0.198637
  11.1935  

julia> norm(A - A')  # though A is almost perfectly symmetric
2.482534153247273e-16

julia> B = (A + A') / 2.  # but if A is symmetrized
3x3 Array{Float64,2}:
  2.31956    20.613    -0.506858
 20.613     201.81     -1.20312 
 -0.506858   -1.20312  11.1883  

julia> eigvals(B)  # then they are sorted
3-element Array{Float64,1}:
   0.198637
  11.1935  
 203.926   
@jiahao jiahao added breaking This change will break code linear algebra design Design of APIs or of the language itself labels Jun 24, 2016
@stevengj
Copy link
Member

If you know you should have a symmetric matrix, you are well-advised to make it perfectly symmetric so that eigvals can use a more efficient algorithm. Maybe the lack of sorting here is a useful clue.

@andreasnoack
Copy link
Member

...and remember that you can simply do eigvals(Symmetric(A)) to enforce that a symmetric solver is being used.

@jeff-regier
Copy link
Author

jeff-regier commented Jun 28, 2016

I'll use Symmetric in my own program, thanks for suggestion.

Returning eigenvalues out-of-order seems to me like a somewhat opaque way to alert users that a matrix isn't perfectly symmetric. Tiny perturbations of real-valued input shouldn't drastically change the output, if possible.

@KristofferC
Copy link
Member

KristofferC commented Jun 28, 2016

There has been discussion about putting tolerances the symmetry checks but nothing concrete has come out of it.

@jiahao
Copy link
Member

jiahao commented Jul 8, 2016

Ref: discussion in #182 about approximate symmetry checks in ishermitian and issymmetric

@stevengj
Copy link
Member

Closed by JuliaLang/julia#21598.

@KristofferC KristofferC transferred this issue from JuliaLang/julia Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking This change will break code design Design of APIs or of the language itself
Projects
None yet
Development

No branches or pull requests

6 participants