Code Execution Report

KMeans.computeCentroids

Summary

Method computeCentroids was called total 66 times. It made total 6600726 outgoing calls. It took 405.151 ms.

Method Calls

Method computeCentroids was called 66 times by only 1 method main.

Method computeCentroids made 6600726 calls to 4 methods. It made maximum 3300000 calls each to methods getY and getX.

Time Consumption

Method computeCentroids took 405.15 ms , out of which 182.81 ms were consumed as self time and 222.35 ms by outgoing calls made to 4 methods. Outgoing calls made to method getX took maximum time which was 112.09 ms . Please note the measurements are uncertain due to short runtime of outgoing calls.


/**
	 * Computes the new positions of centroids for all clusters
	 * 
	 * @param clusters
	 *            Cluster assignment
	 * @param k
	 *            number of clusters
	 * @return New centroid positions
	 */
private static Point2D[] computeCentroids(int[] clusters, int k) {
    Point2D[] centroids = new Point2D[k];
    for (int j = 0; j < centroids.length; j++) {
        double sumX = 0;
        double sumY = 0;
        int count = 0;
        for (int i = 0; i < clusters.length; i++) {
            if (clusters[i] == j) {
                sumX += points[i].getX();
                sumY += points[i].getY();
                count++;
            }
        }
        centroids[j] = new Point2D.Double(sumX / count, sumY / count);
    }
    return centroids;
}