Package org.apache.mahout.math

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


      weightsPerFeature = VectorWritable.readVector(in);
      weightsPerLabel = new DenseVector(VectorWritable.readVector(in));
      perLabelThetaNormalizer = new DenseVector(VectorWritable.readVector(in));

      weightsPerLabelAndFeature = new SparseRowMatrix(weightsPerLabel.size(), weightsPerFeature.size() );
      for (int label = 0; label < weightsPerLabelAndFeature.numRows(); label++) {
        weightsPerLabelAndFeature.assignRow(label, VectorWritable.readVector(in));
      }
    } finally {
      Closeables.closeQuietly(in);
    }
View Full Code Here


    // which specifically details the case of covariance matrix inversion
    // Complexity: O(min(nm2,mn2))
    SingularValueDecomposition svd = new SingularValueDecomposition(m);
    Matrix sInv = svd.getS();
    // Inverse Diagonal Elems
    for (int i = 0; i < sInv.numRows(); i++) {
      double diagElem = sInv.get(i, i);
      if (diagElem > 0.0) {
        sInv.set(i, i, 1 / diagElem);
      } else {
        throw new IllegalStateException("Eigen Value equals to 0 found.");
View Full Code Here

            .stepOffset(10)
            .decayExponent(0.7)
            .lambda(1 * 1.0e-3)
            .learningRate(5);
    int k = 0;
    int[] ordering = permute(gen, data.numRows());
    for (int epoch = 0; epoch < 100; epoch++) {
      for (int row : ordering) {
        lr.train(row, (int) data.get(row, 9), data.viewRow(row));
        System.out.printf("%d,%d,%.3f\n", epoch, k++, lr.auc());
      }
View Full Code Here

    ratings.setQuick(3, 3.0);
    ratings.setQuick(5, 5.0);

    Matrix riIiMaybeTransposed = solver.createRiIiMaybeTransposed(ratings);
    assertEquals(1, riIiMaybeTransposed.numCols(), 1);
    assertEquals(3, riIiMaybeTransposed.numRows(), 3);

    assertEquals(1.0, riIiMaybeTransposed.getQuick(0, 0), EPSILON);
    assertEquals(3.0, riIiMaybeTransposed.getQuick(1, 0), EPSILON);
    assertEquals(5.0, riIiMaybeTransposed.getQuick(2, 0), EPSILON);
  }
View Full Code Here

        SolverTest.randomSequentialAccessSparseMatrix(100, 90, 50, 20, 1.0);
    DistributedRowMatrix dm =
        randomDistributedMatrix(100, 90, 50, 20, 1.0, false);

    Vector expected = new DenseVector(50);
    for (int i = 0; i < m.numRows(); i++) {
      expected.assign(m.viewRow(i), Functions.PLUS);
    }
    expected.assign(Functions.DIV, m.numRows());
    Vector actual = dm.columnMeans("DenseVector");
    assertEquals(0.0, expected.getDistanceSquared(actual), EPSILON);
View Full Code Here

    Vector expected = new DenseVector(50);
    for (int i = 0; i < m.numRows(); i++) {
      expected.assign(m.viewRow(i), Functions.PLUS);
    }
    expected.assign(Functions.DIV, m.numRows());
    Vector actual = dm.columnMeans("DenseVector");
    assertEquals(0.0, expected.getDistanceSquared(actual), EPSILON);
  }

  @Test
View Full Code Here

        SolverTest.randomSequentialAccessSparseMatrix(100, 90, 0, 0, 1.0);
    DistributedRowMatrix dm =
        randomDistributedMatrix(100, 90, 0, 0, 1.0, false);

    Vector expected = new DenseVector(0);
    for (int i = 0; i < m.numRows(); i++) {
      expected.assign(m.viewRow(i), Functions.PLUS);
    }
    expected.assign(Functions.DIV, m.numRows());
    Vector actual = dm.columnMeans();
    assertEquals(0.0, expected.getDistanceSquared(actual), EPSILON);
View Full Code Here

    Vector expected = new DenseVector(0);
    for (int i = 0; i < m.numRows(); i++) {
      expected.assign(m.viewRow(i), Functions.PLUS);
    }
    expected.assign(Functions.DIV, m.numRows());
    Vector actual = dm.columnMeans();
    assertEquals(0.0, expected.getDistanceSquared(actual), EPSILON);
  }

  @Test
View Full Code Here

    for (int row = 0; row < eigenVectors.numRows(); row++) {
      Vector oldEigen = eigenVectors.viewRow(row);
      if (oldEigen == null) {
        break;
      }
      for (int newRow = 0; newRow < eigenVectors2.numRows(); newRow++) {
        Vector newEigen = eigenVectors2.viewRow(newRow);
        if (newEigen != null) {
          if (oldEigen.dot(newEigen) > 0.9) {
            oldEigensFound.add(row);
            break;
View Full Code Here

        new SequenceFileValueIterator<MatrixWritable>(inputPath, true, new Configuration());
    Matrix m = it.next().get();
    it.close();
    PrintStream ps = getPrintStream(outputFile);
    String[] columnLabels = getLabels(m.numCols(), m.getColumnLabelBindings(), "col");
    String[] rowLabels = getLabels(m.numRows(), m.getRowLabelBindings(), "row");
    if (doLabels) {
      ps.print("rowid,");
      ps.print(columnLabels[0]);
      for (int c = 1; c < m.numCols(); c++) {
        ps.print(',' + columnLabels[c]);
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.