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

Weird behaviour of JacobiSVD will full pivoting

Tags: None
(comma "," separated)
Seb
Registered Member
Posts
99
Karma
0
I have wrong results on Mac (GCC 4.2.1) and Win64 (Mingw 4.6) using the following test code:

Code: Select all
        Eigen::MatrixXd matrix(10,6);
        matrix.setZero();
        matrix(0,0) = 1.0;
        matrix(1,1) = 2.0;
        matrix(2,2) = 3.0;
        matrix(3,3) = 4.0;
        matrix(4,4) = 5.0;
        matrix(1,0) = 1.0;
        matrix(2,1) = 1.0;

        Eigen::JacobiSVD<Eigen::MatrixXd, Eigen::FullPivHouseholderQRPreconditioner> svd( matrix , Eigen::ComputeThinU | Eigen::ComputeThinV);
//        Eigen::JacobiSVD<Eigen::MatrixXd> svd( matrix , Eigen::ComputeThinU | Eigen::ComputeThinV);
//        Eigen::JacobiSVD<Eigen::MatrixXd, Eigen::HouseholderQRPreconditioner> svd( matrix , Eigen::ComputeThinU | Eigen::ComputeThinV);

        Eigen::MatrixXd u = svd.matrixU();
        Eigen::MatrixXd v = svd.matrixV();
        Eigen::MatrixXd s = svd.singularValues();
        Eigen::MatrixXd AA = u * s.asDiagonal() * v.transpose();

        std::cout << "matrix: " << std::endl << matrix << std::endl;
        std::cout << "U: " << std::endl << u << std::endl;
        std::cout << "V: " << std::endl << v << std::endl;
        std::cout << "singular values: " << std::endl << s << std::endl;
        std::cout << "matrix (restored from SVD): " << std::endl << AA << std::endl;


The output is:
Code: Select all
matrix:
1 0 0 0 0 0
1 2 0 0 0 0
0 1 3 0 0 0
0 0 0 4 0 0
0 0 0 0 5 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
U:
-2.68156e+154  2.12467e-314  2.78656e-314   1.7644e-314  1.63239e-314  5.43472e-323
-2.68156e+154  2.12466e-314  2.71314e-314  1.22091e-314 -4.20287e-315             0
 2.12465e-314  5.43231e-312  3.66692e-312  9.85896e-312 -2.71945e-312 -2.68156e+154
 2.78134e-309             0   1.0571e-309  7.82591e-309   2.9558e-308 -2.68156e+154
 2.12466e-314  1.25987e-321 -2.52434e+154  8.92817e+153 -1.46106e+153  2.12465e-314
 4.17201e-309  2.12467e-314 -2.52434e+154  8.92817e+153 -1.46106e+153  2.78134e-309
 2.12467e-314  2.12467e-314 -8.99936e+153 -2.43375e+154  6.76556e+153  2.12467e-314
 2.12467e-314  2.12467e-314 -8.99936e+153 -2.43375e+154  6.76556e+153             0
 2.12467e-314  2.12467e-314 -9.26526e+152 -6.85923e+153 -2.59069e+154  2.12467e-314
 6.95336e-309  1.39067e-308     0.0691035      0.511585       1.93223  5.56268e-309
V:
        0         0   0.11309  0.545513  0.830437         0
        0         0  0.492679  0.695022 -0.523653         0
        0         0  0.862832 -0.468359  0.190162         0
        0         1         0         0         0         0
        1         0         0         0         0         0
        0         0         0         0         0         1
singular values:
5
4
3.27307
2.13264
0.859565
0
matrix (restored from SVD):
 4.24935e-314  6.37402e-314  6.37402e-314   8.4987e-314 -1.34078e+155             0
 2.12466e-314    6.374e-314  6.37402e-314  8.49864e-314 -1.34078e+155             0
 1.08859e-311  2.17505e-311  6.37402e-314  2.17292e-311  1.06233e-313             0
 3.05948e-308  1.97626e-323   1.4822e-323             0  1.39067e-308             0
-8.93139e+138 -2.68156e+154 -8.04468e+154  5.03947e-321  1.06233e-313             0
-8.93139e+138 -2.68156e+154 -8.04468e+154  8.49869e-314  2.08601e-308             0
-2.68156e+154 -5.36312e+154 -3.38649e+139   8.4987e-314  1.06234e-313             0
-2.68156e+154 -5.36312e+154 -3.38649e+139   8.4987e-314  1.06234e-313             0
-2.68156e+154 -8.93139e+138             0   8.4987e-314  1.06234e-313             0
            2   5.55112e-16   5.55112e-17  5.56268e-308  3.47668e-308             0


Note,
Eigen::JacobiSVD<Eigen::MatrixXd> svd( matrix , Eigen::ComputeThinU | Eigen::ComputeThinV);
Eigen::JacobiSVD<Eigen::MatrixXd, Eigen::HouseholderQRPreconditioner> svd( matrix , Eigen::ComputeThinU | Eigen::ComputeThinV);
are working. Only FullPivHouseholderQRPreconditioner is not working here. Matrix U is arbitrarily filled.

GCC flags: -O2, -DNDEBUG, -std=c++98

Best regards
Sebastian
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
You should try without -DNDEBUG to get the explanation:

assertion failed: !(m_computeThinU || m_computeThinV) && "JacobiSVD: can't compute thin U or thin V with the FullPivHouseholderQR preconditioner. " "Use the ColPivHouseholderQR preconditioner instead."
Seb
Registered Member
Posts
99
Karma
0
Ups. Thanks! It would be good to produce empty matrices in this case.

I always use NDEBUG because some of the sparse operations need too much time using the old GCC 4.2 :(
Sorry for bugging....
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Indeed, asserts are extremely slow with gcc 4.2 to workaround a compiler bug of this specific version.


Bookmarks



Who is online

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