comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: the (Moore-Penrose) pseudo-inverse of a matrix - anything like scipy.linalg's pinv2 in IDL?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: the (Moore-Penrose) pseudo-inverse of a matrix - anything like scipy.linalg's pinv2 in IDL? [message #83774] Wed, 03 April 2013 06:52 Go to next message
Russell Ryan is currently offline  Russell Ryan
Messages: 122
Registered: May 2012
Senior Member
On Wednesday, April 3, 2013 1:18:16 AM UTC-4, JP wrote:
> Hello IDLers,
>
>
>
> I am adapting a code from python to IDL and I got stuck with the pinv2 function: http://docs.scipy.org/doc/scipy/reference/generated/scipy.li nalg.pinv2.html
>
>
>
> It computes the Moore-Penrose pseudo-inverse of a matrix and I couldn't find anything similar in IDL.
>
>
>
> A search through this group pointed to a post 10 years old where Paul van Delst Lars shared his svd_matrix_invert function (link to post: https://groups.google.com/d/msg/comp.lang.idl-pvwave/NNzCI4h MUP4/n9UzWjazT3YJ )
>
>
>
> Is that an equivalent to the scipy pinv2 i am looking for? And if so, I will appreciate if someone will better algebra skills than me (likely 95% of this community) could suggest how to introduce the rcond keyword available in pinv2.
>
>
>
> thanks a lot.
>
>
>
> JP


I just read the Wikipedia article on Moore-Penrose Inverses. Sounds like you can just do an SVD then operate on the Sigma matrix and the resulting A+ matrix. I'm unaware of any existing IDL code to do this. There are two routines to do the SVD included in the standard distro.

-Russell
Re: the (Moore-Penrose) pseudo-inverse of a matrix - anything like scipy.linalg's pinv2 in IDL? [message #83776 is a reply to message #83774] Wed, 03 April 2013 06:46 Go to previous messageGo to next message
lecacheux.alain is currently offline  lecacheux.alain
Messages: 325
Registered: January 2008
Senior Member
Le mercredi 3 avril 2013 07:18:16 UTC+2, JP a écrit :
> Hello IDLers,
>
>
>
> I am adapting a code from python to IDL and I got stuck with the pinv2 function: http://docs.scipy.org/doc/scipy/reference/generated/scipy.li nalg.pinv2.html
>
>
>
> It computes the Moore-Penrose pseudo-inverse of a matrix and I couldn't find anything similar in IDL.
>
>
>
> A search through this group pointed to a post 10 years old where Paul van Delst Lars shared his svd_matrix_invert function (link to post: https://groups.google.com/d/msg/comp.lang.idl-pvwave/NNzCI4h MUP4/n9UzWjazT3YJ )
>
>
>
> Is that an equivalent to the scipy pinv2 i am looking for? And if so, I will appreciate if someone will better algebra skills than me (likely 95% of this community) could suggest how to introduce the rcond keyword available in pinv2.
>
>
>
> thanks a lot.
>
>
>
> JP

Your problem should likely be solved by using the LA_LEAST_SQUARES function and setting METHOD (to 2 or 3) and RCONDITION keywords
alx.
Re: the (Moore-Penrose) pseudo-inverse of a matrix - anything like scipy.linalg's pinv2 in IDL? [message #83777 is a reply to message #83776] Wed, 03 April 2013 06:33 Go to previous messageGo to next message
Heinz Stege is currently offline  Heinz Stege
Messages: 189
Registered: January 2003
Senior Member
On Tue, 2 Apr 2013 22:18:16 -0700 (PDT), JP wrote:

> Is that an equivalent to the scipy pinv2 i am looking for? And if so, I will appreciate if someone will better algebra skills than me (likely 95% of this community) could suggest how to introduce the rcond keyword available in pinv2.
>
I am very sure, that I am one of the 5%. So be very careful with the
following code. From the description it looks like the scipy function
is doing something like this:

function pinv2,a,rcond=rcond
;
compile_opt defint32,strictarr,logical_predicate
;
svdc,a,w,u,v ; singular value decomposition
;
n=n_elements(w)
threshold=n_elements(rcond)? max(w)*rcond : 0.
ii=where(w gt threshold,count)
if count lt n then begin
message,/info,strtrim(n-count,2)+' small singular values.'
if count le 0 then message,'All singular values are too small.'
end
;
jj=(indgen(n))[ii]*(n+1) ; diagonal elements
matrix=make_array(n,n,type=size(w,/type))
matrix[jj]=1./w[ii]
result=transpose(u)#matrix#v
;
return,result
end

If you want to use double precision, take a look at the IDL function
LA_SVD.

Cheers, Heinz
Re: the (Moore-Penrose) pseudo-inverse of a matrix - anything like scipy.linalg's pinv2 in IDL? [message #83855 is a reply to message #83776] Wed, 03 April 2013 16:08 Go to previous message
JP is currently offline  JP
Messages: 55
Registered: April 2008
Member
Thanks, will test that


On Thursday, 4 April 2013 00:46:22 UTC+11, alx wrote:
> Le mercredi 3 avril 2013 07:18:16 UTC+2, JP a écrit :
>
>> Hello IDLers,
>
>>
>
>>
>
>>
>
>> I am adapting a code from python to IDL and I got stuck with the pinv2 function: http://docs.scipy.org/doc/scipy/reference/generated/scipy.li nalg.pinv2.html
>
>>
>
>>
>
>>
>
>> It computes the Moore-Penrose pseudo-inverse of a matrix and I couldn't find anything similar in IDL.
>
>>
>
>>
>
>>
>
>> A search through this group pointed to a post 10 years old where Paul van Delst Lars shared his svd_matrix_invert function (link to post: https://groups.google.com/d/msg/comp.lang.idl-pvwave/NNzCI4h MUP4/n9UzWjazT3YJ )
>
>>
>
>>
>
>>
>
>> Is that an equivalent to the scipy pinv2 i am looking for? And if so, I will appreciate if someone will better algebra skills than me (likely 95% of this community) could suggest how to introduce the rcond keyword available in pinv2.
>
>>
>
>>
>
>>
>
>> thanks a lot.
>
>>
>
>>
>
>>
>
>> JP
>
>
>
> Your problem should likely be solved by using the LA_LEAST_SQUARES function and setting METHOD (to 2 or 3) and RCONDITION keywords
>
> alx.
Re: the (Moore-Penrose) pseudo-inverse of a matrix - anything like scipy.linalg's pinv2 in IDL? [message #83856 is a reply to message #83777] Wed, 03 April 2013 16:06 Go to previous message
JP is currently offline  JP
Messages: 55
Registered: April 2008
Member
Thanks Heinz,

After my post yesterday I tested Paul's svd_matrix_invert comparing with scipy's pinv2 and it looks like they do the same. I added a rcond keyword too and it also mimics pinv2 behaviour.
From a quick look to your code it looks like it's also doing the same thing but haven't tested.

cheers

Juan



On Thursday, 4 April 2013 00:33:36 UTC+11, Heinz Stege wrote:
> On Tue, 2 Apr 2013 22:18:16 -0700 (PDT), JP wrote:
>
>
>
>> Is that an equivalent to the scipy pinv2 i am looking for? And if so, I will appreciate if someone will better algebra skills than me (likely 95% of this community) could suggest how to introduce the rcond keyword available in pinv2.
>
>>
>
> I am very sure, that I am one of the 5%. So be very careful with the
>
> following code. From the description it looks like the scipy function
>
> is doing something like this:
>
>
>
> function pinv2,a,rcond=rcond
>
> ;
>
> compile_opt defint32,strictarr,logical_predicate
>
> ;
>
> svdc,a,w,u,v ; singular value decomposition
>
> ;
>
> n=n_elements(w)
>
> threshold=n_elements(rcond)? max(w)*rcond : 0.
>
> ii=where(w gt threshold,count)
>
> if count lt n then begin
>
> message,/info,strtrim(n-count,2)+' small singular values.'
>
> if count le 0 then message,'All singular values are too small.'
>
> end
>
> ;
>
> jj=(indgen(n))[ii]*(n+1) ; diagonal elements
>
> matrix=make_array(n,n,type=size(w,/type))
>
> matrix[jj]=1./w[ii]
>
> result=transpose(u)#matrix#v
>
> ;
>
> return,result
>
> end
>
>
>
> If you want to use double precision, take a look at the IDL function
>
> LA_SVD.
>
>
>
> Cheers, Heinz
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Problem with logarithmic axes using AXIS IDL command
Next Topic: Re: Vector representation of data.

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 11:40:05 PDT 2025

Total time taken to generate the page: 0.00652 seconds