|
|
@@ -32,25 +32,27 @@ public class IntegerClusteringResult implements ClusteringResult<Integer> {
|
|
|
}
|
|
|
clusterIdx++;
|
|
|
}
|
|
|
- RealMatrix E = new Array2DRowRealMatrix(clusters.size(), clusters.size());
|
|
|
- E = E.scalarMultiply(0);
|
|
|
- for (int i = 0; i < N; i++) {
|
|
|
- if (!submissionIdx2ClusterIdx.containsKey(i)) continue;
|
|
|
- int clusterA = submissionIdx2ClusterIdx.get(i);
|
|
|
- for (int j = i + 1; j < N; j++) {
|
|
|
- if (!submissionIdx2ClusterIdx.containsKey(j)) continue;
|
|
|
- int clusterB = submissionIdx2ClusterIdx.get(j);
|
|
|
- E.addToEntry(clusterA, clusterB, similarity.getEntry(i, j));
|
|
|
- E.addToEntry(clusterB, clusterA, similarity.getEntry(i, j));
|
|
|
+ if (clusters.size() > 0) {
|
|
|
+ RealMatrix E = new Array2DRowRealMatrix(clusters.size(), clusters.size());
|
|
|
+ E = E.scalarMultiply(0);
|
|
|
+ for (int i = 0; i < N; i++) {
|
|
|
+ if (!submissionIdx2ClusterIdx.containsKey(i)) continue;
|
|
|
+ int clusterA = submissionIdx2ClusterIdx.get(i);
|
|
|
+ for (int j = i + 1; j < N; j++) {
|
|
|
+ if (!submissionIdx2ClusterIdx.containsKey(j)) continue;
|
|
|
+ int clusterB = submissionIdx2ClusterIdx.get(j);
|
|
|
+ E.addToEntry(clusterA, clusterB, similarity.getEntry(i, j));
|
|
|
+ E.addToEntry(clusterB, clusterA, similarity.getEntry(i, j));
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- E = E.scalarMultiply(1 / Arrays.stream(similarity.getData()).flatMapToDouble(DoubleStream::of).sum());
|
|
|
- for (int i = 0; i < clusters.size(); i++) {
|
|
|
- double outWeightSum = E.getRowVector(i).getL1Norm();
|
|
|
- double clusterCommunityStrength = E.getEntry(i, i) - outWeightSum * outWeightSum;
|
|
|
- this.clusters.add(new DefaultCluster<Integer>(clusters.get(i), (float) clusterCommunityStrength, this));
|
|
|
- communityStrength += clusterCommunityStrength;
|
|
|
- }
|
|
|
+ E = E.scalarMultiply(1 / Arrays.stream(similarity.getData()).flatMapToDouble(DoubleStream::of).sum());
|
|
|
+ for (int i = 0; i < clusters.size(); i++) {
|
|
|
+ double outWeightSum = E.getRowVector(i).getL1Norm();
|
|
|
+ double clusterCommunityStrength = E.getEntry(i, i) - outWeightSum * outWeightSum;
|
|
|
+ this.clusters.add(new DefaultCluster<Integer>(clusters.get(i), (float) clusterCommunityStrength, this));
|
|
|
+ communityStrength += clusterCommunityStrength;
|
|
|
+ }
|
|
|
+ }
|
|
|
size = this.clusters.stream().mapToInt(x -> x.getMembers().size()).sum();
|
|
|
}
|
|
|
|