haifengl / smile

Statistical Machine Intelligence & Learning Engine
https://haifengl.github.io
Other
5.99k stars 1.12k forks source link

UPLO property of eigenvector matrix should be null #717

Closed afossa closed 2 years ago

afossa commented 2 years ago

Describe the bug Computing the eigenvalues of a symmetric matrix M (with M.uplo equal to LOWER or UPPER) returns an EVD object whose Vr matrix has the uplo property still set to either LOWER or UPPER.

Expected behavior Independently from the uplo of the input matrix, EVD.Vr.uplo should be null.

Actual behavior EVD.Vr.uplo is the same as M.uplo due to the fact that M is firstly cloned and then Vr is overwritten on the clone of M.

Code snippet

final Matrix L = Matrix.randn(6, 6);
final Matrix P = L.mt(L).uplo(UPLO.LOWER);
final Matrix.EVD evd = P.eigen();
System.out.println("UPLO of Vr: " + evd.Vr.uplo());

Additional context Smile library: fresh clone of master branch Java: OpenJDK 11.0.11 OS: Ubuntu 18.04 Linux 5.4.0

haifengl commented 2 years ago

Fixed. Please try master branch. Thanks!

afossa commented 2 years ago

The eigen decomposition works fine now, but I am getting a NullPointerException if I try to compute the inverse of a matrix from its Cholesky decomposition

Exception in thread "main" java.lang.NullPointerException
    at smile.math.blas.openblas.OpenBLAS.potrs(OpenBLAS.java:1001)
    at smile.math.matrix.Matrix$Cholesky.solve(Matrix.java:2588)
    at smile.math.matrix.Matrix$Cholesky.inverse(Matrix.java:2563)

The issue is solved by re-setting Matrix.Cholesky.lu.uplo to a non-null value, although I am still investigating how this trick affects the solution

haifengl commented 2 years ago

I went too far on uplo. It is fixed now.