Package org.apache.mahout.math

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


      for (int c = 1; c < m.numCols(); c++) {
        ps.print(',' + columnLabels[c]);
      }
      ps.println();
    }
    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++) {
View Full Code Here


    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

    DistributedRowMatrix dm =
        randomDistributedMatrix(100, 90, 50, 20, 1.0, false);
    dm.setConf(getConfiguration());

    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

    DistributedRowMatrix dm =
        randomDistributedMatrix(100, 90, 0, 0, 1.0, false);
    dm.setConf(getConfiguration());

    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

      weightsPerLabel = new DenseVector(VectorWritable.readVector(in));
      if (isComplementary){
        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.close(in, true);
    }
View Full Code Here

   
    Matrix input = recordBatch.getFirst();
    Matrix labels = recordBatch.getSecond();
   
    assertEquals(20, input.numRows() );
    assertEquals(20, labels.numRows() );
   
    //MatrixUtils.debug_print( input );
   
    MatrixUtils.debug_print( labels );
   
View Full Code Here

    RandomGenerator rnd = new MersenneTwister(1234);
    //rnd.nextDouble();
   
    Matrix res = new DenseMatrix( rows, cols );
   
    for ( int r = 0; r < res.numRows(); r++ ) {
     
      for ( int c = 0; c < res.numCols(); c++ ) {
       
        res.set(r,  c, rnd.nextDouble());
        //System.out.println( "next: " + rnd.nextDouble() );
View Full Code Here

    RandomGenerator rnd = new MersenneTwister(1234);
    //rnd.nextDouble();
   
    Matrix res = new DenseMatrix( rows, cols );
   
    for ( int r = 0; r < res.numRows(); r++ ) {
     
      for ( int c = 0; c < res.numCols(); c++ ) {
       
        res.set(r,  c, rnd.nextDouble());
        //System.out.println( "next: " + rnd.nextDouble() );
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.