diff --git a/src/main/java/de/mpii/frequentrulesminning/AssociationRuleMiningSPMF.java b/src/main/java/de/mpii/frequentrulesminning/AssociationRuleMiningSPMF.java index bc0fb77..ff6a3bd 100644 --- a/src/main/java/de/mpii/frequentrulesminning/AssociationRuleMiningSPMF.java +++ b/src/main/java/de/mpii/frequentrulesminning/AssociationRuleMiningSPMF.java @@ -542,6 +542,112 @@ public void showStatistics(AssocRulesExtended rules,boolean export, String fileN + } + + + public void showStatisticsRevisedRules(AssocRulesExtended rules,boolean export, String fileName) throws Exception { + + long revisedRulesCount=rules.getRevisedRuleCount(); + + StringBuilder st=new StringBuilder(); + st.append(toString()); + st.append('\n'); + + + + + st.append("topK\ttype\tAvgConf\tdiff\tAvgConfRO\tdiff\tAvgLIFT\tdiff\tAvgLIFTRO\tdiff"); + st.append('\n'); + + StringBuilder stAll=new StringBuilder(); + stAll.append("TopK\tMeasurement\tAll Rules\tRevised Rules Only\n"); + + + + for(int i=1;i<=10;i++) { + int k=(int)Math.ceil((i*0.1)*revisedRulesCount); + + + double orgAvgConf= rules.getRevisedRulesConfidenceStats(k, false,false).getAverage(); + double orgAvgConfRO= rules.getRevisedRulesConfidenceStats(k, false,true).getAverage(); + + double orgAvgLift = rules.getRevisedRulesLiftStats(k, false,false).getAverage(); + double orgAvgLiftRO = rules.getRevisedRulesLiftStats(k, false,true).getAverage(); +// double orgAvgJaccardCoefficient = rules.getJaccardCoefficientStats(k, false,false).getAverage();; + + + st.append(k+":\tBefore\t"); + st.append(String.format("%.5f",orgAvgConf)+"\t__\t"); + st.append(String.format("%.5f",orgAvgConfRO)+"\t__\t"); + st.append(String.format("%.6f", orgAvgLift)+"\t__\t"); + st.append(String.format("%.6f", orgAvgLiftRO)+"\t__\t"); +// st.append(String.format("%.5f", orgAvgJaccardCoefficient)+"\t__\t"); + st.append('\n'); + + double newAvgConfidence = rules.getRevisedRulesConfidenceStats(k, true, false).getAverage(); + double newAvgConfidenceRO = rules.getRevisedRulesConfidenceStats(k, true, true).getAverage(); + double newAvgLift = rules.getRevisedRulesLiftStats(k, true,false).getAverage(); + double newAvgLiftRO = rules.getRevisedRulesLiftStats(k, true,true).getAverage(); + + +// double newAvgJaccardCoefficient = rules.getJaccardCoefficientStats(k, true,false).getAverage();; + + st.append(k+":\tAfter\t"); + st.append(String.format("%.5f", newAvgConfidence)+"\t"); + st.append(String.format("%.5f", newAvgConfidence-orgAvgConf)+"\t"); + st.append(String.format("%.5f", newAvgConfidenceRO)+"\t"); + st.append(String.format("%.5f", newAvgConfidenceRO-orgAvgConfRO)+"\t"); + + st.append(String.format("%.6f", newAvgLift)+"\t"); + st.append(String.format("%.6f", newAvgLift-orgAvgLift)+"\t"); + st.append(String.format("%.6f", newAvgLiftRO)+"\t"); + st.append(String.format("%.6f", newAvgLiftRO-orgAvgLiftRO)+"\t"); +// st.append(String.format("%.5f", newAvgJaccardCoefficient)+"\t"); +// st.append(String.format("%.5f", newAvgJaccardCoefficient-orgAvgConf)+"\t"); + st.append('\n'); + + st.append("--------------------------------------------------------------------\n"); + + + st.append('\n'); + + + //------------------- + + stAll.append(k+"\t"); + stAll.append("Confidence\t"); + stAll.append(rules.getConfidenceDiffStats(k,false).toString().replaceAll("DoubleSummaryStatistics","")+"\t"); + stAll.append(rules.getConfidenceDiffStats(k,true).toString().replaceAll("DoubleSummaryStatistics","")+"\n"); + stAll.append("\tLift\t"); + stAll.append(rules.getLiftDiffStats(k,false).toString().replaceAll("DoubleSummaryStatistics","")+"\t"); + stAll.append(rules.getLiftDiffStats(k,true).toString().replaceAll("DoubleSummaryStatistics","")+"\n"); +// stAll.append("\tJaccard\t"); +// stAll.append(rules.getJaccardDiffStats(k,false).toString().replaceAll("DoubleSummaryStatistics","")+"\t"); +// stAll.append(rules.getJaccardDiffStats(k,true).toString().replaceAll("DoubleSummaryStatistics","")+"\n"); + stAll.append("--------------------------------------------------------------------\n"); + + + + } + + st.append("RO: revised only\n"); + + + + System.out.println(st.toString()); + System.out.println(stAll.toString()); + if(export){ + BufferedWriter bw=FileUtils.getBufferedUTF8Writer(fileName); + bw.write(st.toString()); + bw.close(); + + BufferedWriter bw2=FileUtils.getBufferedUTF8Writer(fileName+".all"); + bw2.write(stAll.toString()); + bw2.close(); + } + + + } diff --git a/src/main/java/de/mpii/frequentrulesminning/MainCLI.java b/src/main/java/de/mpii/frequentrulesminning/MainCLI.java index c3049ac..f88c150 100644 --- a/src/main/java/de/mpii/frequentrulesminning/MainCLI.java +++ b/src/main/java/de/mpii/frequentrulesminning/MainCLI.java @@ -249,6 +249,7 @@ public void run(CommandLine cmd) throws Exception{ String fileName=outputFilePath+".stat"; miner.showStatistics( rulesStrings,export, fileName); + miner.showStatisticsRevisedRules( rulesStrings,export, fileName+".ro"); if(cmd.hasOption(exportDLVConflictOp.getOpt())){ diff --git a/src/main/java/de/mpii/frequentrulesminning/utils/AssocRulesExtended.java b/src/main/java/de/mpii/frequentrulesminning/utils/AssocRulesExtended.java index 939f4af..3872d3e 100644 --- a/src/main/java/de/mpii/frequentrulesminning/utils/AssocRulesExtended.java +++ b/src/main/java/de/mpii/frequentrulesminning/utils/AssocRulesExtended.java @@ -307,7 +307,7 @@ public String toStringdlvConflict() { } - public DoubleSummaryStatistics getConfidenceStats(int k, boolean exception, boolean revisedOnly){ + public DoubleSummaryStatistics getRevisedRulesConfidenceStats(int k, boolean exception, boolean revisedOnly){ if(exception) return rules.stream().filter((r)-> (!revisedOnly)||r.hasExceptions()).limit(k).mapToDouble(AssocRuleWithExceptions::getRevisedConfidence).summaryStatistics(); else @@ -315,7 +315,7 @@ public DoubleSummaryStatistics getConfidenceStats(int k, boolean exception, bool } - public DoubleSummaryStatistics getConfidenceStats2(int k, boolean exception, boolean revisedOnly){ + public DoubleSummaryStatistics getConfidenceStats(int k, boolean exception, boolean revisedOnly){ if(exception) return rules.stream().limit(k).filter((r)-> (!revisedOnly)||r.hasExceptions()).mapToDouble(AssocRuleWithExceptions::getRevisedConfidence).summaryStatistics(); else @@ -323,6 +323,11 @@ public DoubleSummaryStatistics getConfidenceStats2(int k, boolean exception, boo } + public DoubleSummaryStatistics getRevisedRulesConfidenceDiffStats(int k, boolean revisedOnly){ + + return rules.stream().filter((r)-> (!revisedOnly)||r.hasExceptions()).limit(k).mapToDouble((r)->r.getRevisedConfidence()-r.getConfidence()).summaryStatistics(); + + } public DoubleSummaryStatistics getConfidenceDiffStats(int k, boolean revisedOnly){ @@ -344,6 +349,14 @@ public DoubleSummaryStatistics getJaccardDiffStats(int k, boolean revisedOnly){ } + + public DoubleSummaryStatistics getRevisedRulesLiftStats(int k, boolean withException, boolean revisedOnly){ + if(withException) + return rules.stream().filter((r)-> (!revisedOnly)||r.hasExceptions()).limit(k).mapToDouble(AssocRuleWithExceptions::getRevisedLift).summaryStatistics(); + else + return rules.stream().filter((r)-> (!revisedOnly)||r.hasExceptions()).limit(k).mapToDouble(AssocRuleWithExceptions::getLift).summaryStatistics(); + } + public DoubleSummaryStatistics getLiftStats(int k, boolean withException, boolean revisedOnly){ if(withException) return rules.stream().limit(k).filter((r)-> (!revisedOnly)||r.hasExceptions()).mapToDouble(AssocRuleWithExceptions::getRevisedLift).summaryStatistics(); @@ -357,7 +370,11 @@ public DoubleSummaryStatistics getLiftDiffStats(int k,boolean revisedOnly){ } + public DoubleSummaryStatistics getRevisedRulesLiftDiffStats(int k,boolean revisedOnly){ + + return rules.stream().filter((r)-> (!revisedOnly)||r.hasExceptions()).limit(k).mapToDouble((r)->r.getRevisedLift()-r.getLift()).summaryStatistics(); + } // private void sortByLift(List rulesToSort) {