On Aug 24, 10:44 am, David Streutker <dstreut...@gmail.com> wrote:
> For a reason I haven't quite figured out, the results of PCOMP and the
> ENVI results differ by a factor of the square root of the eigenvalue
> for the corresponding band.
>
> This works for me:
>
> x = [2.5, 0.5, 2.2, 1.9, 3.1, 2.3, 2.0, 1.0, 1.5, 1.1]
> y = [2.4, 0.7, 2.9, 2.2, 3.0, 2.7, 1.6, 1.1, 1.6, 0.9]
>
> ;xmean = x - Mean(x)
> ;ymean = y - Mean(y)
> Window, XSIZE=600, YSIZE=800
> !P.MULTI=[0,1,2]
> Plot, xmean, ymean, PSYM=7
>
> ;dataAdjust = Transpose([ [xmean], [ymean] ])
> dataAdjust = Transpose([ [x], [y] ])
> covArray = Correlate(dataAdjust, /COVARIANCE, /DOUBLE)
> eigenvalues = EIGENQL(covArray, EIGENVECTORS=eigenvectors, /DOUBLE)
>
> Print, 'EIGENVALUES: ', eigenvalues
> Print, 'EIGENVECTORS: '
> Print, eigenvectors
>
> rowFeatureVector = eigenvectors[0,*] ; Take first principle component.
> ;rowFeatureVector = eigenvectors
> finalData = Transpose(rowFeatureVector) ## Transpose(dataAdjust)
> Plot, finaldata+Mean(x), finaldata+mean(y), PSYM=7
> !P.MULTI=0
>
> ; Method using PCOMP in IDL library.
> data = Transpose([[x],[y]])
> ;r = PCOMP(data, /COVARIANCE, NVARIABLES=1, EIGENVALUES=ev, /
> STANDARDIZE)
> r = PCOMP(data, /COVARIANCE, EIGENVALUES=ev)
> Print, 'IDL EIGENVALUES: ', ev
>
> ; Compare methods.
> Window, 1
> ;PLOT, r
> PLOT, r[0,*] / sqrt(ev[0])
> OPLOT, finalData, LINESTYLE=2
>
> Window, 2
> PLOT, r[0,*] / sqrt(ev[0]) + Mean(x), r[0,*] / sqrt(ev[0]) + Mean(y),
> PSYM=2
> ;PLOT, r + Mean(x), r + Mean(y), PSYM=2
> OPLOT, finalData + Mean(x), finalData + Mean(y), PSYM=7
> END
And by "ENVI results", I mean of course the the IDL programmatic (non-
PCOMP) method, which are equivalent. (Sorry, I've got ENVI on the
brain this morning.)
|