How to use function 'eigenvalues' from the stan math library

Dear community

I am kind of new in Stan. I need to calculate eigenvalues and eigenvectors of non-symmetric matrices. I saw that there are two functions in the stan math library called ‘eigenvalues’ and ‘eigenvectors’. I have tried to follow the external C++ examples, but I have not been able to make them work.
Could anybody explain me in an easy way what to do?

Thank you,
Alex

2 Likes

The first question is: Is there some special condition that is going to guarantee these asymmetric matrices have real eigenvalues? Or are you going to have to deal with complex numbers (in which case, the version of Stan Math you are working with matters)?

Let’s say that I will put limits to the parameters’ values to make sure that non complex eigenvalues are involved. Also I would like to add that the operation that I would like to do is the generalized eigenvalue decomposition.

For a generalized eigenvector problem with no structure on the input matrices, I think you would have to write a C++ function that wraps

http://eigen.tuxfamily.org/dox/classEigen_1_1RealQZ.html

but you would have to do some stuff to get the generalized eigenvalues without introducing std::complex. Or use a recent enough Stan Math that has complex number support, call the regular generalized eigensolver in Eigen, and throw away the imaginary parts (which should be numerically zero).

Does next release of stan have an eigenvalue function for non-symmetric functions since Stan now supports complex numbers?

Adding support for special functions like this will be ongoing over the next few versions. Off the top of my head, the answer will still be “not yet”. If you’d like to open an issue to keep track of it, I encourage you to do so. I don’t believe this has been on our radar quite yet

I’ve started the work needed to expose this to the language for the next version

I opened a new issue. Thanks for the reply