Package org.apache.mahout.math

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


    LSMR r = new LSMR();
    Vector x1 = r.solve(m, b);

//    assertEquals(0, m.times(x1).minus(b).norm(2), 1.0e-2);
    double norm = new SingularValueDecomposition(m).getS().viewDiagonal().norm(2);
    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);
View Full Code Here


   * @param recomputeUserFeatures
   */
  public void reCalculateTrans(boolean recomputeUserFeatures) {
    if (recomputeUserFeatures) {
      Matrix iMatrix = new DenseMatrix(itemMatrix);
      itemTransItem = iMatrix.transpose().times(iMatrix);
    } else {
      Matrix uMatrix = new DenseMatrix(userMatrix);
      userTransUser = uMatrix.transpose().times(uMatrix);
    }
  }
View Full Code Here

    if (recomputeUserFeatures) {
      Matrix iMatrix = new DenseMatrix(itemMatrix);
      itemTransItem = iMatrix.transpose().times(iMatrix);
    } else {
      Matrix uMatrix = new DenseMatrix(userMatrix);
      userTransUser = uMatrix.transpose().times(uMatrix);
    }
  }

  private synchronized void updateMatrix(int id, Matrix m) {
    double normA = 0;
View Full Code Here

      if (recomputeUserFeatures) {
        Matrix I = identityV(dataModel.getNumItems());
        Matrix I2 = identityV(numFeatures);
        Matrix iTi = itemTransItem.clone();
        Matrix itemM = new DenseMatrix(itemMatrix);
        XTCX = iTi.plus(itemM.transpose().times(C.minus(I)).times(itemM));

        Matrix diag = solve(XTCX.plus(I2.times(preventOverfitting)), I2);
        Matrix results = diag.times(itemM.transpose().times(C)).times(prefVector.transpose());
        updateMatrix(id, results);
      } else {
View Full Code Here

      } else {
        Matrix I = identityV(dataModel.getNumUsers());
        Matrix I2 = identityV(numFeatures);
        Matrix uTu = userTransUser.clone();
        Matrix userM = new DenseMatrix(userMatrix);
        XTCX = uTu.plus(userM.transpose().times(C.minus(I)).times(userM));

        Matrix diag = solve(XTCX.plus(I2.times(preventOverfitting)), I2);
        Matrix results = diag.times(userM.transpose().times(C)).times(prefVector.transpose());
        updateMatrix(id, results);
      }
View Full Code Here

        Vector sq = SSVDHelper.loadAndSumUpVectors(sqPath, conf);
        Vector sb = SSVDHelper.loadAndSumUpVectors(sbPath, conf);
        Matrix mC = sq.cross(sb);

        bbtSquare.assign(mC, Functions.MINUS);
        bbtSquare.assign(mC.transpose(), Functions.MINUS);

        Matrix outerSq = sq.cross(sq);
        outerSq.assign(Functions.mult(xisquaredlen));
        bbtSquare.assign(outerSq, Functions.PLUS);
View Full Code Here

    print(a);
    Matrix m = new DenseMatrix(4, 4).assign(a);
    assertEquals(0, m.minus(a).aggregate(Functions.PLUS, Functions.ABS), 1.0e-10);
    print(m);

    assertEquals(0, m.transpose().times(m).minus(a.transpose().times(a)).aggregate(
        Functions.PLUS, Functions.ABS), 1.0e-10);
    assertEquals(0, m.plus(m).minus(a.plus(a)).aggregate(Functions.PLUS, Functions.ABS), 1.0e-10);
  }

  private static void print(Matrix m) {
View Full Code Here

      new GivensThinSolver(m.rowSize(), m.columnSize());
    qrSolver.solve(m);

    Matrix qtm = new DenseMatrix(qrSolver.getThinQtTilde());

    assertOrthonormality(qtm.transpose(), false, SVD_EPSILON);

    Matrix aClone =
      new DenseMatrix(qrSolver.getThinQtTilde()).transpose()
                                                .times(qrSolver.getRTilde());
View Full Code Here

      public double apply(double arg1) {
        return gen.nextGaussian();
      }
    });

    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));
View Full Code Here

  private static Matrix lowRankMatrix() {
    Matrix u = new RandomTrinaryMatrix(1, 20, 4, false);
    Matrix d = new DiagonalMatrix(new double[]{5, 3, 1, 0.5});
    Matrix v = new RandomTrinaryMatrix(2, 23, 4, false);

    return u.times(d).times(v.transpose());
  }
}
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.