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

Home » Public Forums » archive » Avoiding multiple FOR loops
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Avoiding multiple FOR loops [message #75539] Fri, 18 March 2011 15:47
fgg is currently offline  fgg
Messages: 67
Registered: April 2010
Member
Hi there,

I'm writing a program for regression model selection by exhaustive
search (based on the RMSE, for example). The code is relatively
simple, but as the maximum size of subsets to examine increases,
processing speed decreases significantly. Below is the piece of the
code that deals with subsets of 6 variables. Is there a better way of
doing this? i.e. a way of avoiding the multiple FOR loops, which are
being used to calculate the RMSE for all possible combinations.

if (nvar eq 6) then begin
index = -1l
for i=0l,maxn-6 do begin
for j=i+1,maxn-5 do begin
for k=j+1,maxn-4 do begin
for l=k+1,maxn-3 do begin
for m=l+1,maxn-2 do begin
for n=m+1,maxn-1 do begin
index = index +1
x = [data[i,*],
data[j,*], data[k,*], data[l,*], data[m,*], data[n,*]]
coef = regress(x, y,
const=const, yfit=yfit)
rms[index] =
sqrt(total((y-yfit)^2)/n_elements(y))
endfor
endfor
endfor
endfor
endfor
endfor
... [+ statements]
endif

Thanks!
[Message index]
 
Read Message
Previous Topic: Re: IDL Book Tour
Next Topic: IDL

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

Current Time: Wed Oct 08 15:57:09 PDT 2025

Total time taken to generate the page: 0.00399 seconds