RE: [eigen] How about pseudo-inverse?

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


Hi,
You selected only the singular values over the tolerance. However, you don't select the corresponding values on V and U? I just compared to the Matlab code so maybe I'm just confused.

Philippe

-----Message d'origine-----
De : Listengine [mailto:listengine@xxxxxxxxxxxxxxxxx] De la part de Ricard Marxer Piñón
Envoyé : 21 janvier 2010 10:16
À : eigen@xxxxxxxxxxxxxxxxxxx
Objet : Re: [eigen] How about pseudo-inverse?

Hi,

I implemented my own version like this.  But I don't know if it is
really correct, so please correct me if I'm wrong:

#include <Eigen/Core>
#include <Eigen/Array>
#include <Eigen/SVD>

typedef Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic > MatrixXR;

// SVD method
void pseudoInverse(const MatrixXR& a, MatrixXR* result, Real epsilon) {
  Eigen::SVD<MatrixXR> svd = a.svd();

  // As done in Matlab:
  // http://en.wikipedia.org/wiki/Moore-Penrose_pseudoinverse
  Real tolerance = epsilon * max(a.cols(), a.rows()) *
svd.singularValues().cwise().abs().maxCoeff();

  (*result) = svd.matrixV() * (svd.singularValues().cwise() >
tolerance).select(svd.singularValues().cwise().inverse(),
0).asDiagonal() * svd.matrixU().adjoint();
}

ricard

On Thu, Jan 21, 2010 at 3:55 PM,  <hamelin.philippe@xxxxxxx> wrote:
> Hello,
> I'm just new to the mailing list (and to Eigen2). I'm currently programming
> an underwater vehicle simulator using Eigen2. I actually need the
> pseudo-inverse of a rectangular matrix. I didn't find anything about that in
> the code. There's seems to be a preliminary version of the SVD which could
> help to do pseudo-inverse. So, does anyone has something to suggest to me
> about that?
>
> Thank you,
>
> Philippe Hamelin, ing. jr, M. Ing
> Chercheur / Researcher
>
> Tel: (450) 652-8499 x2198
> Fax: (450) 652-1316
>
> Institut de recherche d'Hydro-Québec
> Unité robotique et civil
> 1740, boul. Lionel-Boulet
> Varennes (QC) J1X 1S1, Canada
>
>



-- 
ricard
http://www.ricardmarxer.com
http://www.caligraft.com





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