optimatika / ojAlgo

oj! Algorithms
http://ojalgo.org
MIT License
464 stars 208 forks source link

problems with Eigenvalue #105

Closed hongtaicao closed 6 years ago

hongtaicao commented 6 years ago

javadoc: Eigenvalue The example of a 3 by 3 matrix locates at the end of this post.

Q1. getEigenpair(int index)

What does the parameter mean?

I assume index means the which eigenpair. For a 3 by 3 matrix, index should be in range [0, 2]. However, I got the following: getD() returns org.ojalgo.matrix.store.RawStore < 3 x 3 > getV() returns org.ojalgo.matrix.store.GenericDenseStore < 3 x 3 > getEigenpair(1) throws the following

java.lang.ArrayIndexOutOfBoundsException: 3
    at org.ojalgo.array.ReferenceTypeArray.set(ReferenceTypeArray.java:279)
    at org.ojalgo.array.PlainArray.set(PlainArray.java:123)
    at org.ojalgo.array.Array1D.set(Array1D.java:550)
    at org.ojalgo.matrix.decomposition.Eigenvalue.copyEigenvector(Eigenvalue.java:254)
    at org.ojalgo.matrix.decomposition.Eigenvalue.getEigenpair(Eigenvalue.java:279)
    ...

I think destination.set(i, tmpV.doubleValue(i, index)); of Eigenvalue.java:254 calls the wrong set function (Array1D.java:550).

Q2

Why to have both getEigenvalues() v.s. getD() for eigenvalues getEigenvectors() v.s. getV() for eigenvectors with different return types? Why does getD() and getV() always return double when decomposing a real matrix? It's possible that the eigenvectors are complex.

Q3

I want to request more documentation and example codes for common tasks.

Data

apete commented 6 years ago

A1: I confirm there is a problem and will have look at it

A2: I believe it's standard behaviour to return matrices of the same (element) type as the original matrix. Since the eigenvalues can be complex it is also convenient to be able directly get as complex numbers.

A3: This is an open source project. You're welcome to contribute documentation. I believe the wiki is editable by anyone.

apete commented 6 years ago

Please verify that the getEigenpair(int) now works:

https://github.com/optimatika/ojAlgo/tree/hotfix/EigenvalueProblems

If you verify this there shortly be a v45.1.1 release

hongtaicao commented 6 years ago

Thank you. The function getEigenpair(int index) works as my expectation. It should be fixed.

apete commented 6 years ago

v45.1.1, with this fix, is now released.