Debian Codegraph @

metastudentPkg/lib/groupB/pp2/prediction/evaluation/EvaluationPlots.java

raw
1 package pp2.prediction.evaluation;
2
3 import java.io.BufferedWriter;
4 import java.io.File;
5 import java.io.FilenameFilter;
6 import java.io.IOException;
7 import java.util.regex.Matcher;
8 import java.util.regex.Pattern;
9
10 import pp2.tools.RMethods;
11 import pp2.tools.Tools;
12
13 public class EvaluationPlots {
14
15 public EvaluationPlots(String directory, FilenameFilter filter, String rPath, int predictCol, int actualCol) {
16 AddEvaluation ae = new AddEvaluation(directory, filter, predictCol, actualCol);
17 FilenameFilter evalFil = new FilenameFilter() {
18
19 @Override
20 public boolean accept(File file, String name) {
21 if(name.endsWith(".eval")) {
22 return true;
23 }
24 return false;
25 }
26 };
27 try {
28 String name = directory+File.separator+"evaluation-summary";
29 BufferedWriter summary = Tools.writeToFile(name);
30 summary.write("#Mean_Recall\tMedian_Recall\tMean_Precision\tMedian_Precision\n");
31 RMethods rm = new RMethods(rPath);
32 rm.startRScript(name+".R");
33 rm.addLineToScript("meanRecall <- c()");
34 rm.addLineToScript("medianRecall <- c()");
35 rm.addLineToScript("meanPrecision <- c()");
36 rm.addLineToScript("medianPrecision <- c()");
37 rm.addLineToScript("labels <- c()");
38
39 for(File file : new File(directory).listFiles(evalFil)) {
40 Pattern cv = Pattern.compile("cv=(\\d+)");
41 Matcher ma = cv.matcher(file.getName());
42 int cvRound = 1;
43 if(ma.find()) {
44 cvRound = Integer.parseInt(ma.group(1));
45 }
46 double meanRecall = 0;
47 double medianRecall = 0;
48 double meanPrecision = 0;
49 double medianPrecision = 0;
50
51 int preCol = ae.getPrecisionCol();
52 int recCol = ae.getRecallCol();
53
54 rm.addLineToScript("x <- read.table(\""+file.getAbsolutePath()+"\")");
55 rm.addLineToScript("mR <- mean(x[["+recCol+"]])");
56 rm.addLineToScript("meR <- median(x[["+recCol+"]])");
57 rm.addLineToScript("mP <- mean(x[["+preCol+"]])");
58 rm.addLineToScript("meP <- median(x[["+preCol+"]])");
59 rm.addLineToScript("meanRecall <- c(meanRecall,mR)");
60 rm.addLineToScript("medianRecall <- c(medianRecall,meR)");
61 rm.addLineToScript("meanPrecision <- c(meanPrecision,mP)");
62 rm.addLineToScript("medianPrecision <- c(medianPrecision,meP)");
63 }
64
65 rm.addLineToScript("pdf(\""+name+".pdf\")");
66 //TODO: plot
67 summary.flush();
68 summary.close();
69 } catch (IOException e) {
70 e.printStackTrace();
71 }
72
73 }
74 }