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

NullPointerException in OrderedComplexEigenDecomposition #249

Closed
axkr opened this issue Apr 20, 2023 · 4 comments
Closed

NullPointerException in OrderedComplexEigenDecomposition #249

axkr opened this issue Apr 20, 2023 · 4 comments

Comments

@axkr
Copy link
Contributor

axkr commented Apr 20, 2023

Follow up from #248:

Thanks for the change, which works for most cases, but this case for matrix

Array2DRowRealMatrix{{1.0,0.0,0.0},{-2.0,1.0,0.0},{0.0,0.0,1.0}}

and the following call:

ComplexEigenDecomposition ced = new OrderedComplexEigenDecomposition(matrix, //
          ComplexEigenDecomposition.DEFAULT_EIGENVECTORS_EQUALITY, //
          ComplexEigenDecomposition.DEFAULT_EPSILON, //
          ComplexEigenDecomposition.DEFAULT_EPSILON_AV_VD_CHECK, //
          (c1, c2) -> Double.compare(c2.norm(), c1.norm()));

throws a NullPointerException

java.lang.NullPointerException: null
	at org.hipparchus.linear.AbstractFieldMatrix.setColumnVector(AbstractFieldMatrix.java:566) ~[classes/:?]
	at org.hipparchus.linear.ComplexEigenDecomposition.<init>(ComplexEigenDecomposition.java:143) ~[classes/:?]
	at org.hipparchus.linear.OrderedComplexEigenDecomposition.<init>(OrderedComplexEigenDecomposition.java:98) ~[classes/:?]

The eigenvectors contain a nullvalue at line ComplexEigenDecomposition.java:143
image

I would have expected a 0-vector {0.0,0.0,0.0} instead of the null value.

@maisonobe
Copy link
Contributor

I think that instead of returning a zero vector (as mentioned in #248 discussion), we should trigger an exception.
The eigen decomposition theorem is that decomposition is always possible "if the matrix P of eigen vectors is a square matrix". The example in MathWorld is about a 2x2 matrix where the space of eigenvectors is only 1, and the matrix in this issue is a 3x3 matrix where the space of eigenvectors is only 2.
In both cases, the eigen decomposition theorem does not apply, the matrix P is not square.

@axkr
Copy link
Contributor Author

axkr commented Apr 21, 2023

We want to implement the MMA behavior; how can we do it, if hipparchus triggers an exception?
image

https://reference.wolfram.com/language/ref/Eigenvectors.html

@maisonobe
Copy link
Contributor

OK, then I'll add the zeros, with some documentation.
It nevertheless looks strange to me as Wolfram Alpha really returns two eigenvectors for this matrix.

@axkr
Copy link
Contributor Author

axkr commented Apr 21, 2023

Yes there are some "conventions" described in the reference for symbolic and numerical evaluations.

The first 2 examples are symbolic evaluations the last 2 are numerical:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants