Re: [eigen] How about pseudo-inverse? |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] How about pseudo-inverse?
- From: Ricard Marxer Piñón <email@xxxxxxxxxxxxxxxx>
- Date: Thu, 21 Jan 2010 16:15:41 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:from:date:x-google-sender-auth:message-id:subject:to :content-type:content-transfer-encoding; bh=3ydDHm8olAXVykr8Gp17lPVpfgAuW+hks4cQssEySE8=; b=xk4fx4TGO3RwVOFigI8nzcfUmHwHVBrWrcdXidlxs6J1xIV2N/WsRgIizAkwIELio+ 1eMI9VdwiHTtP/gmOlBWt3PG/mfpIFx5a8Ra8s9PD5Yog+9t0cBA56ROmESv8vcnjFz4 aGrUain6NWBJ2weSqsRnRh62iiOJkJo+IgsgE=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:content-type :content-transfer-encoding; b=bYSNG6eDiWbrlmwMxmbwhx+xA1XFMXW9KA/60KzPzg9Jt2Fdr+bvVDTrscps2GsOrx 9RpYjMMsmNYthr7kCtESoGMKsHjIq0kg9EWrDhJvvlNygCa+tsxC6WUk2nWn8mOJUN/d WLM6yDtPHU0wT7YKo07ZlKv18ygdEuN1Yv5IA=
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