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

Home » Public Forums » archive » How to speed up or remove this FOR loop
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
How to speed up or remove this FOR loop [message #74453] Fri, 14 January 2011 01:00 Go to next message
johan[1] is currently offline  johan[1]
Messages: 11
Registered: December 2010
Junior Member
I do have 768 profiles, each 24 pixels long, each to whom I want to
fit a Gaussain and getting the mean and SD. I am using the following
FOR loop calling mpfitexpr. It works fine but it takes forever to
complete!

expr = 'P[0] + GAUSS1(X, P[1:3])'

t = indgen(24)
start = [20.D, 10, 2., 1000.]

for i=0,(size(profiles,/dim))[1]-1 do begin
r = profiles[*,i]
result = mpfitexpr(expr, t, r, 1, start, /QUIET)
endfor

Anyway to speed it up or to remove the FOR loop?
Re: How to speed up or remove this FOR loop [message #74535 is a reply to message #74453] Fri, 21 January 2011 08:02 Go to previous messageGo to next message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
On Friday, January 14, 2011 4:00:25 AM UTC-5, johan wrote:
> I do have 768 profiles, each 24 pixels long, each to whom I want to
> fit a Gaussain and getting the mean and SD. I am using the following
> FOR loop calling mpfitexpr. It works fine but it takes forever to
> complete!
>
> expr = 'P[0] + GAUSS1(X, P[1:3])'
>
> t = indgen(24)
> start = [20.D, 10, 2., 1000.]
>
> for i=0,(size(profiles,/dim))[1]-1 do begin
> r = profiles[*,i]
> result = mpfitexpr(expr, t, r, 1, start, /QUIET)
> endfor
>
Before I had suggested using MPFITFUN instead of MPFITEXPR, which should provide a modest speedup since one doesn't need an indirect function evaluation. Now I am going to suggest not to use the MPFIT* routines at all, but to instead use the ITTVIS supplied GAUSSFIT(). The MPFIT* routines are more robust, with more checking for overflows, NANs and more user diagnostics, but for simple Gaussian fits the overhead for GAUSSFIT() is *much* lower. (A factor of 4 speedup is possible.) --Wayne
Re: How to speed up or remove this FOR loop [message #74655 is a reply to message #74535] Tue, 25 January 2011 16:12 Go to previous message
johan[1] is currently offline  johan[1]
Messages: 11
Registered: December 2010
Junior Member
On Jan 21, 4:02 pm, wlandsman <wlands...@gmail.com> wrote:
> On Friday, January 14, 2011 4:00:25 AM UTC-5, johan wrote:
>> I do have 768 profiles, each 24 pixels long, each to whom I want to
>> fit a Gaussain and getting the mean and SD. I am using the following
>> FOR loop calling mpfitexpr. It works fine but it takes forever to
>> complete!
>
>>    expr = 'P[0] + GAUSS1(X, P[1:3])'
>
>>    t = indgen(24)
>>    start = [20.D, 10, 2., 1000.]
>
>>    for i=0,(size(profiles,/dim))[1]-1 do begin
>>            r = profiles[*,i]
>>            result = mpfitexpr(expr, t, r, 1, start, /QUIET)
>>    endfor
>
> Before I had suggested using MPFITFUN instead of MPFITEXPR, which should provide a modest speedup since one doesn't need an indirect function evaluation.   Now I am going to suggest not to use the MPFIT* routines at all, but to instead use the ITTVIS supplied GAUSSFIT().     The MPFIT* routines are more robust, with more checking for overflows, NANs and more user diagnostics, but for simple Gaussian fits the overhead for GAUSSFIT() is *much* lower.   (A factor of 4 speedup is possible.)  --Wayne

I did end up using the native Gaussfit and it works fine and fast. It
is a lot of fitting but it as you said, simple fits. Thanks!
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Need help with map projection conversion in ENVI
Next Topic: Re: Coyote's BIG Idea

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

Current Time: Wed Oct 08 13:53:37 PDT 2025

Total time taken to generate the page: 0.00650 seconds