/** Check results against symmetric matrices that are randomly generated */
  public void checkRandomSymmetric() {
    for (int N = 1; N <= 15; N++) {
      for (int i = 0; i < 20; i++) {
        //                DenseMatrix64F A = RandomMatrices.createSymmetric(N,-1,1,rand);
        AMatrix z = Matrixx.createRandomMatrix(3, 3);
        AMatrix A = z.innerProduct(z.getTranspose());

        SymmetricQRAlgorithmDecomposition alg = createDecomposition();

        assertNotNull(alg.decompose(A));

        performStandardTests(alg, A.toMatrix(), -1);
      }
    }
  }
  /** Sees if the pair of eigenvalue and eigenvector was found in the decomposition. */
  public void testForEigenpair(
      SymmetricQRAlgorithmDecomposition alg, double valueReal, double valueImg, double... vector) {
    int N = alg.getNumberOfEigenvalues();

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

      if (Math.abs(c.x - valueReal) < 1e-4 && Math.abs(c.y - valueImg) < 1e-4) {

        //                if( c.isReal() ) {
        if (Math.abs(c.y - 0) < 1e-8)
          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);

            if (error < 1e-3 || error2 < 1e-3) numMatched++;
          } else {
            numMatched++;
          }
        else if (Math.abs(c.y - 0) > 1e-8) {
          numMatched++;
        }
      }
    }

    assertEquals(1, numMatched);
  }
예제 #3
0
 public CholeskyResult(AMatrix L) {
   this(L, IdentityMatrix.create(L.rowCount()), L.getTranspose());
 }