Example usage for org.apache.mahout.clustering.kmeans Kluster Kluster

List of usage examples for org.apache.mahout.clustering.kmeans Kluster Kluster

Introduction

In this page you can find the example usage for org.apache.mahout.clustering.kmeans Kluster Kluster.

Prototype

public Kluster(Vector center, int clusterId, DistanceMeasure measure) 

Source Link

Document

Construct a new cluster with the given point as its center

Usage

From source file:sigis.kmeansmultiplek.AnotherKmeans.java

private void writeClusterInitialCenters(final Configuration conf, List<DenseVector> points) throws IOException {
    final Path writerPath = new Path(CLUSTERS_PATH + "/part-00000");

    final SequenceFile.Writer writer = SequenceFile.createWriter(conf, SequenceFile.Writer.file(writerPath),
            SequenceFile.Writer.keyClass(Text.class), SequenceFile.Writer.valueClass(Kluster.class));

    Random rand = new Random();
    for (int i = 0; i < numberOfCluster; i++) {
        int randomNum = rand.nextInt((points.size() - 0) + 1);
        final Vector vec = points.get(randomNum);

        // write the initial centers
        final Kluster cluster = new Kluster(vec, i, new EuclideanDistanceMeasure());
        writer.append(new Text(cluster.getIdentifier()), cluster);
    }/*w  ww.  j  a v  a 2  s  .  c  o m*/

    writer.close();
}