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 17:59:22 +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=/qpNo+xepbYRlcrSST3/rRbJeV50tniL5Dhs08V+hmY=; b=DSoQXW3TcbiPbVbhfY2gU0FpH91wOc6FlTlR1qbqjPF5Hfo6C0hcn9H3o06rvW1lZV 6oVe+rvj/EiKsUqLccZUG45Hb9jfWfaobUaSXTyM7Py9xR58QQXtPNTOWX2doHQje0Ku a7Dfi+8TukMT/gh53KVDlu9ZYsUgL0c6fwC00=
- 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=qE0ndIFOAsZDvOMJG6N7XEvbb5N98ifO91cuv2vjcPd3VWnQlcIS0W0+mSt3LlUK2A k64h/cGdj/IMXlBrRucLtb5ZB7nzEd7oGVh2+pw5L641jGbsn1YUXCjB1o4UtIp70Kxn HQRkLHqN/BGes1pKmpntlEv4a4RckQUbk0mUI=
In this snippet the "select()" method will set to 0 those singular
values that are under the tolerance. I really don't know how they do
it in Matlab. The comment is because in the Wikipedia they say, that
Matlab puts a threshold on the singular value, but I must confess I
don't know what they do with those singular values that fall under
that threshold.
But I warn you, I'm no expert, so better check against other sources
or test with sample data. I would appreciate if you see any errors to
let me know so that I could fix it in my code as well.
cheers,
ricard
On Thu, Jan 21, 2010 at 4:57 PM, <hamelin.philippe@xxxxxxx> wrote:
> 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
>
>
>
>
>
--
ricard
http://www.ricardmarxer.com
http://www.caligraft.com