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

SVD & Determinant

Tags: None
(comma "," separated)
seanl
Registered Member
Posts
6
Karma
0

SVD & Determinant

Thu Mar 07, 2013 2:21 pm
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!
seanl
Registered Member
Posts
6
Karma
0

Re: SVD & Determinant

Thu Mar 07, 2013 2:25 pm
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?
jitseniesen
Registered Member
Posts
204
Karma
2

Re: SVD & Determinant

Thu Mar 07, 2013 2:33 pm
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?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: SVD & Determinant

Thu Mar 07, 2013 8:11 pm
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.
seanl
Registered Member
Posts
6
Karma
0

Re: SVD & Determinant

Thu Mar 07, 2013 8:39 pm
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.


Bookmarks



Who is online

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