Package org.apache.mahout.clustering.iterator

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


  public void writeToSeqFiles(Path path) throws IOException {
    writePolicy(policy, path);
    Configuration config = new Configuration();
    FileSystem fs = FileSystem.get(path.toUri(), config);
    SequenceFile.Writer writer = null;
    ClusterWritable cw = new ClusterWritable();
    for (int i = 0; i < models.size(); i++) {
      try {
        Cluster cluster = models.get(i);
        cw.setValue(cluster);
        writer = new SequenceFile.Writer(fs, config,
            new Path(path, "part-" + String.format(Locale.ENGLISH, "%05d", i)), IntWritable.class,
            ClusterWritable.class);
        Writable key = new IntWritable(i);
        writer.append(key, cw);
View Full Code Here


    List<Cluster> clusterModels = Lists.newArrayList();
    Path finalClustersPath = finalClustersPath(conf, clusterOutputPath);
    Iterator<?> it = new SequenceFileDirValueIterator<Writable>(finalClustersPath, PathType.LIST,
        PathFilters.partFilter(), null, false, conf);
    while (it.hasNext()) {
      ClusterWritable next = (ClusterWritable) it.next();
      Cluster cluster = next.getValue();
      cluster.configure(conf);
      clusterModels.add(cluster);
    }
    return clusterModels;
  }
View Full Code Here

    FileStatus[] clusterFiles = fileSystem.listStatus(clusterOutputPath, PathFilters.finalPartFilter());
    Iterator<?> it = new SequenceFileDirValueIterator<Writable>(
        clusterFiles[0].getPath(), PathType.LIST, PathFilters.partFilter(),
        null, false, conf);
    while (it.hasNext()) {
      ClusterWritable next = (ClusterWritable) it.next();
      Cluster cluster = next.getValue();
      cluster.configure(conf);
      clusters.add(cluster);
    }
    return clusters;
  }
View Full Code Here

  public static void configureWithClusterInfo(Configuration conf, Path clusterPath, Collection<Cluster> clusters) {
    for (Writable value : new SequenceFileDirValueIterable<Writable>(clusterPath, PathType.LIST,
        PathFilters.partFilter(), conf)) {
      Class<? extends Writable> valueClass = value.getClass();
      if (valueClass.equals(ClusterWritable.class)) {
        ClusterWritable clusterWritable = (ClusterWritable) value;
        value = clusterWritable.getValue();
        valueClass = value.getClass();
      }
      log.debug("Read 1 Cluster from {}", clusterPath);
     
      if (valueClass.equals(Kluster.class)) {
View Full Code Here

                maxEigens.put(index, v);
                Text newText = new Text(key.toString());
                chosenTexts.put(index, newText);
                Kluster newCluster = new Kluster(value.get(), index, measure);
                newCluster.observe(value.get(), 1);
                ClusterWritable clusterWritable = new ClusterWritable();
                clusterWritable.setValue(newCluster);
                chosenClusters.put(index, clusterWritable);
              }
            }
          }
        }
View Full Code Here

    for (Writable value : new SequenceFileDirValueIterable<Writable>(clusterPath, PathType.LIST,
        PathFilters.partFilter(), conf)) {
      Class<? extends Writable> valueClass = value.getClass();
     
      if (valueClass.equals(ClusterWritable.class)) {
        ClusterWritable clusterWritable = (ClusterWritable) value;
        value = clusterWritable.getValue();
        valueClass = value.getClass();
      }
     
      if (valueClass.equals(Kluster.class)) {
        // get the cluster info
View Full Code Here

      SequenceFile.Writer writer = new SequenceFile.Writer(fs, conf, new Path(
          output, "part-m-" + part++), Text.class, ClusterWritable.class);
      try {
        for (VectorWritable value : new SequenceFileValueIterable<VectorWritable>(s.getPath(), conf)) {
          MeanShiftCanopy initialCanopy = MeanShiftCanopy.initialCanopy(value.get(), id++, measure);
          ClusterWritable clusterWritable = new ClusterWritable();
          clusterWritable.setValue(initialCanopy);
          writer.append(new Text(), clusterWritable);
        }
      } finally {
        Closeables.close(writer, false);
      }
View Full Code Here

                AbstractCluster.formatVector(cluster.getCenter(), null),
                cluster.getNumObservations(),
                AbstractCluster.formatVector(cluster.getRadius(), null),
                clustersOut.getName());
          }
          ClusterWritable clusterWritable = new ClusterWritable();
          clusterWritable.setValue(cluster);
          writer.append(new Text(cluster.getIdentifier()), clusterWritable);
        }
      } finally {
        Closeables.close(writer, false);
      }
View Full Code Here

          output, "part-m-" + part++), IntWritable.class,
          WeightedVectorWritable.class);
      try {
        for (Pair<Writable, ClusterWritable> record
            : new SequenceFileIterable<Writable, ClusterWritable>(s.getPath(), conf)) {
          ClusterWritable clusterWritable = record.getSecond();
          MeanShiftCanopy canopy = (MeanShiftCanopy) clusterWritable.getValue();
          MeanShiftCanopy closest = MeanShiftCanopyClusterer.findCoveringCanopy(canopy, clusters);
          writer.append(new IntWritable(closest.getId()), new WeightedVectorWritable(1, canopy.getCenter()));
        }
      } finally {
        Closeables.close(writer, false);
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.8,1.8));
      refCenters.add(new Pair<Double,Double>(4.433333333333334, 4.433333333333334));
      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

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.