mathjs icon indicating copy to clipboard operation
mathjs copied to clipboard

Add a function that only finds eigenvalues, not eigenvectors

Open cshaa opened this issue 4 years ago • 4 comments

The current implementation of eigs for complex matrices (see PR #1743) starts with finding eigenvalues and then proceeds to find eigenvectors. Since not everybody needs eigenvectors, a significant portion of time could be saved by skipping this part. This is one small step towards fixing #1175.

cshaa avatar Apr 12 '21 21:04 cshaa

👍 makes sense

josdejong avatar Apr 18 '21 08:04 josdejong

May I work on this?

Priyaraj17 avatar May 22 '21 10:05 Priyaraj17

Yes, definitely :) The algorithms you'll want to use are in /src/function/matrix/eigs/. I'm not sure about the algorithm for real symmetric matrices, but the one for complex matrices has a boolean argument indicating whether it sould find eigenvectors or not, so the implementation should be fairly simple there.

cshaa avatar May 22 '21 12:05 cshaa

Thanks for your offer @Priyaraj17 👍

josdejong avatar May 22 '21 14:05 josdejong

Since the flag to only find eigenvalues is already there in src/function/matrix/eigs/complexEigs.js, it would only take a small change to the definition of the eigs() function to enable this. (The overhead of eigenvectors in the real symmetric case is much less, and so at least as a first pass you could just compute them and throw them away in that case.) So this would still be a potentially worthwhile change. Allowing the second argument to eigs to be a options object with properties precision (a number) and/or eigenvectors (a boolean, defaulting to true), but when it is just a number interpreting it as precision, would be a plausible non-breaking way to achieve this. Or possibly since we are about to break anyway (see #3032), would we want to just change the second argument of eigs() to have to be such an options object? Just a thought, I could do a quick PR in time for v12 if desired.

gwhitney avatar Oct 03 '23 03:10 gwhitney

Great idea!

It would be neat to change the syntax of eigs and complexEigs to have an object with options { precision?: number, eigenvectors?: boolean }. I'm also wondering about the second argument of complexEigs, the size of the matrix N, that could be easily determined inside the function itself.

Right now, complexEigs is not exposed in the public API, it is only used internally inside eigs, so we can change the syntax as we like. I would like to keep the arguments of eigs backward compatible so it's not a breaking change, and I think that is perfectly possible: then it has the following syntax:

eigs(x)
eigs(x, precision)
eigs(x, options) // options: { precision?, eigenvectors? }

josdejong avatar Oct 04 '23 09:10 josdejong

Fixed now in v12.0.0 via #3057.

josdejong avatar Oct 26 '23 10:10 josdejong