From: Sunsern C. <sch...@us...> - 2009-06-08 23:40:53
|
Update of /cvsroot/jboost/jboost/src/jboost/monitor In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv11232/src/jboost/monitor Modified Files: Tag: jboost-2_0 Monitor.java Log Message: jboost 2.0 Index: Monitor.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/monitor/Monitor.java,v retrieving revision 1.13 retrieving revision 1.13.2.1 diff -C2 -d -r1.13 -r1.13.2.1 *** Monitor.java 19 Feb 2009 14:23:29 -0000 1.13 --- Monitor.java 8 Jun 2009 23:40:49 -0000 1.13.2.1 *************** *** 1,4 **** --- 1,5 ---- package jboost.monitor; import java.io.BufferedWriter; + import java.io.ByteArrayOutputStream; import java.io.FileWriter; import java.io.IOException; *************** *** 8,18 **** import java.util.ArrayList; import java.util.Date; import jboost.Predictor; import jboost.booster.Booster; - import jboost.booster.BrownBoost; - import jboost.booster.MulticlassWrapMH; import jboost.booster.RobustBoost; import jboost.controller.Configuration; - import jboost.controller.Configuration; import jboost.examples.ExampleSet; --- 9,17 ---- import java.util.ArrayList; import java.util.Date; + import jboost.Predictor; import jboost.booster.Booster; import jboost.booster.RobustBoost; import jboost.controller.Configuration; import jboost.examples.ExampleSet; *************** *** 24,27 **** --- 23,27 ---- */ public class Monitor { + private static Date startTime; private static Date afterInitTime; *************** *** 40,46 **** private PrintWriter trainBoostingStream; private String trainBoostingFilename; private PrintWriter testBoostingStream; private String testBoostingFilename; ! /** a stream for logging resampling activity private PrintWriter samplingStream; --- 40,50 ---- private PrintWriter trainBoostingStream; private String trainBoostingFilename; + private ByteArrayOutputStream trainBoostingBuffer; private PrintWriter testBoostingStream; private String testBoostingFilename; ! private ByteArrayOutputStream testBoostingBuffer; ! ! ! /** a stream for logging resampling activity private PrintWriter samplingStream; *************** *** 111,115 **** infoStream.println(); infoStream.println("Configuration parameters:\n" + config); ! infoStream.println(""); infoStream.println("FILENAMES"); infoStream.println("specFilename = " + config.getSpecFileName()); --- 115,128 ---- infoStream.println(); infoStream.println("Configuration parameters:\n" + config); ! infoStream.println(); ! ! // RobustBoost: binary case ! if (m_booster instanceof RobustBoost) { ! RobustBoost rb = (RobustBoost)m_booster; ! infoStream.println("RobustBoost parameters:"); ! infoStream.println(rb.getParameters()); ! infoStream.println(); ! } ! infoStream.println("FILENAMES"); infoStream.println("specFilename = " + config.getSpecFileName()); *************** *** 134,137 **** --- 147,153 ---- new FileWriter(testBoostingFilename))); + trainBoostingBuffer = new ByteArrayOutputStream(); + testBoostingBuffer = new ByteArrayOutputStream(); + afterInitTime= new Date(); infoStream.println("Init Start time = " + startTime); *************** *** 142,152 **** infoStream.println("iter \tbound \ttrain \ttest \ttime"); } - // RobustBoost: multiclass case - else if (booster instanceof MulticlassWrapMH) { - Booster b = ((MulticlassWrapMH)booster).m_booster; - if (b instanceof RobustBoost) { - infoStream.println("iter \tbound \ttrain \ttest \ttime"); - } - } else { infoStream.println("iter \tbound \ttrain \ttest"); --- 158,161 ---- *************** *** 186,189 **** --- 195,199 ---- NumberFormat f= new DecimalFormat("0.0000"); + if (iter > 0) infoStream.print("\n"); // RobustBoost: binary case if (m_booster instanceof RobustBoost) { *************** *** 192,204 **** + f.format(trainError) + "\t" + f.format(testError) + "\t" + f.format(currentTime)); } - // RobustBoost: multiclass case - else if (m_booster instanceof MulticlassWrapMH) { - Booster b = ((MulticlassWrapMH)m_booster).m_booster; - if (b instanceof RobustBoost) { - double currentTime = ((RobustBoost)b).getCurrentTime(); - infoStream.print(iter + "\t" + f.format(theoryBound) + "\t" - + f.format(trainError) + "\t" + f.format(testError) + "\t" + f.format(currentTime)); - } - } // otherwise else { --- 202,205 ---- *************** *** 208,212 **** infoStream.flush(); logBoosting(iter, combined, base); - infoStream.println(""); } --- 209,212 ---- *************** *** 274,278 **** // output the weights for (j= 0; j < tWeights[i].length; j++){ ! boostingStream.print(f.format(tWeights[i][j])); if (j != tmp.length -1) boostingStream.print(SEPARATOR); --- 274,279 ---- // output the weights for (j= 0; j < tWeights[i].length; j++){ ! // output it in log scale ! boostingStream.print(f.format(Math.log(tWeights[i][j]))); if (j != tmp.length -1) boostingStream.print(SEPARATOR); *************** *** 319,329 **** /** output the scores distribution of the training set */ private void logBoosting(int iter, Predictor combined, Predictor base) { ! if (boostingPrintRate == 0 && m_booster instanceof BrownBoost) { ! BrownBoost b = (BrownBoost) m_booster; ! if (!b.isFinished()) { ! return; ! } ! } ! if ((boostingPrintRate==0 && !(m_booster instanceof BrownBoost)) || (boostingPrintRate > 0 && boostingPrintRate != iter)) return; --- 320,324 ---- /** 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; *************** *** 331,337 **** if (boostingPrintRate == -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" --- 326,331 ---- if (boostingPrintRate == -1) { // print score when highest order digit in iter changes. ! double m=Math.floor(Math.log(iter) / Math.log(10.0)); ! int t = (int) Math.pow(10.0, m); if (iter == 0) t= 1; // fix bug in "pow" *************** *** 339,358 **** return; } logBoostingTrainTest(trainBoostingStream, trainSet, iter, combined, base); logBoostingTrainTest(testBoostingStream, testSet, iter, combined, base); trainBoostingStream.flush(); testBoostingStream.flush(); ! infoStream.print(" \t# output boosting data #"); } /** close the monitor output files */ public void close() throws IOException { endTime= new Date(); ! infoStream.println("End time=" + endTime); infoStream.close(); if (trainBoostingStream != null) trainBoostingStream.close(); if (testBoostingStream != null) testBoostingStream.close(); log("finished closing output files"); } --- 333,383 ---- return; } + + // save to buffer + if (boostingPrintRate == -3) { + trainBoostingBuffer.reset(); + testBoostingBuffer.reset(); + PrintWriter wTrain = new PrintWriter(trainBoostingBuffer); + PrintWriter wTest = new PrintWriter(testBoostingBuffer); + logBoostingTrainTest(wTrain, trainSet, iter, combined, base); + logBoostingTrainTest(wTest, testSet, iter, combined, base); + wTrain.close(); + wTest.close(); + return; + } + logBoostingTrainTest(trainBoostingStream, trainSet, iter, combined, base); logBoostingTrainTest(testBoostingStream, testSet, iter, combined, base); trainBoostingStream.flush(); testBoostingStream.flush(); ! infoStream.print(" \t# output boosting data #"); } /** close the monitor output files */ public void close() throws IOException { + + // print buffer to files + if (boostingPrintRate == -3) { + trainBoostingStream.print(trainBoostingBuffer.toString()); + testBoostingStream.print(testBoostingBuffer.toString()); + infoStream.print(" \t# output boosting data #"); + } + endTime= new Date(); ! infoStream.println("\nEnd time=" + endTime); ! ! // RobustBoost: binary case ! if (m_booster instanceof RobustBoost) { ! RobustBoost rb = (RobustBoost)m_booster; ! infoStream.println("\nrb_t = " + rb.getCurrentTime()); ! } ! infoStream.close(); + if (trainBoostingStream != null) trainBoostingStream.close(); if (testBoostingStream != null) testBoostingStream.close(); + log("finished closing output files"); } |