Package org.ejml.simple

Examples of org.ejml.simple.SimpleMatrix


        }
    }

    private void checkDecomposition(boolean compact, DenseMatrix64F a,
                                    QRColPivDecompositionHouseholderColumn alg) {
        SimpleMatrix Q = SimpleMatrix.wrap(alg.getQ(null, compact));
        SimpleMatrix R = SimpleMatrix.wrap(alg.getR(null, compact));
        SimpleMatrix P = SimpleMatrix.wrap(alg.getPivotMatrix(null));

        SimpleMatrix AA = SimpleMatrix.wrap(a);

        SimpleMatrix expected = AA.mult(P);
        SimpleMatrix found = Q.mult(R);

//        Q.print();
//        R.print();
//        P.print();
//        System.out.println("asdfasdf");
View Full Code Here


    public void computeY_t_V() {
        int M = r-2;
        initMatrices(M);

        // Y'*V
        SimpleMatrix expected = Y.transpose().mult(V);

        BlockMatrix64F Ab = BlockMatrixOps.convert(A.getMatrix(),r);
        double found[] = new double[ M ];

        BlockHouseHolder.computeY_t_V(r,new D1Submatrix64F(Ab,0, A.numRows(), 0, r),M,found);

        for( int i = 0; i < M; i++ ) {
            assertEquals(expected.get(i),found[i],1e-8);
        }
    }
View Full Code Here

    }

    private void checkDecomposition(int height, int width, boolean compact ) {
        QRDecomposition<DenseMatrix64F> alg = createQRDecomposition();

        SimpleMatrix A = new SimpleMatrix(height,width);
        RandomMatrices.setRandom(A.getMatrix(),rand);

        assertTrue(alg.decompose(A.copy().getMatrix()));

        int minStride = Math.min(height,width);

        SimpleMatrix Q = new SimpleMatrix(height,compact ? minStride : height);
        alg.getQ(Q.getMatrix(), compact);
        SimpleMatrix R = new SimpleMatrix(compact ? minStride : height,width);
        alg.getR(R.getMatrix(), compact);


        // see if Q has the expected properties
        assertTrue(MatrixFeatures.isOrthogonal(Q.getMatrix(),1e-6));
View Full Code Here

        int width = 5;
        int height = 10;

        QRDecomposition<DenseMatrix64F> alg = createQRDecomposition();

        SimpleMatrix A = new SimpleMatrix(height,width);
        RandomMatrices.setRandom(A.getMatrix(),rand);

        alg.decompose(A.getMatrix());

        // get the results from a provided matrix
        DenseMatrix64F Q_provided = RandomMatrices.createRandom(height,height,rand);
        DenseMatrix64F R_provided = RandomMatrices.createRandom(height,width,rand);
       
View Full Code Here

        int width = 5;
        int height = 10;

        QRDecomposition<DenseMatrix64F> alg = createQRDecomposition();

        SimpleMatrix A = new SimpleMatrix(height,width);
        RandomMatrices.setRandom(A.getMatrix(),rand);

        alg.decompose(A.getMatrix());

        // check the case where it creates the matrix first
        assertTrue(alg.getR(null,true).numRows == width);
        assertTrue(alg.getR(null,false).numRows == height);
View Full Code Here

        int height = 10;
        int width = 5;

        QRDecomposition<DenseMatrix64F> alg = createQRDecomposition();

        SimpleMatrix A = new SimpleMatrix(height,width);
        RandomMatrices.setRandom(A.getMatrix(),rand);

        alg.decompose(A.getMatrix());

        SimpleMatrix Q = new SimpleMatrix(height,width);
        alg.getQ(Q.getMatrix(), true);

        // see if Q has the expected properties
        assertTrue(MatrixFeatures.isOrthogonal(Q.getMatrix(),1e-6));

        // try to extract it with the wrong dimensions
        Q = new SimpleMatrix(height,height);
        try {
            alg.getQ(Q.getMatrix(), true);
            fail("Didn't fail");
        } catch( RuntimeException e ) {}
    }
