From: Aaron A. <aa...@us...> - 2007-09-18 03:26:04
|
Update of /cvsroot/jboost/jboost/src/jboost/monitor In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv9842/monitor Modified Files: Monitor.java Log Message: New log file format. Index: Monitor.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/monitor/Monitor.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Monitor.java 10 Jul 2007 01:33:31 -0000 1.6 --- Monitor.java 18 Sep 2007 03:25:59 -0000 1.7 *************** *** 26,56 **** private static Date endTime; private String outputStem; ! private PrintWriter infoStream; // the stream for providing private String infoFilename; ! // a high-level log of the program's progress. - - /** parameter that controls when scores are printed */ - private int scoresPrintRate; - private PrintWriter testScoresStream; // a stream for the test data scores - private String testScoresOutputFilename; - private PrintWriter trainScoresStream; // a stream for the training data scores - private String trainScoresOutputFilename; ! /** margin streams and varialbes */ ! private int marginPrintRate; ! private PrintWriter testMarginStream; // a stream for the test data scores ! private String testMarginOutputFilename; ! private PrintWriter trainMarginStream; // a stream for the training data scores ! private String trainMarginOutputFilename; - /** surfing streams and varialbes */ - private int surfPrintRate; - private PrintWriter surfStream; // a stream for the training data scores - private String surfOutputFilename; ! /** a stream for logging resampling activity */ private PrintWriter samplingStream; private String samplingOutputFilename; /** log file info */ --- 26,47 ---- private static Date endTime; private String outputStem; ! ! /** a high-level log of the program's progress. */ private String infoFilename; ! private PrintWriter infoStream; ! /** training and testing streams and variables */ ! private int boostingPrintRate; ! private PrintWriter trainBoostingStream; ! private String trainBoostingFilename; ! private PrintWriter testBoostingStream; ! private String testBoostingFilename; ! /** a stream for logging resampling activity private PrintWriter samplingStream; private String samplingOutputFilename; + */ /** log file info */ *************** *** 106,116 **** infoFilename= config.getString("info", outputStem + ".info"); ! trainScoresOutputFilename= outputStem + ".train.scores"; ! testScoresOutputFilename= outputStem + ".test.scores"; ! trainMarginOutputFilename= outputStem + ".train.margin"; ! testMarginOutputFilename= outputStem + ".test.margin"; ! surfOutputFilename= outputStem + ".surfing"; - samplingOutputFilename= outputStem + ".sampling"; try { infoStream= --- 97,103 ---- infoFilename= config.getString("info", outputStem + ".info"); ! trainBoostingFilename = outputStem + ".train.boosting.info"; ! testBoostingFilename = outputStem + ".test.boosting.info"; try { infoStream= *************** *** 125,139 **** infoStream.println("trainFilename = " + config.getTrainFileName()); infoStream.println("testFilename = " + config.getTestFileName()); ! infoStream.println("trainScoresOutputFilename = " ! +trainScoresOutputFilename); ! infoStream.println("testScoresOutputFilename = " + ! testScoresOutputFilename); ! infoStream.println("trainMarginOutputFilename = " ! +trainMarginOutputFilename); ! infoStream.println("testMarginOutputFilename = " ! +testMarginOutputFilename); infoStream.println("resultOutputFilename = " + config.getResultOutputFileName()); - infoStream.println("samplingOutputFilename = " + samplingOutputFilename); infoStream.println("logOutputFilename = " + logOutputFilename); infoStream.println(""); --- 112,119 ---- infoStream.println("trainFilename = " + config.getTrainFileName()); infoStream.println("testFilename = " + config.getTestFileName()); ! infoStream.println("trainBoostingInfo = " + trainBoostingFilename); ! infoStream.println("testBoostingInfo = " + testBoostingFilename); infoStream.println("resultOutputFilename = " + config.getResultOutputFileName()); infoStream.println("logOutputFilename = " + logOutputFilename); infoStream.println(""); *************** *** 141,170 **** infoStream.println("Test set size = " + testSet.getExampleNo()); infoStream.println(""); ! scoresPrintRate= config.getInt("a", 0); ! marginPrintRate= scoresPrintRate; ! surfPrintRate= scoresPrintRate; ! if (scoresPrintRate != 0) { ! trainScoresStream= new PrintWriter(new BufferedWriter( ! new FileWriter(trainScoresOutputFilename))); ! testScoresStream= new PrintWriter(new BufferedWriter( ! new FileWriter(testScoresOutputFilename))); ! samplingStream= new PrintWriter(new BufferedWriter( ! new FileWriter(samplingOutputFilename))); ! logLabels(); ! // output train and test m_labels onto the samplingStream ! samplingStream.close(); ! } ! if (marginPrintRate != 0) { ! trainMarginStream= new PrintWriter( new BufferedWriter( ! new FileWriter(trainMarginOutputFilename))); ! testMarginStream= new PrintWriter( ! new BufferedWriter( ! new FileWriter(testMarginOutputFilename))); ! } ! if (marginPrintRate != 0) { ! surfStream = new PrintWriter( new BufferedWriter( ! new FileWriter(surfOutputFilename))); } afterInitTime= new Date(); --- 121,133 ---- infoStream.println("Test set size = " + testSet.getExampleNo()); infoStream.println(""); ! boostingPrintRate= config.getInt("a", 0); ! ! if (boostingPrintRate != 0) { ! trainBoostingStream = new PrintWriter( new BufferedWriter( ! new FileWriter(trainBoostingFilename))); ! testBoostingStream = new PrintWriter( new BufferedWriter( ! new FileWriter(testBoostingFilename))); } afterInitTime= new Date(); *************** *** 180,183 **** --- 143,147 ---- /** print the m_labels of trainSet and testSet onto samplingStream */ + /* private void logLabels() { ArrayList labels= trainSet.getBinaryLabels(); *************** *** 195,198 **** --- 159,163 ---- labels= null; } + */ /** generate logs for current boosting iteration */ *************** *** 205,289 **** + f.format(trainError) + "\t" + f.format(testError)); infoStream.flush(); ! logScores(iter, combined, base); ! logMargins(iter, combined, base); ! logSurfing(iter, combined, base); ! infoStream.println(); ! } ! ! /** output the scores distribution of the training set */ ! private void logScores(int iter, Predictor combined, Predictor base) { ! if (scoresPrintRate == 0 || // never print scores ! (scoresPrintRate > 0 && scoresPrintRate != iter)) ! // or print scores only on iteration scoresPrintRate ! return; ! if (scoresPrintRate == -1) { ! // print score when highest order digit in iter changes. ! double m= ! java.lang.Math.floor( ! java.lang.Math.log(iter) / java.lang.Math.log(10.0)); ! int t= (int) java.lang.Math.pow(10.0, m); ! if (iter == 0) ! t= 1; // fix bug in "pow" ! if ((iter % t) != 0) ! return; ! } ! infoStream.print(" \t# output scores #"); ! // output training scores ! // double m_margins[] = m_booster.getMargins(); // get m_margins from the ! // m_booster ! ArrayList trainScores= trainSet.calcScores(iter, combined, base); ! trainScoresStream.println( ! "iteration=" + iter + ", elements=" + trainScores.size()); ! for (int i= 0; i < trainScores.size(); i++) ! trainScoresStream.println((Double) trainScores.get(i)); ! trainScores= null; // release memory ! // output test scores ! ArrayList testScores= testSet.calcScores(iter, combined, base); ! testScoresStream.println( ! "iteration=" + iter + ", elements=" + testScores.size()); ! for (int i= 0; i < testScores.size(); i++) ! testScoresStream.println((Double) testScores.get(i)); ! testScores.clear(); // release memory ! testScores= null; } ! ! ! /** output the scores distribution of the training set */ ! private void logSurfing(int iter, Predictor combined, Predictor base) { ! if (surfPrintRate == 0 || // never print surf ! (surfPrintRate > 0 && surfPrintRate != iter)) ! // or print surf only on iteration surfPrintRate ! return; ! if (surfPrintRate == -1) { ! // print score when highest order digit in iter changes. ! double m= ! java.lang.Math.floor( ! java.lang.Math.log(iter) / java.lang.Math.log(10.0)); ! int t= (int) java.lang.Math.pow(10.0, m); ! if (iter == 0) ! t= 1; // fix bug in "pow" ! if ((iter % t) != 0) ! return; } - infoStream.print(" \t# output surf #"); - // output training surf - // double m_margins[] = m_booster.getMargins(); // get m_margins from the - // m_booster ! surfStream.println("iteration=" + iter + ", elements=" + trainSet.getExampleNo()); ! if(m_booster instanceof BrownBoost) { ! surfStream.print(((BrownBoost)m_booster).surfingData()); } } - /** output the scores distribution of the training set */ ! private void logMargins(int iter, Predictor combined, Predictor base) { ! if (marginPrintRate == 0 || // never print scores ! (marginPrintRate > 0 && scoresPrintRate != iter)) ! // or print scores only on iteration scoresPrintRate return; ! if (marginPrintRate == -1) { // print score when highest order digit in iter changes. double m= --- 170,287 ---- + f.format(trainError) + "\t" + f.format(testError)); infoStream.flush(); ! logBoosting(iter, combined, base); ! infoStream.println(""); } ! ! ! /** ! * Provides logging for both the train and test sets. ! */ ! private void logBoostingTrainTest(PrintWriter boostingStream, ExampleSet tSet, int iter, Predictor combined, Predictor base) { ! // Output the training data ! boostingStream.println("iteration=" + iter + ! ", elements=" + tSet.size() + ! ", boosting_params=" + m_booster.getParamString() ! ); ! ! // Get the relavant data structures (arrays and lists) ! ArrayList tMargin = tSet.calcMargins(iter, combined, base); ! ArrayList tScores = tSet.calcScores(iter, combined, base); ! ArrayList tLabelIndices = tSet.getBinaryLabels(); ! double[][] tWeights = null; ! double[][] tPotentials = null; ! if (boostingStream.equals(trainBoostingStream)) { ! tWeights = m_booster.getWeights(); ! tPotentials = m_booster.getPotentials(); } ! NumberFormat f= new DecimalFormat("0.0000"); ! double[] tmp = null; ! Boolean[] labeltmp = null; ! int j = 0; ! for (int i=0; i < tMargin.size(); i++) { ! // output the example number ! boostingStream.print("[" +i + "]; "); ! ! // output the margins ! boostingStream.print("["); ! tmp = ((double[]) tMargin.get(i)); ! for (j= 0; j < tmp.length; j++){ ! boostingStream.print(f.format(tmp[j])); ! if (j != tmp.length -1) ! boostingStream.print(","); ! } ! boostingStream.print("]; "); ! ! ! // output the scores ! boostingStream.print("["); ! tmp = ((double[]) tScores.get(i)); ! for (j= 0; j < tmp.length; j++){ ! boostingStream.print(f.format(tmp[j])); ! if (j != tmp.length -1) ! boostingStream.print(","); ! } ! boostingStream.print("]; "); ! ! ! ! if (boostingStream.equals(trainBoostingStream)) { ! ! // output the weights ! boostingStream.print("["); ! for (j= 0; j < tWeights[i].length; j++){ ! boostingStream.print(f.format(tWeights[i][j])); ! if (j != tmp.length -1) ! boostingStream.print(","); ! } ! boostingStream.print("]; "); ! ! ! // output the potentials ! boostingStream.print("["); ! for (j= 0; j < tPotentials[i].length; j++){ ! boostingStream.print(f.format(tPotentials[i][j])); ! if (j != tmp.length -1) ! boostingStream.print(","); ! } ! boostingStream.print("]; "); ! ! ! } ! ! ! // output the labels ! boostingStream.print("["); ! labeltmp = ((Boolean[]) tLabelIndices.get(i)); ! for (j= 0; j < labeltmp.length; j++){ ! boostingStream.print(labeltmp[j].booleanValue() ? "+1" : "-1"); ! if (j != tmp.length -1) ! boostingStream.print(","); ! } ! boostingStream.print("]; "); ! ! boostingStream.println(""); } + + + // release memory + tMargin.clear(); + tScores.clear(); + tLabelIndices.clear(); + tMargin= null; + tScores= null; + tLabelIndices = null; + tWeights = null; + tPotentials = null; } /** output the scores distribution of the training set */ ! private void logBoosting(int iter, Predictor combined, Predictor base) { ! if (boostingPrintRate == 0 || ! (boostingPrintRate > 0 && boostingPrintRate != iter)) return; ! if (boostingPrintRate == -1) { // print score when highest order digit in iter changes. double m= *************** *** 296,317 **** return; } ! infoStream.print(" \t# output margins #"); ! // output training scores ! // double m_margins[] = m_booster.getMargins(); // get m_margins from the ! // m_booster ! ArrayList trainMargin= trainSet.calcMargins(iter, combined, base); ! trainMarginStream.println( ! "iteration=" + iter + ", elements=" + trainMargin.size()); ! for (int i= 0; i < trainMargin.size(); i++) ! trainMarginStream.println((Double) trainMargin.get(i)); ! trainMargin= null; // release memory ! // output test scores ! ArrayList testMargin= testSet.calcMargins(iter, combined, base); ! testMarginStream.println( ! "iteration=" + iter + ", elements=" + testMargin.size()); ! for (int i= 0; i < testMargin.size(); i++) ! testMarginStream.println((Double) testMargin.get(i)); ! testMargin.clear(); // release memory ! testMargin= null; } --- 294,302 ---- return; } ! logBoostingTrainTest(trainBoostingStream, trainSet, iter, combined, base); ! logBoostingTrainTest(testBoostingStream, testSet, iter, combined, base); ! trainBoostingStream.flush(); ! testBoostingStream.flush(); ! infoStream.print(" \t# output boosting data #"); } *************** *** 324,337 **** infoStream.println("End time=" + endTime); infoStream.close(); ! if (trainScoresStream != null) ! trainScoresStream.close(); ! if (testScoresStream != null) ! testScoresStream.close(); ! if (trainMarginStream != null) ! trainMarginStream.close(); ! if (testMarginStream != null) ! testMarginStream.close(); ! if (surfStream != null) ! surfStream.close(); log("finished closing output files"); } --- 309,316 ---- infoStream.println("End time=" + endTime); infoStream.close(); ! if (trainBoostingStream != null) ! trainBoostingStream.close(); ! if (testBoostingStream != null) ! testBoostingStream.close(); log("finished closing output files"); } |