// show the old centroid and the new centroid private void displayCentroidMigration() { System.out.println("----------------------Centroid Movement---------------------"); for (Cluster c : clusters) { System.out.print(c.getOldCentroid() + "->"); System.out.print(c.getCentroid() + "\n"); } }
// determine if any centroid has moved more than threshold // since the last iteration private boolean centroidsHaveMoved() { for (int i = 0; i < clusters.size(); i++) { Cluster c = clusters.get(i); NamedVectorInstance center = c.getCentroid(); NamedVectorInstance oldCenter = c.getOldCentroid(); for (int j = 0; j < center.size(); j++) if (Math.abs(center.get(j) - oldCenter.get(j)) > threshold) return true; } return false; }