Package org.apache.mahout.math

Examples of org.apache.mahout.math.Matrix.times()


    // has a condition number of almost 500,000 and the normal equation condition
    // number is that squared.  This means that we don't get the exact answer with
    // a fast iterative solution.
    // Thus, we have to check the residuals rather than testing that the answer matched
    // the ideal.
    assertEquals(0, m.times(x1).minus(b).norm(2), 1.0e-2);
    assertEquals(0, m.transpose().times(m).times(x1).minus(m.transpose().times(b)).norm(2), 1.0e-7);

    // and we need to check that the error estimates are pretty good.
    assertEquals(m.times(x1).minus(b).norm(2), r.getResidualNorm(), 1.0e-5);
    assertEquals(m.transpose().times(m).times(x1).minus(m.transpose().times(b)).norm(2), r.getNormalEquationResidual(), 1.0e-9);
View Full Code Here


    // the ideal.
    assertEquals(0, m.times(x1).minus(b).norm(2), 1.0e-2);
    assertEquals(0, m.transpose().times(m).times(x1).minus(m.transpose().times(b)).norm(2), 1.0e-7);

    // and we need to check that the error estimates are pretty good.
    assertEquals(m.times(x1).minus(b).norm(2), r.getResidualNorm(), 1.0e-5);
    assertEquals(m.transpose().times(m).times(x1).minus(m.transpose().times(b)).norm(2), r.getNormalEquationResidual(), 1.0e-9);
  }
 
  @Test
  public void random() {
View Full Code Here

    double actual = m.transpose().times(m).times(x1).minus(m.transpose().times(b)).norm(2);
    System.out.printf("%.4f\n", actual / norm * 1.0e6);
    assertEquals(0, actual, norm * 1.0e-5);

    // and we need to check that the error estimates are pretty good.
    assertEquals(m.times(x1).minus(b).norm(2), r.getResidualNorm(), 1.0e-5);
    assertEquals(actual, r.getNormalEquationResidual(), 1.0e-9);
  }

  private static Matrix hilbert(int n) {
    Matrix r = new DenseMatrix(n, n);
View Full Code Here

        sInv.set(i, i, 1 / diagElem);
      } else {
        throw new IllegalStateException("Eigen Value equals to 0 found.");
      }
    }
    inverseCovarianceMatrix = svd.getU().times(sInv.times(svd.getU().transpose()));
    Preconditions.checkArgument(inverseCovarianceMatrix != null, "inverseCovarianceMatrix not initialized");
  }

  public Matrix getInverseCovarianceMatrix() {
    return inverseCovarianceMatrix;
View Full Code Here

    double beta = u.norm(2);
    if (beta > 0) {
      u = u.divide(beta);
    }

    Vector v = transposedA.times(u);
    int m = A.numRows();
    int n = A.numCols();

    int minDim = Math.min(m, n);
    if (iterationLimit == -1) {
View Full Code Here

        // store data for local-reorthogonalization of V
        if (localOrtho) {
          localVEnqueue(v);
        }
        v = transposedA.times(u).minus(v.times(beta));
        // local-reorthogonalization of V
        if (localOrtho) {
          v = localVOrtho(v);
        }
        alpha = v.norm(2);
View Full Code Here

      new double[]{0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000}};
    Matrix x = new DenseMatrix(m);
    EigenDecomposition eig = new EigenDecomposition(x, true);
    Matrix d = eig.getD();
    Matrix v = eig.getV();
    check("EigenvalueDecomposition (evil)...", x.times(v), v.times(d));
  }

  @Test
  public void testDeficientRank() {
    Matrix a = new DenseMatrix(10, 3).assign(new DoubleFunction() {
View Full Code Here

    a = a.transpose().times(a);

    EigenDecomposition eig = new EigenDecomposition(a);
    Matrix d = eig.getD();
    Matrix v = eig.getV();
    check("EigenvalueDecomposition (rank deficient)...", a.times(v), v.times(d));

    Assert.assertEquals(0, eig.getImagEigenvalues().norm(1), 1.0e-10);
    Assert.assertEquals(3, eig.getRealEigenvalues().norm(0), 1.0e-10);
  }
View Full Code Here

      }
    }
    EigenDecomposition eig = new EigenDecomposition(a);
    Matrix d = eig.getD();
    Matrix v = eig.getV();
    check("EigenvalueDecomposition (nonsymmetric)...", a.times(v), v.times(d));
  }

  @Test
  public void testSequential() {
    int validld = 3;
View Full Code Here

    }

    EigenDecomposition Eig = new EigenDecomposition(A);
    Matrix D = Eig.getD();
    Matrix V = Eig.getV();
    check("EigenvalueDecomposition (nonsymmetric)...", A.times(V), V.times(D));

    A = A.transpose().times(A);
    Eig = new EigenDecomposition(A);
    D = Eig.getD();
    V = Eig.getV();
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.