Re: [math] eigenvector doubts and issues

2013-11-09 Thread Thomas Neidhart
On 11/09/2013 10:38 AM, andrea antonello wrote:
> Dear all,
> I have a doubt about using the eigenvector part of the library.
> 
> I created a small dataset to represent 3d coordinates in a cartesian plane:
> 
> double[] x = {1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3};
> double[] y = {0.5, 1, 1.5, 2, 0.5, 1, 1.5, 2, 0.5, 1, 1.5, 2};
> double[] z = {1, 1, 1, 2, 1, 1, 2, 2, 1, 2, 2, 2};
> 
> The datasset represents a step from z value 1 to 2 on a regular grid
> (with a diagonali trend).
> 
> I would expect to gain from the eigenvector with lowest eigenvalue a
> line splitting this particular set in a quite clean way the higher z
> points from the lower ones.
> 
> So I calculate the covariance matrix which results in:
> 0.7272727272727273 0.0 0.18181818181818182
> 0.0 0.3409090909090909 0.22727272727272727
> 0.18181818181818182 0.22727272727272727 0.2727272727272727
> 
> and then I simply calculate the eigenvector/values which result in:
> 
> eigenVal: 0.8056498828134406, eigenVect: [0.9015723557614027,
> 0.19005937823202243, 0.38864472217295326]
> eigenVal: 0.4874287594020183, eigenVect: [-0.37995167578226796,
> 0.7774478202831089, 0.5012101463530935]
> eigenVal: 0.04783044869363171, eigenVect: [-0.20689130333844696,
> -0.5995434258526233, 0.773138842071603]
> 
> doing exactly the same thing with Jama results in:
> 
> eigenVal: 0.8056498828134406, eigenVect: [-0.7731388420716028,
> 0.5012101463530931, -0.38864472217295326]
> eigenVal: 0.48742875940201863, eigenVect: [0.5995434258526229,
> 0.7774478202831089, -0.1900593782320223]
> eigenVal: 0.0478304486936319, eigenVect: [0.20689130333844694,
> -0.37995167578226785, -0.9015723557614027]
> 
> In fact if I use Jama's eigenvector with lowest eigenvalue, I am able
> to construct a line of slope y =
> (0.206891303338447/-0.379951675782268) *x, which splits my dataset the
> way I would like to have it.
> The same doesn't apply to the result of the apache commons math lib,
> which seems to be reflected on the secondary diagonal.
> 
> Since I am no expert in this field, I might be doing somthing really
> wrong. If someone could give me a hint, it would be greatly
> appreciated.

Hi Andrea,

the result of CM and jama are identical, the difference is just in the
way how the data is stored.

Afaik in jama calling getV() returns a vector in row format whereas in
CM the are stored in column format.

If you transpose the matrix (or call getVT()) you will see that the
vectors are identical, except for the signs and order. The reason for
this is that for CM the eigenvalues/eigenvectors are sorted in
descending order in case of a symmetric matrix, which is the case for
your matrix.

Thomas

-
To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
For additional commands, e-mail: user-h...@commons.apache.org



[math] eigenvector doubts and issues

2013-11-09 Thread andrea antonello
Dear all,
I have a doubt about using the eigenvector part of the library.

I created a small dataset to represent 3d coordinates in a cartesian plane:

double[] x = {1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3};
double[] y = {0.5, 1, 1.5, 2, 0.5, 1, 1.5, 2, 0.5, 1, 1.5, 2};
double[] z = {1, 1, 1, 2, 1, 1, 2, 2, 1, 2, 2, 2};

The datasset represents a step from z value 1 to 2 on a regular grid
(with a diagonali trend).

I would expect to gain from the eigenvector with lowest eigenvalue a
line splitting this particular set in a quite clean way the higher z
points from the lower ones.

So I calculate the covariance matrix which results in:
0.7272727272727273 0.0 0.18181818181818182
0.0 0.3409090909090909 0.22727272727272727
0.18181818181818182 0.22727272727272727 0.2727272727272727

and then I simply calculate the eigenvector/values which result in:

eigenVal: 0.8056498828134406, eigenVect: [0.9015723557614027,
0.19005937823202243, 0.38864472217295326]
eigenVal: 0.4874287594020183, eigenVect: [-0.37995167578226796,
0.7774478202831089, 0.5012101463530935]
eigenVal: 0.04783044869363171, eigenVect: [-0.20689130333844696,
-0.5995434258526233, 0.773138842071603]

doing exactly the same thing with Jama results in:

eigenVal: 0.8056498828134406, eigenVect: [-0.7731388420716028,
0.5012101463530931, -0.38864472217295326]
eigenVal: 0.48742875940201863, eigenVect: [0.5995434258526229,
0.7774478202831089, -0.1900593782320223]
eigenVal: 0.0478304486936319, eigenVect: [0.20689130333844694,
-0.37995167578226785, -0.9015723557614027]

In fact if I use Jama's eigenvector with lowest eigenvalue, I am able
to construct a line of slope y =
(0.206891303338447/-0.379951675782268) *x, which splits my dataset the
way I would like to have it.
The same doesn't apply to the result of the apache commons math lib,
which seems to be reflected on the secondary diagonal.

Since I am no expert in this field, I might be doing somthing really
wrong. If someone could give me a hint, it would be greatly
appreciated.

Best regards,
Andrea

-
To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
For additional commands, e-mail: user-h...@commons.apache.org