Re: Most Common IDL Programming Errors [message #59812 is a reply to message #59735] |
Wed, 09 April 2008 09:31   |
Kenneth P. Bowman
Messages: 585 Registered: May 2000
|
Senior Member |
|
|
In article <MPG.22666eb3ce01c4fd98a324@news.frii.com>,
David Fanning <news@dfanning.com> wrote:
> Kenneth P. Bowman writes:
>
>> David, I have some EOF code that is only a few lines long if you want it
>> (using LA_EIGENQL).
>
> Yes, thank you. We are having difficulties determining which
> is the "correct" implementation around here. We are going
> to take a vote later today. I could use more ammunition. :-)
>
> Cheers,
>
> David
I believe this code fragment is correct. �;-)
The input array 'values' is an nvar x nt (number of times) observation matrix.
This code first calculates the nvar x nvar covariance matrix 'cov' by using
MATRIX_MULTIPLY. For large data sets you may want to compute
the covariance matrix out of memory.
The eigenvalues and eigenvectors are found using LA_EIGENQL. The code
calculates the first 'nev' eigenvalues and eigenvectors of the
covariance matrix. (I say first because we normally sort the
eigenvalues from largest to smallest. LA_EIGENQL does the reverse, so
actually it is the last 'nev' eigenvalues, hence the calls to REVERSE.)
cov = MATRIX_MULTIPLY(values, values, /BTRANSPOSE)/nt ;Compute covariance matrix
eigenval = LA_EIGENQL(cov, EIGENVECTORS = eigenvec, $ ;Compute eigenvalues and eigenvectors
RANGE = [nvar - nev, nvar-1])
eigenval = REVERSE(eigenval) ;Sort eigenvalues from largest to smallest
eigenvec = REVERSE(eigenvec, 2) ;Sort eigenvectors as eigenvalues
Cheers, Ken
|
|
|