Package mikera.matrixx

Examples of mikera.matrixx.Matrix


       
        performStandardTests(alg,A,1);
    }

    public void checkIdentity() {
        Matrix I = Matrix.createIdentity(4);

        SymmetricQRAlgorithmDecomposition alg = createDecomposition();

        assertNotNull(alg.decompose(I));
View Full Code Here


        testForEigenpair(alg,1,0,0,0,1,0);
        testForEigenpair(alg,1,0,0,0,0,1);
    }

    public void checkAllZeros() {
        Matrix A = Matrix.create(5,5);

        SymmetricQRAlgorithmDecomposition alg = createDecomposition();

        assertNotNull(alg.decompose(A));
View Full Code Here

//    }

    public void checkLargeValue( boolean symmetric) {
        for( int i = 0; i < 20; i++ ) {
            SymmetricQRAlgorithmDecomposition alg = createDecomposition();
            Matrix z = Matrix.createRandom(3, 3);
            Matrix A = z.innerProduct(z.getTranspose())// symmetric

//            CommonOps.scale(1e-200,A);
//            A.scale(1e100);

            assertNotNull(alg.decompose(A));
View Full Code Here

//                    throw new RuntimeException("Egads");
//                }
                assertFalse(v.hasUncountable());

//                CommonOps.mult(A,v,tempA);
                Matrix ta = Matrix.create(A.rowCount(), 1);
                ta.setColumn(0, (v));
                AMatrix tempA = Multiplications.multiply(A, ta);
//                CommonOps.scale(c.real,v,tempB);
                Matrix tb = Matrix.create(v.length(), 1);
                tb.setColumn(0, v);
                AMatrix tempB = tb.multiplyCopy(c.x);
//                double max = NormOps.normPInf(A);
                double max = normPInf(A);
                if( max == 0 ) max = 1;
               
                double error = diffNormF(tempA,tempB)/max;
View Full Code Here

        double[][] dataA = {{-3.0, 1.0, 3.0,-3.0, 0.0},
              { 2.0,-4.0, 0.0,-2.0, 0.0},
              { 1.0,-4.0, 4.0, 1.0,-3.0},
              {-1.0,-3.0, 2.0, 2.0,-4.0},
              {-5.0, 3.0, 1.0, 3.0, 1.0}};
        Matrix A = Matrix.create(dataA);

//        A.print();

        SvdImplicitQrAlgorithm svd = createHelper(A);
View Full Code Here

        svd.setVt(Matrix.createIdentity(n));
        assertTrue(svd.process(values));

//        System.out.println("Vector total steps = "+svd.totalSteps);

        Matrix Ut = Matrix.create(svd.getUt());
        Matrix Vt = Matrix.create(svd.getVt());
        DiagonalMatrix W = DiagonalMatrix.create(svd.diag);
//
//            Ut.mult(W).mult(V).print();
        Matrix A_found = Multiplications.multiply(Multiplications.multiply(Ut.getTranspose(), W), Vt);
//            A_found.print();

        assertEquals(diag[0],A_found.get(0,0),1e-8);
        for( int i = 0; i < n-1; i++ ) {
            assertEquals(diag[i+1],A_found.get(i+1,i+1),1e-8);
            assertEquals(off[i],A_found.get(i,i+1),1e-8);
        }
    }
View Full Code Here

     */
    public void checkCharacteristicEquation( SymmetricQRAlgorithmDecomposition alg ,
                                             Matrix A ) {
        int N = alg.getNumberOfEigenvalues();

        Matrix a = Matrix.create(A);

        for( int i = 0; i < N; i++ ) {
            Vector2 c = alg.getEigenvalue(i);

            if( Math.abs(c.y - 0) < 1e-8 ) {
                // test using the characteristic equation
                Matrix temp = Matrix.createIdentity(A.columnCount());
                temp.scale(c.x);
                temp.sub(a);
                double det = temp.determinant();

                // extremely crude test.  given perfect data this is probably considered a failure...  However,
                // its hard to tell what a good test value actually is.
                assertEquals(0, det, 0.1);
            }
View Full Code Here

    abstract protected QRDecomposition createQRDecomposition(boolean compact);

    @Test
    public void testModifiedInput() {
        Matrix A = Matrix.createRandom(3, 4);
        HouseholderQR alg = new HouseholderQR(false);
        alg.decompose(A);
        A.equals(A);
    }
View Full Code Here

     */
    public void testVectorsLinearlyIndependent( SymmetricQRAlgorithmDecomposition alg ) {
        int N = alg.getNumberOfEigenvalues();

        // create a matrix out of the eigenvectors
        Matrix A = Matrix.create(N,N);

        int off = 0;
        for( int i = 0; i < N; i++ ) {
            AVector v = alg.getEigenVector(i);

            // it can only handle real eigenvectors
            if( v == null )
                off++;
            else {
                for( int j = 0; j < N; j++ ) {
                    A.set(i-off,j,v.get(j));
                }
            }
        }

        // see if there are any real eigenvectors
        if( N == off )
            return;

//        A.reshape(N-off,N, false);
        A = A.reshape(N-off, N);
       
        AltLU lu = new AltLU();
        lu._decompose(A);
        assertFalse(lu.isSingular());
//        assertTrue(MatrixFeatures.isRowsLinearIndependent(A));
View Full Code Here

    }

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

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

        IQRResult result = alg.decompose(A);
        assertNotNull(result);

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

        Matrix Q = result.getQ().toMatrix();
        Matrix R = result.getR().toMatrix();
        assertTrue(Q.rowCount() == height && Q.columnCount() == height);
        assertTrue(R.rowCount() == (compact ? minStride : height));
        assertTrue(R.columnCount() == width);

        // see if Q has the expected properties
        assertTrue(Q.isOrthogonal(1e-8));

        // see if it has the expected properties
        R = R.reshape(A.rowCount(), A.columnCount());
        Matrix A_found = Multiplications.multiply(Q, R);

        A.epsilonEquals(A_found,1e-6);
        assertTrue(Multiplications.multiply(Q.getTranspose(),A).epsilonEquals(R,1e-6));
    }
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.