-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
Idea: linear algebra methods for decomposition, eigenvalues and etc.. #1175
Comments
yeah, this would be awesome of course 😎 |
Related: #672 |
Hi, just letting you know I am currently working on eigenvalue/vector function. |
awesome @honeybar ! |
Any progress? |
I haven't had any update about it. |
Any progress now? We have just "found out" that numeric.js has a bug in calculating eig values. And I was not able to find any trustworthy javascript library. + can this be takend out of Math.js docs? Its recommending numeric.js for eig calculations Issues with numeric.js |
@josdejong Hi, I am so sorry. It is been a while and I am busy with work. I dont think I am able to complete it. Feel free to pass it over to anyone. |
Thanks for getting back @honeybar, no problem at all! Anyone interested in implementing eigenvalues and eigenvectors? |
I am interested. I have already written a small diagonalization library : https://github.com/arkajitmandal/DiagonalizeJS |
That is exactly what we're looking for Arkajit! Thanks for your offer. Would be great if you can implement this in mathjs. Note that right now mathjs supports numbers and BigNumbers. An implementation for both would be great but it makes sense to me to start simple with just support for numbers. What do you think is a good approach to integrated this functionality in mathjs? |
I agree, I would start with simple. I will begin with the eigenvalue eigenvectors for real symmetric matrix. |
I think |
I have started coding. I will ask you if I get some problem. Thanks |
Hi !
After running build-and-test my unit-tests pass, how ever I get this error: 35 passing (3s)
Could you tell me what am I missing thanks in advance. |
That looks promising Arkajit 👍 The issue |
@arkajitmandal This looks awesome, any updates? :) |
The present version of MathJS now has a math.eigs function that can compute eigenvalue/eigenvector for real symmetrix matrix. |
Cool! In my opinion the best way to implement a general-case function eigs_general(M: Matrix)
{
let E = math.identity( math.size(M) );
let l = math.symbols('l');
let charEqn = math.evaluate( 'det( M - l*E )', {M, E, l} );
let eigVals = math.solve( charEqn, l );
let eigVecs = [];
for (ev of eigVals) {
mat = math.evaluate('M - ev*E', {M, E});
eigVecs.push( ...math.kernel(mat) );
}
return [eigVals, eigVecs];
} I know it sounds daunting at first, but imho it would benefit math.js as a whole. If you don't have time for that, I should be able to do that some time later this month. But if you think another approach would be better, go ahead! |
I think I would focus on other parts, .... JosDeJong would be able to let you know if this is something he would like to have for mathjs. :) |
@m93a do you mean like first use symbolic computation to turn I think implementing a solver for polynomial equations will be great to have on it's own, but as far as I know you can't "just" solve every polynomial symbolically, or is it? And how will this scale if you have a large real world matrix with ugly values? Will it feasible computationally to write it out as a polynomial and evaluate it? I have the feeling that it will explode. Probably going the numerical way is probably more robust and performant (and there are proven algorithms and libraries we can use for inspiration). I don't know for sure though. What do you guys think? |
@josdejong I think that the problem of finding eigenvalues of a matrix is equivalent to that of solving a polynomial. So yes, the polynomial would grow with O(n²), but so would the problem itself. But I haven't studied this problem for long enough, so it's possible I'm missing something important. However, there's a great article about eigenvalue algorithms on Wikipedia. It says, for example, that:
So it seems that we can take the naïve approach I suggested and move the hard numerical algorithms to the polynomial solver. I'll take more time to look at it after my QM exam next week 😅️ |
That is an excellent Wikipedia page 👍 . What sounds like the easiest solution to me is pick one of the iterative, numeric methods listed on that page, one that works for generic matrices. It could be interesting to experiment with your idea of writing out the polynomial and solve that (numerically with a root-finding algorithm?). My gut feeling though is that that will be more complicated and very slow. But maybe you can prove me wrong 😄 . |
I started reading Numerical recipes in Fortran 77 and there they say:
So you were right, there are much better ways to tackle the issue. According to the book, a good library will provide methods that return:
Computing eigenvectors takes a lot of time, even when you know the eigenvalues. They also say that the library should have algorithms for these specific cases:
I'll try to implement an algorithm that computes all eigenvalues and all eigenvectors for a complex, non-Hermitian matrix, I'm starting issue #1741 for that. But even after I'm done with the algorithm, there will still be a lot to improve. |
Thanks for your research and the update @m93a , sounds like a good start 👍 |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Hi again =)
Throwing another idea of implementing some useful methods of linalg, mostly inspired by Numpy. Again, anyone who is doing Machine Learning in JS will benefit from Math.js if we can support APIs like:
https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.linalg.svd.html#numpy.linalg.svd
https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.linalg.eig.html#numpy.linalg.eig
The text was updated successfully, but these errors were encountered: