Package org.apache.mahout.matrix

Examples of org.apache.mahout.matrix.SparseVector$NonZeroIterator


   * Compute the centroid by averaging the pointTotals
   *
   * @return a point which is the new centroid
   */
  public Vector computeCentroid() {
    Vector result = new SparseVector(pointTotal.cardinality());
    for (int i = 0; i < pointTotal.cardinality(); i++)
      result.set(i, pointTotal.get(i) / numPoints);
    return result;
  }
View Full Code Here


  }

  private static List<Vector> getPoints(double[][] raw) {
    List<Vector> points = new ArrayList<Vector>();
    for (double[] fr : raw) {
      Vector vec = new SparseVector(fr.length);
      vec.assign(fr);
      points.add(vec);
    }
    return points;
  }
View Full Code Here

  public static List<Vector> getPoints(double[][] raw) {
    List<Vector> points = new ArrayList<Vector>();
    for (int i = 0; i < raw.length; i++) {
      double[] fr = raw[i];
      Vector vec = new SparseVector(fr.length);
      vec.assign(fr);
      points.add(vec);
    }
    return points;
  }
View Full Code Here

    compare(distanceMeasure, vectors);

    vectors = new Vector[4];
   
    vectors[0] = new SparseVector(5);
    vectors[0].setQuick(0, 1);
    vectors[0].setQuick(3, 1);
    vectors[0].setQuick(4, 1);

    vectors[1] = new SparseVector(5);
    vectors[1].setQuick(0, 2);
    vectors[1].setQuick(3, 2);
    vectors[1].setQuick(4, 2);

    vectors[2] = new SparseVector(5);
    vectors[2].setQuick(0, 6);
    vectors[2].setQuick(3, 6);
    vectors[2].setQuick(4, 6);
   
    vectors[3] = new SparseVector(5);

    compare(distanceMeasure, vectors);
  }
View Full Code Here

  private static List<Vector> getPoints(double[][] raw) {
    List<Vector> points = new ArrayList<Vector>();
    int i = 0;
    for (double[] fr : raw) {
      Vector vec = new SparseVector(String.valueOf(i++), fr.length);
      vec.assign(fr);
      points.add(vec);
    }
    return points;
  }
View Full Code Here

    /*while (reader.ready()) {
      System.out.println(reader.readLine());
      count++;
    }*/
    Text txt = new Text();
    SparseVector vector = new SparseVector();
    while (reader.next(txt, vector)) {
      count++;
      System.out.println("Txt: " + txt + " Vec: " + vector.asFormatString());
    }
    // the point [3.0,3.0] is covered by both canopies
    assertEquals("number of points", 2 + 2 * points.size(), count);
    reader.close();
  }
View Full Code Here

    /*while (reader.ready()) {
      System.out.println(reader.readLine());
      count++;
    }*/
    Text txt = new Text();
    SparseVector can = new SparseVector();
    while (reader.next(txt, can)) {
      count++;
    }
    /*while (reader.ready()) {
      System.out.println(reader.readLine());
View Full Code Here

          UncommonDistributions.rNorm(my, sdy)});
    }
  }

  private void addSample(double[] values) {
    Vector v = new SparseVector(2);
    for (int j = 0; j < values.length; j++) {
      v.setQuick(j, values[j]);
    }
    sampleData.add(v);
  }
View Full Code Here

    @Override
    public Vector next() {
      if (!hasNext()) {
        throw new NoSuchElementException();
      }
      Vector result = type == VectorType.SPARSE ? new SparseVector(numItems) : new DenseVector(numItems);
      result.assign(new UnaryFunction(){
        @Override
        public double apply(double arg1) {
          return random.nextDouble();
        }
View Full Code Here

    writer.write(iter);
    writer.close();

    SequenceFile.Reader seqReader = new SequenceFile.Reader(fs, path, conf);
    LongWritable key = new LongWritable();
    SparseVector value = new SparseVector();
    int count = 0;
    while (seqReader.next(key, value)){
      count++;
    }
    assertEquals(count + " does not equal: " + 50, 50, count);
View Full Code Here

TOP

Related Classes of org.apache.mahout.matrix.SparseVector$NonZeroIterator

Copyright © 2018 www.massapicom. 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.