Package mikera.matrixx

Examples of mikera.matrixx.Matrix


        if( !canR ) return;

        double[][] dataA = {{1, 2, 4},
             {2, 13, 23},
             {4, 23, 90}};
        Matrix A = Matrix.create(dataA);

        double [][] dataR = {{1,2,4},
                  {0,3,5},
                  {0,0,7}};
        Matrix R = Matrix.create(dataR);

        ICholeskyResult ans = Cholesky.decompose(A);
        assertNotNull(ans);
        Matrix foundR = ans.getU().toMatrix();

        assertArrayEquals(R.getElements(),foundR.getElements(),1e-8);
    }
View Full Code Here


     */
    @Test
    public void testNotPositiveDefinite() {
      double dataA[][] = {{1,-2},
                   {-1,-2}};
        Matrix A = Matrix.create(dataA);

        assertNull(Cholesky.decompose(A));
    }
View Full Code Here

    /**
     * Decomposes the matrix, extracts H and Q, then sees if it can recompute A using similar matrix stuff.
     */
    @Test
    public void testItAllTogether() {
        Matrix A = Matrix.createRandom(5,5);

        checkItAll(A);
    }
View Full Code Here

        checkItAll(A);
    }

    private void checkItAll(Matrix A) {
        HessenbergResult result = HessenbergSimilarDecomposition.decompose(A);
        Matrix Q = result.getQ().toMatrix();
        Matrix H = result.getH().toMatrix();
//        System.out.println("-------- H ---------");
//        UtilEjml.print(H,"%8.2e");
//        System.out.println("-------- Q ---------");
//        UtilEjml.print(Q,"%8.2e");
        assertTrue(isOrthogonal(Q, TOLERANCE));

        H = Multiplications.multiply(Q, Multiplications.multiply(H, Q.getTranspose()));

//        System.out.println("------- A ----------");
//        UtilEjml.print(A,"%8.2e");
//        System.out.println("----- Found A ------");
//        UtilEjml.print(H,"%8.2e");

        assertTrue(!H.hasUncountable());

        assertTrue(A.epsilonEquals(H,TOLERANCE));
    }
View Full Code Here

    /**
     * Make sure it doesn't change the input
     */
    @Test
    public void testInputUnmodified() {
        Matrix A = Matrix.createRandom(4,4);
        Matrix B = A.copy();
        HessenbergSimilarDecomposition.decompose(A);
        assertTrue(A.equals(B));
    }
View Full Code Here

    @Test
    public void testDecompose() {
      double[][] dataA = {{1,2,4},
                {2,7,23},
                {4,23,98}};
        Matrix A = Matrix.create(dataA);

        double[][] dataL = {{1,0,0},
                  {2,1,0},
                  {4,5,1}};
        Matrix L = Matrix.create(dataL);

        double D[] = new double[]{1,3,7};

        ICholeskyLDUResult ans = CholeskyLDU.decompose(A);
        assertNotNull(ans);

        Matrix foundL = ans.getL().toMatrix();

        assertArrayEquals(L.getElements(),foundL.getElements(), 1e-5);
        assertArrayEquals(D, ans.getD().getLeadingDiagonal().toDoubleArray(), 1e-5);
    }
View Full Code Here

     * If it is not positive definate it should fail
     */
    @Test
    public void testNotPositiveDefinate() {
      double[][] dataA = {{1,-1},{-1,-2}};
      Matrix A = Matrix.create(dataA);
     
        assertNull(CholeskyLDU.decompose(A));
    }
View Full Code Here

    }

    public void testDecompositionOfTrivial()
    {
//      Test 1
      Matrix A = Matrix.create(new double[][] {{5,2,3},
          {1.5, -2, 8},
          {-3, 4.7, -0.5}});
      SvdImplicitQr alg = createSvd();
      assertNotNull(alg._decompose(A));
      assertEquals(3, rank(alg, EPS));
      assertEquals(0, nullity(alg, EPS));
      double []w = alg.getSingularValues().toDoubleArray();
      checkNumFound(1,1e-5,9.59186,w);
      checkNumFound(1,1e-5,5.18005,w);
      checkNumFound(1,1e-5,4.55558,w);
      checkComponents(alg,A);
//      Test 2
        Matrix B = Matrix.create(new double[][] {{1, 2, 3},
                         {4, 5, 6},
                         {7, 8, 9}});
        alg = createSvd();
        assertNotNull(alg._decompose(B));
        assertEquals(2, rank(alg, 10*EPS));
 
View Full Code Here

        checkNumFound(1,1e-5,0,w);
        checkComponents(alg,B);
    }

    public void testWide() {
        Matrix A = Matrix.createRandom(1,1);
        A.sub(0.5);
        A.scale(2);
        SvdImplicitQr alg = createSvd();
        assertNotNull(alg._decompose(A));

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

    @Test
    public void fullTest() {

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

            Matrix A = createSymmetric(width,-1,1,rand);

            TridiagonalDecompositionHouseholder alg = createDecomposition();
            alg.decompose(A);

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

//            SimpleMatrix A_found = Q.mult(T).mult(Q.transpose());
            Matrix A_found = Multiplications.multiply(Q, Multiplications.multiply(T, Q.getTranspose()));

            assertTrue("width = "+width,A.epsilonEquals(A_found,1e-8));
        }
    }
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.