org.apache.commons.math.linear.EigenDecompositionImpl Java Examples

The following examples show how to use org.apache.commons.math.linear.EigenDecompositionImpl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EigenDecompositionImplTest.java    From astor with GNU General Public License v2.0 7 votes vote down vote up
/** test eigenvalues for a big matrix. */
public void testBigMatrix() {
    Random r = new Random(17748333525117l);
    double[] bigValues = new double[200];
    for (int i = 0; i < bigValues.length; ++i) {
        bigValues[i] = 2 * r.nextDouble() - 1;
    }
    Arrays.sort(bigValues);
    EigenDecomposition ed =
        new EigenDecompositionImpl(createTestMatrix(r, bigValues), MathUtils.SAFE_MIN);
    double[] eigenValues = ed.getRealEigenvalues();
    assertEquals(bigValues.length, eigenValues.length);
    for (int i = 0; i < bigValues.length; ++i) {
        assertEquals(bigValues[bigValues.length - i - 1], eigenValues[i], 2.0e-14);
    }
}
 
Example #2
Source File: EigenSolverTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** test non invertible matrix */
public void testNonInvertible() {
    Random r = new Random(9994100315209l);
    RealMatrix m =
        EigenDecompositionImplTest.createTestMatrix(r, new double[] { 1.0, 0.0, -1.0, -2.0, -3.0 });
    DecompositionSolver es = new EigenDecompositionImpl(m, MathUtils.SAFE_MIN).getSolver();
    assertFalse(es.isNonSingular());
    try {
        es.getInverse();
        fail("an exception should have been thrown");
    } catch (InvalidMatrixException ime) {
        // expected behavior
    } catch (Exception e) {
        fail("wrong exception caught");
    }
}
 
Example #3
Source File: EigenDecompositionImplTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** test a matrix already in tridiagonal form. */
public void testTridiagonal() {
    Random r = new Random(4366663527842l);
    double[] ref = new double[30];
    for (int i = 0; i < ref.length; ++i) {
        if (i < 5) {
            ref[i] = 2 * r.nextDouble() - 1;
        } else {
            ref[i] = 0.0001 * r.nextDouble() + 6;                
        }
    }
    Arrays.sort(ref);
    TriDiagonalTransformer t =
        new TriDiagonalTransformer(createTestMatrix(r, ref));
    EigenDecomposition ed =
        new EigenDecompositionImpl(t.getMainDiagonalRef(),
                                   t.getSecondaryDiagonalRef(),
                                   MathUtils.SAFE_MIN);
    double[] eigenValues = ed.getRealEigenvalues();
    assertEquals(ref.length, eigenValues.length);
    for (int i = 0; i < ref.length; ++i) {
        assertEquals(ref[ref.length - i - 1], eigenValues[i], 2.0e-14);
    }
    
}
 
Example #4
Source File: EigenDecompositionImplTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** test eigenvalues for a big matrix. */
public void testBigMatrix() {
    Random r = new Random(17748333525117l);
    double[] bigValues = new double[200];
    for (int i = 0; i < bigValues.length; ++i) {
        bigValues[i] = 2 * r.nextDouble() - 1;
    }
    Arrays.sort(bigValues);
    EigenDecomposition ed =
        new EigenDecompositionImpl(createTestMatrix(r, bigValues), MathUtils.SAFE_MIN);
    double[] eigenValues = ed.getRealEigenvalues();
    assertEquals(bigValues.length, eigenValues.length);
    for (int i = 0; i < bigValues.length; ++i) {
        assertEquals(bigValues[bigValues.length - i - 1], eigenValues[i], 2.0e-14);
    }
}
 
Example #5
Source File: EigenDecompositionImplTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** test a matrix already in tridiagonal form. */
public void testTridiagonal() {
    Random r = new Random(4366663527842l);
    double[] ref = new double[30];
    for (int i = 0; i < ref.length; ++i) {
        if (i < 5) {
            ref[i] = 2 * r.nextDouble() - 1;
        } else {
            ref[i] = 0.0001 * r.nextDouble() + 6;                
        }
    }
    Arrays.sort(ref);
    TriDiagonalTransformer t =
        new TriDiagonalTransformer(createTestMatrix(r, ref));
    EigenDecomposition ed =
        new EigenDecompositionImpl(t.getMainDiagonalRef(),
                                   t.getSecondaryDiagonalRef(),
                                   MathUtils.SAFE_MIN);
    double[] eigenValues = ed.getRealEigenvalues();
    assertEquals(ref.length, eigenValues.length);
    for (int i = 0; i < ref.length; ++i) {
        assertEquals(ref[ref.length - i - 1], eigenValues[i], 2.0e-14);
    }
    
}
 
