SumOfClusterVariances extends ClusterEvaluator<T> { @Override public double score(final List<? extends Cluster<T>> clusters) { double varianceSum = 0.0; for (final Cluster<T> cluster : clusters) { if (!cluster.getPoints().isEmpty()) { final Clusterable center = centroidOf(cluster); final Variance stat = new Variance(); for (final T point : cluster.getPoints()) { stat.increment(distance(point, center)); } varianceSum += stat.getResult(); } } return varianceSum; } SumOfClusterVariances(final DistanceMeasure measure); @Override double score(final List<? extends Cluster<T>> clusters);  }
@Test public void testScore() { final DoublePoint[] points1 = new DoublePoint[] { new DoublePoint(new double[] { 1 }), new DoublePoint(new double[] { 2 }), new DoublePoint(new double[] { 3 }) }; final DoublePoint[] points2 = new DoublePoint[] { new DoublePoint(new double[] { 1 }), new DoublePoint(new double[] { 5 }), new DoublePoint(new double[] { 10 }) }; final List<Cluster<DoublePoint>> clusters = new ArrayList<Cluster<DoublePoint>>(); final Cluster<DoublePoint> cluster1 = new Cluster<DoublePoint>(); for (DoublePoint p : points1) { cluster1.addPoint(p); } clusters.add(cluster1); assertEquals(1.0/3.0, evaluator.score(clusters), 1e-6); final Cluster<DoublePoint> cluster2 = new Cluster<DoublePoint>(); for (DoublePoint p : points2) { cluster2.addPoint(p); } clusters.add(cluster2); assertEquals(6.148148148, evaluator.score(clusters), 1e-6); }