Example usage for org.apache.commons.math.stat.clustering KMeansPlusPlusClusterer cluster

List of usage examples for org.apache.commons.math.stat.clustering KMeansPlusPlusClusterer cluster

Introduction

In this page you can find the example usage for org.apache.commons.math.stat.clustering KMeansPlusPlusClusterer cluster.

Prototype

public List<Cluster<T>> cluster(final Collection<T> points, final int k, final int maxIterations) 

Source Link

Document

Runs the K-means++ clustering algorithm.

Usage

From source file:org.mart.crs.management.tempo.TempoExtractor.java

protected void extractTempo() {
    List<EuclideanFloatPoint> pointList = new ArrayList<EuclideanFloatPoint>();
    for (BeatSegment beatSegment : beatStructure.getBeatSegments()) {
        pointList.add(new EuclideanFloatPoint(new double[] { beatSegment.getDuration() }));
    }/*from  w  ww .  j  a va 2s  . com*/

    KMeansPlusPlusClusterer clusterer = new KMeansPlusPlusClusterer(new Random(2039091238l));
    List<Cluster<EuclideanFloatPoint>> cluster = clusterer.cluster(pointList, numberOfCluster, 100);

    int maxIndex = 0;
    int maxNumberOfPoints = 0;
    for (int i = 0; i < numberOfCluster; i++) {
        int numberOfPoints = cluster.get(i).getPoints().size();
        if (numberOfPoints > maxNumberOfPoints) {
            maxIndex = i;
            maxNumberOfPoints = numberOfPoints;
        }
    }

    float beatLength = (float) cluster.get(maxIndex).getCenter().getPoint()[0];
    this.tempo = 60 / beatLength;

}

From source file:playground.christoph.evacuation.analysis.EvacuationTimeClusterer.java

Map<BasicLocation, List<Double>> buildCluster(int numClusters, int iterations) {

    createCostMap();/*from w  w w.  j  a  v a  2  s  . c  o  m*/

    KMeansPlusPlusClusterer<ClusterableLocation> clusterer = new KMeansPlusPlusClusterer<ClusterableLocation>(
            MatsimRandom.getLocalInstance());

    List<ClusterableLocation> points = getClusterableLocations();

    buildQuadTree(points);

    log.info("do clustering...");
    List<Cluster<ClusterableLocation>> list = clusterer.cluster(points, numClusters, iterations);

    Map<BasicLocation, List<Double>> map = new HashMap<BasicLocation, List<Double>>();

    for (Cluster<ClusterableLocation> cluster : list) {
        BasicLocation center = cluster.getCenter().getBasicLocation();

        List<Double> evacuationTimes = new ArrayList<Double>();
        for (ClusterableLocation location : cluster.getPoints()) {
            List<Double> pointTravelTimes = locationMap.get(location.getBasicLocation());
            evacuationTimes.addAll(pointTravelTimes);
        }

        map.put(center, evacuationTimes);
    }

    log.info("done.");

    return map;
}