Package mikera.matrixx

Examples of mikera.matrixx.Matrix


    public void testLots() {
        SvdImplicitQr alg = createSvd();

        for( int i = 1; i < 8; i+=2 ) {
            for( int j = 1; j < 8; j+=2 ) {
                Matrix A = Matrix.createRandom(i,j);
                A.sub(0.5);
                A.scale(2);

                assertNotNull(alg._decompose(A));

                checkComponents(alg,A);
            }
View Full Code Here


    }

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

        Matrix A = Matrix.createRandom(width, width);

        qr.householder(w,A);

//        SimpleMatrix U = new SimpleMatrix(width,1, true, qr.getQR()[w]).extractMatrix(w,width,0,1);
        Matrix temp = Matrix.create(width,1);
        temp.setElements(qr.getQR()[w]);
        AStridedMatrix U = temp.subMatrix(w, width-w, 0, 1);
       
        U.set(0,0,1); // this is not explicity set and is assumed to be 1
        Matrix I = Matrix.createIdentity(width-w);
//        SimpleMatrix Q = I.minus(U.mult(U.transpose()).scale(qr.getGamma()));
        Matrix temp1 = Multiplications.multiply(U, U.getTranspose());
        temp1.scale(qr.getGamma());
        I.sub(temp1);
        Matrix Q = I;


        // check the expected properties of Q
        assertTrue(Q.epsilonEquals(Q.getTranspose(),1e-6));
        assertTrue(Q.epsilonEquals(Q.inverse(),1e-6));

//        SimpleMatrix result = Q.mult(A.extractMatrix(w,width,w,width));
        AStridedMatrix result = Multiplications.multiply(Q, A.subMatrix(w,width-w,w,width-w));

        for( int i = 1; i < width-w; i++ ) {
View Full Code Here

    /**
     * Makes sure transposed flag is correctly handled.
     */
    public void checkGetU_Transpose() {
        Matrix A = Matrix.createRandom(5, 7);
        A.sub(0.5);
        A.scale(2);

        SvdImplicitQr alg = createSvd();
        assertNotNull(alg._decompose(A));

        Matrix U = alg.getU().toMatrix();
        Matrix Ut = alg.getU().getTranspose().toMatrix();

        Matrix found = U.getTransposeCopy().toMatrix();

        assertArrayEquals(Ut.getElements(), found.getElements(), 1e-6);
    }
View Full Code Here

     */
    public void testLargeToSmall() {
        SvdImplicitQr alg = createSvd();

        // first the larger one
        Matrix A = Matrix.createRandom(10,10);
        A.sub(0.5);
        A.scale(2);
        assertNotNull(alg._decompose(A));
        checkComponents(alg,A);

        // then the smaller one
        A = Matrix.createRandom(5,5);
        A.sub(0.5);
        A.scale(2);
       
        assertNotNull(alg._decompose(A));
        checkComponents(alg,A);
    }
View Full Code Here

        DebugQR qr = new DebugQR(width,width);

        double gamma = 0.2;
        double tau = 0.75;

        Matrix U = Matrix.createRandom(width, 1);
        Matrix A = Matrix.createRandom(width, width);

        qr.convertToColumnMajor(A);

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

//        SimpleMatrix u_sub = U.extractMatrix(w,width,0,1);
        AStridedMatrix u_sub = U.subMatrix(w, width-w, 0, 1);
        u_sub.set(0,0,1);// assumed to be 1 in the algorithm
//        SimpleMatrix A_sub = A.extractMatrix(w,width,w,width);
        AStridedMatrix A_sub = A.subMatrix(w,width-w,w,width-w);
//        SimpleMatrix expected = I.minus(u_sub.mult(u_sub.transpose()).scale(gamma)).mult(A_sub);
        Matrix temp1 = Multiplications.multiply(u_sub, u_sub.getTranspose());
        temp1.scale(gamma);
        I.sub(temp1);
        Matrix expected = Multiplications.multiply(I, A_sub);

        qr.updateA(w,U.asDoubleArray(),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

        return num;
    }

    private void checkComponents( SvdImplicitQr svd , Matrix expected )
    {
        Matrix U = svd.getU().toMatrix();
        Matrix Vt = svd.getV().getTranspose().toMatrix();
        Matrix W = svd.getS().toMatrix();

        assertTrue( !U.hasUncountable() );
        assertTrue( !Vt.hasUncountable() );
        assertTrue( !W.hasUncountable() );

        if( svd.isCompact() ) {
          assertTrue(W.columnCount()==W.rowCount());
          assertTrue(U.columnCount()==W.rowCount());
            assertTrue(Vt.rowCount()==W.columnCount());
        } else {
          assertTrue(U.columnCount()==W.rowCount());
          assertTrue(W.columnCount()==Vt.rowCount());
          assertTrue(U.columnCount()==U.rowCount());
            assertTrue(Vt.columnCount()==Vt.rowCount());
        }

        Matrix found = Multiplications.multiply(U, Multiplications.multiply(W, Vt));

//        found.print();
//        expected.print();

//        assertTrue(expected.equals(found));
        assertArrayEquals(expected.toDoubleArray(), found.toDoubleArray(), 1e-6);
    }
View Full Code Here

        for( int s = 2; s < sizes.length; s++ ) {
            int N = sizes[s];
//            System.out.println("N = "+N);

            for( int i = 0; i < 2; i++ ) {
                Matrix A = Matrix.createRandom(N,N);
                A.multiply(2);
                A.sub(1);
               
                assertNotNull(alg.decompose(A));

                performStandardTests(alg,A,-1);
            }
View Full Code Here

    /**
     * Sees if it correctly computed the eigenvalues.  Does not check eigenvectors.
     */
    public void checkKnownSymmetric_JustValue() {
        Matrix A = Matrix.create(new double[][]
               {{0.98139,   0.78650,   0.78564},
                {0.78650,   1.03207,   0.29794},
                {0.78564,   0.29794,   0.91926}});
        SymmetricQRAlgorithmDecomposition alg = createDecomposition();

View Full Code Here

    /**
     * Compare results against a simple matrix with known results where some the eigenvalues
     * are real and some are complex.
     */
    public void checkKnownComplex() {
        Matrix A = Matrix.create(new double[][] {{-0.418284, 0.279875, 0.452912},
                                                 {-0.093748, -0.045179, 0.310949},
                                                 {0.250513, -0.304077, -0.031414}});

        SymmetricQRAlgorithmDecomposition alg = createDecomposition();

View Full Code Here

    /**
     * For some eigenvector algorithms this is a difficult matrix that requires a special
     * check for.  If it fails that check it will either loop forever or exit before converging.
     */
    public void checkExceptional() {
        Matrix A = Matrix.create(new double [][]
                {{0, 0, 0, 0, 1},
                {1, 0, 0, 0, 0},
                {0, 1, 0, 0, 0},
                {0, 0, 1, 0, 0},
                {0, 0, 0, 1, 0}});
View Full Code Here

TOP

Related Classes of mikera.matrixx.Matrix

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.