Example #6
Source File: EigenSolverTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** test non invertible matrix */
public void testNonInvertible() {
    Random r = new Random(9994100315209l);
    RealMatrix m =
        EigenDecompositionImplTest.createTestMatrix(r, new double[] { 1.0, 0.0, -1.0, -2.0, -3.0 });
    DecompositionSolver es = new EigenDecompositionImpl(m, MathUtils.SAFE_MIN).getSolver();
    assertFalse(es.isNonSingular());
    try {
        es.getInverse();
        fail("an exception should have been thrown");
    } catch (InvalidMatrixException ime) {
        // expected behavior
    } catch (Exception e) {
        fail("wrong exception caught");
    }
}
 
Example #7
Source File: EigenDecompositionImplTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** test a matrix already in tridiagonal form. */
public void testTridiagonal() {
    Random r = new Random(4366663527842l);
    double[] ref = new double[30];
    for (int i = 0; i < ref.length; ++i) {
        if (i < 5) {
            ref[i] = 2 * r.nextDouble() - 1;
        } else {
            ref[i] = 0.0001 * r.nextDouble() + 6;
        }
    }
    Arrays.sort(ref);
    TriDiagonalTransformer t =
        new TriDiagonalTransformer(createTestMatrix(r, ref));
    EigenDecomposition ed =
        new EigenDecompositionImpl(t.getMainDiagonalRef(),
                                   t.getSecondaryDiagonalRef(),
                                   MathUtils.SAFE_MIN);
    double[] eigenValues = ed.getRealEigenvalues();
    assertEquals(ref.length, eigenValues.length);
    for (int i = 0; i < ref.length; ++i) {
        assertEquals(ref[ref.length - i - 1], eigenValues[i], 2.0e-14);
    }

}
 
Example #8
Source File: EigenSolverTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** test non invertible matrix */
public void testNonInvertible() {
    Random r = new Random(9994100315209l);
    RealMatrix m =
        EigenDecompositionImplTest.createTestMatrix(r, new double[] { 1.0, 0.0, -1.0, -2.0, -3.0 });
    DecompositionSolver es = new EigenDecompositionImpl(m, MathUtils.SAFE_MIN).getSolver();
    assertFalse(es.isNonSingular());
    try {
        es.getInverse();
        fail("an exception should have been thrown");
    } catch (InvalidMatrixException ime) {
        // expected behavior
    } catch (Exception e) {
        fail("wrong exception caught");
    }
}
 
Example #9
Source File: EigenDecompositionImplTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** test eigenvalues for a big matrix. */
public void testBigMatrix() {
    Random r = new Random(17748333525117l);
    double[] bigValues = new double[200];
    for (int i = 0; i < bigValues.length; ++i) {
        bigValues[i] = 2 * r.nextDouble() - 1;
    }
    Arrays.sort(bigValues);
    EigenDecomposition ed =
        new EigenDecompositionImpl(createTestMatrix(r, bigValues), MathUtils.SAFE_MIN);
    double[] eigenValues = ed.getRealEigenvalues();
    assertEquals(bigValues.length, eigenValues.length);
    for (int i = 0; i < bigValues.length; ++i) {
        assertEquals(bigValues[bigValues.length - i - 1], eigenValues[i], 2.0e-14);
    }
}
 
