Package org.apache.mahout.math

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


    SequenceFileValueIterator<MatrixWritable> it =
        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++) {
View Full Code Here


    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]);
      }
      ps.println();
    }
    for (int r = 0; r < m.numRows(); r++) {
View Full Code Here

    for (int r = 0; r < m.numRows(); r++) {
      if (doLabels) {
        ps.print(rowLabels[0] + ',');
      }
      ps.print(Double.toString(m.getQuick(r,0)));
      for (int c = 1; c < m.numCols(); c++) {
        ps.print(",");
        ps.print(Double.toString(m.getQuick(r,c)));
      }
      ps.println();
    }
View Full Code Here

        "--tempDir", tmpDir.getAbsolutePath() });

    Matrix similarityMatrix = MathHelper.readMatrix(conf, new Path(outputDir.getAbsolutePath(), "part-r-00000"), 3, 3);

    assertNotNull(similarityMatrix);
    assertEquals(3, similarityMatrix.numCols());
    assertEquals(3, similarityMatrix.numRows());

    assertEquals(1.0, similarityMatrix.get(0, 0), EPSILON);
    assertEquals(1.0, similarityMatrix.get(1, 1), EPSILON);
    assertEquals(1.0, similarityMatrix.get(2, 2), EPSILON);
View Full Code Here

        "--tempDir", tmpDir.getAbsolutePath() });

    Matrix similarityMatrix = MathHelper.readMatrix(conf, new Path(outputDir.getAbsolutePath(), "part-r-00000"), 3, 3);

    assertNotNull(similarityMatrix);
    assertEquals(3, similarityMatrix.numCols());
    assertEquals(3, similarityMatrix.numRows());

    assertEquals(0.0, similarityMatrix.get(0, 0), EPSILON);
    assertEquals(0.5, similarityMatrix.get(0, 1), EPSILON);
    assertEquals(0.0, similarityMatrix.get(0, 2), EPSILON);
View Full Code Here

        "--tempDir", tmpDir.getAbsolutePath() });

    Matrix similarityMatrix = MathHelper.readMatrix(conf, new Path(outputDir.getAbsolutePath(), "part-r-00000"), 3, 3);

    assertNotNull(similarityMatrix);
    assertEquals(3, similarityMatrix.numCols());
    assertEquals(3, similarityMatrix.numRows());

    assertEquals(0.0, similarityMatrix.get(0, 0), EPSILON);
    assertEquals(0.5, similarityMatrix.get(0, 1), EPSILON);
    assertEquals(0.0, similarityMatrix.get(0, 2), EPSILON);
View Full Code Here

  @Test
  public void testGetMatrix() {
      ConfusionMatrix cm = fillCM(VALUES, LABELS, DEFAULT_LABEL);
      Matrix m = cm.getMatrix();
      Map<String, Integer> rowLabels = m.getRowLabelBindings();
      assertEquals(cm.getLabels().size(), m.numCols());
      assertTrue(rowLabels.keySet().contains(LABELS[0]));
      assertTrue(rowLabels.keySet().contains(LABELS[1]));
      assertTrue(rowLabels.keySet().contains(DEFAULT_LABEL));
      assertEquals(2, cm.getCorrect(LABELS[0]));
      assertEquals(20, cm.getCorrect(LABELS[1]));
View Full Code Here

            2.428986e-05},};
    // fetch the alpha matrix using the forward algorithm
    Matrix alpha = HmmAlgorithms.forwardAlgorithm(getModel(), getSequence(), false);
    // first do some basic checking
    assertNotNull(alpha);
    assertEquals(4, alpha.numCols());
    assertEquals(7, alpha.numRows());
    // now compare the resulting matrices
    for (int i = 0; i < 4; ++i) {
      for (int j = 0; j < 7; ++j) {
        assertEquals(alphaExpectedA[i][j], alpha.get(j, i), EPSILON);
View Full Code Here

            2.428986e-05},};
    // fetch the alpha matrix using the forward algorithm
    Matrix alpha = HmmAlgorithms.forwardAlgorithm(getModel(), getSequence(), true);
    // first do some basic checking
    assertNotNull(alpha);
    assertEquals(4, alpha.numCols());
    assertEquals(7, alpha.numRows());
    // now compare the resulting matrices
    for (int i = 0; i < 4; ++i) {
      for (int j = 0; j < 7; ++j) {
        assertEquals(Math.log(alphaExpectedA[i][j]), alpha.get(j, i), EPSILON);
View Full Code Here

        {0.0004390858, 0.007076994, 0.01063512, 0.013556, 0.0304, 0.17, 1}};
    // fetch the beta matrix using the backward algorithm
    Matrix beta = HmmAlgorithms.backwardAlgorithm(getModel(), getSequence(), false);
    // first do some basic checking
    assertNotNull(beta);
    assertEquals(4, beta.numCols());
    assertEquals(7, beta.numRows());
    // now compare the resulting matrices
    for (int i = 0; i < 4; ++i) {
      for (int j = 0; j < 7; ++j) {
        assertEquals(betaExpectedA[i][j], beta.get(j, i), EPSILON);
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.