コード例 #1
0
ファイル: DunnIndex.java プロジェクト: ahmad-bakr/IHDBSCAN
 /**
  * Calculate the cluster size or diameter
  *
  * @param c cluster
  * @return cluster size or diameter
  */
 private double calculateClusterSize(Cluster c) {
   double size = 0;
   ArrayList<Integer> clusterPoints = c.getPointsIDs();
   for (int i = 0; i < clusterPoints.size(); i++) {
     DatasetPattern point1 = this.dataset.get(clusterPoints.get(i));
     for (int j = 0; j < clusterPoints.size(); j++) {
       if (i == j) continue;
       DatasetPattern point2 = this.dataset.get(clusterPoints.get(j));
       size += EuclideanDistance.calculateDistance(point1, point2);
     }
   }
   return size / (clusterPoints.size() * (clusterPoints.size() - 1));
 }
コード例 #2
0
ファイル: DunnIndex.java プロジェクト: ahmad-bakr/IHDBSCAN
 /**
  * calculate the minimum distance between two clusters
  *
  * @param ci cluster ci
  * @param cj cluster cj
  * @return min distance between ci and cj
  */
 private double calculateMinDistanceBetweenTwoClusters(Cluster ci, Cluster cj) {
   double minDist = 0;
   ArrayList<Integer> ciPoints = ci.getPointsIDs();
   ArrayList<Integer> cjPoints = cj.getPointsIDs();
   for (int i = 0; i < ciPoints.size(); i++) {
     DatasetPattern ciPoint = this.dataset.get(ciPoints.get(i));
     for (int j = 0; j < cjPoints.size(); j++) {
       DatasetPattern cjPoint = this.dataset.get(cjPoints.get(j));
       double distance = EuclideanDistance.calculateDistance(ciPoint, cjPoint);
       minDist += distance;
     }
   }
   return minDist / ((ciPoints.size() - 1) * (cjPoints.size() * 1));
 }