You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Axel <ax...@gmail.com> on 2009/09/20 07:41:25 UTC

[Math] EigenDecompositionImpl#getEigenvector()

Hello

I'm trying to calculate the Eigenvectors of this Wikipedia example:
http://en.wikipedia.org/wiki/Eigenvalue_algorithm#Identifying_eigenvectors

with this JUnit method:

  public void testEigenDecomposition() {
    double[][] m = { { 0.0, 1.0, -1.0 }, { 1.0, 1.0, 0.0 }, { -1.0,
0.0, 1.0 } };
    RealMatrix rm = new Array2DRowRealMatrix(m);
    assertEquals(rm.toString(),
        "Array2DRowRealMatrix{{0.0,1.0,-1.0},{1.0,1.0,0.0},{-1.0,0.0,1.0}}");
    EigenDecompositionImpl ed = new EigenDecompositionImpl(rm,
        MathUtils.SAFE_MIN);
    RealVector rv0 = ed.getEigenvector(0);
    assertEquals(rv0.toString(), "{(NaN); (NaN); (NaN)}");
  }

but I'm getting only {(NaN); (NaN); (NaN)} as a result vector.

Is this intentionally (because of numerical inaccuracy?) or am I doing
something wrong in using EigenDecompositionImpl?

-- 
Axel Kramer
http://code.google.com/p/symja

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [Math] EigenDecompositionImpl#getEigenvector()

Posted by Phil Steitz <ph...@gmail.com>.
Ted Dunning wrote:
> Numerical issues should not impinge on a computation this small.
> 
> For reference, I replicated your computation and found reasonable
> eigenvalues and vectors:
> 
>> m = matrix(c(0,1,-1,1,1,0,-1,0,1), nrow=3)
>> m
>      [,1] [,2] [,3]
> [1,]    0    1   -1
> [2,]    1    1    0
> [3,]   -1    0    1
>> eig(m)
> Error: could not find function "eig"
>> eigen(m)
> $values
> [1]  2  1 -1
> 
> $vectors
>            [,1]      [,2]       [,3]
> [1,]  0.5773503 0.0000000  0.8164966
> [2,]  0.5773503 0.7071068 -0.4082483
> [3,] -0.5773503 0.7071068  0.4082483
> 
> 
> Your usage appears to be in accord with the suggested usage, but have you
> tried it with a tolerance of, say, 1e-3?
> 
> On Sat, Sep 19, 2009 at 10:41 PM, Axel <ax...@gmail.com> wrote:
> 
>> Hello
>>
>> I'm trying to calculate the Eigenvectors of this Wikipedia example:
>> http://en.wikipedia.org/wiki/Eigenvalue_algorithm#Identifying_eigenvectors
>>
>> with this JUnit method:
>>
>>  public void testEigenDecomposition() {
>>    double[][] m = { { 0.0, 1.0, -1.0 }, { 1.0, 1.0, 0.0 }, { -1.0,
>> 0.0, 1.0 } };
>>    RealMatrix rm = new Array2DRowRealMatrix(m);
>>    assertEquals(rm.toString(),
>>
>>  "Array2DRowRealMatrix{{0.0,1.0,-1.0},{1.0,1.0,0.0},{-1.0,0.0,1.0}}");
>>    EigenDecompositionImpl ed = new EigenDecompositionImpl(rm,
>>        MathUtils.SAFE_MIN);
>>    RealVector rv0 = ed.getEigenvector(0);
>>    assertEquals(rv0.toString(), "{(NaN); (NaN); (NaN)}");
>>  }
>>
>> but I'm getting only {(NaN); (NaN); (NaN)} as a result vector.
>>
>> Is this intentionally (because of numerical inaccuracy?) or am I doing
>> something wrong in using EigenDecompositionImpl?
>>
>> --
>> Axel Kramer
>> http://code.google.com/p/symja
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>>
> 
> 
Thanks for reporting this. Looks like a bug. The eigenvalues are
being correctly computed but all three eigenvectors are coming out
<NaN, NaN, NaN>

This is being tracked as MATH-297.

Phil

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [Math] EigenDecompositionImpl#getEigenvector()

Posted by Axel <ax...@gmail.com>.
On Sun, Sep 20, 2009 at 7:51 AM, Ted Dunning <te...@gmail.com> wrote:
> Numerical issues should not impinge on a computation this small.
...
> Your usage appears to be in accord with the suggested usage, but have you
> tried it with a tolerance of, say, 1e-3?
This gives the same result: {(NaN); (NaN); (NaN)}

--
Axel Kramer
http://code.google.com/p/symja

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [Math] EigenDecompositionImpl#getEigenvector()

Posted by Ted Dunning <te...@gmail.com>.
Numerical issues should not impinge on a computation this small.

For reference, I replicated your computation and found reasonable
eigenvalues and vectors:

> m = matrix(c(0,1,-1,1,1,0,-1,0,1), nrow=3)
> m
     [,1] [,2] [,3]
[1,]    0    1   -1
[2,]    1    1    0
[3,]   -1    0    1
> eig(m)
Error: could not find function "eig"
> eigen(m)
$values
[1]  2  1 -1

$vectors
           [,1]      [,2]       [,3]
[1,]  0.5773503 0.0000000  0.8164966
[2,]  0.5773503 0.7071068 -0.4082483
[3,] -0.5773503 0.7071068  0.4082483

>

Your usage appears to be in accord with the suggested usage, but have you
tried it with a tolerance of, say, 1e-3?

On Sat, Sep 19, 2009 at 10:41 PM, Axel <ax...@gmail.com> wrote:

> Hello
>
> I'm trying to calculate the Eigenvectors of this Wikipedia example:
> http://en.wikipedia.org/wiki/Eigenvalue_algorithm#Identifying_eigenvectors
>
> with this JUnit method:
>
>  public void testEigenDecomposition() {
>    double[][] m = { { 0.0, 1.0, -1.0 }, { 1.0, 1.0, 0.0 }, { -1.0,
> 0.0, 1.0 } };
>    RealMatrix rm = new Array2DRowRealMatrix(m);
>    assertEquals(rm.toString(),
>
>  "Array2DRowRealMatrix{{0.0,1.0,-1.0},{1.0,1.0,0.0},{-1.0,0.0,1.0}}");
>    EigenDecompositionImpl ed = new EigenDecompositionImpl(rm,
>        MathUtils.SAFE_MIN);
>    RealVector rv0 = ed.getEigenvector(0);
>    assertEquals(rv0.toString(), "{(NaN); (NaN); (NaN)}");
>  }
>
> but I'm getting only {(NaN); (NaN); (NaN)} as a result vector.
>
> Is this intentionally (because of numerical inaccuracy?) or am I doing
> something wrong in using EigenDecompositionImpl?
>
> --
> Axel Kramer
> http://code.google.com/p/symja
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>


-- 
Ted Dunning, CTO
DeepDyve