Example #10
Source File: EigenDecompositionImplTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** test eigenvalues for a big matrix. */
public void testBigMatrix() {
    Random r = new Random(17748333525117l);
    double[] bigValues = new double[200];
    for (int i = 0; i < bigValues.length; ++i) {
        bigValues[i] = 2 * r.nextDouble() - 1;
    }
    Arrays.sort(bigValues);
    EigenDecomposition ed =
        new EigenDecompositionImpl(createTestMatrix(r, bigValues), MathUtils.SAFE_MIN);
    double[] eigenValues = ed.getRealEigenvalues();
    assertEquals(bigValues.length, eigenValues.length);
    for (int i = 0; i < bigValues.length; ++i) {
        assertEquals(bigValues[bigValues.length - i - 1], eigenValues[i], 2.0e-14);
    }
}
 
Example #11
Source File: EigenSolverTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** test non invertible matrix */
public void testNonInvertible() {
    Random r = new Random(9994100315209l);
    RealMatrix m =
        EigenDecompositionImplTest.createTestMatrix(r, new double[] { 1.0, 0.0, -1.0, -2.0, -3.0 });
    DecompositionSolver es = new EigenDecompositionImpl(m, MathUtils.SAFE_MIN).getSolver();
    assertFalse(es.isNonSingular());
    try {
        es.getInverse();
        fail("an exception should have been thrown");
    } catch (InvalidMatrixException ime) {
        // expected behavior
    } catch (Exception e) {
        fail("wrong exception caught");
    }
}
 
Example #12
Source File: EigenDecompositionImplTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Verifies operation on indefinite matrix
 */
public void testZeroDivide() {
    RealMatrix indefinite = MatrixUtils.createRealMatrix(new double [][] {
            { 0.0, 1.0, -1.0 }, 
            { 1.0, 1.0, 0.0 }, 
            { -1.0,0.0, 1.0 }        
    });
    EigenDecomposition ed = new EigenDecompositionImpl(indefinite, MathUtils.SAFE_MIN);
    checkEigenValues((new double[] {2, 1, -1}), ed, 1E-12);
    double isqrt3 = 1/Math.sqrt(3.0);
    checkEigenVector((new double[] {isqrt3,isqrt3,-isqrt3}), ed, 1E-12);
    double isqrt2 = 1/Math.sqrt(2.0);
    checkEigenVector((new double[] {0.0,-isqrt2,-isqrt2}), ed, 1E-12);
    double isqrt6 = 1/Math.sqrt(6.0);
    checkEigenVector((new double[] {2*isqrt6,-isqrt6,isqrt6}), ed, 1E-12);
}
 
Example #13
Source File: EigenDecompositionImplTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Verifies operation on indefinite matrix
 */
public void testZeroDivide() {
    RealMatrix indefinite = MatrixUtils.createRealMatrix(new double [][] {
            { 0.0, 1.0, -1.0 }, 
            { 1.0, 1.0, 0.0 }, 
            { -1.0,0.0, 1.0 }        
    });
    EigenDecomposition ed = new EigenDecompositionImpl(indefinite, MathUtils.SAFE_MIN);
    checkEigenValues((new double[] {2, 1, -1}), ed, 1E-12);
    double isqrt3 = 1/Math.sqrt(3.0);
    checkEigenVector((new double[] {isqrt3,isqrt3,-isqrt3}), ed, 1E-12);
    double isqrt2 = 1/Math.sqrt(2.0);
    checkEigenVector((new double[] {0.0,-isqrt2,-isqrt2}), ed, 1E-12);
    double isqrt6 = 1/Math.sqrt(6.0);
    checkEigenVector((new double[] {2*isqrt6,-isqrt6,isqrt6}), ed, 1E-12);
}
 
Example #14
Source File: EigenDecompositionImplTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** test a matrix already in tridiagonal form. */
public void testTridiagonal() {
    Random r = new Random(4366663527842l);
    double[] ref = new double[30];
    for (int i = 0; i < ref.length; ++i) {
        if (i < 5) {
            ref[i] = 2 * r.nextDouble() - 1;
        } else {
            ref[i] = 0.0001 * r.nextDouble() + 6;                
        }
    }
    Arrays.sort(ref);
    TriDiagonalTransformer t =
        new TriDiagonalTransformer(createTestMatrix(r, ref));
    EigenDecomposition ed =
        new EigenDecompositionImpl(t.getMainDiagonalRef(),
                                   t.getSecondaryDiagonalRef(),
                                   MathUtils.SAFE_MIN);
    double[] eigenValues = ed.getRealEigenvalues();
    assertEquals(ref.length, eigenValues.length);
    for (int i = 0; i < ref.length; ++i) {
        assertEquals(ref[ref.length - i - 1], eigenValues[i], 2.0e-14);
    }
    
}
 
