Eigen Library - Pseudo-Inverse of Matrix (Matlab - pinv)
Asked Answered
A

1

5

I am trying to find the pseudo-inverse of a matrix using the Eigen Library. They have a class that does implement it, however I do not know how to put script the syntax.

This is how it is shown on the website (https://eigen.tuxfamily.org/dox/classEigen_1_1CompleteOrthogonalDecomposition.html#ab2fd4c81aa1cd8bc917c7f135505cb7f):

const Inverse Eigen::CompleteOrthogonalDecomposition< MatrixType >::pseudoInverse ( ) const

Antiserum answered 9/6, 2017 at 19:12 Comment(1)
And what exactly is your problem? Please edit your question to provide a minimal reproducible example as well as a clear problem statement.Mho
G
13

It's a method of the CompleteOrthogonalDecomposition class. So you have to perform that decomposition of a matrix before you use it. For example

#include <Eigen/QR>    

Eigen::MatrixXd A = ... // fill in A
Eigen::MatrixXd pinv = A.completeOrthogonalDecomposition().pseudoInverse();
Gradey answered 9/6, 2017 at 19:19 Comment(6)
Though it's recommended to use other solvers in most cases.Fad
Yes, definitelyGradey
@AdiShavit Why is it recommended to use other solvers?Buenrostro
@AdiShavit, could you give references? Which solvers would you recommend?Chafin
@ignacio: Eigen docs say not to use it (not efficient or numerically stable: see eigen.tuxfamily.org/dox/…). See eigen.tuxfamily.org/dox/group__LeastSquares.html for better suggestions for solving linear systems in Eigen.Rockery
Result of A.completeOrthogonalDecomposition().pseudoInverse() and MATLAB pinv() are not the same. Please refer to gitlab.com/libeigen/eigen/-/issues/2462 for more detail information.Garnes

© 2022 - 2024 — McMap. All rights reserved.