Example usage for org.apache.mahout.math Centroid Centroid

List of usage examples for org.apache.mahout.math Centroid Centroid

Introduction

In this page you can find the example usage for org.apache.mahout.math Centroid Centroid.

Prototype

public Centroid(int key, Vector initialValue, double weight) 

Source Link

Usage

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.
 */// w w w . j  a v a 2s  .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());
        }
    });
}