Example #15
Source File: EigenDecompositionImplTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** test eigenvalues for a big matrix. */
public void testBigMatrix() {
    Random r = new Random(17748333525117l);
    double[] bigValues = new double[200];
    for (int i = 0; i < bigValues.length; ++i) {
        bigValues[i] = 2 * r.nextDouble() - 1;
    }
    Arrays.sort(bigValues);
    EigenDecomposition ed =
        new EigenDecompositionImpl(createTestMatrix(r, bigValues), MathUtils.SAFE_MIN);
    double[] eigenValues = ed.getRealEigenvalues();
    assertEquals(bigValues.length, eigenValues.length);
    for (int i = 0; i < bigValues.length; ++i) {
        assertEquals(bigValues[bigValues.length - i - 1], eigenValues[i], 2.0e-14);
    }
}
 
Example #16
Source File: EigenDecompositionImplTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** test diagonal matrix */
public void testDiagonal() {
    double[] diagonal = new double[] { -3.0, -2.0, 2.0, 5.0 };
    RealMatrix m = createDiagonalMatrix(diagonal, diagonal.length, diagonal.length);
    EigenDecomposition ed = new EigenDecompositionImpl(m, MathUtils.SAFE_MIN);
    assertEquals(diagonal[0], ed.getRealEigenvalue(3), 2.0e-15);
    assertEquals(diagonal[1], ed.getRealEigenvalue(2), 2.0e-15);
    assertEquals(diagonal[2], ed.getRealEigenvalue(1), 2.0e-15);
    assertEquals(diagonal[3], ed.getRealEigenvalue(0), 2.0e-15);
}
 
Example #17
Source File: EigenSolverTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** test invertible matrix */
public void testInvertible() {
    Random r = new Random(9994100315209l);
    RealMatrix m =
        EigenDecompositionImplTest.createTestMatrix(r, new double[] { 1.0, 0.5, -1.0, -2.0, -3.0 });
    DecompositionSolver es = new EigenDecompositionImpl(m, MathUtils.SAFE_MIN).getSolver();
    assertTrue(es.isNonSingular());
    RealMatrix inverse = es.getInverse();
    RealMatrix error =
        m.multiply(inverse).subtract(MatrixUtils.createRealIdentityMatrix(m.getRowDimension()));
    assertEquals(0, error.getNorm(), 4.0e-15);
}
 
Example #18
Source File: EigenDecompositionImplTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Matrix with eigenvalues {2, 0, 12}
 */
public void testDistinctEigenvalues() {
    RealMatrix distinct = MatrixUtils.createRealMatrix(new double[][] {
            {3, 1, -4},  
            {1, 3, -4}, 
            {-4, -4, 8}
    });
    EigenDecomposition ed = new EigenDecompositionImpl(distinct, MathUtils.SAFE_MIN);
    checkEigenValues((new double[] {2, 0, 12}), ed, 1E-12);
    checkEigenVector((new double[] {1, -1, 0}), ed, 1E-12);
    checkEigenVector((new double[] {1, 1, 1}), ed, 1E-12);
    checkEigenVector((new double[] {-1, -1, 2}), ed, 1E-12);
}
 
Example #19
Source File: EigenDecompositionImplTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Matrix with eigenvalues {8, -1, -1}
 */
public void testRepeatedEigenvalue() {
    RealMatrix repeated = MatrixUtils.createRealMatrix(new double[][] {
            {3,  2,  4},
            {2,  0,  2},
            {4,  2,  3}
    }); 
    EigenDecomposition ed = new EigenDecompositionImpl(repeated, MathUtils.SAFE_MIN);
    checkEigenValues((new double[] {8, -1, -1}), ed, 1E-12);
    checkEigenVector((new double[] {2, 1, 2}), ed, 1E-12);
}
 
Example #20
Source File: EigenDecompositionImplTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Matrix with eigenvalues {8, -1, -1}
 */
