Package org.ejml.simple

Examples of org.ejml.simple.SimpleMatrix


        checkMatrix(5,5);
        checkMatrix(7,7);
    }

    private void checkMatrix( int numRows , int numCols ) {
        SimpleMatrix A = SimpleMatrix.random(numRows,numCols,-1,1,rand);

        QRExampleSimple alg = new QRExampleSimple();

        alg.decompose(A);

        SimpleMatrix Q = alg.getQ();
        SimpleMatrix R = alg.getR();

        SimpleMatrix A_found = Q.mult(R);

        assertTrue( A.isIdentical(A_found,1e-8));
    }
View Full Code Here


    public void extract() {
        DenseMatrix64F A = RandomMatrices.createRandom(5,10,-1,1,rand);

        D1Submatrix64F S = new D1Submatrix64F(A,2,4,1,10);

        SimpleMatrix M = S.extract();

        DenseMatrix64F E = CommonOps.extract(A,2,4,1,10);

        assertTrue(MatrixFeatures.isEquals(E,M.getMatrix()));
    }
View Full Code Here

        LUDecomposition<DenseMatrix64F> alg = create(3,3);
        assertTrue(alg.decompose(A));

        assertFalse(alg.isSingular());

        SimpleMatrix L = SimpleMatrix.wrap(alg.getLower(null));
        SimpleMatrix U = SimpleMatrix.wrap(alg.getUpper(null));
        SimpleMatrix P = SimpleMatrix.wrap(alg.getPivot(null));

        EjmlUnitTests.assertEquals(octLower,L.getMatrix(),1e-5);
        EjmlUnitTests.assertEquals(octUpper,U.getMatrix(),1e-5);

        DenseMatrix64F A_found = P.mult(L).mult(U).getMatrix();
        assertTrue(MatrixFeatures.isIdentical(A_found,A,1e-8));
    }
View Full Code Here

            checkWithDefinition(lower,5);
        }
    }

    private void checkWithDefinition(boolean lower, int size) {
        SimpleMatrix A = SimpleMatrix.wrap( RandomMatrices.createSymmPosDef(size,rand));

        CholeskyDecomposition<DenseMatrix64F> cholesky = create(lower);
        assertTrue(DecompositionFactory.decomposeSafe(cholesky,A.getMatrix()));

        SimpleMatrix T = SimpleMatrix.wrap(cholesky.getT(null));
        SimpleMatrix found;

        if( lower ) {
            found = T.mult(T.transpose());
        } else {
            found = T.transpose().mult(T);
View Full Code Here

    @Test
    public void fullTest() {

        for( int width = 1; width < 20; width += 2 ) {

            SimpleMatrix A = SimpleMatrix.wrap(RandomMatrices.createSymmetric(width,-1,1,rand));

            TridiagonalSimilarDecomposition<DenseMatrix64F> alg = createDecomposition();


            assertTrue(safeDecomposition(alg,A.getMatrix()));

            // test the results using the decomposition's definition
            SimpleMatrix Q = SimpleMatrix.wrap(alg.getQ(null,false));
            SimpleMatrix T = SimpleMatrix.wrap(alg.getT(null));

            SimpleMatrix A_found = Q.mult(T).mult(Q.transpose());

            assertTrue("width = "+width,MatrixFeatures.isIdentical(A.getMatrix(),A_found.getMatrix(),1e-8));
        }
    }
View Full Code Here

            LUDecomposition<DenseMatrix64F> alg = create(i,i);
            assertTrue(alg.decompose(A));

            assertFalse(alg.isSingular());

            SimpleMatrix L = SimpleMatrix.wrap(alg.getLower(null));
            SimpleMatrix U = SimpleMatrix.wrap(alg.getUpper(null));
            SimpleMatrix P = SimpleMatrix.wrap(alg.getPivot(null));

            DenseMatrix64F A_found = P.transpose().mult(L).mult(U).getMatrix();
            assertTrue(MatrixFeatures.isIdentical(A_found,A,1e-8));
        }
    }
View Full Code Here

        LUDecomposition<DenseMatrix64F> alg = create(2,3);

        assertTrue(alg.decompose(A));
//        assertFalse(alg.isSingular());

        SimpleMatrix L = SimpleMatrix.wrap(alg.getLower(null));
        SimpleMatrix U = SimpleMatrix.wrap(alg.getUpper(null));
        SimpleMatrix P = SimpleMatrix.wrap(alg.getPivot(null));

        DenseMatrix64F A_found = P.mult(L).mult(U).getMatrix();

        assertTrue(MatrixFeatures.isIdentical(A_found,A,1e-8));
    }
View Full Code Here

        LUDecomposition<DenseMatrix64F> alg = create(3,2);

        assertTrue(alg.decompose(A));
//        assertFalse(alg.isSingular());

        SimpleMatrix L = SimpleMatrix.wrap(alg.getLower(null));
        SimpleMatrix U = SimpleMatrix.wrap(alg.getUpper(null));
        SimpleMatrix P = SimpleMatrix.wrap(alg.getPivot(null));

        DenseMatrix64F A_found = P.transpose().mult(L).mult(U).getMatrix();

        assertTrue(MatrixFeatures.isIdentical(A_found,A,1e-8));
    }
View Full Code Here

            }
        }
    }

    private void checkNaive(int m, int n) {
        SimpleMatrix A = SimpleMatrix.wrap(RandomMatrices.createRandom(m,n,rand));

        BidiagonalDecompositionRow decomp = new BidiagonalDecompositionRow();
        BidiagonalDecompositionNaive naive = new BidiagonalDecompositionNaive();

        assertTrue(decomp.decompose(A.getMatrix().copy()));
        assertTrue(naive.decompose(A.getMatrix()));

        SimpleMatrix U = SimpleMatrix.wrap(decomp.getU(null,false,false));
        SimpleMatrix B = SimpleMatrix.wrap(decomp.getB(null,false));
        SimpleMatrix V = SimpleMatrix.wrap(decomp.getV(null,false,false));

//        U.print();
//        B.print();
//        naive.getB().print();
//        V.print();
//        naive.getV().print();

//        naive.getVTran().print();

        assertTrue(naive.getB().isIdentical(B,1e-8));
        assertTrue(naive.getU().isIdentical(U,1e-8));
        assertTrue(naive.getV().isIdentical(V,1e-8));

        // check the decomposition
        DenseMatrix64F foundA = U.mult(B).mult(V.transpose()).getMatrix();

//        A.print();
//        foundA.print();

        assertTrue(MatrixFeatures.isIdentical(A.getMatrix(),foundA,1e-8));
View Full Code Here

        for( int width = 1; width <= 3*r; width++ ) {
//            System.out.println("width "+width);
            int end = width;
            int offset = width > 1 ? 1 : 0;

            SimpleMatrix A = SimpleMatrix.random(r,width,-1,1,rand);
            BlockMatrix64F Ab = BlockMatrixOps.convert(A.getMatrix(),r);
            BlockMatrix64F Bb = Ab.copy();

            SimpleMatrix b = A.extractVector(true,rowA).scale(alpha);

            BlockVectorOps.scale_row(r,new D1Submatrix64F(Ab),rowA, alpha, new D1Submatrix64F(Bb),rowB,offset,end);

            checkVector_row(rowB, end, offset, A, Bb, b);
        }
View Full Code Here

TOP

Related Classes of org.ejml.simple.SimpleMatrix

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.