[GRASS-dev] reg i.pca module

Hi All,

i.pca outputs raster bands and the pixel values are transformed obivously. But anyone can tell me how the transformation works

if a pixel P1 has value X after i.pca it will be Y

Is there any specific math equation that is applied to every pixel by PCA?

Regards,
Rashad

On 06/02/13 18:49, Rashad M wrote:

Hi All,

i.pca outputs raster bands and the pixel values are transformed
obivously. But anyone can tell me how the transformation works

if a pixel P1 has value X after i.pca it will be Y

Is there any specific math equation that is applied to every pixel by PCA?

http://en.wikipedia.org/wiki/Principal_component_analysis
and
http://grasswiki.osgeo.org/wiki/Principal_Component_Analysis

Moritz

On Wednesday 06 of February 2013 23:19:36 Rashad M wrote:

Hi All,

Hi Rashad!

i.pca outputs raster bands and the pixel values are transformed obivously.
But anyone can tell me how the transformation works

if a pixel P1 has value X after i.pca it will be Y

Is there any specific math equation that is applied to every pixel by PCA?

For sure. There are two _good_ grassy-sources to start with:

1. the i.pca's manual
http://grass.osgeo.org/grass70/manuals/i.pca.html

2.the GRASS-Wiki page explains all one needs to know -- even if it requires
some clean-up
<http://grasswiki.osgeo.org/wiki/Principal_Components_Analysis&gt;

