Package org.apache.mahout.math

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


        "--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


  @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

    ratings.setQuick(1, 1.0);
    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

    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

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

    Matrix riIiMaybeTransposed = AlternatingLeastSquaresSolver.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

  public void testGetMatrix() {
    ConfusionMatrix confusionMatrix = fillConfusionMatrix(VALUES, LABELS, DEFAULT_LABEL);
    Matrix m = confusionMatrix.getMatrix();
    Map<String, Integer> rowLabels = m.getRowLabelBindings();

    assertEquals(confusionMatrix.getLabels().size(), m.numCols());
    assertTrue(rowLabels.keySet().contains(LABELS[0]));
    assertTrue(rowLabels.keySet().contains(LABELS[1]));
    assertTrue(rowLabels.keySet().contains(DEFAULT_LABEL));
    assertEquals(2, confusionMatrix.getCorrect(LABELS[0]));
    assertEquals(20, confusionMatrix.getCorrect(LABELS[1]));
View Full Code Here

    //MatrixUtils.debug_print(data_set.getSecond());
   
    Matrix input = data_set.getFirst();
    //Matrix labels = data_set.getSecond();
   
    int visible_neuron_count = input.numCols();
    int hidden_neuron_count = visible_neuron_count / 2;
   
    RestrictedBoltzmannMachine rbm = new RestrictedBoltzmannMachine(visible_neuron_count, hidden_neuron_count, null);

View Full Code Here

    //MatrixUtils.debug_print(data_set.getSecond());
   
    Matrix input = data_set.getFirst();
    Matrix labels = data_set.getSecond();
   
    LogisticRegression logRegression = new LogisticRegression( input, input.numCols(), labels.numCols());

    double learningRate = 0.001;
   
    for (int i = 0; i < 10000; i++) {
     
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.