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

Home » Public Forums » archive » How to avoid the FOR loop when using TM_TEST?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: How to avoid the FOR loop when using TM_TEST? [message #55545 is a reply to message #55497] Mon, 27 August 2007 07:07 Go to previous messageGo to previous message
wanglin1981 is currently offline  wanglin1981
Messages: 10
Registered: August 2007
Junior Member
On Aug 26, 12:26 am, Allan Whiteford <allan-remove-th...@-and-
this.phys-dot-strath.ac.uk> wrote:
> wanglin1...@gmail.com wrote:
>> I need to test the significance for each spatial point between two
>> data sets (names are A(ix,iy,it1) and B(ix,iy,it2), ix and iy are
>> spatial point, and it1 and it2 are temporal point) using the TM_TEST
>> function. As the TM_TEST is not valid for two-dimentional matrix, I
>> had to use the FOR loop as follows, which cost a lot of time.
>
>> for j=0,iy-1 do begin
>> for i=0,ix-1 do begin
>> temp1=tm_test(A(i,j,*),B(i,j,*))
>> sighl(i,j)=temp1(1)
>> endfor
>> endfor
>
>> Is it possible to avoid the FOR loops?
>
>> Thanks!
>
> Lin,
>
> Welcome to the group :).
>
> For the code you have, you can get a significant speed up if you replace
> it all (including the loops) with:
>
> na=(size(a,/dim))[2]
> nb=(size(b,/dim))[2]
> meanx=total(a,3) / na
> meany=total(b,3) / nb
> df = 1.0*(na+nb-2)
> t = (meanx-meany)/sqrt((((total((a-rebin(meanx,ix,iy,na))^2,3) + $
> total((b-rebin(meany,ix,iy,nb))^2,3) )/df) * (1.0/na + 1.0/nb)))
> sighl = ibeta(0.5*df,0.5,df/(df+t^2))
>
> give or take some line breaks which I'm sure have been broken posting it
> across a newsgroup.
>
> This will give you s sighl array identical to the one you get with your
> present code.
>
> However, unless the speed is a real issue then your present solution is
> much easier to read and maintain. Note also that this doesn't give any
> of the other options which tm_test takes.
>
> Good question; keep them coming.
>
> Thanks,
>
> Allan- Hide quoted text -
>
> - Show quoted text -

Allan,

Thank you very much. After using the code you provided, the speed is
significantly improved, and I got the exact same result as that using
TM_TEST. Your method is illuminating for me when I meet with similar
problems.

Also, I really appreciate your encouragement. Learning IDL is a
journal full of challenge and interest. I enjoy this journey very much
and will keep moving on.

Regards,

Lin
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Syntax Error Confusion
Next Topic: Re: How to read ASTER in ENVI?

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

Current Time: Sun Oct 12 07:18:37 PDT 2025

Total time taken to generate the page: 0.64180 seconds