And, of course (sorry for insisting and self-advertising) my work (available
at the link I've PMed to you). I've put a lot of effort to compile material &
explain what PCA is, what it does and how it does it. It would be really
nice, for me, to have some feedback if it helps, in any way, to understand
PCA.

If you had a look and found the material useless, please, be so kind and tell
me so -- strait (PM or ML, the same). I'd really like to know what you think
as I am planing to continue this effort in time, and expand it.

Best, Nikos

Rashad M wrote:

> Hi All,

> i.pca outputs raster bands and the pixel values are transformed
> obivously. But anyone can tell me how the transformation works

> if a pixel P1 has value X after i.pca it will be Y

> Is there any specific math equation that is applied to every pixel by PCA?

Moritz Lennert wrote:

http://en.wikipedia.org/wiki/Principal_component_analysis
and
http://grasswiki.osgeo.org/wiki/Principal_Component_Analysis

Ehm, right -- I've overlooked your post Moritz, apologies.

Nikos

Thanks Nikos and Mortiz,

From GRASS Wiki what I got is I need more details of step.6 in the Background section
i.e project original dataset signals (PC’s or PC scores: eigenvector * input-data) to get

projecting the dataset is based on the text output of i.pca eigen values and input data.

I guess there must be a simple transformation equation that can be applied to every pixel in the input data to get the raster output of i.pca.

Nikos, Your thesis is a long read and I only need a very small part from it. If you could tell me those( I strongly believe you can ) then it will be great. I need to start coding after this and this is only a small part of it. my actual work is pure pixel identification for spectral unmixing

···

On Thu, Feb 7, 2013 at 5:43 AM, Nikos Alexandris <nik@nikosalexandris.net> wrote:

Rashad M wrote:

Hi All,

i.pca outputs raster bands and the pixel values are transformed
obivously. But anyone can tell me how the transformation works

if a pixel P1 has value X after i.pca it will be Y

Is there any specific math equation that is applied to every pixel by PCA?

Moritz Lennert wrote:

http://en.wikipedia.org/wiki/Principal_component_analysis
and
http://grasswiki.osgeo.org/wiki/Principal_Component_Analysis

Ehm, right – I’ve overlooked your post Moritz, apologies.

Nikos


grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev

Regards,
Rashad

Hi

As mentioned in wiki does the output pixel = eigenvector * input pixel?

···

On Thu, Feb 7, 2013 at 10:59 AM, Rashad M <mohammedrashadkm@gmail.com> wrote:

Thanks Nikos and Mortiz,

From GRASS Wiki what I got is I need more details of step.6 in the Background section
i.e project original dataset signals (PC’s or PC scores: eigenvector * input-data) to get

projecting the dataset is based on the text output of i.pca eigen values and input data.

I guess there must be a simple transformation equation that can be applied to every pixel in the input data to get the raster output of i.pca.

Nikos, Your thesis is a long read and I only need a very small part from it. If you could tell me those( I strongly believe you can ) then it will be great. I need to start coding after this and this is only a small part of it. my actual work is pure pixel identification for spectral unmixing

Regards,
Rashad

On Thu, Feb 7, 2013 at 5:43 AM, Nikos Alexandris <nik@nikosalexandris.net> wrote:

Rashad M wrote:

Hi All,

i.pca outputs raster bands and the pixel values are transformed
obivously. But anyone can tell me how the transformation works

if a pixel P1 has value X after i.pca it will be Y

Is there any specific math equation that is applied to every pixel by PCA?

Moritz Lennert wrote:

http://en.wikipedia.org/wiki/Principal_component_analysis
and
http://grasswiki.osgeo.org/wiki/Principal_Component_Analysis

Ehm, right – I’ve overlooked your post Moritz, apologies.

Nikos


grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev

Regards,
Rashad

[all deleted]

Hey Rashad,

i.pca will output for you Principal Components. As many variables you will
feed to the algorithm (PCA), as many Principal Components you will get.

You don't need, normally, to do anything else than use the Principal
Components. I.e., you can selectively reject some Principal Components which
are not of interest and play with the rest. The simplest example that falls
into my mind is, e.g. to discard the last Pincipal Component which is "famous"
as to hold noise.

Could you please elaborate a bit more on what exactly you are after? It
depends on how much detail you want to squeeze out of PCA -- I mean,
understand each and every step and, possibly, modify the algorithm (?).

Best, Nikos

On 07/02/13 06:31, Rashad M wrote:

Hi

As mentioned in wiki does the output pixel = eigenvector * input pixel?

Yes, possibly depending on how the eigenvector is formulated. PCA is "just" a linear transformation from original pixel space to PC space.

Moritz

Hi,

I am trying to develop a tool for grass which is one of the things that xgobi[1] does. The idea is from Markus Neteler which is to identify pure pixel/end members from a PCA plot. Since i.pca transforms pixel position is lost. So I need to find out how the pixel values are changed during a PC Analysis. spectral unmixing (i.spec.unmix) needs pure pixels for classification which is not easy to obtain or needs a device field spectrometer which is expensive. So a module in GRASS GIS to do will make the life a lot easier

[1] http://www2.research.att.com/areas/stat/xgobi/

···

On Thu, Feb 7, 2013 at 1:16 PM, Nikos Alexandris <nik@nikosalexandris.net> wrote:

[all deleted]

Hey Rashad,

i.pca will output for you Principal Components. As many variables you will
feed to the algorithm (PCA), as many Principal Components you will get.

You don’t need, normally, to do anything else than use the Principal
Components. I.e., you can selectively reject some Principal Components which
are not of interest and play with the rest. The simplest example that falls
into my mind is, e.g. to discard the last Pincipal Component which is “famous”
as to hold noise.

Could you please elaborate a bit more on what exactly you are after? It
depends on how much detail you want to squeeze out of PCA – I mean,
understand each and every step and, possibly, modify the algorithm (?).

Best, Nikos

Regards,
Rashad

Rashad M wrote:

I am trying to develop a tool for grass which is one of the things that
xgobi[1] does. The idea is from Markus Neteler which is to identify pure
pixel/end members from a PCA plot. Since i.pca transforms pixel position
is lost. So I need to find out how the pixel values are changed during a PC
Analysis.

A quick response (without really thinking about it):

IIUC what you want to do, I think that it is not possible. Will (try to)
re-think later...

Best, Nikos

[..]

[1] http://www2.research.att.com/areas/stat/xgobi/

[rest deleted]

Hi,

On Thu, Feb 7, 2013 at 2:46 PM, Moritz Lennert <mlennert@club.worldonline.be

wrote:

On 07/02/13 06:31, Rashad M wrote:

Hi

As mentioned in wiki does the output pixel = eigenvector * input pixel?

Yes, possibly depending on how the eigenvector is formulated. PCA is
"just" a linear transformation from original pixel space to PC space.

What do you mean by depending on "how the eigenvector is formulated"?

Can anyone confirm this because its blocking me

Moritz

--
Regards,
   Rashad

On Fri, Feb 8, 2013 at 4:48 PM, Rashad M <mohammedrashadkm@gmail.com> wrote:

Hi,

On Thu, Feb 7, 2013 at 2:46 PM, Moritz Lennert
<mlennert@club.worldonline.be> wrote:

On 07/02/13 06:31, Rashad M wrote:

Hi

As mentioned in wiki does the output pixel = eigenvector * input pixel?

Yes, possibly depending on how the eigenvector is formulated. PCA is
"just" a linear transformation from original pixel space to PC space.

What do you mean by depending on "how the eigenvector is formulated"?

From the example in the manual:

The first PCA has the eigenvector

0.2824, 0.3342, 0.5092,-0.0087, 0.5264, 0.5217

Thus the output cells for PCA1 are calculated with

PCA1 = 0.2824 * (band1 - mean(band1) + 0.3342 * (band2 - mean(band2) +
... + 0.5217 * (band7 - mean(band7))

The output cells for the other PCA's are calculated accordingly.

Can anyone confirm this because its blocking me

HTH,

Markus M

Rashad M wrote:

I am trying to develop a tool for grass which is one of the things that
xgobi[1] does.

Nice! I have used xgobi in the past -- it's really impressive, fancy. But,
it is only a visualisation tool. Which may be, of course, very important in
trying to interpret multivariate data (in "our" case, both untransformed and
extracted Principal Components).

The idea is from Markus Neteler which is to identify pure
pixel/end members from a PCA plot. Since i.pca transforms pixel position is
lost.

My comments below might be useful, might be not (?).

In a multi-spectral data-set, we know, more or less, for example what amounts
of surface reflectance we expect for certain landscape features.

In the new, transformed "space" or, let's call it the (new) rotated coordinate
system, there is no previous knowledge on how exactly each of the transformed
values are "connected" to the landscape features.

A Principal Component, is effectively, a mixture of _parts_ of information from
_all_ original variables. The way the original scatterplot (in the simple
case of a bi-variate data set) rotates, is driven in such a way as to match
the maximum possible projection(s) of the points in the main coordinate system
axes ( == seeking for largest possible variances in the data). Note, the
whole PCA process is bound to the global statistics of your input multi-
variate dataset.

So I need to find out how the pixel values are changed during a PC
Analysis.

Random example with a 3-variate data set from the wiki:

r.mapcalc 'pc.1 = .4372107421*map.1 +.7210155161 *map.2 + .5375717557*map.3'

Very *roughly* interpreting the above calculation:

the 1st PC will be the sum of (weighted) parts from the original
variables/maps, i.e.:

0.43 from the 1st original variable

PLUS

0.72 from the 2nd original variable

PLUS

0.53 from the 3rd original variable

Now, you have a new transformed pixel value.

Note, you there are different versions of PCA. One typical example is that you
might want or you might not want to use the correlation matrix instead of the
var-covariance matrix.

Best, N

spectral unmixing (i.spec.unmix) needs pure pixels for
classification which is not easy to obtain or needs a device field
spectrometer which is expensive. So a module in GRASS GIS to do will make
the life a lot easier

[1] http://www2.research.att.com/areas/stat/xgobi/

On Thu, Feb 7, 2013 at 10:21 AM, Rashad M <mohammedrashadkm@gmail.com> wrote:

Hi,

I am trying to develop a tool for grass which is one of the things that
xgobi[1] does. The idea is from Markus Neteler which is to identify pure
pixel/end members from a PCA plot.

Background: it has been shown that pure pixels (endmembers) for spectral
unmixing are in the corners of the PCA feature space.

Attached an old drawing from my master thesis (1999) about the topic.

Since i.pca transforms pixel position is lost.

This is why I used the coordinates as raster pixel *attributes* in XGOBI
to relate original pixels and PCA transformed pixels to each other.

The east, north coordinates I stored as attributes, the PCA in XGOBI
supported to keep them alongside the transformed pixel. Solved.

What's needed in GRASS: That the i.pca modules allows to keep
raster pixel text labels in which the original position could be stored.
Then a little parsing of the category label and the original position
of a PCA transformed pixel could still be retrieved.

Hope this explains what I did those days in my thesis.

cheers
Markus

(attachments)

pca3d_EN.pdf (134 KB)

Maybe a complex number structure would be good where only the real part is analyzed by pca and the imaginary part is keeping a unique id for each original pixel…

On Feb 10, 2013 11:51 AM, “Markus Neteler” <neteler@osgeo.org> wrote:

On Thu, Feb 7, 2013 at 10:21 AM, Rashad M <mohammedrashadkm@gmail.com> wrote:

Hi,

I am trying to develop a tool for grass which is one of the things that
xgobi[1] does. The idea is from Markus Neteler which is to identify pure
pixel/end members from a PCA plot.

Background: it has been shown that pure pixels (endmembers) for spectral
unmixing are in the corners of the PCA feature space.

Attached an old drawing from my master thesis (1999) about the topic.

Since i.pca transforms pixel position is lost.

This is why I used the coordinates as raster pixel attributes in XGOBI
to relate original pixels and PCA transformed pixels to each other.

The east, north coordinates I stored as attributes, the PCA in XGOBI
supported to keep them alongside the transformed pixel. Solved.

What’s needed in GRASS: That the i.pca modules allows to keep
raster pixel text labels in which the original position could be stored.
Then a little parsing of the category label and the original position
of a PCA transformed pixel could still be retrieved.

Hope this explains what I did those days in my thesis.

cheers
Markus


grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev