Registered Member
|
Hi, I am new to Eigen but I can't seem to figure out the problem that I'm having. I am using Eigen's SVD to calculate some singular values from a matrix "R" (I think it's a 3x3 matrix):
Eigen::JacobiSVD<Eigen::MatrixXd> svd(R, Eigen::ComputeThinU | Eigen::ComputeThinV); //SVD Matrix Eigen::MatrixXd U; Eigen::MatrixXd S; Eigen::MatrixXd V; double UdVd; U=svd.matrixU(); S=svd.singularValues(); V=svd.matrixV(); However, I noticed that I get different behavior when I then do: UdVd=U.determinant()*V.determinant(); std::cout << U << std::endl; ---OUTPUT--- 4.20253e-07 0.707107 -0.707107 9.86222e-10 0.707107 0.707107 1 -2.97861e-07 2.96466e-07 versus, simply: std::cout << U << std::endl; ---OUTPUT--- 0 0 1 1 3.14303e-05 0 3.14303e-05 -1 0 That is, given the same input, R, the matrix U that gets printed out is different if I omit the determinant function call. I expect U to be the same since the input is the same. Is this assumption incorrect or am I missing something here? Thanks! |
Registered Member
|
In fact, I get different results again if I do:
U.determinant(); std::cout << U << std::endl; or V.determinant(); std::cout << U << std::endl; In the latter case, I don't really understand why calculating the determinant of V could affect U. I wonder if this has anything to do with aliasing? |
Registered Member
|
You are right, computing the determinant should not change the matrix U. Unfortunately, I cannot reproduce the problem you are seeing, and I have no idea what's causing it. Could you please give us a self-contained program exhibiting the issue, and tell us the version of Eigen and the compiler that you are using?
|
Moderator
|
Indeed that does not make sense. If you are running linux or osx, I'd strongly recommend to run your program under valgrind ($ valgrind path/to/executable) to check possible memory issues.
|
Registered Member
|
My mistake. It had to do with:
Eigen::JacobiSVD<Eigen::MatrixXd> svd(R, Eigen::ComputeThinU | Eigen::ComputeThinV); I declared the "svd" matrix but "R" had not been filled yet (R had been declared but not filled). If I declare "svd" AFTER "R" has been filled then all is fine! I apologize for this oversight. |
Registered users: Bing [Bot], Google [Bot], Sogou [Bot], Yahoo [Bot]