List of usage examples for org.apache.commons.math.stat.clustering KMeansPlusPlusClusterer KMeansPlusPlusClusterer
public KMeansPlusPlusClusterer(final Random random)
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 ww w.j av a 2 s . c o m 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();//w w w . j av a 2s . 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; }