source: other-projects/is-sheet-music-encore/trunk/image-identification-terminal/javaAccuracyCalculator.java@ 33439

Last change on this file since 33439 was 33439, checked in by cpb16, 5 years ago

Have created properties file and accessibility from javaClassifierComparision. Have created download middle page only variant of image-downloader system. Have created EndToEndSystem bash script that will be used as makefile, with makefile being used to execute preset useful commands to the EndToEndSystem. It needs to be fleshed out as only has one script, this script can run a classifier and place the results into a subdirectory defined by the user

File size: 3.6 KB
Line 
1import java.io.File;
2import java.io.BufferedReader;
3import java.io.BufferedWriter;
4import java.io.FileReader;
5import java.io.FileWriter;
6import java.util.*;
7public class javaAccuracyCalculator{
8
9 //Read in log.txt, grab first item in array of each line
10 //Counter for everytime have readline
11 //Calculate accuracy rate
12 public static void main(String[] args) {
13 try {
14 if (args.length != 3) {
15 System.out.println("Usage: imageClassifier <inputFilename> <classifierType> <outputFilename>");
16 }
17 else {
18 Date d = new Date();
19 String inputFilename = args[0];
20 String classifierType = args[1];
21 String outputFilename = args[2];
22 FileReader fileReader = new FileReader(inputFilename);
23 BufferedReader buf = new BufferedReader(fileReader);
24 FileWriter fw = new FileWriter(outputFilename,true);
25 String line = null;
26 String[] item;
27 float trueAccuracyRate =0;
28 float falseAccuracyRate =0;
29 float overallAccuracyRate=0;
30 //
31 int sheetMusicCount = 0;
32 int notSheetMusicCount = 0;
33 //
34 int truePositive = 0;
35 int trueNegative = 0;
36 //
37 int falsePositive = 0;
38 int falseNegative = 0;
39
40 //Splits into each record, since readLine splits by "\n"
41 while ((line = buf.readLine()) != null) {
42 item = line.split("\t");
43 //Calculate AccuracyRates
44 if(item[1].contains("/SheetMusic/")){
45 sheetMusicCount++;
46 if(item[3].equals("true")){
47 truePositive++;
48 }
49 else if(item[3].equals("false") || item[3].equals("null")){
50 falseNegative++;
51 }
52 else {
53 System.err.println("Error log file");
54 }
55 }
56 if(item[1].contains("/NotSheetMusic/")){
57 notSheetMusicCount++;
58 if(item[3].equals("true")){
59 falsePositive++;
60 }
61 else if(item[3].equals("false")|| item[3].equals("null")){
62 trueNegative++;
63 }
64 else{
65 System.err.println("Error log file");
66 }
67 }
68 }
69
70
71 //Correctly identified SheetMusic as SheetMusic
72
73 //TruthAccuracyRate
74 if(sheetMusicCount != 0){
75 trueAccuracyRate = ((float)truePositive/(float)sheetMusicCount)*(float)100;
76 }
77 else {
78 trueAccuracyRate = 0;
79 }
80
81 //FalseAccuracyRate
82 if(notSheetMusicCount != 0){
83 //Amount of Correctly identified NotSheetSheetMusic as NotSheetMusic
84 falseAccuracyRate = ((float)trueNegative/(float)notSheetMusicCount)*(float)100;
85 }
86 else {
87 falseAccuracyRate = 0;
88 }
89
90 //Overall accuaracy
91 if(notSheetMusicCount != 0 && sheetMusicCount != 0) {
92 overallAccuracyRate = (truePositive + trueNegative)/(float)(sheetMusicCount+notSheetMusicCount)*(float)100;
93 }
94 else if (sheetMusicCount == 0) {
95 overallAccuracyRate = falseAccuracyRate;
96 }
97 else if(notSheetMusicCount == 0) {
98 overallAccuracyRate = trueAccuracyRate;
99 }
100 else {
101 overallAccuracyRate = -1;
102 System.out.println("There is nothing to compare");
103 }
104
105 fw.write("Date: " + d.toString() + '\n'
106 + "Classifier: " + classifierType + '\n'
107 + "truePositive: " + truePositive + '\n'
108 + "falseNegative: " + falseNegative + '\n'
109 + "falsePositve: " + falsePositive + '\n'
110 + "trueNegative: " + trueNegative + '\n'
111 + "SheetMusicAccuracyRate: " + trueAccuracyRate + "%" + '\n'
112 + "NotSheetMusicAccuracyRate: " + falseAccuracyRate + "%" + '\n'
113 + "OverallAccuracyRate: " + overallAccuracyRate + "%" + '\n' +
114 "****************************************************************" + '\n');
115 buf.close();
116 fw.close();
117 }
118 }
119 catch(Exception e){
120 System.err.println(e);
121 }
122 }
123
124}
Note: See TracBrowser for help on using the repository browser.