package main; import java.io.FileOutputStream; import java.io.IOException; import java.io.LineNumberReader; import java.io.PrintStream; import java.util.ArrayList; import preprocessing.Parser; public class Curve { public static void main(String[] args) throws IOException { String path = args[0]; String file_in = args[1]; String out_filename = args[2]; ArrayList class_list = new ArrayList (); ArrayList score_list = new ArrayList (); Get_Curve (path, file_in, class_list, score_list); double interval = 5.0; double step = 0.1; int max = (int)((interval * 2)/step); FileOutputStream file_out = new FileOutputStream(out_filename); PrintStream pstream = new PrintStream(file_out); for (int index = 0; index <= max; index++) { Get_Performance (-interval, class_list, score_list, pstream); interval -= 0.1; } file_out.close(); } public static void Get_Curve ( String path, String file, ArrayList class_list, ArrayList score_list ) { Parser parser = new Parser(); LineNumberReader scores = parser.Open_File (path + file); String[] s = null; do { s = parser.getTokens (scores, "\n"); if (s == null) { break; } String[] S = s[0].split(" "); score_list.add(Double.parseDouble(S[0])); class_list.add(Integer.parseInt(S[2])); } while (s != null); try { scores.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void Get_Performance ( double threshold, ArrayList class_list, ArrayList score_list, PrintStream pstream) { /*Evaluating the object training over the train list*/ int size = score_list.size(); int tp = 0, fp = 0, fn = 0, tn = 0; for (int index = 0 ; index < size; index++) { double v = score_list.get(index); int sclass = class_list.get(index); if ( (sclass == 1) && (v >= threshold) ) { tp++; /*Text class and correctly classified as text*/ } else if ( (sclass == 1) && (v < threshold) ) { fn++; /*Text class but classified as non-text*/ } else if ( (sclass == -1) && (v < threshold) ) { tn++; /*Non-Text class and correctly classified as non-text*/ } else if ( (sclass == -1) && (v >= threshold) ) { fp++; /*Non-Text class but classified as text*/ } } double P = 0.0; if ((tp + fp) != 0) { P = (double )tp / (double)(tp + fp); } double R = 0.0; if ((tp + fn) != 0) { R = (double )tp / (double)(tp + fn); } double Tau = 0.0; if ((tp + fn) != 0) { Tau = (double )fn / (double)(tp + fn); } double Beta = 0.0; if ((tp + fn) != 0) { Beta = (double )fp / (double)(tn + fp); } pstream.printf("%+f %f %f %f %f %5d %5d %5d %5d %5d\n", threshold, P, R, Tau, Beta, tp, fp, tn, fn, tp + fp + tn + fn); } }