From 5b7cd51e4dbc06084014ede0cf0df5674b0eec28 Mon Sep 17 00:00:00 2001 From: Kui LIU Date: Fri, 4 Aug 2017 13:36:54 +0200 Subject: [PATCH] Output the sizes of common clusters. --- .../FixPatternMining/CommonPatterns.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/java/edu/lu/uni/serval/FixPatternMining/CommonPatterns.java b/src/main/java/edu/lu/uni/serval/FixPatternMining/CommonPatterns.java index e8db8dc..3df6d3b 100644 --- a/src/main/java/edu/lu/uni/serval/FixPatternMining/CommonPatterns.java +++ b/src/main/java/edu/lu/uni/serval/FixPatternMining/CommonPatterns.java @@ -6,6 +6,8 @@ import java.util.List; import java.util.Map; 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; public class CommonPatterns { @@ -28,16 +30,21 @@ public class CommonPatterns { private List getCommonClustersByNumber(Map> clusterMap) { List commonClusterNum = new ArrayList<>(); + String numbersMapStr = "";// numbers of instances in each common cluster. for (Map.Entry> entry : clusterMap.entrySet()) { List elements = entry.getValue(); int size = elements.size(); if (size >= LEAST_NUMBER) { // TODO how to set this threshold? - commonClusterNum.add(entry.getKey()); + int key = entry.getKey(); + commonClusterNum.add(key); totalNumberofTrainingData += size; + numbersMapStr += key + ":" + size + "\n"; } } + FileHelper.outputToFile(Configuration.COMMON_CLUSTERS_SIZES, numbersMapStr, false); + return commonClusterNum; } @@ -50,18 +57,25 @@ public class CommonPatterns { List elements = entry.getValue(); ratios.put(entry.getKey(), (double) elements.size() / sizes); } + + String numbersMapStr = "";// numbers of instances in each common cluster. + MapSorter sorter = new MapSorter(); ratios = sorter.sortByValueDescending(ratios); double counterRatio = 0.0; for (Map.Entry entry : ratios.entrySet()) { 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(); if (counterRatio >= 0.8) { // TODO: how to set the value of this threshold? break; } } + FileHelper.outputToFile(Configuration.COMMON_CLUSTERS_SIZES, numbersMapStr, false); + return commonClusterNum; }