How to speed up or remove this FOR loop [message #74453] |
Fri, 14 January 2011 01:00  |
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   |
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  |
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!
|
|
|