correlation matrix [message #35323] |
Wed, 11 June 2003 12:04  |
kevinlausten
Messages: 6 Registered: April 2003
|
Junior Member |
|
|
I have written code to create the correlation matix of a data cube,
however, it seems to run slower than I would expect. I am I doing
anything inefficiently?
for r = 0, (nrows-1) do begin
for c = 0, (ncols-1) do begin
;sum = 0
for bb = 0, (nbands-1) do begin
ref(bb) = in_cube(bb, c, r)
; 'ref' equals 'back_cube' for all values of 'bb' at location
; (c, r)
endfor
;print, ref
temp = ref#transpose(ref)
; 'temp' equals the product of 'ref' and the transpose of 'ref'
sum = sum + temp
; 'sum' is a running total of the value of 'temp' at location
; (c, r)
endfor
endfor
final0 = fltarr(nbands, nbands)
; 'final0' is a floating point aray of size (nbands, nbands)
n = npixels
; 'n' is a variable equal to 'npixels'
final0= sum/n
; final0 is correlation matrix
Thanks
Kevin
|
|
|
Re: correlation matrix [message #35462 is a reply to message #35323] |
Wed, 11 June 2003 18:18  |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
kevinlausten@hotmail.com (Kevin M. Lausten) writes:
> I have written code to create the correlation matix of a data cube,
> however, it seems to run slower than I would expect. I am I doing
> anything inefficiently?
>
> for r = 0, (nrows-1) do begin
> for c = 0, (ncols-1) do begin
> ;sum = 0
> for bb = 0, (nbands-1) do begin
> ref(bb) = in_cube(bb, c, r)
> ; 'ref' equals 'back_cube' for all values of 'bb' at location
> ; (c, r)
> endfor
Whatever the IN_CUBE() is, it will be the limiting factor in your
snippet, since it is in the innermost loop. If you can vectorize
IN_CUBE over BB then your routine should be faster.
Good luck,
Craig
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
|
|
|