0

I'm trying to solve Generalized Eigenvalue Problem with Java and I'm currently using OjAlgo, but it cannot solve random symmetrical A and B. Only positive definite symmetrical A and B for the moment. My A and B are random symmetrical. Not positive definite.

So I will try with Python this time. Calling Python code from Java. I have one question.

Calling this MATLAB code:

[V, D] = eig(A, B)

Will solve this problem:

A*V = B*V*D

What is the equivalent code for [V, D] = eig(A, B) in Python, or other language/library that can be controlled from Java?

The current setup to solve this problem, I have been used GNU Octave for the moment, by writing a file AB, then use ProcessBuilder class to run a .m file that will load that AB and then do its procedure and then save a file VD and then after that, Java will read that VD file. Yes...it's working. But I think there must be a better way to do it?

Have a look at my project. It's image classification in Java. It's working with Yale database and Jaffed Database. Very good.

https://github.com/DanielMartensson/jFaces---Image-classification-in-Java-

Example how I solve A and B in octave:

>> A
A =

   3.509281  -0.290541   0.849415   2.013013   0.063750
  -0.290541   1.818891  -0.474449   0.278068  -1.287872
   0.849415  -0.474449   1.340873   0.739895   0.882484
   2.013013   0.278068   0.739895   1.645680   0.414309
   0.063750  -1.287872   0.882484   0.414309   4.045986

>> B
B =

   5.4158   2.8121   2.6082   3.7357  -3.8168
   2.8121   6.7481   1.6286   2.6166  -1.5062
   2.6082   1.6286   3.9394   1.7020  -3.1379
   3.7357   2.6166   1.7020   3.2538  -2.6001
  -3.8168  -1.5062  -3.1379  -2.6001   3.4518

>> [V, D] = eig(A, B)
V =

   0.300780  -0.195288   0.209747   0.946256   1.940305
   0.366251  -0.228222  -0.050912  -0.057503  -0.652739
   0.243410   0.292928   0.295219  -0.315470   2.340029
  -0.538232   0.328562  -0.767245  -0.821764   0.776394
   0.098344  -0.251445   0.047482  -0.026229   4.613170

D =

Diagonal Matrix

     0.086670            0            0            0            0
            0     0.219835            0            0            0
            0            0     0.420197            0            0
            0            0            0     1.207737            0
            0            0            0            0   157.713007

>>
euraad
  • 2,467
  • 5
  • 30
  • 51
  • See, among other posts, https://stackoverflow.com/questions/54191262/eiga-b-in-python-giving-error-takes-1-positional-argument-but-2-were-given/54191413#54191413 – Andras Deak -- Слава Україні May 16 '20 at 21:52
  • 1
    @AndrasDeak Nope. Scipy can only handle positive definitive matrices. I'm talking about random symmetrical matricies. – euraad May 16 '20 at 21:56
  • 1
    Please produce an actual example which isn't handled by `scipy.linalg.eig`. – Andras Deak -- Слава Україні May 16 '20 at 21:58
  • It's OK to use another library. As long it's a better way than writing a huge file and let Octave read it and then Octave write a huge file and then let Java read it. Sounds like a very dumb way to communicate. – euraad May 16 '20 at 21:58
  • The example you give is composed of positive definite matrices (all eigenvalues are positive which is true iff the matrices are +ve definite), and `scipy.linalg.eig` provides a sensible result with precisely the same eigenvalues and a matrix of eigenvectors that are plausibly a scaled version of the ones you give. – nanofarad May 16 '20 at 22:08
  • @nanofarad so...could you close the question as a dupe until OP proves it isn't? – Andras Deak -- Слава Україні May 16 '20 at 22:09
  • @nanofarad But is not positive definite that all elements must be greater than 0? – euraad May 16 '20 at 22:11
  • No, positive definite means that `v M v >= 0` for any vector `v` and equality only holds for `v=0`. There's a theorem that in this case every eigenvalue of `M` is positive. – Andras Deak -- Слава Україні May 16 '20 at 22:12
  • 1
    @AndrasDeak I'm not sure whether it is a dupe yet because the problem hasn't been established; I will reopen if needed. – nanofarad May 16 '20 at 22:12
  • @DanielMårtensson No, it means that [every eigenvalue](https://en.wikipedia.org/wiki/Definiteness_of_a_matrix#Connections) is strictly positive. The sign of individual elements is irrelevant (and is not preserved through transformations that preserve eigenvalues) – nanofarad May 16 '20 at 22:13
  • 2
    The [`scipy.linalg.eig`](https://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.eig.html) documentation says nothing about the matrices being positive definite. Perhaps you are confusing it with [`scipy.linalg.eigh`](https://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.eigh.html). – Warren Weckesser May 16 '20 at 22:13

0 Answers0