RE: [eigen] SVD with singular matrices

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


This simple test fails:

bool testSingularMatrixSVD()
{
    MatrixXd a(2,2), avalidation(2,2);
    unsigned int rows = 2;
    unsigned int cols = 2;

    a <<    1,     1,
            0,     0;

    Eigen::SVD<MatrixXd> svd(a);
    MatrixXd sigma = MatrixXd::Zero(rows,cols);
    MatrixXd matU  = MatrixXd::Zero(rows,rows);
    sigma.diagonal() = svd.singularValues();
    matU = svd.matrixU();
    avalidation = matU * sigma * svd.matrixV().transpose();

    cout << "testSingularMatrixSVD() : ";
    if((a).isApprox(avalidation, 1e-12))
    {
        cout << "Success." << endl;
        return true;
    }
    else
    {
        cout << "Fail." << endl;
        return false;
    }

} 


-----Message d'origine-----
De : Listengine [mailto:listengine@xxxxxxxxxxxxxxxxx] De la part de Benoit Jacob
Envoyé : 29 septembre 2010 10:32
À : eigen@xxxxxxxxxxxxxxxxxxx
Objet : Re: [eigen] SVD with singular matrices

2010/9/29  <hamelin.philippe@xxxxxxx>:
> Hello,
>
> when updating from eigen2 to eigen3, I found that my pseudo-inverse was not
> working correctly for singular matrices. However, just replacing SVD with
> JacobiSVD makes it work. Before looking further, is there any limitation
> with SVD with singular matrices such as:
>
> [1 1;0 0]

JacobiSVD always works, and is always precise. But it's slow for large matrices.

SVD uses the Golub-Kahan bidiagonalization approach. So it's faster,
but potentially inaccurate for certain singular matrices.

I would be surprised though if the above 2x2 matrix was enough to
expose problems in it. That would be a bug. Can you make a compilable
test case?

Thanks,
Benoit

>
> Thank you,
>
> ------------------------------------
> Philippe Hamelin, ing. jr, M. Ing
> Chercheur / Researcher
>
> T: 450-652-8499 x2198
> F: 450-652-1316
>
> Expertise robotique et civil
> Institut de recherche d'Hydro-Québec (IREQ)
> 1740, boul. Lionel-Boulet
> Varennes (QC) J3X 1S1, Canada
>





Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/