package machinelearning.kmeans;

import java.util.List;

public class ClustersScoring<T>{

    List<Cluster<T>> clusters = null;
    GenericTool<T> genericTool = null;

    public ClustersScoring(List<Cluster<T>> clusters, GenericTool<T> genericTool){
        this.clusters = clusters;
        this.genericTool = genericTool;
    }

    public double getSilhouetteScore(){
        for(Cluster<T> cluster : this.clusters){
            double a = 0.0;
            double b= 0.0;
            for(T point : cluster.getPoints()){
                for(T otherPoint : cluster.getPoints()){
                    if(!otherPoint.equals(point))
                        a += genericTool.distanceBetween(point, otherPoint);
                }

                //a += genericTool.distanceBetween(po);
            }
        }
        return 0.0;
    }

    public double getBasicScore(){
        double score = 0.0;
        int clustersSize = clusters.size();
        for(int i=0; i<clustersSize; i++){
            Cluster<T> cluster = clusters.get(i);
            for(int j=i+1; j<clustersSize; j++){
                score += this.genericTool.distanceBetween(cluster.getCentroid(),clusters.get(j).getCentroid());
            }
            double distanceInCluster = 0.0;
            for(T point : cluster.getPoints()){
                distanceInCluster += genericTool.distanceBetween(point,cluster.getCentroid());
            }
            score += 1.0/distanceInCluster;
        }
        return score;
    }
}

@@ -431,107 +431,536 @@
     
-double a = 0.0;%0A            double b= 0.0
+%0A        %7D%0A        return 0.0;%0A    %7D%0A    %0A    private double computeSilhouetteForPoint(T point, Cluster%3CT%3E associatedCluster, Cluster%3CT%3E nearestCluster)%7B%0A        double a = computeSilhouettePartClusterForPoint(point, associatedCluster, true);%0A        double b = computeSilhouettePartClusterForPoint(point, nearestCluster, false);%0A        double silhouette = (b - a)/(Math.max(a,b))
 ;%0A    
+%7D%0A
     
+%0A
     
-for(T point : cluster.getPoints())%7B%0A        
+private double computeSilhouettePartClusterForPoint(T point, Cluster%3CT%3E cluster,boolean sameCluster)%7B%0A        double value = 0.0;%0A
     
@@ -1020,19 +1020,27 @@
     
-        if(
+if(!sameCluster %7C%7C 
 !oth
@@ -1082,17 +1082,13 @@
     
-        
-a
+value
  += 
@@ -1147,117 +1147,61 @@
     
-        %7D%0A%0A                //a += genericTool.distanceBetween(po);%0A            %7D%0A        %7D%0A        return 0.0
+%7D%0A        return value /= ((double)cluster.getSize())
 ;%0A  

Update ClustersScoring.java