Package org.ejml.simple

Examples of org.ejml.simple.SimpleMatrix


    }

    @Test
    public void multPlusTransA() {
        for( int width = r+1; width <= r*3; width++ ) {
            SimpleMatrix A = SimpleMatrix.random(width,width,-1,1,rand);
            SimpleMatrix U = SimpleMatrix.random(r,width,-1,1,rand);
            SimpleMatrix V = SimpleMatrix.random(r,width,-1,1,rand);

            BlockMatrix64F Ab = BlockMatrixOps.convert(A.getMatrix(),r);
            BlockMatrix64F Ub = BlockMatrixOps.convert(U.getMatrix(),r);
            BlockMatrix64F Vb = BlockMatrixOps.convert(V.getMatrix(),r);

            SimpleMatrix expected = A.plus(U.transpose().mult(V));

            TridiagonalDecompositionBlockHouseholder.multPlusTransA(r,new D1Submatrix64F(Ub)
                    ,new D1Submatrix64F(Vb),new D1Submatrix64F(Ab));


            for( int i = r; i < width; i++ ) {
                for( int j = i; j < width; j++ ) {
                    assertEquals(i+" "+j,expected.get(i,j),Ab.get(i,j),1e-8);
                }
            }
        }
    }
View Full Code Here


    }

    private void checkRankNUpdate(int lengthA, int heightB) {
        double alpha = -2.0;
        SimpleMatrix origA = SimpleMatrix.random(lengthA,lengthA,-1,1,rand);
        SimpleMatrix origB = SimpleMatrix.random(heightB,lengthA,-1,1,rand);

        BlockMatrix64F blockA = BlockMatrixOps.convert(origA.getMatrix(),N);
        BlockMatrix64F blockB = BlockMatrixOps.convert(origB.getMatrix(),N);

        D1Submatrix64F subA = new D1Submatrix64F(blockA,0, origA.numRows(), 0, origA.numCols());
        D1Submatrix64F subB = new D1Submatrix64F(blockB,0, origB.numRows(), 0, origB.numCols());

        SimpleMatrix expected = origA.plus(origB.transpose().mult(origB).scale(alpha));
        BlockInnerRankUpdate.rankNUpdate(N,alpha,subA,subB);

        assertTrue(GenericMatrixOps.isEquivalent(expected.getMatrix(),blockA,1e-8));
    }
View Full Code Here

        // matrix being updated is less than a block
        checkSymmRankNMinus_U(N-1, N-2);
    }

    private void checkSymmRankNMinus_U(int lengthA, int heightB) {
        SimpleMatrix origA = SimpleMatrix.wrap(RandomMatrices.createSymmPosDef(lengthA,rand));
        SimpleMatrix origB = SimpleMatrix.random(heightB,lengthA,-1,1,rand);

        BlockMatrix64F blockA = BlockMatrixOps.convert(origA.getMatrix(),N);
        BlockMatrix64F blockB = BlockMatrixOps.convert(origB.getMatrix(),N);

        D1Submatrix64F subA = new D1Submatrix64F(blockA,0, origA.numRows(), 0, origA.numCols());
        D1Submatrix64F subB = new D1Submatrix64F(blockB,0, origB.numRows(), 0, origB.numCols());

        SimpleMatrix expected = origA.plus(origB.transpose().mult(origB).scale(-1));
        BlockInnerRankUpdate.symmRankNMinus_U(N,subA,subB);

        assertTrue(GenericMatrixOps.isEquivalentTriangle(true,expected.getMatrix(),blockA,1e-8));
    }
