Пример #1
0
  @Override
  public void addMultiple(AMatrix m, double factor) {
    checkRowCount(m.rowCount());
    int cc = checkColumnCount(m.columnCount());

    for (int i = 0; i < cc; i++) {
      getColumnView(i).addMultiple(m.getColumn(i), factor);
    }
  }
Пример #2
0
  @Test
  public void testOuterProducts() {
    AVector v = Vectorz.createUniformRandomVector(5);
    INDArray a = v.outerProduct(v);
    assertTrue(a instanceof AMatrix);

    AMatrix m = (AMatrix) a;
    AVector v2 = v.clone();
    v2.square();
    assertEquals(v2, m.getLeadingDiagonal());
  }
  /** 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);
      }
    }
  }
Пример #4
0
 @Override
 public AMatrix innerProduct(AMatrix a) {
   if (a instanceof ADiagonalMatrix) {
     return innerProduct((ADiagonalMatrix) a);
   } else if (a instanceof Matrix) {
     return innerProduct((Matrix) a);
   }
   if (!(dimensions == a.rowCount()))
     throw new IllegalArgumentException(ErrorMessages.incompatibleShapes(this, a));
   int acc = a.columnCount();
   Matrix m = Matrix.create(dimensions, acc);
   for (int i = 0; i < dimensions; i++) {
     double dv = unsafeGetDiagonalValue(i);
     for (int j = 0; j < acc; j++) {
       m.unsafeSet(i, j, dv * a.unsafeGet(i, j));
     }
   }
   return m;
 }
 private double diffNormF(AMatrix tempA, AMatrix tempB) {
   AMatrix temp = tempA.copy();
   temp.sub(tempB);
   double total = temp.elementSquaredSum();
   temp.abs();
   double scale = temp.elementMax();
   return Math.abs(scale - 0) > 1e-12 ? total / scale : 0;
 }
  /** 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);
  }
Пример #7
0
 public CholeskyResult(AMatrix L) {
   this(L, IdentityMatrix.create(L.rowCount()), L.getTranspose());
 }
Пример #8
0
 @Override
 public ZeroVector innerProduct(AMatrix m) {
   if (m.rowCount() != length)
     throw new IllegalArgumentException("Incompatible vector*matrix sizes");
   return ZeroVector.create(m.columnCount());
 }
 private static double normPInf(AMatrix A) {
   return A.absCopy().elementMax();
 }
Пример #10
0
 @Override
 public boolean isSameShape(AMatrix m) {
   return (dimensions == m.rowCount()) && (dimensions == m.columnCount());
 }