How to get rank of a matrix in Eigen library?

佐手、 提交于 2019-12-23 16:42:25

问题


How to get rank of a matrix in eigen?


回答1:


You need to convert your matrix to a rank-revealing decomposition. For instance FullPivLU. If you have a matrix3f it looks like this :

FullPivLU<Matrix3f> lu_decomp(your_matrix);
auto rank = lu_decomp.rank();

Edit

Decomposing the matrix is the most common way to get the rank. Although, LU is not the most reliable way to achieve it for floating values as explained on the rank article on wikipedia

When applied to floating point computations on computers, basic Gaussian elimination (LU decomposition) can be unreliable, and a rank-revealing decomposition should be used instead. An effective alternative is the singular value decomposition (SVD), but there are other less expensive choices, such as QR decomposition with pivoting (so-called rank-revealing QR factorization), which are still more numerically robust than Gaussian elimination. Numerical determination of rank requires a criterion for deciding when a value, such as a singular value from the SVD, should be treated as zero, a practical choice which depends on both the matrix and the application.

So you might get more accurate results with Eigen::ColPivHouseholderQR< MatrixType >




回答2:


use QR or SVD decomposition and check the resulted matrix should also work. SVD may be more reliable.



来源:https://stackoverflow.com/questions/31041921/how-to-get-rank-of-a-matrix-in-eigen-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!