Package org.apache.mahout.clustering.iterator

Examples of org.apache.mahout.clustering.iterator.ClusterWritable


    Set<Text> keys = writer.getKeys();
    assertEquals("Number of centroids", 3, keys.size());
    int i = 0;
    for (Text key : keys) {
      List<ClusterWritable> data = writer.getValue(key);
      ClusterWritable clusterWritable = data.get(0);
    Canopy canopy = (Canopy)clusterWritable.getValue();
    assertEquals(manhattanCentroids.get(i).asFormatString()
          + " is not equal to "
          + canopy.computeCentroid().asFormatString(), manhattanCentroids
          .get(i), canopy.computeCentroid());
      i++;
View Full Code Here


    Set<Text> keys = writer.getKeys();
    assertEquals("Number of centroids", 3, keys.size());
    int i = 0;
    for (Text key : keys) {
      List<ClusterWritable> data = writer.getValue(key);
      ClusterWritable clusterWritable = data.get(0);
      Canopy canopy = (Canopy)clusterWritable.getValue();
      assertEquals(euclideanCentroids.get(i).asFormatString()
          + " is not equal to "
          + canopy.computeCentroid().asFormatString(), euclideanCentroids
          .get(i), canopy.computeCentroid());
      i++;
View Full Code Here

    Path path = new Path(output, "clusters-0-final/part-r-00000");
    FileSystem fs = FileSystem.get(path.toUri(), config);
    SequenceFile.Reader reader = new SequenceFile.Reader(fs, path, config);
    try {
      Writable key = new Text();
      ClusterWritable clusterWritable = new ClusterWritable();
    assertTrue("more to come", reader.next(key, clusterWritable));
      assertEquals("1st key", "C-0", key.toString());

      List<Pair<Double,Double>> refCenters = Lists.newArrayList();
      refCenters.add(new Pair<Double,Double>(1.5,1.5));
      refCenters.add(new Pair<Double,Double>(4.333333333333334,4.333333333333334));
    Pair<Double,Double> c = new Pair<Double,Double>(clusterWritable.getValue() .getCenter().get(0),
      clusterWritable.getValue().getCenter().get(1));
      assertTrue("center "+c+" not found", findAndRemove(c, refCenters, EPSILON));
      assertTrue("more to come", reader.next(key, clusterWritable));
      assertEquals("2nd key", "C-1", key.toString());
      c = new Pair<Double,Double>(clusterWritable.getValue().getCenter().get(0),
          clusterWritable.getValue().getCenter().get(1));
      assertTrue("center "+c+" not found", findAndRemove(c, refCenters, EPSILON));
      assertFalse("more to come", reader.next(key, clusterWritable));
    } finally {
      Closeables.close(reader, true);
    }
View Full Code Here

  @Override
  protected void cleanup(Context context) throws IOException, InterruptedException {
    int reducer = 0;
    for (MeanShiftCanopy canopy : canopies) {
      clusterer.shiftToMean(canopy);
      ClusterWritable clusterWritable = new ClusterWritable();
      clusterWritable.setValue(canopy);
      context.write(new Text(String.valueOf(reducer)), clusterWritable);
      reducer++;
      if (reducer >= numReducers) {
        reducer = 0;
      }
View Full Code Here

    Path canopyOutputDir = new Path(output, Cluster.CLUSTERS_DIR + '0' + Cluster.FINAL_ITERATION_SUFFIX);
    Path path = new Path(canopyOutputDir, "part-r-00000");
    SequenceFile.Writer writer = new SequenceFile.Writer(fs, conf, path,
        Text.class, ClusterWritable.class);
    try {
      ClusterWritable clusterWritable = new ClusterWritable();
      for (Canopy canopy : canopies) {
        canopy.computeParameters();
        if (log.isDebugEnabled()) {
          log.debug("Writing Canopy:{} center:{} numPoints:{} radius:{}",
                    canopy.getIdentifier(),
                    AbstractCluster.formatVector(canopy.getCenter(), null),
                    canopy.getNumObservations(),
                    AbstractCluster.formatVector(canopy.getRadius(), null));
        }
        if (canopy.getNumObservations() > clusterFilter) {
          clusterWritable.setValue(canopy);
          writer.append(new Text(canopy.getIdentifier()), clusterWritable);
        }
      }
    } finally {
      Closeables.close(writer, false);
View Full Code Here

      canopyClusterer.addPointToCanopies(point, canopies);
    }
    for (Canopy canopy : canopies) {
      canopy.computeParameters();
      if (canopy.getNumObservations() > clusterFilter) {
        ClusterWritable clusterWritable = new ClusterWritable();
        clusterWritable.setValue(canopy);
        context.write(new Text(canopy.getIdentifier()), clusterWritable);
      }
    }
  }
View Full Code Here

  @Override
  protected void map(WritableComparable<?> key, VectorWritable point, Context context)
    throws IOException, InterruptedException {
    MeanShiftCanopy canopy = MeanShiftCanopy.initialCanopy(point.get(), nextCanopyId++, measure);
    ClusterWritable clusterWritable = new ClusterWritable();
    clusterWritable.setValue(canopy);
    context.write(new Text(key.toString()), clusterWritable);
  }
View Full Code Here

          newCluster.observe(value.get(), 1);
          Text newText = new Text(key.toString());
          int currentSize = chosenTexts.size();
          if (currentSize < k) {
            chosenTexts.add(newText);
            ClusterWritable clusterWritable = new ClusterWritable();
            clusterWritable.setValue(newCluster);
            chosenClusters.add(clusterWritable);
          } else {
            int j = random.nextInt(index);
            if (j < k) {
              chosenTexts.set(j, newText);
              ClusterWritable clusterWritable = new ClusterWritable();
              clusterWritable.setValue(newCluster);
              chosenClusters.set(j, clusterWritable);
            }
          }
          index++;
        }
View Full Code Here

      boolean converged = clusterer.shiftToMean(canopy);
      if (converged) {
        context.getCounter("Clustering", "Converged Clusters").increment(1);
      }
      allConverged = converged && allConverged;
      ClusterWritable clusterWritable = new ClusterWritable();
      clusterWritable.setValue(canopy);
      context.write(new Text(canopy.getIdentifier()), clusterWritable);
    }

  }
View Full Code Here

    int count = 0;
    for (Text k : collector1.getKeys()) {
      count++;
      List<ClusterWritable> vl = collector1.getValue(k);
      assertEquals("non-singleton centroid!", 1, vl.size());
      ClusterWritable clusterWritable = vl.get(0);
      Vector v = clusterWritable.getValue().getCenter();
      assertEquals("cetriod vector is wrong length", 2, v.size());
      if ( (Math.abs(v.get(0) - 1.5) < EPSILON)
                  && (Math.abs(v.get(1) - 1.5) < EPSILON)
                  && !got15) {
        got15 = true;
View Full Code Here

TOP

Related Classes of org.apache.mahout.clustering.iterator.ClusterWritable

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.