Output the sizes of common clusters.
This commit is contained in:
@@ -6,6 +6,8 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import edu.lu.uni.serval.FixPatternMining.DataPrepare.DataPreparation;
|
import edu.lu.uni.serval.FixPatternMining.DataPrepare.DataPreparation;
|
||||||
|
import edu.lu.uni.serval.config.Configuration;
|
||||||
|
import edu.lu.uni.serval.utils.FileHelper;
|
||||||
import edu.lu.uni.serval.utils.MapSorter;
|
import edu.lu.uni.serval.utils.MapSorter;
|
||||||
|
|
||||||
public class CommonPatterns {
|
public class CommonPatterns {
|
||||||
@@ -28,16 +30,21 @@ public class CommonPatterns {
|
|||||||
|
|
||||||
private List<Integer> getCommonClustersByNumber(Map<Integer, List<Integer>> clusterMap) {
|
private List<Integer> getCommonClustersByNumber(Map<Integer, List<Integer>> clusterMap) {
|
||||||
List<Integer> commonClusterNum = new ArrayList<>();
|
List<Integer> commonClusterNum = new ArrayList<>();
|
||||||
|
String numbersMapStr = "";// numbers of instances in each common cluster.
|
||||||
|
|
||||||
for (Map.Entry<Integer, List<Integer>> entry : clusterMap.entrySet()) {
|
for (Map.Entry<Integer, List<Integer>> entry : clusterMap.entrySet()) {
|
||||||
List<Integer> elements = entry.getValue();
|
List<Integer> elements = entry.getValue();
|
||||||
int size = elements.size();
|
int size = elements.size();
|
||||||
if (size >= LEAST_NUMBER) { // TODO how to set this threshold?
|
if (size >= LEAST_NUMBER) { // TODO how to set this threshold?
|
||||||
commonClusterNum.add(entry.getKey());
|
int key = entry.getKey();
|
||||||
|
commonClusterNum.add(key);
|
||||||
totalNumberofTrainingData += size;
|
totalNumberofTrainingData += size;
|
||||||
|
numbersMapStr += key + ":" + size + "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FileHelper.outputToFile(Configuration.COMMON_CLUSTERS_SIZES, numbersMapStr, false);
|
||||||
|
|
||||||
return commonClusterNum;
|
return commonClusterNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,18 +57,25 @@ public class CommonPatterns {
|
|||||||
List<Integer> elements = entry.getValue();
|
List<Integer> elements = entry.getValue();
|
||||||
ratios.put(entry.getKey(), (double) elements.size() / sizes);
|
ratios.put(entry.getKey(), (double) elements.size() / sizes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String numbersMapStr = "";// numbers of instances in each common cluster.
|
||||||
|
|
||||||
MapSorter<Integer, Double> sorter = new MapSorter<Integer, Double>();
|
MapSorter<Integer, Double> sorter = new MapSorter<Integer, Double>();
|
||||||
ratios = sorter.sortByValueDescending(ratios);
|
ratios = sorter.sortByValueDescending(ratios);
|
||||||
double counterRatio = 0.0;
|
double counterRatio = 0.0;
|
||||||
for (Map.Entry<Integer, Double> entry : ratios.entrySet()) {
|
for (Map.Entry<Integer, Double> entry : ratios.entrySet()) {
|
||||||
counterRatio += entry.getValue();
|
counterRatio += entry.getValue();
|
||||||
commonClusterNum.add(entry.getKey());
|
int key = entry.getKey();
|
||||||
|
commonClusterNum.add(key);
|
||||||
|
numbersMapStr += key + ":" + clusterMap.get(key).size() + "\n";
|
||||||
totalNumberofTrainingData += clusterMap.get(entry.getKey()).size();
|
totalNumberofTrainingData += clusterMap.get(entry.getKey()).size();
|
||||||
if (counterRatio >= 0.8) { // TODO: how to set the value of this threshold?
|
if (counterRatio >= 0.8) { // TODO: how to set the value of this threshold?
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FileHelper.outputToFile(Configuration.COMMON_CLUSTERS_SIZES, numbersMapStr, false);
|
||||||
|
|
||||||
return commonClusterNum;
|
return commonClusterNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user