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

incorrect rank of matrix

Tags: None
(comma "," separated)
eendebakpt
Registered Member
Posts
2
Karma
0

incorrect rank of matrix

Thu Jan 30, 2014 7:42 pm
Dear all,

On the Eigen website there is a catalogue of matrix decompositions. I need to calculate the rank and eigenvalues of matrices of the form Q=X^T X. Based on the catalogue I selected JacobiSVD to calculate the rank and eigenvalues of X. Using these I can calculate the eigenvalues of Q. It turns out that JacobiSVD returns a different rank than the FullPivLU method (using sympy I checked that the FullPivLU method returns the correct rank, one of the eigenvalues is zero).

Which methods can I use to be sure the rank and eigenvalues are correct? In the catalogue the reliability of the JacobiSVD is stated as Excellent-Proven, but for my matrices the rank is not correct. An example matrix X is included below.

With kind regards,
Pieter Eendebak

matrix X (48 x 22)

1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
1 -1 -1 -1 -1 -1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 1 1 1 1
1 -1 -1 -1 -1 1 1 -1 -1 -1 -1 -1 -1 1 1 1 1 1 1 1 1 -1
1 -1 -1 -1 -1 1 1 -1 -1 -1 -1 -1 -1 1 1 1 1 1 1 1 1 -1
1 -1 -1 -1 1 -1 -1 -1 -1 -1 1 1 1 -1 -1 -1 1 -1 -1 -1 1 -1
1 -1 -1 1 -1 1 -1 -1 1 1 -1 -1 1 1 1 -1 1 -1 -1 1 -1 1
1 -1 -1 1 1 -1 1 -1 1 1 1 1 -1 -1 -1 1 1 1 1 -1 -1 1
1 -1 -1 1 1 -1 1 -1 1 1 1 1 -1 -1 -1 1 1 1 1 -1 -1 1
1 -1 -1 1 1 1 -1 -1 1 1 1 1 -1 1 1 -1 -1 -1 -1 1 1 1
1 -1 -1 1 1 1 -1 -1 1 1 1 1 -1 1 1 -1 -1 -1 -1 1 1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2014 9:36 am
I tried JacobiSVD, FullPivLU, and ColPivHouseholderQR, and they all return 21 for the rank using the devel branch:
Code: Select all


#include <Eigen/Eigen>
#include <iostream>
using namespace Eigen;

int main() {
  MatrixXd M(48,22);

  M << 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
  1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
  1,-1,-1,-1,-1,-1,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,1,1,1,1,
  1,-1,-1,-1,-1,1,1,-1,-1,-1,-1,-1,-1,1,1,1,1,1,1,1,1,-1,
  1,-1,-1,-1,-1,1,1,-1,-1,-1,-1,-1,-1,1,1,1,1,1,1,1,1,-1,
  1,-1,-1,-1,1,-1,-1,-1,-1,-1,1,1,1,-1,-1,-1,1,-1,-1,-1,1,-1,
  1,-1,-1,1,-1,1,-1,-1,1,1,-1,-1,1,1,1,-1,1,-1,-1,1,-1,1,
  1,-1,-1,1,1,-1,1,-1,1,1,1,1,-1,-1,-1,1,1,1,1,-1,-1,1,
  1,-1,-1,1,1,-1,1,-1,1,1,1,1,-1,-1,-1,1,1,1,1,-1,-1,1,
  1,-1,-1,1,1,1,-1,-1,1,1,1,1,-1,1,1,-1,-1,-1,-1,1,1,1,
  1,-1,-1,1,1,1,-1,-1,1,1,1,1,-1,1,1,-1,-1,-1,-1,1,1,1,
  1,-1,-1,1,1,1,1,-1,1,1,1,1,-1,1,1,-1,-1,1,1,-1,-1,-1,
  1,-1,1,-1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,1,-1,1,-1,-1,1,
  1,-1,1,-1,1,-1,1,1,-1,1,1,-1,1,-1,1,-1,1,1,-1,1,-1,1,
  1,-1,1,-1,1,-1,1,1,-1,1,1,-1,1,-1,1,-1,1,1,-1,1,-1,1,
  1,-1,1,-1,1,1,-1,1,-1,1,1,-1,1,1,-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,-1,1,-1,1,-1,1,-1,1,1,-1,1,-1,1,-1,1,1,-1,1,-1,1,
  1,1,-1,1,1,-1,1,1,-1,1,-1,1,-1,1,-1,1,1,-1,1,-1,-1,1,
  1,1,1,-1,-1,-1,-1,-1,1,1,1,1,-1,1,1,-1,-1,1,1,-1,-1,-1,
  1,1,1,-1,-1,-1,1,-1,1,1,1,1,-1,1,1,-1,-1,-1,-1,1,1,1,
  1,1,1,-1,-1,-1,1,-1,1,1,1,1,-1,1,1,-1,-1,-1,-1,1,1,1,
  1,1,1,-1,-1,1,-1,-1,1,1,1,1,-1,-1,-1,1,1,1,1,-1,-1,1,
  1,1,1,-1,-1,1,-1,-1,1,1,1,1,-1,-1,-1,1,1,1,1,-1,-1,1,
  1,1,1,-1,1,-1,1,-1,1,1,-1,-1,1,1,1,-1,1,-1,-1,1,-1,1,
  1,1,1,1,-1,1,1,-1,-1,-1,1,1,1,-1,-1,-1,1,-1,-1,-1,1,-1,
  1,1,1,1,1,-1,-1,-1,-1,-1,-1,-1,-1,1,1,1,1,1,1,1,1,-1,
  1,1,1,1,1,-1,-1,-1,-1,-1,-1,-1,-1,1,1,1,1,1,1,1,1,-1,
  1,1,1,1,1,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,1,1,1,1,
  1,1,1,1,1,1,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
  1,1,1,1,1,1,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1;
 
  JacobiSVD<MatrixXd> svd(M);
  FullPivLU<MatrixXd> lu(M);
  ColPivHouseholderQR<MatrixXd> qr(M);
  std::cout << svd.rank() << ", " << lu.rank() << ", " << qr.rank() << "\n";

}
eendebakpt
Registered Member
Posts
2
Karma
0

Re: incorrect rank of matrix

Sat Feb 01, 2014 10:19 pm
Thanks for the reply. With the Eigen version from the repository all methods return indeed 21 as the rank.

In Eigen 3.2 (the latest stable version) the JacobiSVD object has no rank function. I have therefore used svd.nonzeroSingularValues() to compute the rank. In Eigen 3.2 and the latest version from the repository the function svd.nonzeroSingularValues() returns 22 (and NOT 21). The smallest eigenvalue is 1.64635e-15, which is close to zero but not exactly zero. This means that rank() returns a different number than nonzeroSingularValues().
It would be nice if the behaviour of rank() and nonzeroSingularValues() is consistent or at least the difference is documented.

With kind regards,
Pieter Eendebak
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS


Bookmarks



Who is online

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