This forum has been archived. All content is frozen. Please use KDE Discuss instead.

getting values out of GeneralizedEigenSolver

Tags: None
(comma "," separated)
danpojar
Registered Member
Posts
6
Karma
0
Hello, I'm new to this library and I am trying to get some results fast.
I am using the generalized eigen solver, I can cout the values but I cannot access them individually or convert them with

eigen2cv(MatrixXd(ges.eigenvals().real()), vals);

In fact when compiling
ges.eigenvals().real();
gives
YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY

How could I acces each element of the vector of eigenvalues individually?

Thank you for reading,
Dan
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Can you be more specific? The following works for me:
Code: Select all
#include <Eigen/Eigen>
using namespace Eigen;
int main() {
  int n = 10;
  MatrixXd A(n,n), B(n,n);
  A.setRandom();
  B.setRandom();
  GeneralizedEigenSolver<MatrixXd> gen(A,B);
  VectorXd eivals = gen.eigenvalues().real();
}


BTW, in the case A and B are symmetric and one is positive definite, I'd recommend GeneralizedSelfAdjointEigenSolver: http://eigen.tuxfamily.org/dox/classEig ... olver.html
danpojar
Registered Member
Posts
6
Karma
0
First, thank you for the effort of answering. Your code does run without any issues.
Second, i've spent all day building opencv 2.4.6 hoping that their eigen module is faulty and it would work in the last version.
The difference is that I'm not generating the values randomly, I'm filling the matrices from OpenCv like this:

Mat vecs,vals;
MatrixXf A;
MatrixXf B;
MatrixXf AmlB;
VectorXf evals;

cv2eigen(S, A);
cv2eigen(C, B);

GeneralizedEigenSolver<MatrixXd> ges(A,B);

now, i get the same error at the GeneralizedEigenSolver constructor.

With the older OpenCv version it was stopping only when calling
eivals = ges.geteigenvalues().real();

and previously
ges.compute(A, B);
didn't raise errors.

Dan
jitseniesen
Registered Member
Posts
204
Karma
2
Is the issue perhaps that A and B are of type MatrixXf (matrix of floats), but ges is expecting MatrixXd (matrix of doubles)? Can you change the type of ges to GeneralizedEigenSolver<MatrixXf> ?
danpojar
Registered Member
Posts
6
Karma
0
Yes, as I was headding to the forum to write this issue I noticed you have already noticed it.
Thank you for putting up with this :P


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot], Yahoo [Bot]