Avoiding multiple FOR loops [message #75539] |
Fri, 18 March 2011 15:47 |
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!
|
|
|