Example usage for org.apache.mahout.clustering.iterator ClusterWritable getValue

List of usage examples for org.apache.mahout.clustering.iterator ClusterWritable getValue

Introduction

In this page you can find the example usage for org.apache.mahout.clustering.iterator ClusterWritable getValue.

Prototype

public Cluster getValue() 

Source Link

Usage

From source file:DisplayClustering.java

License:Apache License

protected static List<Cluster> readClustersWritable(Path clustersIn) {
    List<Cluster> clusters = Lists.newArrayList();
    Configuration conf = new Configuration();
    for (ClusterWritable value : new SequenceFileDirValueIterable<ClusterWritable>(clustersIn, PathType.LIST,
            PathFilters.logsCRCFilter(), conf)) {
        Cluster cluster = value.getValue();
        log.info("Reading Cluster:{} center:{} numPoints:{} radius:{}", cluster.getId(),
                AbstractCluster.formatVector(cluster.getCenter(), null), cluster.getNumObservations(),
                AbstractCluster.formatVector(cluster.getRadius(), null));
        clusters.add(cluster);/*from   w  ww.j av  a  2  s.  c  o  m*/
    }
    return clusters;
}

From source file:com.modofo.molo.cluster.DisplayClustering.java

License:Apache License

protected static List<Cluster> readClustersWritable(Path clustersIn) {
    List<Cluster> clusters = Lists.newArrayList();
    Configuration conf = new Configuration();
    for (ClusterWritable value : new SequenceFileDirValueIterable<ClusterWritable>(clustersIn, PathType.LIST,
            PathFilters.logsCRCFilter(), conf)) {
        Cluster cluster = value.getValue();
        log.info("Reading Cluster:{} center:{} numPoints:{} radius:{}",
                new Object[] { cluster.getId(), AbstractCluster.formatVector(cluster.getCenter(), null),
                        cluster.getNumObservations(),
                        AbstractCluster.formatVector(cluster.getRadius(), null) });
        clusters.add(cluster);/*ww  w  . j a  v  a  2  s  .co m*/
    }
    return clusters;
}

From source file:org.conan.mymahout.clustering.streaming.tools.IOUtils.java

License:Apache License

/**
 * Converts CentroidWritable values in a sequence file into Centroids lazily.
 * @param dirIterable the source iterable (comes from a SequenceFileDirIterable).
 * @return an Iterable<Centroid> with the converted vectors.
 *//*from w ww .ja  v a 2 s  .c  om*/
public static Iterable<Centroid> getCentroidsFromClusterWritableIterable(
        Iterable<ClusterWritable> dirIterable) {
    return Iterables.transform(dirIterable, new Function<ClusterWritable, Centroid>() {
        int numClusters = 0;

        @Override
        public Centroid apply(ClusterWritable input) {
            Preconditions.checkNotNull(input);
            return new Centroid(numClusters++, input.getValue().getCenter().clone(),
                    input.getValue().getTotalObservations());
        }
    });
}

From source file:sample.DisplayClustering.java

License:Apache License

protected static List<Cluster> readClustersWritable(Path clustersIn) {
    List<Cluster> clusters = new ArrayList<>();
    Configuration conf = new Configuration();
    for (ClusterWritable value : new SequenceFileDirValueIterable<ClusterWritable>(clustersIn, PathType.LIST,
            PathFilters.logsCRCFilter(), conf)) {
        Cluster cluster = value.getValue();
        System.out.println("Cluster: " + cluster.getId() + " "
                + AbstractCluster.formatVector(cluster.getCenter(), null) + " " + cluster.getNumObservations()
                + " " + AbstractCluster.formatVector(cluster.getRadius(), null));
        clusters.add(cluster);/*from  ww w  .j a v  a 2s.  c o  m*/
    }
    return clusters;
}

From source file:utils.ReaderSeqFile.java

public static void main(String[] args) throws IOException, URISyntaxException {

    //URI uri = new URI("/home/asabater/data_to_cluster");
    URI uri = new URI("/home/asabater/Desktop/part-r-00000");
    Configuration conf = new Configuration();
    FileSystem fs = FileSystem.get(uri, conf);
    Path path = new Path(uri);
    FileOutputStream out = new FileOutputStream("/home/asabater/nuevo/cluster");
    SequenceFile.Reader reader = null;
    try {//ww w.  j a  v a  2 s.  com
        reader = new SequenceFile.Reader(fs, path, conf);
        Writable key = (Writable) ReflectionUtils.newInstance(reader.getKeyClass(), conf);
        ClusterWritable value = (ClusterWritable)
        //final WeightedPropertyVectorWritable value = new WeightedPropertyVectorWritable();
        ReflectionUtils.newInstance(reader.getValueClass(), conf);
        long position = reader.getPosition();
        System.out.println("TRYING:" + reader.getPosition());
        while (reader.next(key, value)) {
            System.out.println(value.getClass());
            System.out.printf("%s\t%s\n", key, value.getValue().toString());
            position = reader.getPosition(); // beginning of next record
        }
        out.close();
    } finally {
        IOUtils.closeStream(reader);
    }
}