public void testRepeatedEigenvalue() {
    RealMatrix repeated = MatrixUtils.createRealMatrix(new double[][] {
            {3,  2,  4},
            {2,  0,  2},
            {4,  2,  3}
    });
    EigenDecomposition ed = new EigenDecompositionImpl(repeated, MathUtils.SAFE_MIN);
    checkEigenValues((new double[] {8, -1, -1}), ed, 1E-12);
    checkEigenVector((new double[] {2, 1, 2}), ed, 1E-12);
}
 
Example #21
Source File: EigenDecompositionImplTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testDimension2() {
    RealMatrix matrix =
        MatrixUtils.createRealMatrix(new double[][] {
                { 59.0, 12.0 },
                { 12.0, 66.0 }
        });
    EigenDecomposition ed = new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN);
    assertEquals(75.0, ed.getRealEigenvalue(0), 1.0e-15);
    assertEquals(50.0, ed.getRealEigenvalue(1), 1.0e-15);
}
 
Example #22
Source File: EigenDecompositionImplTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testDimension4WithoutSplit() {
    RealMatrix matrix =
        MatrixUtils.createRealMatrix(new double[][] {
                               {  0.5608, -0.2016,  0.1152, -0.2976 },
                               { -0.2016,  0.4432, -0.2304,  0.1152 },
                               {  0.1152, -0.2304,  0.3088, -0.1344 },
                               { -0.2976,  0.1152, -0.1344,  0.3872 }
                           });
    EigenDecomposition ed = new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN);
    assertEquals(1.0, ed.getRealEigenvalue(0), 1.0e-15);
    assertEquals(0.4, ed.getRealEigenvalue(1), 1.0e-15);
    assertEquals(0.2, ed.getRealEigenvalue(2), 1.0e-15);
    assertEquals(0.1, ed.getRealEigenvalue(3), 1.0e-15);
}
 
Example #23
Source File: EigenDecompositionImplTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testMath308() {

        double[] mainTridiagonal = {
            22.330154644539597, 46.65485522478641, 17.393672330044705, 54.46687435351116, 80.17800767709437
        };
        double[] secondaryTridiagonal = {
            13.04450406501361, -5.977590941539671, 2.9040909856707517, 7.1570352792841225
        };

        // the reference values have been computed using routine DSTEMR
        // from the fortran library LAPACK version 3.2.1
        double[] refEigenValues = {
            82.044413207204002, 53.456697699894512, 52.536278520113882, 18.847969733754262, 14.138204224043099
        };
        RealVector[] refEigenVectors = {
            new ArrayRealVector(new double[] { -0.000462690386766, -0.002118073109055,  0.011530080757413,  0.252322434584915,  0.967572088232592 }),
            new ArrayRealVector(new double[] {  0.314647769490148,  0.750806415553905, -0.167700312025760, -0.537092972407375,  0.143854968127780 }),
            new ArrayRealVector(new double[] {  0.222368839324646,  0.514921891363332, -0.021377019336614,  0.801196801016305, -0.207446991247740 }),
            new ArrayRealVector(new double[] {  0.713933751051495, -0.190582113553930,  0.671410443368332, -0.056056055955050,  0.006541576993581 }),
            new ArrayRealVector(new double[] {  0.584677060845929, -0.367177264979103, -0.721453187784497,  0.052971054621812, -0.005740715188257 })
        };

        EigenDecomposition decomposition =
            new EigenDecompositionImpl(mainTridiagonal, secondaryTridiagonal, MathUtils.SAFE_MIN);

        double[] eigenValues = decomposition.getRealEigenvalues();
        for (int i = 0; i < refEigenValues.length; ++i) {
            assertEquals(refEigenValues[i], eigenValues[i], 1.0e-5);
            assertEquals(0, refEigenVectors[i].subtract(decomposition.getEigenvector(i)).getNorm(), 2.0e-7);
        }

    }
 
Example #24
Source File: EigenDecompositionImplTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Matrix with eigenvalues {8, -1, -1}
 */
