[GRASS-dev] Re: i.cca eigenvector computation strangeness

Soeren Gebbert soerengebbert at googlemail.com
Tue Aug 18 16:30:12 EDT 2009

Hello Hamish,

2009/8/18 Hamish <hamish_b at yahoo.com>

> Soeren wrote:
> > I have verified every step between the old and the new
> > version of i.cca. The difference is only in the eigen vector
> > computation.
> >
> > So the big question is ... which result is correct???
> is it more a matter of popular convention than correctness?
> i.e. does it depend on your reference frame / POV ?

I don't know. That may be the point.
I faced similar problems while implementing the
Karhunen-Loeve-Transformation for 3d geometric body alignment. Dependent on
the sign of the eigen vectors, the bodies are rotated by 180° on the
principal axes. So i had to rotate the bodies for correct alignment by 180°.
In case of a sphere or a cube, the rotation was irrelevant.
So maybe the sign is irrelevant and the result must be interpreted dependent
on the POV?

> > The new one looks more reasonable to me, but well this is
> > only one example ... .
> >
> > Do i have found a bug in the numerical recipes eigen vector
> > code, or is the sign of eigen vectors not fixed and changes
> > with the chosen algorithm?
> perhaps the output of the i.pca module, the m.eigensystem module (addons),
> and R-stats can give you some confidence in one flavour over another.

I notice the same behavior with i.pca. The eigen vectors between old and new
version have different signs.
I have tested this with the landsat satellite images from the north carolina
data set.

For validation i have put the sources of my development version of grass6
and a patched grass6.4RC5 version (for eigen vector output of i.cca) on my
web side:


Anybody who is interested in this issue, can compile them and run the
following script for each grass version with the nc data set:

# Set the region to the landsat images
g.region rast=lsat5_1987_10
i.group group=LandSat
i.group group=LandSat subgroup=visible
i.cluster group=LandSat subgroup=visible sigfile=sig.txt classes=5
i.cca --v group=LandSat subgroup=visible signature=sig.txt output=test_cca_1

i.group group=LandSat subgroup=infra
i.cluster group=LandSat subgroup=infra sigfile=sig.txt classes=4
i.cca --v group=LandSat subgroup=infra signature=sig.txt output=test_cca_2

# Compute the principal components
i.pca --o input=lsat5_1987_10,lsat5_1987_20,lsat5_1987_30 output=test_pca_1
i.pca --o input=lsat5_1987_20,lsat5_1987_30,lsat5_1987_40 output=test_pca_2
i.pca --o input=lsat5_1987_30,lsat5_1987_40,lsat5_1987_50 output=test_pca_3

You will see the different eigen vector signs.

> I'd guess it is highly likely that you are correct and this source was
> adapted from Fortran beginnings.

I dont know. The code of i.pca and i.cca seems to be correct. I guess the
cca developer was not very familiar with the C way of counting but the code
seems to be well structured.

The only way to validate i.pca and i.cca are analytical results which can be

adopted to grass using r.mapcalc to create the input raster maps for i.cca
and i.pca.
But i strongly guess ... there are no analytical results for validation. :/

I guess, the sign of the eigen vectors are not of great important's.
So the new versions of i.pca and .icca are working correctly  ... like the
old ones. :)

Best regards

> Hamish
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/grass-dev/attachments/20090818/5b9ef2c0/attachment.html

More information about the grass-dev mailing list