View Full Code Here

        // matrix being updated is less than a block
        checkSymmRankNMinus_L(N-1, N-2);
    }

    private void checkSymmRankNMinus_L(int lengthA, int widthB) {
        SimpleMatrix origA = SimpleMatrix.wrap(RandomMatrices.createSymmPosDef(lengthA,rand));
        SimpleMatrix origB = SimpleMatrix.random(lengthA,widthB,-1,1,rand);

        BlockMatrix64F blockA = BlockMatrixOps.convert(origA.getMatrix(),N);
        BlockMatrix64F blockB = BlockMatrixOps.convert(origB.getMatrix(),N);

        D1Submatrix64F subA = new D1Submatrix64F(blockA,0, origA.numRows(), 0, origA.numCols());
        D1Submatrix64F subB = new D1Submatrix64F(blockB,0, origB.numRows(), 0, origB.numCols());

        SimpleMatrix expected = origA.plus(origB.mult(origB.transpose()).scale(-1));
        BlockInnerRankUpdate.symmRankNMinus_L(N,subA,subB);

//        expected.print();
//        blockA.print();

        assertTrue(GenericMatrixOps.isEquivalentTriangle(false,expected.getMatrix(),blockA,1e-8));
    }
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(w)).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

        DenseMatrix64F A = RandomMatrices.createRandom(6,6,rand);
        DenseMatrix64F u = RandomMatrices.createRandom(6,1,rand);
        DenseMatrix64F w = RandomMatrices.createRandom(6,1,rand);
        double gamma = -45;

        SimpleMatrix _A = SimpleMatrix.wrap(A);
        SimpleMatrix _u = SimpleMatrix.wrap(u);
        SimpleMatrix _w = SimpleMatrix.wrap(w);
       
        SimpleMatrix expected = _A.plus(_u.mult(_w.transpose()).scale(gamma));
        DenseMatrix64F found = new DenseMatrix64F(6,6);

        VectorVectorMult.rank1Update(gamma,A,u,w,found);

        EjmlUnitTests.assertEquals(expected.getMatrix(),found,1e-8);
    }
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);

        CommonOps.transpose(A.getMatrix(),qr.getQR());

        // 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);

        DenseMatrix64F found = qr.getQR();

        for( int i = w+1; i < width; i++ ) {
            assertEquals(U.get(i,0),found.get(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.get(j,i);

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

        // test it out on a variety of sizes
        for( int width = 1; width <= 3*r; width++ ) {
//            System.out.println("********* width "+width);

            // create a random symmetric matrix
            SimpleMatrix A = SimpleMatrix.wrap(RandomMatrices.createSymmetric(width,-1,1,rand));

            TridiagonalDecompositionHouseholderOrig decomp = new TridiagonalDecompositionHouseholderOrig();
            decomp.decompose(A.getMatrix());

            D1Submatrix64F Ab = insertIntoBlock(offX,offY,A,r);
            D1Submatrix64F V = new D1Submatrix64F(new BlockMatrix64F(r,offX+A.numCols(),r));
            V.col0 = offX;
            V.row1 = Ab.row1-Ab.row0;
            int gammaOffset = offX;
            double gammas[] = new double[gammaOffset+A.numCols()];
            TridiagonalBlockHelper.tridiagUpperRow(r,Ab,gammas,V);

            DenseMatrix64F expected = decomp.getQT();

            // see if the decomposed matrix is the same
View Full Code Here

        DenseMatrix64F A = RandomMatrices.createRandom(6,6,rand);
        DenseMatrix64F u = RandomMatrices.createRandom(6,1,rand);
        DenseMatrix64F w = RandomMatrices.createRandom(6,1,rand);
        double gamma = -45;

        SimpleMatrix _A = SimpleMatrix.wrap(A);
        SimpleMatrix _u = SimpleMatrix.wrap(u);
        SimpleMatrix _w = SimpleMatrix.wrap(w);

        SimpleMatrix expected = _A.plus(_u.mult(_w.transpose()).scale(gamma));
        DenseMatrix64F found = A.copy();

        VectorVectorMult.rank1Update(gamma,found,u,w);

        EjmlUnitTests.assertEquals(expected.getMatrix(),found,1e-8);
    }
View Full Code Here

//            System.out.println("width!!!  "+width);
            double betas[] = new double[ r ];
            for( int i = 0; i < r; i++ )
                betas[i] = i + 0.5;

            SimpleMatrix A = SimpleMatrix.random(r,width,-1,1,rand);

            // Compute W directly using SimpleMatrix
            SimpleMatrix v = A.extractVector(true,0);
            v.set(0,0);
            v.set(1,1);
            SimpleMatrix Y = v;
            SimpleMatrix W = v.scale(-betas[0]);

            for( int i = 1; i < A.numRows(); i++ ) {
                v = A.extractVector(true,i);

                for( int j = 0; j <= i; j++ )
                    v.set(j,0);
                if( i+1 < A.numCols())
                    v.set(i+1,1);

                SimpleMatrix z = v.transpose().plus(W.transpose().mult(Y.mult(v.transpose()))).scale(-betas[i]);

                W = W.combine(i,0,z.transpose());
                Y = Y.combine(i,0,v);
            }

            // now compute it using the block matrix stuff
            BlockMatrix64F Ab = BlockMatrixOps.convert(A.getMatrix(),r);
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.