How to get eigenvectors of nonsymmetric matrix in Stan?

375 views Asked by At

Stan provides the functions

vector eigenvalues_sym(matrix A)
matrix eigenvectors_sym(matrix A)

for getting eigenvalues and eigenvectors of a symmetric matrix A, but what if your matrix is nonsymmetric? Can you still get the eigenvalues and eigenvectors? Also, is there a way to test whether I'm getting the correct eigenvectors? How do I test parts of a Stan program?

1

There are 1 answers

2
Bob Carpenter On

Stan only provides the symmetric case because we can't guarantee the answer isn't complex otherwise.

While it would be possible to code up complexes as pairs of real and start implementing some of this in Stan, it would be a huge pain. I'm afraid we only provide the symmetric case, because we can't guarantee the answer is real and we don't support . Anything else would have to be implemented from scratch in C++ or in Stan and included.

Ben Goodrich suggested a workaround in C++ that requires recompiling Stan from source for non-symmetric matrices known to produce real eigendecompositions, but it's hardly an in-language solution and not something we really recommend people do, because it'll need to be updated with each update of Stan.