Package mikera.matrixx

Examples of mikera.matrixx.Matrix


                    if( vector.length > 0 ) {
                        AVector v = alg.getEigenVector(i);
                        AMatrix e = Matrix.createFromRows(vector);
                        e = e.getTranspose();
                       
                        Matrix t = Matrix.create(v.length(), 1);
                        t.setColumn(0, v);
                        double error = diffNormF(e,t);
//                        CommonOps.changeSign(e);
                        e.multiply(-1);
                        double error2 = diffNormF(e,t);
View Full Code Here


        int height = 10;
        int width = 5;

        QRDecomposition alg = createQRDecomposition(true);

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

        IQRResult result = alg.decompose(A);

        Matrix Q = result.getQ().toMatrix();

        // see if Q has the expected properties
        assertTrue(Q.isOrthogonal(1e-8));
    }
View Full Code Here

public class TestCholesky {

  @Test
  public void testCholeskyRegression() {
    Matrix original = Matrix.create(new double[][] {{4,12,-16},{12,37,-43},{-16,-43,98}})
    Matrix a=Matrix.create(original);
    ICholeskyResult r=Cholesky.decompose(a);
    validateCholesky(a,r);
   
    assertEquals(original,a);
  }
View Full Code Here

public class TestBanded {

  @Test
  public void testBandwidths() {
    Matrix m=Matrix.create(6, 6);
   
    assertEquals(0,m.upperBandwidth());
    assertEquals(5,m.upperBandwidthLimit());
    assertEquals(0,m.lowerBandwidth());
    assertEquals(5,m.lowerBandwidthLimit());
   
    m.getBand(-1).fill(1.0);
    assertEquals(0,m.upperBandwidth());
    assertEquals(1,m.lowerBandwidth());
  }
View Full Code Here

  @Test
  public void testDecompose() {
//    TEST: 1
    double[][] dataA = {{5, 2, 3}, {1.5, -2, 8}, {-3, 4.7, -0.5}};
    Matrix A = Matrix.create(dataA);
    LUPResult ans = AltLU.decompose(A);
    AMatrix L = ans.getL();
    AMatrix U = ans.getU();
    AMatrix P = ans.getP();
   
    double[][] exceptDataL = {{1, 0, 0}, {-0.6, 1, 0}, {0.3, -0.44068, 1}};
    double[][] exceptDataU = {{5, 2, 3}, {0, 5.9, 1.3}, {0, 0, 7.67288}};
    double[][] exceptDataP = {{1, 0, 0}, {0, 0, 1}, {0, 1, 0}};
    Matrix exceptL = Matrix.create(exceptDataL);
    Matrix exceptU = Matrix.create(exceptDataU);
    Matrix exceptP = Matrix.create(exceptDataP);
    assertArrayEquals(L.getElements(), exceptL.data, 1e-5);
    assertArrayEquals(U.getElements(), exceptU.data, 1e-5);
    assertArrayEquals(P.getElements(), exceptP.data, 1e-5);
    assertTrue(Math.abs(-226.350 - ans.computeDeterminant()) < 1e-3);
   
//    TEST: 2
    dataA = new double[][]{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
    Matrix B = Matrix.create(dataA);
    ans = AltLU.decompose(B);
    L = ans.getL();
    U = ans.getU();
    P = ans.getP();
 
View Full Code Here

  @Test
  public void testDeterminant()
  {
      int width = 10;

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

      double minorVal = A.determinant();

      AltLU alg = new AltLU();
      LUPResult result = alg._decompose(A);
      double luVal = result.computeDeterminant();
View Full Code Here

  }

  @Test
  public void _solveVectorInternal() {
      int width = 10;
      Matrix LU = Matrix.createRandom(width,width);

      double a[] = new double[]{1,2,3,4,5,6,7,8,9,10};
      double b[] = new double[]{1,2,3,4,5,6,7,8,9,10};
      for( int i = 0; i < width; i++ ) LU.set(i,i,1);

      TriangularSolver.solveL(LU.data,a,width);
      TriangularSolver.solveU(LU.data,a,width);

      DebugDecompose alg = new DebugDecompose(width);
View Full Code Here

      }
  }
 
  @Test
  public void testModifiedInput() {
      Matrix A = Matrix.createRandom(5, 5);
      Matrix B = A.copy();
      AltLU.decompose(A);
      assertTrue(B.epsilonEquals(A));
  }
View Full Code Here

   * Uses the decomposition returned from octave, which uses LAPACK
   */
  @Test
  public void testDecomposition()
  {
      Matrix A = Matrix.create(new double[][] {{5, 2, 3},{1.5, -2, 8},{-3, 4.7, -0.5}});

      Matrix octLower = Matrix.create(new double[][] {{1, 0, 0},{-0.6, 1, 0},{0.3, -0.44068, 1}});
      Matrix octUpper = Matrix.create(new double[][] {{5, 2, 3},{0, 5.9, 1.3},{0, 0, 7.67288}});

      LUPResult result = AltLU.decompose(A);
      assertNotNull(result);

      // not singular
      assertFalse(Math.abs(result.computeDeterminant() - 0) < 1e-8);

      AMatrix L = result.getL();
      AMatrix U = result.getU();
      AMatrix P = result.getP();

      assertTrue(octLower.epsilonEquals(L,1e-5));
      assertTrue(octUpper.epsilonEquals(U,1e-5));

//      DenseMatrix64F A_found = P.mult(L).mult(U).getMatrix();
      Matrix A_found = Multiplications.multiply(P, Multiplications.multiply(L, U));
      assertTrue(A_found.epsilonEquals(A,1e-8));
  }
View Full Code Here

  @Test
  public void testDecomposition2()
  {
      for( int i = 2; i <= 20; i++ ) {
          Matrix A = Matrix.createRandom(i,i);

          LUPResult result =AltLU.decompose(A);
          assertNotNull(result);

       // not singular
          assertFalse(Math.abs(result.computeDeterminant() - 0) < 1e-8);

          AMatrix L = result.getL();
          AMatrix U = result.getU();
          AMatrix P = result.getP();

//          DenseMatrix64F A_found = P.transpose().mult(L).mult(U).getMatrix();
          Matrix A_found = Multiplications.multiply(P, Multiplications.multiply(L, U));
          assertTrue(A_found.epsilonEquals(A,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.