View Full Code Here

    }

    private void checkSubHouse(int w , int width) {
        DebugQR qr = new DebugQR(width,width);

        SimpleMatrix A = new SimpleMatrix(width,width);
        RandomMatrices.setRandom(A.getMatrix(),rand);

        qr.householder(w,A.getMatrix());

        SimpleMatrix U = new SimpleMatrix(width,1, true, qr.getQR()[w]).extractMatrix(w,width,0,1);
        U.set(0,0,1); // this is not explicity set and is assumed to be 1
        SimpleMatrix I = SimpleMatrix.identity(width-w);
        SimpleMatrix Q = I.minus(U.mult(U.transpose()).scale(qr.getGamma()));


        // check the expected properties of Q
        assertTrue(Q.isIdentical(Q.transpose(),1e-6));
        assertTrue(Q.isIdentical(Q.invert(),1e-6));

        SimpleMatrix result = Q.mult(A.extractMatrix(w,width,w,width));

        for( int i = 1; i < width-w; i++ ) {
            assertEquals(0,result.get(i,0),1e-5);
        }
    }
View Full Code Here

        DebugQR qr = new DebugQR(width,width);

        double gamma = 0.2;
        double tau = 0.75;

        SimpleMatrix U = new SimpleMatrix(width,1);
        SimpleMatrix A = new SimpleMatrix(width,width);

        RandomMatrices.setRandom(U.getMatrix(),rand);
        RandomMatrices.setRandom(A.getMatrix(),rand);

        qr.convertToColumnMajor(A.getMatrix());

        // compute the results using standard matrix operations
        SimpleMatrix I = SimpleMatrix.identity(width-w);

        SimpleMatrix u_sub = U.extractMatrix(w,width,0,1);
        u_sub.set(0,0,1);// assumed to be 1 in the algorithm
        SimpleMatrix A_sub = A.extractMatrix(w,width,w,width);
        SimpleMatrix expected = I.minus(u_sub.mult(u_sub.transpose()).scale(gamma)).mult(A_sub);

        qr.updateA(w,U.getMatrix().getData(),gamma,tau);

        double[][] found = qr.getQR();

        for( int i = w+1; i < width; i++ ) {
            assertEquals(U.get(i,0),found[w][i],1e-8);
        }

        // the right should be the same
        for( int i = w; i < width; i++ ) {
            for( int j = w+1; j < width; j++ ) {
                double a = expected.get(i-w,j-w);
                double b = found[j][i];

                assertEquals(a,b,1e-6);
            }
        }
View Full Code Here

    }

    private void checkSubHouse(int w , int width) {
        DebugQR qr = new DebugQR(width,width);

        SimpleMatrix A = new SimpleMatrix(width,width);
        RandomMatrices.setRandom(A.getMatrix(),rand);

        qr.householder(w,A.getMatrix());

        SimpleMatrix U = new SimpleMatrix(width,1, true, qr.getU()).extractMatrix(w,width,0,1);

        SimpleMatrix I = SimpleMatrix.identity(width-w);
        SimpleMatrix Q = I.minus(U.mult(U.transpose()).scale(qr.getGamma()));


        // check the expected properties of Q
        assertTrue(Q.isIdentical(Q.transpose(),1e-6));
        assertTrue(Q.isIdentical(Q.invert(),1e-6));

        SimpleMatrix result = Q.mult(A.extractMatrix(w,width,w,width));

        for( int i = 1; i < width-w; i++ ) {
            assertEquals(0,result.get(i,0),1e-5);
        }
    }
View Full Code Here

    @Test
    public void convertSimple() {
        BlockMatrix64F A = BlockMatrixOps.createRandom(4,6,-1,1,rand,3);

        SimpleMatrix S = BlockMatrixOps.convertSimple(A);

        assertEquals(A.numRows,S.numRows());
        assertEquals(A.numCols,S.numCols());

        for( int i = 0; i < A.numRows; i++ ) {
            for( int j = 0; j < A.numCols; j++ ) {
                assertEquals(A.get(i,j),S.get(i,j),1e-8);
            }
        }
    }
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.