public void testRepeatedEigenvalue() {
    RealMatrix repeated = MatrixUtils.createRealMatrix(new double[][] {
            {3,  2,  4},
            {2,  0,  2},
            {4,  2,  3}
    }); 
    EigenDecomposition ed = new EigenDecompositionImpl(repeated, MathUtils.SAFE_MIN);
    checkEigenValues((new double[] {8, -1, -1}), ed, 1E-12);
    checkEigenVector((new double[] {2, 1, 2}), ed, 1E-12);
}
 
Example #25
Source File: EigenDecompositionImplTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** test diagonal matrix */
public void testDiagonal() {
    double[] diagonal = new double[] { -3.0, -2.0, 2.0, 5.0 };
    RealMatrix m = createDiagonalMatrix(diagonal, diagonal.length, diagonal.length);
    EigenDecomposition ed = new EigenDecompositionImpl(m, MathUtils.SAFE_MIN);
    assertEquals(diagonal[0], ed.getRealEigenvalue(3), 2.0e-15);
    assertEquals(diagonal[1], ed.getRealEigenvalue(2), 2.0e-15);
    assertEquals(diagonal[2], ed.getRealEigenvalue(1), 2.0e-15);
    assertEquals(diagonal[3], ed.getRealEigenvalue(0), 2.0e-15);
}
 
Example #26
Source File: EigenDecompositionImplTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** test A = VDVt */
public void testAEqualVDVt() {
    EigenDecomposition ed = new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN);
    RealMatrix v  = ed.getV();
    RealMatrix d  = ed.getD();
    RealMatrix vT = ed.getVT();
    double norm = v.multiply(d).multiply(vT).subtract(matrix).getNorm();
    assertEquals(0, norm, 6.0e-13);
}
 
Example #27
Source File: EigenDecompositionImplTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** test eigenvectors */
public void testEigenvectors() {
    EigenDecomposition ed = new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN);
    for (int i = 0; i < matrix.getRowDimension(); ++i) {
        double lambda = ed.getRealEigenvalue(i);
        RealVector v  = ed.getEigenvector(i);
        RealVector mV = matrix.operate(v);
        assertEquals(0, mV.subtract(v.mapMultiplyToSelf(lambda)).getNorm(), 1.0e-13);
    }
}
 
Example #28
Source File: EigenDecompositionImplTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** test eigenvalues */
public void testEigenvalues() {
    EigenDecomposition ed = new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN);
    double[] eigenValues = ed.getRealEigenvalues();
    assertEquals(refValues.length, eigenValues.length);
    for (int i = 0; i < refValues.length; ++i) {
        assertEquals(refValues[i], eigenValues[i], 3.0e-15);
    }
}
 
Example #29
Source File: EigenDecompositionImplTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testDimension4WithoutSplit() {
    RealMatrix matrix =
        MatrixUtils.createRealMatrix(new double[][] {
                               {  0.5608, -0.2016,  0.1152, -0.2976 },
                               { -0.2016,  0.4432, -0.2304,  0.1152 },
                               {  0.1152, -0.2304,  0.3088, -0.1344 },
                               { -0.2976,  0.1152, -0.1344,  0.3872 }
                           });
    EigenDecomposition ed = new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN);
    assertEquals(1.0, ed.getRealEigenvalue(0), 1.0e-15);
    assertEquals(0.4, ed.getRealEigenvalue(1), 1.0e-15);
    assertEquals(0.2, ed.getRealEigenvalue(2), 1.0e-15);
    assertEquals(0.1, ed.getRealEigenvalue(3), 1.0e-15);
}
 
Example #30
Source File: EigenDecompositionImplTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testDimension4WithSplit() {
    RealMatrix matrix =
        MatrixUtils.createRealMatrix(new double[][] {
                               {  0.784, -0.288,  0.000,  0.000 },
                               { -0.288,  0.616,  0.000,  0.000 },
                               {  0.000,  0.000,  0.164, -0.048 },
                               {  0.000,  0.000, -0.048,  0.136 }
                           });
    EigenDecomposition ed = new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN);
    assertEquals(1.0, ed.getRealEigenvalue(0), 1.0e-15);
    assertEquals(0.4, ed.getRealEigenvalue(1), 1.0e-15);
    assertEquals(0.2, ed.getRealEigenvalue(2), 1.0e-15);
    assertEquals(0.1, ed.getRealEigenvalue(3), 1.0e-15);
}