You can subscribe to this list here.
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(37) |
Jun
(11) |
Jul
(5) |
Aug
|
Sep
(3) |
Oct
(22) |
Nov
|
Dec
(7) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2008 |
Jan
(7) |
Feb
(1) |
Mar
(1) |
Apr
(9) |
May
(1) |
Jun
(2) |
Jul
(8) |
Aug
(7) |
Sep
(29) |
Oct
|
Nov
(1) |
Dec
|
2009 |
Jan
(8) |
Feb
(18) |
Mar
(5) |
Apr
|
May
|
Jun
(12) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Aaron A. <aa...@us...> - 2008-08-15 21:42:02
|
Update of /cvsroot/jboost/jboost/src/jboost/booster In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv25194/src/jboost/booster Modified Files: YabaBoost.java Log Message: Small changes to YabaBoost Index: YabaBoost.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/YabaBoost.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** YabaBoost.java 10 Apr 2008 07:54:17 -0000 1.9 --- YabaBoost.java 15 Aug 2008 21:41:59 -0000 1.10 *************** *** 5,9 **** import jboost.booster.BrownBoost; import jboost.controller.Configuration; - import jboost.controller.ControllerConfiguration; import jboost.booster.MixedBinaryPrediction; --- 5,8 ---- *************** *** 104,109 **** nc = config.getDouble("nc", 0.15); setParams(c1,c2,theta,nc); ! if (config instanceof ControllerConfiguration && ! ((ControllerConfiguration) config).getCostSensitive()) { rpos = config.getDouble("pos_c",1.0); rneg = config.getDouble("neg_c",1.0); --- 103,108 ---- nc = config.getDouble("nc", 0.15); setParams(c1,c2,theta,nc); ! if (config instanceof Configuration && ! ((Configuration) config).getCostSensitive()) { rpos = config.getDouble("pos_c",1.0); rneg = config.getDouble("neg_c",1.0); *************** *** 472,503 **** System.err.println("Average potential difference is too big!"); /* ! m_s = m_oldS; ! System.err.println("Outputting all data to outfile!"); ! dump_everything(vars); ! s = m_c - m_s; ! double old_mu = m_theta - m_c1* ( Math.exp(-s) - Math.exp(-m_c) ); ! double theta_step = 0; ! if(vars.Potential-m_initialPotential > 0) { ! theta_step = - THETA_UPDATE_STEP; ! } else if(vars.Potential-m_initialPotential < 0) { ! theta_step = THETA_UPDATE_STEP/(Math.PI/3); // irrational number ! } ! m_theta += theta_step; ! m_c1 = m_c1 + theta_step / (Math.exp(-(0)) - Math.exp(-m_c)); ! double new_mu = m_theta - m_c1* ( Math.exp(-s) - Math.exp(-m_c) ); ! System.out.println("old_mu="+old_mu+", new_mu="+new_mu); ! double margin = 0; ! s = 0; ! double mu = m_theta - m_c1 * (Math.exp(-s) - Math.exp(-m_c)); ! double sd = Math.sqrt(m_c2 * (Math.exp(-2*s) - Math.exp(-2*m_c))) + FINISH_GAME_NOW; ! double pot = (1 - erf((margin-mu)/sd)) / 2; ! System.out.println("New potential is: " + pot); ! System.out.println("New intial potential is: " + calculatePotential(0, m_c)); ! System.out.println("New theta is:" + m_theta); ! return solve_constraints(hyp_err); */ --- 471,502 ---- System.err.println("Average potential difference is too big!"); /* ! m_s = m_oldS; ! System.err.println("Outputting all data to outfile!"); ! dump_everything(vars); ! s = m_c - m_s; ! double old_mu = m_theta - m_c1* ( Math.exp(-s) - Math.exp(-m_c) ); ! double theta_step = 0; ! if(vars.Potential-m_initialPotential > 0) { ! theta_step = - THETA_UPDATE_STEP; ! } else if(vars.Potential-m_initialPotential < 0) { ! theta_step = THETA_UPDATE_STEP/(Math.PI/3); // irrational number ! } ! m_theta += theta_step; ! m_c1 = m_c1 + theta_step / (Math.exp(-(0)) - Math.exp(-m_c)); ! double new_mu = m_theta - m_c1* ( Math.exp(-s) - Math.exp(-m_c) ); ! System.out.println("old_mu="+old_mu+", new_mu="+new_mu); ! double margin = 0; ! s = 0; ! double mu = m_theta - m_c1 * (Math.exp(-s) - Math.exp(-m_c)); ! double sd = Math.sqrt(m_c2 * (Math.exp(-2*s) - Math.exp(-2*m_c))) + FINISH_GAME_NOW; ! double pot = (1 - erf((margin-mu)/sd)) / 2; ! System.out.println("New potential is: " + pot); ! System.out.println("New intial potential is: " + calculatePotential(0, m_c)); ! System.out.println("New theta is:" + m_theta); ! return solve_constraints(hyp_err); */ *************** *** 678,682 **** double ret = norm * Math.exp(- Math.pow((margin-mu)/sd,2) / 2.0); if (USE_CONFIDENCE) { ! if (margin < mu) ret = 0; else ret = 2*ret; } --- 677,681 ---- double ret = norm * Math.exp(- Math.pow((margin-mu)/sd,2) / 2.0); if (USE_CONFIDENCE) { ! if (margin < mu) ret = 0; else ret = 2*ret; } *************** *** 729,743 **** } /* ! System.out.println("S:"+s); ! System.out.println("mu:"+mu); ! System.out.println("sd:"+sd); ! System.out.println("margin:"+margin); ! System.out.println("pot:"+pot); ! System.out.println("pot:"+ -(pot*2 -1)); System.out.println("YabaBoost:\n" ! + "\t m_c: " + m_c + "\n" ! + "\t m_c1: " + m_c1 + "\n" ! + "\t m_c2: " + m_c2 + "\n" ! + "\t m_theta: " + m_theta + "\n"); */ return pot; --- 728,742 ---- } /* ! System.out.println("S:"+s); ! System.out.println("mu:"+mu); ! System.out.println("sd:"+sd); ! System.out.println("margin:"+margin); ! System.out.println("pot:"+pot); ! System.out.println("pot:"+ -(pot*2 -1)); System.out.println("YabaBoost:\n" ! + "\t m_c: " + m_c + "\n" ! + "\t m_c1: " + m_c1 + "\n" ! + "\t m_c2: " + m_c2 + "\n" ! + "\t m_theta: " + m_theta + "\n"); */ return pot; |
From: Aaron A. <aa...@us...> - 2008-08-15 21:38:19
|
Update of /cvsroot/jboost/jboost/src/jboost/controller In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv23932/controller Modified Files: Configuration.java Controller.java ControllerTest.java Log Message: More commits related to removing ControllerConfiguration, Also now outputs training and testing info files at the end of all BrownBoost classes Index: ControllerTest.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/controller/ControllerTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ControllerTest.java 27 May 2007 11:20:23 -0000 1.2 --- ControllerTest.java 15 Aug 2008 21:38:13 -0000 1.3 *************** *** 19,23 **** private Controller m_controller; ! private ControllerConfiguration m_config; /* * @see TestCase#setUp() --- 19,23 ---- private Controller m_controller; ! private Configuration m_config; /* * @see TestCase#setUp() *************** *** 28,32 **** File.separatorChar + "src/jboost/controller/jboost.config"}; System.out.println(args[1]); ! m_config= new ControllerConfiguration(null, args); Monitor.init_log(m_config); m_controller= new Controller(m_config); --- 28,32 ---- File.separatorChar + "src/jboost/controller/jboost.config"}; System.out.println(args[1]); ! m_config= new Configuration(null, args); Monitor.init_log(m_config); m_controller= new Controller(m_config); *************** *** 38,42 **** File.separatorChar + "src/jboost/controller/weightedjboost.config"}; System.out.println(args[1]); ! m_config= new ControllerConfiguration(null, args); Monitor.init_log(m_config); m_controller= new Controller(m_config); --- 38,42 ---- File.separatorChar + "src/jboost/controller/weightedjboost.config"}; System.out.println(args[1]); ! m_config= new Configuration(null, args); Monitor.init_log(m_config); m_controller= new Controller(m_config); *************** *** 217,221 **** String[] args= {"-CONFIG", System.getProperty("jboost.home") + File.separatorChar + "src/jboost/controller/weightedjboost.config"}; ! m_config= new ControllerConfiguration(null, args); // learn for 40 rounds, write to file, reload and learn for 40 more rounds m_config.addOption("numRounds", Integer.toString(rounds/2)); --- 217,221 ---- String[] args= {"-CONFIG", System.getProperty("jboost.home") + File.separatorChar + "src/jboost/controller/weightedjboost.config"}; ! m_config= new Configuration(null, args); // learn for 40 rounds, write to file, reload and learn for 40 more rounds m_config.addOption("numRounds", Integer.toString(rounds/2)); *************** *** 261,265 **** String[] args= {"-CONFIG", System.getProperty("jboost.home") + File.separatorChar + "src/jboost/controller/multilabeljboost.config"}; ! m_config= new ControllerConfiguration(null, args); m_config.addOption("numRounds", Integer.toString(rounds/2)); m_config.addOption("booster_type", "jboost.booster.LogLossBoost"); --- 261,265 ---- String[] args= {"-CONFIG", System.getProperty("jboost.home") + File.separatorChar + "src/jboost/controller/multilabeljboost.config"}; ! m_config= new Configuration(null, args); m_config.addOption("numRounds", Integer.toString(rounds/2)); m_config.addOption("booster_type", "jboost.booster.LogLossBoost"); *************** *** 304,308 **** String[] args= {"-CONFIG", System.getProperty("jboost.home") + File.separatorChar + "src/jboost/controller/weightedjboost.config"}; ! m_config= new ControllerConfiguration(null, args); m_config.addOption("numRounds", Integer.toString(rounds)); m_config.addOption("booster_type", "jboost.booster.LogLossBoost"); --- 304,308 ---- String[] args= {"-CONFIG", System.getProperty("jboost.home") + File.separatorChar + "src/jboost/controller/weightedjboost.config"}; ! m_config= new Configuration(null, args); m_config.addOption("numRounds", Integer.toString(rounds)); m_config.addOption("booster_type", "jboost.booster.LogLossBoost"); *************** *** 310,316 **** m_controller.startLearning(); m_controller.outputLearningResults(); ! m_config.addOption(ControllerConfiguration.SERIALIZED_INPUT,"src/jboost/controller/weightedatree.serialized"); ! m_config.addOption(ControllerConfiguration.SAMPLE_TRAINING_DATA, "true"); ! m_config.addOption(ControllerConfiguration.SAMPLE_THRESHOLD_WEIGHT, "0.005"); m_controller= new Controller(m_config); m_controller.startLearning(); --- 310,316 ---- m_controller.startLearning(); m_controller.outputLearningResults(); ! m_config.addOption(Configuration.SERIALIZED_INPUT,"src/jboost/controller/weightedatree.serialized"); ! m_config.addOption(Configuration.SAMPLE_TRAINING_DATA, "true"); ! m_config.addOption(Configuration.SAMPLE_THRESHOLD_WEIGHT, "0.005"); m_controller= new Controller(m_config); m_controller.startLearning(); Index: Configuration.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/controller/Configuration.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Configuration.java 5 Dec 2007 06:39:57 -0000 1.8 --- Configuration.java 15 Aug 2008 21:38:13 -0000 1.9 *************** *** 3,6 **** --- 3,7 ---- import java.io.BufferedReader; import java.io.FileNotFoundException; + import java.io.File; import java.io.IOException; import java.util.HashMap; *************** *** 16,20 **** * This class provides the utilities for parsing the command line which * specifies the setting of the options in the different packages. [...1388 lines suppressed...] public Command(String n, String v) { ! name= n; ! value= v; } public String getValue() { ! checkCount++; ! return (value); } public int getCount() { ! return (checkCount); } public String toString() { ! String retval= new String("-"); ! retval += name + " " + value; ! return (retval); } } + Index: Controller.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/controller/Controller.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Controller.java 13 Aug 2008 19:51:31 -0000 1.9 --- Controller.java 15 Aug 2008 21:38:13 -0000 1.10 *************** *** 57,61 **** private Vector m_splitterBuilderVector; // configuration object ! private ControllerConfiguration m_config; // m_monitor private Monitor m_monitor; --- 57,61 ---- private Vector m_splitterBuilderVector; // configuration object ! private Configuration m_config; // m_monitor private Monitor m_monitor; *************** *** 73,82 **** public static void main(String[] argv) { ! ControllerConfiguration configuration= null; Controller controller= null; try { // read the command line ! configuration= new ControllerConfiguration(DEFAULT_MANPAGE, argv); Monitor.init_log(configuration); configuration.checkCommandValues(); --- 73,82 ---- public static void main(String[] argv) { ! Configuration configuration= null; Controller controller= null; try { // read the command line ! configuration= new Configuration(DEFAULT_MANPAGE, argv); Monitor.init_log(configuration); configuration.checkCommandValues(); *************** *** 103,107 **** * Build a default controller */ ! public Controller(ControllerConfiguration configuration) throws Exception { m_config= configuration; init(); --- 103,107 ---- * Build a default controller */ ! public Controller(Configuration configuration) throws Exception { m_config= configuration; init(); *************** *** 161,165 **** // load serialized tree, if necessary ! String serializedFile= m_config.getString(ControllerConfiguration.SERIALIZED_INPUT, null); if (serializedFile != null) { m_serializedTree= loadTree(serializedFile); --- 161,165 ---- // load serialized tree, if necessary ! String serializedFile= m_config.getString(Configuration.SERIALIZED_INPUT, null); if (serializedFile != null) { m_serializedTree= loadTree(serializedFile); *************** *** 444,448 **** System.out.println(); ! if (Monitor.logLevel > 3) m_monitor.logIteration( iterNo, --- 444,448 ---- System.out.println(); ! if (Monitor.logLevel > 1) m_monitor.logIteration( iterNo, *************** *** 581,586 **** int counter= 0; start= System.currentTimeMillis(); ! boolean sampling= m_config.getBool(ControllerConfiguration.SAMPLE_TRAINING_DATA, false); ! double threshold= m_config.getDouble(ControllerConfiguration.SAMPLE_THRESHOLD_WEIGHT, 0.500); while ((example= m_trainStream.getExample()) != null) { --- 581,586 ---- int counter= 0; start= System.currentTimeMillis(); ! boolean sampling= m_config.getBool(Configuration.SAMPLE_TRAINING_DATA, false); ! double threshold= m_config.getDouble(Configuration.SAMPLE_THRESHOLD_WEIGHT, 0.500); while ((example= m_trainStream.getExample()) != null) { |
From: Aaron A. <aa...@us...> - 2008-08-15 21:38:17
|
Update of /cvsroot/jboost/jboost/src/jboost/monitor In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv23932/monitor Modified Files: Monitor.java Log Message: More commits related to removing ControllerConfiguration, Also now outputs training and testing info files at the end of all BrownBoost classes Index: Monitor.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/monitor/Monitor.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Monitor.java 4 Jul 2008 22:34:57 -0000 1.10 --- Monitor.java 15 Aug 2008 21:38:13 -0000 1.11 *************** *** 11,15 **** import jboost.booster.Booster; import jboost.booster.BrownBoost; ! import jboost.controller.ControllerConfiguration; import jboost.controller.Configuration; import jboost.examples.ExampleSet; --- 11,15 ---- import jboost.booster.Booster; import jboost.booster.BrownBoost; ! import jboost.controller.Configuration; import jboost.controller.Configuration; import jboost.examples.ExampleSet; *************** *** 95,99 **** */ public Monitor(Booster booster, ExampleSet training, ! ExampleSet testing, ControllerConfiguration config) { trainSet= training; testSet= testing; --- 95,99 ---- */ public Monitor(Booster booster, ExampleSet training, ! ExampleSet testing, Configuration config) { trainSet= training; testSet= testing; *************** *** 128,139 **** 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(); infoStream.println("Init Start time = " + startTime); --- 128,138 ---- boostingPrintRate= config.getInt("a", 0); ! trainBoostingStream = new PrintWriter( ! new BufferedWriter( ! new FileWriter(trainBoostingFilename))); ! testBoostingStream = new PrintWriter( ! new BufferedWriter( ! new FileWriter(testBoostingFilename))); ! afterInitTime= new Date(); infoStream.println("Init Start time = " + startTime); *************** *** 278,300 **** /** 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= ! 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; } ! logBoostingTrainTest(trainBoostingStream, trainSet, iter, combined, base); ! logBoostingTrainTest(testBoostingStream, testSet, iter, combined, base); ! trainBoostingStream.flush(); ! testBoostingStream.flush(); ! infoStream.print(" \t# output boosting data #"); } --- 277,306 ---- /** 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; ! ! 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" ! if ((iter % t) != 0) ! return; ! } ! logBoostingTrainTest(trainBoostingStream, trainSet, iter, combined, base); ! logBoostingTrainTest(testBoostingStream, testSet, iter, combined, base); ! trainBoostingStream.flush(); ! testBoostingStream.flush(); ! infoStream.print(" \t# output boosting data #"); } |
From: Aaron A. <aa...@us...> - 2008-08-15 21:31:51
|
Update of /cvsroot/jboost/jboost/src/jboost/controller In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv21124 Removed Files: ControllerConfiguration.java Log Message: Removing the CVS file for ControllerConfiguration. Functionallity has already been removed and placed into Configuration.java. Aaron --- ControllerConfiguration.java DELETED --- |
From: Aaron A. <aa...@us...> - 2008-08-13 19:51:34
|
Update of /cvsroot/jboost/jboost/src/jboost/controller In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv13148/src/jboost/controller Modified Files: Controller.java Log Message: Controller can now be built (commented out BrownBoost positive/negative initial potential calls) -- Aaron Index: Controller.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/controller/Controller.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Controller.java 3 Jun 2008 03:17:39 -0000 1.8 --- Controller.java 13 Aug 2008 19:51:31 -0000 1.9 *************** *** 146,151 **** System.out.println("\tPotential loss of m_booster: " + b.getInitialPotential()); if (b.isCostSensitive()) { ! System.out.println("\tPotential loss of positive examples m_booster: " + b.getPositiveInitialPotential()); ! System.out.println("\tPotential loss of negative examples m_booster: " + b.getNegativeInitialPotential()); } System.exit(0); --- 146,151 ---- System.out.println("\tPotential loss of m_booster: " + b.getInitialPotential()); if (b.isCostSensitive()) { ! //System.out.println("\tPotential loss of positive examples m_booster: " + b.getPositiveInitialPotential()); ! //System.out.println("\tPotential loss of negative examples m_booster: " + b.getNegativeInitialPotential()); } System.exit(0); |
From: Aaron A. <aa...@us...> - 2008-07-31 22:17:00
|
Update of /cvsroot/jboost/jboost/scripts In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv19445 Modified Files: atreeplot.R Added Files: marginplot.R parse.R perlre.R Log Message: marginplot is now finished, made atreeplot a proper function instead of a command line script Index: atreeplot.R =================================================================== RCS file: /cvsroot/jboost/jboost/scripts/atreeplot.R,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** atreeplot.R 30 Jul 2008 05:42:06 -0000 1.1 --- atreeplot.R 31 Jul 2008 22:16:52 -0000 1.2 *************** *** 1,121 **** ! tree2graph <- function() { ! ! } ! ! print.usage <- function() { ! show("\t -i (--info) file.info \t File containing runtime information (required) \n") ! show("\t -s (--spec) file.spec \t Spec file (optional, will default to spec file in info file) \n") ! show("\t -t (--tree) file.tree \t File containing the ADTree in text format (required) \n") ! show("\t -d (--dir) directory \t Directory to use (optional, defaults to '.') \n") ! show("\t -l (--labels) \t Flip the labels (-1 becomes +1) (optional)\n") ! show("\t --truncate \t Truncate threshold values to increase readability\n") ! show("\t --threshold num \t A given depth to stop the tree from becoming too large. (optional) \n") ! show("\t -h (--help) \t Print this usage information \n") ! } ! ! parse.args <- function(argv) { ! tree = "" ! flip = FALSE ! depth = 0 ! spec = "" ! for (i in 1:length(argv)) { ! arg = argv[i] ! if (arg=="--tree") { ! tree = argv[i+1] ! } else if (arg=="--flip") { ! flip = TRUE ! } else if (arg=="--depth") { ! depth = as.numeric(argv[i+1]) ! } else if (arg=="--spec") { ! spec = argv[i+1] ! } ! } ! return(list(tree=tree, flip=flip, depth=depth, spec=spec)) ! } ! ! parse.labels <- function(specfile) { ! lines = readLines(specfile) ! labels = list() ! for (i in 1:length(lines)) { ! line = lines[i] ! line = sub("^.*labels\\s*\\((.*)\\).*$", "labels \\1", line, perl=TRUE) ! if (substr(line, 1, 6)=="labels") { ! labels = unlist(strsplit(substr(line,7,9999999),",")) ! } ! } ! labels <- ! return(labels) ! } ! ! ! argv <- commandArgs() ! tmp <- parse.args(argv) ! treefile <- tmp$tree ! specfile <- tmp$spec ! flip.labels <- tmp$flip ! depth <- tmp$depth ! ! if (treefile=="" || specfile=="") { ! print.usage() ! q("no") ! } ! ! show(paste("Tree File:", treefile)) ! show(paste("Spec File:", specfile)) ! ! labels = parse.labels(specfile) ! num.labels = length(labels); ! if (num.labels < 2) { ! show("There don't seem to be enough labels in the spec file...") ! show("Labels found:") ! show(labels) ! q("no") ! } ! show(c("Labels are:", labels)) ! ! lines = readLines(treefile) ! ! ! perl.re <- function(str, expr) { ! ret = c("FALSE") ! #show(c(str, expr)) ! is.present <- grep(expr, c(str,"as"), perl=TRUE) ! #show(is.present) ! if (length(is.present) > 0) { ! # get number of captures ! expr <- unlist(strsplit(expr, NULL)) ! #show(expr) ! out <- "TRUE" ! k <- 0 ! for (i in 1:length(expr)) { ! if (paste(expr[i-1],expr[i],sep="")=="\\(") { next; } ! if (expr[i]=="(") { ! k <- k + 1 ! out = paste(out, paste("\\",k,sep=""), sep="|") ! #show(out) ! } ! } ! expr <- paste(expr, collapse="") ! ret <- unlist(strsplit(sub(expr, out, str), "|")) ! #show(c(expr, out, str)) ! ret <- sub(expr, out, str) ! ret <- unlist(strsplit(ret, "\\|")) ! #show(ret) ! } ! return(ret) ! } ! ! ! ! ! ! ! ! ! ! library(igraph) - g <- graph.empty() - g$layout <- layout.reingold.tilford --- 1,5 ---- ! source("parse.R") ! source("perlre.R") library(igraph) *************** *** 143,146 **** --- 27,31 ---- #prediction 1: BinaryPrediction. p(1)= -0.8696119797754972 + # Example of binary tree #0 [R] prediction = BinaryPrediction. p(1)= 0.11523437500000003 #1 [R.0] Splitter = InequalitySplitter. char_freq_bang < 0.0785 *************** *** 151,295 **** #29 [R.0:1.0:1] prediction = BinaryPrediction. p(1)= -0.19531250000000003 ! index.to.vertex <- list() ! i <- 1 ! depth <- 0 ! width <- 0 ! while (i <= length(lines)) { ! index <- "" ! type <- "" ! label <- "" ! ! line = lines[i] ! #show(sprintf("Line is: %s", line)) ! x <- perl.re(line, "^([0-9]+)\\s*\\[(.*)\\].*Splitter\\s*=\\s*(.*)$") ! if (x[1]=="TRUE") { ! #show("Setting type to splitter") ! type = "splitter"; ! iteration = x[2]; ! index = x[3]; ! label = x[4]; ! #show(sprintf("Label of splitter is: %s", label)) } ! x <- perl.re(line, "^([0-9]+)\\s*\\[(.*)\\].*prediction\\s*=\\s*(.*)$") ! if (x[1]=="TRUE") { ! #show("Setting type to predictor") ! type = "predictor"; ! iteration = x[2] ! index = x[3] ! label = x[4] ! predType = x[4]; ! #show(c(type, iteration, index, label)) ! x <- perl.re(predType, ".*MultiPrediction.*") ! y <- perl.re(predType, ".*BinaryPrediction.*=(.*)") if (x[1]=="TRUE") { ! label = ""; ! for (j in 1:num.labels) { ! i <- i + 1 ! line = lines[i] ! #prediction 0: BinaryPrediction. p(1)= -0.6496414920651304 ! x <- perl.re(line,"^.*prediction.*=\\s*(.*)") ! #show(sprintf("Prediction Binary value is %0.4f", as.numeric(x[2]))) ! if (x[1]=="TRUE") { ! pred = x[2] ! } else { ! break } ! if (flip.labels) { ! pred = paste("-",pred,sep="") } - label = paste(label, labels[j], ": ", pred, "\n", sep=""); - } - } else if (y[1]=="TRUE") { - label = y[2] - if(flip.labels) { - label = as.numeric(label) - label = - label - label = as.character(label) } } - } ! #show(sprintf("Type is: %s", type)) ! #show(sprintf("Index is: %s", index)) ! #show(sprintf("Label is: %s", label)) ! if (type=="splitter") { ! g <- add.vertices(g, 1) ! V(g)$frame.color[length(V(g))] <- "blue" ! V(g)$color[length(V(g))] <- "white" ! V(g)$label[length(V(g))] <- paste(iteration, label, sep=": ") ! V(g)$label.cex <- 1.4 ! V(g)$shape[length(V(g))] <- "rectangle" ! V(g)$label.color <- "black" ! ! this.vertex <- length(V(g))-1 ! index.to.vertex[[index]] = this.vertex ! ! parent.index <- substr(index,1,nchar(index)-2) ! parent.vertex <- index.to.vertex[[parent.index]] ! ! g <- add.edges(g, c(parent.vertex,this.vertex)) ! E(g)$color[length(E(g))] <- "black" ! E(g)$width[length(E(g))] <- 5 ! } ! ! if (type=="predictor") { ! g <- add.vertices(g, 1) ! V(g)$frame.color[length(V(g))] <- "yellow" ! V(g)$color[length(V(g))] <- "white" ! V(g)$label[length(V(g))] <- label ! V(g)$shape[length(V(g))] <- "rectangle" ! V(g)$label.cex <- 1 ! V(g)$label.color <- "black" ! this.vertex <- length(V(g))-1 ! index.to.vertex[[index]] = this.vertex - if (index!="R") { parent.index <- substr(index,1,nchar(index)-2) parent.vertex <- index.to.vertex[[parent.index]] g <- add.edges(g, c(parent.vertex,this.vertex)) ! ans <- substr(index,nchar(index), nchar(index)) ! if (ans=="0") { ! E(g)$color[length(E(g))] <- "red" ! E(g)$label[length(E(g))] <- "False" ! } else if (ans=="1") { ! E(g)$color[length(E(g))] <- "green" ! E(g)$label[length(E(g))] <- "True" ! } else { ! error(paste("The splitter has an invalid return value!\n 1 or 0 expected, recieved", ans)) ! } ! E(g)$label.cex <- 1.5 ! E(g)$label.color <- "black" ! E(g)$width[length(E(g))] <- 10 ! } ! } ! w <- warnings() ! if (length(w)>0) { ! show(w) } - i <- i + 1 - } ! # Flip so that the root is at the top ! coords <- g$layout(g) ! coords[,2] <- max(coords[,2])-coords[,2] ! ! fname <- sprintf("%s.eps", treefile) ! show(sprintf("Writing file to '%s'", fname)) ! postscript(file=sprintf("%s.eps", treefile), fonts=c("serif", "Palatino"), paper="special", width=70, height=40, horizontal=TRUE) ! plot(1, type="n", axes=FALSE, xlab=NA, ylab=NA, xlim=c(-1,1), ylim=c(-1,1)) ! sw <- strwidth(paste("", V(g)$label, "")) ! sh <- strheight(paste("", V(g)$label, "")) ! plot(g, add=TRUE, layout=coords, vertex.size=sw*110, vertex.size2=sh*100*3) ! dev.off() --- 36,190 ---- #29 [R.0:1.0:1] prediction = BinaryPrediction. p(1)= -0.19531250000000003 ! ! plot.atree <- function(treefile, specfile, flip.labels=F, depth=-1, width=-1, height=-1) { ! labels = parse.labels(specfile) ! num.labels = length(labels); ! if (num.labels < 2) { ! show("There don't seem to be enough labels in the spec file...") ! show("Labels found:") ! show(labels) ! return } + show(c("Labels are:", labels)) ! lines = readLines(treefile) ! ! g <- graph.empty() ! g$layout <- layout.reingold.tilford ! index.to.vertex <- list() ! i <- 1 ! while (i <= length(lines)) { ! index <- "" ! type <- "" ! label <- "" ! ! line = lines[i] ! #show(sprintf("Line is: %s", line)) ! x <- perl.re(line, "^([0-9]+)\\s*\\[(.*)\\].*Splitter\\s*=\\s*(.*)$") if (x[1]=="TRUE") { ! #show("Setting type to splitter") ! type = "splitter"; ! iteration = x[2]; ! index = x[3]; ! label = x[4]; ! #show(sprintf("Label of splitter is: %s", label)) ! } ! ! x <- perl.re(line, "^([0-9]+)\\s*\\[(.*)\\].*prediction\\s*=\\s*(.*)$") ! if (x[1]=="TRUE") { ! #show("Setting type to predictor") ! type = "predictor"; ! iteration = x[2] ! index = x[3] ! label = x[4] ! predType = x[4]; ! #show(c(type, iteration, index, label)) ! x <- perl.re(predType, ".*MultiPrediction.*") ! y <- perl.re(predType, ".*BinaryPrediction.*=(.*)") ! if (x[1]=="TRUE") { ! label = ""; ! for (j in 1:num.labels) { ! i <- i + 1 ! line = lines[i] ! #prediction 0: BinaryPrediction. p(1)= -0.6496414920651304 ! x <- perl.re(line,"^.*prediction.*=\\s*(.*)") ! #show(sprintf("Prediction Binary value is %0.4f", as.numeric(x[2]))) ! if (x[1]=="TRUE") { ! pred = x[2] ! } else { ! break ! } ! if (flip.labels) { ! pred = paste("-",pred,sep="") ! } ! label = paste(label, labels[j], ": ", pred, "\n", sep=""); } ! } else if (y[1]=="TRUE") { ! label = y[2] ! if(flip.labels) { ! label = as.numeric(label) ! label = - label ! label = as.character(label) } } } ! #show(sprintf("Type is: %s", type)) ! #show(sprintf("Index is: %s", index)) ! #show(sprintf("Label is: %s", label)) ! if (type=="splitter") { ! g <- add.vertices(g, 1) ! V(g)$frame.color[length(V(g))] <- "blue" ! V(g)$color[length(V(g))] <- "white" ! V(g)$label[length(V(g))] <- paste(iteration, label, sep=": ") ! V(g)$label.cex <- 1.4 ! V(g)$shape[length(V(g))] <- "rectangle" ! V(g)$label.color <- "black" ! this.vertex <- length(V(g))-1 ! index.to.vertex[[index]] = this.vertex parent.index <- substr(index,1,nchar(index)-2) parent.vertex <- index.to.vertex[[parent.index]] g <- add.edges(g, c(parent.vertex,this.vertex)) + E(g)$color[length(E(g))] <- "black" + E(g)$width[length(E(g))] <- 5 + } ! if (type=="predictor") { ! g <- add.vertices(g, 1) ! V(g)$frame.color[length(V(g))] <- "yellow" ! V(g)$color[length(V(g))] <- "white" ! V(g)$label[length(V(g))] <- label ! V(g)$shape[length(V(g))] <- "rectangle" ! V(g)$label.cex <- 1 ! V(g)$label.color <- "black" ! this.vertex <- length(V(g))-1 ! index.to.vertex[[index]] = this.vertex + if (index!="R") { + parent.index <- substr(index,1,nchar(index)-2) + parent.vertex <- index.to.vertex[[parent.index]] + g <- add.edges(g, c(parent.vertex,this.vertex)) + ans <- substr(index,nchar(index), nchar(index)) + if (ans=="0") { + E(g)$color[length(E(g))] <- "red" + E(g)$label[length(E(g))] <- "False" + } else if (ans=="1") { + E(g)$color[length(E(g))] <- "green" + E(g)$label[length(E(g))] <- "True" + } else { + error(paste("The splitter has an invalid return value!\n 1 or 0 expected, recieved", ans)) + } + E(g)$label.cex <- 1.5 + E(g)$label.color <- "black" + E(g)$width[length(E(g))] <- 10 + } + } ! w <- warnings() ! if (length(w)>0) { ! show(w) ! } ! i <- i + 1 } + # Flip so that the root is at the top + coords <- g$layout(g) + coords[,2] <- max(coords[,2])-coords[,2] ! fname <- sprintf("%s.eps", treefile) ! show(sprintf("Writing file to '%s'", fname)) ! postscript(file=sprintf("%s.eps", treefile), fonts=c("serif", "Palatino"), paper="special", width=70, height=40, horizontal=TRUE) ! plot(1, type="n", axes=FALSE, xlab=NA, ylab=NA, xlim=c(-1,1), ylim=c(-1,1)) ! sw <- strwidth(paste("", V(g)$label, "")) ! sh <- strheight(paste("", V(g)$label, "")) ! plot(g, add=TRUE, layout=coords, vertex.size=sw*110, vertex.size2=sh*100*3) ! dev.off() ! } --- NEW FILE: marginplot.R --- source("parse.R") get.pdfs <- function(x, show.scores, show.sep) { pdfs <- list() for (i in 1:length(x)) { pdfs[[i]] <- list() margins <- sapply(x[[i]]$data, function(d){return(d$margin)}) if (show.scores || show.sep) { scores <- sapply(x[[i]]$data, function(d){return(d$score)}) #scores * margins } else { pdfs[[i]]$x <- sort(margins) pdfs[[i]]$y <- (1:length(margins))/length(margins) } } return(pdfs) } plot.margin <- function(infofile, specfile, datafile="", iteration=-1, outname=paste(infofile,"margin","eps",sep="."), show.scores=F, show.sep=F, ...) { # Get the data and needed iterations x <- parse.info(infofile, specfile) x <- get.iters(x, iteration) # Get the cumulative pdfs for the score/margin pdfs <- get.pdfs(x,show.scores,show.sep) # Set up some plot parameters xlabel <- "Margins" # y \\Sigma_t \\alpha h_t(x)" if (show.scores) { xlabel <- "Scores" # \\Sigma_t \\alpha h_t(x)" } ylabel <- "Cumulative Distribution" title <- paste("Margins for", infofile) # Plot the margin pdfs postscript(file=outname) plot(0, 0, type="n", xlim=c(-1,1), ylim=c(0,1), main=title, xlab=xlabel, ylab=ylabel, ...) for (i in 1:length(pdfs)) { lines(pdfs[[i]]$x, pdfs[[1]]$y) } dev.off() } --- NEW FILE: perlre.R --- perl.re <- function(str, expr) { ret = c("FALSE") #show(c(str, expr)) is.present <- grep(expr, c(str,"as"), perl=TRUE) #show(is.present) if (length(is.present) > 0) { # get number of captures expr <- unlist(strsplit(expr, NULL)) #show(expr) out <- "TRUE" k <- 0 for (i in 1:length(expr)) { if (paste(expr[i-1],expr[i],sep="")=="\\(") { next; } if (expr[i]=="(") { k <- k + 1 out = paste(out, paste("\\",k,sep=""), sep="|") #show(out) } } expr <- paste(expr, collapse="") ret <- unlist(strsplit(sub(expr, out, str), "|")) #show(c(expr, out, str)) ret <- sub(expr, out, str) ret <- unlist(strsplit(ret, "\\|")) #show(ret) } return(ret) } --- NEW FILE: parse.R --- parse.spec <- function(specfile) { lines = readLines(specfile) labels = list() for (i in 1:length(lines)) { line = lines[i] line = sub("^.*labels\\s*\\((.*)\\).*$", "labels \\1", line, perl=TRUE) if (substr(line, 1, 6)=="labels") { labels = unlist(strsplit(substr(line,7,9999999),",")) } } return(list(labels=labels)) } parse.labels <- function(specfile) { lines = readLines(specfile) labels = list() for (i in 1:length(lines)) { line = lines[i] line = sub("^.*labels\\s*\\((.*)\\).*$", "labels \\1", line, perl=TRUE) if (substr(line, 1, 6)=="labels") { labels = unlist(strsplit(substr(line,7,9999999),",")) } } return(labels) } parse.infoline <- function(line, num.classes) { s <- unlist(strsplit(line, ":")) id <- as.numeric(s[1]) margin <- as.numeric(s[2]) if (num.classes <= 2) { score <- as.numeric(s[3]) label <- as.numeric(s[4]) } else { score <- as.numeric(unlist(strsplit(s[3],","))) label <- as.numeric(unlist(strsplit(s[4],","))) } return(list(id=id, margin=margin, score=score, label=label)) } parse.params <- function(param.line) { s <- unlist(strsplit(param.line, ":")) iterstr <- unlist(strsplit(s[1], "=")) iter <- as.numeric(iterstr[2]) elts <- unlist(strsplit(s[2], "=")) num.examples <- as.numeric(elts[2]) boost.params <- unlist(strsplit(s[3], "=")) boost.params <- c("booster", boost.params[2:length(boost.params)]) boost.params <- paste(boost.params, collapse="=") return( list(iter=iter, num.examples=num.examples, boost.params=boost.params) ) } parse.info <- function(fname,specname) { labels <- parse.labels(specname) num.classes <- length(labels) con <- file(fname, open="r") param.line <- scan(con, what="raw", nlines=1, sep="\n", quiet=T) params <- parse.params(param.line) num.examples <- params$num.examples example.lines <- scan(con, what="raw", nlines=num.examples, sep="\n", quiet=T) #show(example.lines) parsed.iters = list() i <- 0 while(TRUE) { i <- i + 1 parsed.iters[[i]] <- list() parsed.iters[[i]]$params <- parse.params(param.line) parsed.iters[[i]]$data <- lapply(example.lines, parse.infoline, num.classes=num.classes) param.line <- scan(con, what="raw", nlines=1, sep="\n", quiet=T) if (length(param.line)==0) { break; } example.lines <- scan(con, what="raw", nlines=num.examples, sep="\n", quiet=T) } close(con) return(parsed.iters) } get.iters <- function(x, iters) { ret <- list() if (length(iters)==1) { if (iters < 1) { ret[[1]] <- x[[length(x)]] } else { ret[[1]] <- x[[iters]] } } else { i <- 1 for (j in 1:length(x)) { if (j %in% iters) { ret[[i]] <- x[[j]] i <- i + 1 } } } return(ret) } print.usage <- function() { show("\t -i (--info) file.info \t File containing runtime information (required) \n") show("\t -s (--spec) file.spec \t Spec file (optional, will default to spec file in info file) \n") show("\t -t (--tree) file.tree \t File containing the ADTree in text format (required) \n") show("\t -d (--dir) directory \t Directory to use (optional, defaults to '.') \n") show("\t -l (--labels) \t Flip the labels (-1 becomes +1) (optional)\n") show("\t --truncate \t Truncate threshold values to increase readability\n") show("\t --threshold num \t A given depth to stop the tree from becoming too large. (optional) \n") show("\t -h (--help) \t Print this usage information \n") } parse.args <- function(argv) { tree = "" flip = FALSE depth = 0 spec = "" for (i in 1:length(argv)) { arg = argv[i] if (arg=="--tree") { tree = argv[i+1] } else if (arg=="--flip") { flip = TRUE } else if (arg=="--depth") { depth = as.numeric(argv[i+1]) } else if (arg=="--spec") { spec = argv[i+1] } } return(list(tree=tree, flip=flip, depth=depth, spec=spec)) } |
From: Aaron A. <aa...@us...> - 2008-07-31 22:15:39
|
Update of /cvsroot/jboost/jboost/scripts In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv18899 Added Files: DESCRIPTION README Log Message: meta files for the jboost CRAN package --- NEW FILE: README --- How to use scripts ----------------- Requirements: * R (version 2.6 or higher) * igraph (R package, can be obtained via install.packages or CRAN) * jboost (R package, can be obtained via install.packages or CRAN) The best way to use the scripts is to install the jboost package. This can be done by using the 'install.packages()' from R or by downloading the JBoost package from CRAN and installing via 'R CMD INSTALL jboost'. How to make the package: -------------------------- for (f in dir(pattern=".R$")) source(f) rm(f) package.skeleton("jboost", ls(), force=TRUE) system(paste("cp DESCRIPTION ", "jboost", "/DESCRIPTION", sep="")) system(paste("rm ", "jboost", "/Read-and-delete-me", sep="")) system(paste("R CMD build", "jboost")) --- NEW FILE: DESCRIPTION --- Package: jboost Version: 0.1 Date: 2008-07-31 Title: Plotting JBoost output Author: Aaron Arvey <aa...@cs...> Maintainer: Aaron Arvey <aa...@cs...> Depends: R (>= 2.6.0), igraph Suggests: lattice Description: Boosting can be analyzed in many ways. These functions help visualize margins, scores, atrees, error rates, early stopping, and other related tasks. License: GPL (>= 2) URL: http://jboost.sourceforge.net http://www.sourceforge.com/projects/jboost |
From: Aaron A. <aa...@us...> - 2008-07-30 05:42:10
|
Update of /cvsroot/jboost/jboost/scripts In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv17028 Added Files: atreeplot.R Log Message: R method for plotting atrees --- NEW FILE: atreeplot.R --- tree2graph <- function() { } print.usage <- function() { show("\t -i (--info) file.info \t File containing runtime information (required) \n") show("\t -s (--spec) file.spec \t Spec file (optional, will default to spec file in info file) \n") show("\t -t (--tree) file.tree \t File containing the ADTree in text format (required) \n") show("\t -d (--dir) directory \t Directory to use (optional, defaults to '.') \n") show("\t -l (--labels) \t Flip the labels (-1 becomes +1) (optional)\n") show("\t --truncate \t Truncate threshold values to increase readability\n") show("\t --threshold num \t A given depth to stop the tree from becoming too large. (optional) \n") show("\t -h (--help) \t Print this usage information \n") } parse.args <- function(argv) { tree = "" flip = FALSE depth = 0 spec = "" for (i in 1:length(argv)) { arg = argv[i] if (arg=="--tree") { tree = argv[i+1] } else if (arg=="--flip") { flip = TRUE } else if (arg=="--depth") { depth = as.numeric(argv[i+1]) } else if (arg=="--spec") { spec = argv[i+1] } } return(list(tree=tree, flip=flip, depth=depth, spec=spec)) } parse.labels <- function(specfile) { lines = readLines(specfile) labels = list() for (i in 1:length(lines)) { line = lines[i] line = sub("^.*labels\\s*\\((.*)\\).*$", "labels \\1", line, perl=TRUE) if (substr(line, 1, 6)=="labels") { labels = unlist(strsplit(substr(line,7,9999999),",")) } } labels <- return(labels) } argv <- commandArgs() tmp <- parse.args(argv) treefile <- tmp$tree specfile <- tmp$spec flip.labels <- tmp$flip depth <- tmp$depth if (treefile=="" || specfile=="") { print.usage() q("no") } show(paste("Tree File:", treefile)) show(paste("Spec File:", specfile)) labels = parse.labels(specfile) num.labels = length(labels); if (num.labels < 2) { show("There don't seem to be enough labels in the spec file...") show("Labels found:") show(labels) q("no") } show(c("Labels are:", labels)) lines = readLines(treefile) perl.re <- function(str, expr) { ret = c("FALSE") #show(c(str, expr)) is.present <- grep(expr, c(str,"as"), perl=TRUE) #show(is.present) if (length(is.present) > 0) { # get number of captures expr <- unlist(strsplit(expr, NULL)) #show(expr) out <- "TRUE" k <- 0 for (i in 1:length(expr)) { if (paste(expr[i-1],expr[i],sep="")=="\\(") { next; } if (expr[i]=="(") { k <- k + 1 out = paste(out, paste("\\",k,sep=""), sep="|") #show(out) } } expr <- paste(expr, collapse="") ret <- unlist(strsplit(sub(expr, out, str), "|")) #show(c(expr, out, str)) ret <- sub(expr, out, str) ret <- unlist(strsplit(ret, "\\|")) #show(ret) } return(ret) } library(igraph) g <- graph.empty() g$layout <- layout.reingold.tilford # Example of MultiPrediction #0 [R] prediction = MultiPrediction. #prediction 0: BinaryPrediction. p(1)= -0.6496414920651304 #prediction 1: BinaryPrediction. p(1)= -0.2938933324510595 # #1 [R.0] Splitter = EqualitySplit: 2 highest-degree = phd #1 [R.0:0] prediction = MultiPrediction. #prediction 0: BinaryPrediction. p(1)= -0.6206059321542053 #prediction 1: BinaryPrediction. p(1)= 0.9952607782884548 # #1 [R.0:1] prediction = MultiPrediction. #prediction 0: BinaryPrediction. p(1)= 0.2326437273762824 #prediction 1: BinaryPrediction. p(1)= -0.9175790854074412 # #2 [R.0:1.0] Splitter = InequalitySplitter. age < 37.0 #2 [R.0:1.0:0] prediction = MultiPrediction. #prediction 0: BinaryPrediction. p(1)= -1.5519953894118494 #prediction 1: BinaryPrediction. p(1)= -1.244560833852431 # #2 [R.0:1.0:1] prediction = MultiPrediction. #prediction 0: BinaryPrediction. p(1)= 1.8377755517791101 #prediction 1: BinaryPrediction. p(1)= -0.8696119797754972 #0 [R] prediction = BinaryPrediction. p(1)= 0.11523437500000003 #1 [R.0] Splitter = InequalitySplitter. char_freq_bang < 0.0785 #1 [R.0:0] prediction = BinaryPrediction. p(1)= 0.3720703125 #1 [R.0:1] prediction = BinaryPrediction. p(1)= -0.3720703125 #29 [R.0:1.0] Splitter = InequalitySplitter. word_freq_internet < 0.555 #29 [R.0:1.0:0] prediction = BinaryPrediction. p(1)= -0.19531250000000003 #29 [R.0:1.0:1] prediction = BinaryPrediction. p(1)= -0.19531250000000003 index.to.vertex <- list() i <- 1 depth <- 0 width <- 0 while (i <= length(lines)) { index <- "" type <- "" label <- "" line = lines[i] #show(sprintf("Line is: %s", line)) x <- perl.re(line, "^([0-9]+)\\s*\\[(.*)\\].*Splitter\\s*=\\s*(.*)$") if (x[1]=="TRUE") { #show("Setting type to splitter") type = "splitter"; iteration = x[2]; index = x[3]; label = x[4]; #show(sprintf("Label of splitter is: %s", label)) } x <- perl.re(line, "^([0-9]+)\\s*\\[(.*)\\].*prediction\\s*=\\s*(.*)$") if (x[1]=="TRUE") { #show("Setting type to predictor") type = "predictor"; iteration = x[2] index = x[3] label = x[4] predType = x[4]; #show(c(type, iteration, index, label)) x <- perl.re(predType, ".*MultiPrediction.*") y <- perl.re(predType, ".*BinaryPrediction.*=(.*)") if (x[1]=="TRUE") { label = ""; for (j in 1:num.labels) { i <- i + 1 line = lines[i] #prediction 0: BinaryPrediction. p(1)= -0.6496414920651304 x <- perl.re(line,"^.*prediction.*=\\s*(.*)") #show(sprintf("Prediction Binary value is %0.4f", as.numeric(x[2]))) if (x[1]=="TRUE") { pred = x[2] } else { break } if (flip.labels) { pred = paste("-",pred,sep="") } label = paste(label, labels[j], ": ", pred, "\n", sep=""); } } else if (y[1]=="TRUE") { label = y[2] if(flip.labels) { label = as.numeric(label) label = - label label = as.character(label) } } } #show(sprintf("Type is: %s", type)) #show(sprintf("Index is: %s", index)) #show(sprintf("Label is: %s", label)) if (type=="splitter") { g <- add.vertices(g, 1) V(g)$frame.color[length(V(g))] <- "blue" V(g)$color[length(V(g))] <- "white" V(g)$label[length(V(g))] <- paste(iteration, label, sep=": ") V(g)$label.cex <- 1.4 V(g)$shape[length(V(g))] <- "rectangle" V(g)$label.color <- "black" this.vertex <- length(V(g))-1 index.to.vertex[[index]] = this.vertex parent.index <- substr(index,1,nchar(index)-2) parent.vertex <- index.to.vertex[[parent.index]] g <- add.edges(g, c(parent.vertex,this.vertex)) E(g)$color[length(E(g))] <- "black" E(g)$width[length(E(g))] <- 5 } if (type=="predictor") { g <- add.vertices(g, 1) V(g)$frame.color[length(V(g))] <- "yellow" V(g)$color[length(V(g))] <- "white" V(g)$label[length(V(g))] <- label V(g)$shape[length(V(g))] <- "rectangle" V(g)$label.cex <- 1 V(g)$label.color <- "black" this.vertex <- length(V(g))-1 index.to.vertex[[index]] = this.vertex if (index!="R") { parent.index <- substr(index,1,nchar(index)-2) parent.vertex <- index.to.vertex[[parent.index]] g <- add.edges(g, c(parent.vertex,this.vertex)) ans <- substr(index,nchar(index), nchar(index)) if (ans=="0") { E(g)$color[length(E(g))] <- "red" E(g)$label[length(E(g))] <- "False" } else if (ans=="1") { E(g)$color[length(E(g))] <- "green" E(g)$label[length(E(g))] <- "True" } else { error(paste("The splitter has an invalid return value!\n 1 or 0 expected, recieved", ans)) } E(g)$label.cex <- 1.5 E(g)$label.color <- "black" E(g)$width[length(E(g))] <- 10 } } w <- warnings() if (length(w)>0) { show(w) } i <- i + 1 } # Flip so that the root is at the top coords <- g$layout(g) coords[,2] <- max(coords[,2])-coords[,2] fname <- sprintf("%s.eps", treefile) show(sprintf("Writing file to '%s'", fname)) postscript(file=sprintf("%s.eps", treefile), fonts=c("serif", "Palatino"), paper="special", width=70, height=40, horizontal=TRUE) plot(1, type="n", axes=FALSE, xlab=NA, ylab=NA, xlim=c(-1,1), ylim=c(-1,1)) sw <- strwidth(paste("", V(g)$label, "")) sh <- strheight(paste("", V(g)$label, "")) plot(g, add=TRUE, layout=coords, vertex.size=sw*110, vertex.size2=sh*100*3) dev.off() |
From: Aaron A. <aa...@cs...> - 2008-07-23 13:08:15
|
> Thanks for the info, this is very helpful. Can you or aaron update the > documentation, right now the focumentation on the jboost web site says > nothing about comments in the data file. Directions for how to get to the JBoost site are available from SourceForge when signed in as an admin. > Another thing I am confused about is what are the specs for labels. I thought > it can be any char string. Mayank thinks it can only be numbers. The demos have both numbers and characters, though no hyphens. I don't know the exact specs, but I'm guessing there's either some other problem or its the hyphens. > Aaron, the error reports from jboost when it cannot parse the input file > should be more elaborate. At a minimum, it should quote the error line. Agreed. Someone should update this some day... I think part of the difficulty for changing this is how exceptions are currently used/caught, though it's been a while since I looked at this. (Though the last time I looked at this code was to put in exactly what you're talking about.) > On the other hand, printing the whole manpage for any error makes not sense. > I would complete remove this internal man page, so only one needs to be > maintained! The internal man page should be the one maintained. An error may be filesystem related or because jboost is being ran in an unexpected directory. As such, the only guarenteed object to be accessible is the interal man page (unless there's a memory error, but then everything is going down anyways). Aaron > On Jul 22, 2008, at 1:49 PM, William Beaver wrote: > >> Hello Yoav, >> >> There is no automatic way to get from the examples in boosting.info back to >> the source of the example. Using the example ID in boosting.info (first >> column) to get the row number of the example in the .data file, you then >> parse out the comment you've placed in the data file. This comment is >> application specific and points you to the source of that example. For >> example, in dros work the comment contains a [stack id, slice id, object >> id] tuple. For dc audio i store [audio sourcepath, sample start, sample >> length]. >> >> The comments are C style: '//' line comments and '/*' '*/' inline comments. >> You can place them anywhere now, as long as the .spec structure is >> maintained. I place the comments after the example terminator and end the >> whole thing with a '\n' (just to make it more human friendly). >> >> I have some matlab parsing code for the boosting.info file; it's mostly a >> hack but have on my todo list to build a nicer, object-based general >> purpose parser. In the meantime can send you the paring snippets if you'd >> like. >> >> from somewhere in Oregon, >> -William >> >> >> >> On Jul 20, 2008, at 8:33 AM, Yoav Freund wrote: >> >>> Hi William, >>> >>> I would like to use comments to trace back examples with small margins. I >>> see that you fixed a bug in that regard, >>> but I am not sure what is the specification for comments, it is not >>> documented in >>> >>> http://jboost.sourceforge.net/doc.html#input >>> >>> Is a comment anything that appears after the example terminator symbol in >>> the line? Does it need to have // in front of it (lines that start with // >>> are ignored). Does jboost store the comment somewhere or can you retrieve >>> the comment based on the example index number in the jboost log file? >>> >>> Yoav >>> >>> On May 16, 2008, at 2:50 PM, william beaver wrote: >>> >>>> Update of /cvsroot/jboost/jboost/src/jboost/tokenizer >>>> In directory >>>> sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv10384/src/jboost/tokenizer >>>> >>>> Modified Files: >>>> LTStreamTokenizer.java >>>> Log Message: >>>> fixed legacy bugs that prevented comments from being parsed reliably, or >>>> at all. >>>> >>>> Index: LTStreamTokenizer.java >>>> =================================================================== >>>> RCS file: >>>> /cvsroot/jboost/jboost/src/jboost/tokenizer/LTStreamTokenizer.java,v >>>> retrieving revision 1.1.1.1 >>>> retrieving revision 1.2 >>>> diff -C2 -d -r1.1.1.1 -r1.2 >>>> *** LTStreamTokenizer.java 16 May 2007 04:06:02 -0000 1.1.1.1 >>>> --- LTStreamTokenizer.java 16 May 2008 18:50:01 -0000 1.2 >>>> *************** >>>> *** 71,75 **** >>>> this.terminator= terminator; >>>> terLen= terminator.length(); >>>> ! minLen= terLen >= 2 ? 2 : terLen; >>>> for (int i= 0, terLines= 0; i < terLen; i++) >>>> if (terminator.charAt(i) == '\n') >>>> --- 71,75 ---- >>>> this.terminator= terminator; >>>> terLen= terminator.length(); >>>> ! minLen= terLen <= 2 ? 2 : terLen; >>>> for (int i= 0, terLines= 0; i < terLen; i++) >>>> if (terminator.charAt(i) == '\n') >>>> *************** >>>> *** 135,139 **** >>>> while (true) { >>>> // if(Monitor.logLevel>3) Monitor.log("strLen=" + >>>> strLen + " toCopy=" + toCopy + " i=" + i); >>>> ! if (i > strLen - minLen) { >>>> try { >>>> numRead= br.read(cBuf, 0, bufLen); >>>> --- 135,139 ---- >>>> while (true) { >>>> // if(Monitor.logLevel>3) Monitor.log("strLen=" + >>>> strLen + " toCopy=" + toCopy + " i=" + i); >>>> ! if (i > strLen - minLen) { >>>> try { >>>> numRead= br.read(cBuf, 0, bufLen); >>>> *************** >>>> *** 206,210 **** >>>> if (Util.even(numEscapes)) { // line comment starts! >>>> curTok += strBuf.substring(toCopy, i - numEscapes / 2); >>>> ! ongoingComment= true; >>>> } else // escpaed, part of token >>>> curTok >>>> --- 206,210 ---- >>>> if (Util.even(numEscapes)) { // line comment starts! >>>> curTok += strBuf.substring(toCopy, i - numEscapes / 2); >>>> ! lineComment= true; >>>> } else // escpaed, part of token >>>> curTok >>>> >>>> >>>> ------------------------------------------------------------------------- >>>> This SF.net email is sponsored by: Microsoft >>>> Defy all challenges. Microsoft(R) Visual Studio 2008. >>>> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ >>>> _______________________________________________ >>>> jboost-cvs mailing list >>>> jbo...@li... >>>> https://lists.sourceforge.net/lists/listinfo/jboost-cvs >> >> -william >> >> ------------ >> William Beaver >> wb...@cs... >> >> > |
From: Yoav F. <yoa...@gm...> - 2008-07-22 18:35:14
|
Hi William, Thanks for the info, this is very helpful. Can you or aaron update the documentation, right now the focumentation on the jboost web site says nothing about comments in the data file. Another thing I am confused about is what are the specs for labels. I thought it can be any char string. Mayank thinks it can only be numbers. I got some error when I tried to use the strings "cell-edge" and "random-seg", but the error was completely uninterpretable. Something about no allowing "-" in a flag. Maybe this means that "-" is not allowed in a label value? How about the - in -1 ? Aaron, the error reports from jboost when it cannot parse the input file should be more elaborate. At a minimum, it should quote the error line. On the other hand, printing the whole manpage for any error makes not sense. I would complete remove this internal man page, so only one needs to be maintained! Yoav On Jul 22, 2008, at 1:49 PM, William Beaver wrote: > Hello Yoav, > > There is no automatic way to get from the examples in boosting.info > back to the source of the example. Using the example ID in > boosting.info (first column) to get the row number of the example in > the .data file, you then parse out the comment you've placed in the > data file. This comment is application specific and points you to > the source of that example. For example, in dros work the comment > contains a [stack id, slice id, object id] tuple. For dc audio i > store [audio sourcepath, sample start, sample length]. > > The comments are C style: '//' line comments and '/*' '*/' inline > comments. You can place them anywhere now, as long as the .spec > structure is maintained. I place the comments after the example > terminator and end the whole thing with a '\n' (just to make it more > human friendly). > > I have some matlab parsing code for the boosting.info file; it's > mostly a hack but have on my todo list to build a nicer, object- > based general purpose parser. In the meantime can send you the > paring snippets if you'd like. > > from somewhere in Oregon, > -William > > > > On Jul 20, 2008, at 8:33 AM, Yoav Freund wrote: > >> Hi William, >> >> I would like to use comments to trace back examples with small >> margins. I see that you fixed a bug in that regard, >> but I am not sure what is the specification for comments, it is not >> documented in >> >> http://jboost.sourceforge.net/doc.html#input >> >> Is a comment anything that appears after the example terminator >> symbol in the line? Does it need to have // in front of it (lines >> that start with // are ignored). Does jboost store the comment >> somewhere or can you retrieve the comment based on the example >> index number in the jboost log file? >> >> Yoav >> >> On May 16, 2008, at 2:50 PM, william beaver wrote: >> >>> Update of /cvsroot/jboost/jboost/src/jboost/tokenizer >>> In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv10384/src/ >>> jboost/tokenizer >>> >>> Modified Files: >>> LTStreamTokenizer.java >>> Log Message: >>> fixed legacy bugs that prevented comments from being parsed >>> reliably, or at all. >>> >>> Index: LTStreamTokenizer.java >>> =================================================================== >>> RCS file: /cvsroot/jboost/jboost/src/jboost/tokenizer/ >>> LTStreamTokenizer.java,v >>> retrieving revision 1.1.1.1 >>> retrieving revision 1.2 >>> diff -C2 -d -r1.1.1.1 -r1.2 >>> *** LTStreamTokenizer.java 16 May 2007 04:06:02 -0000 1.1.1.1 >>> --- LTStreamTokenizer.java 16 May 2008 18:50:01 -0000 1.2 >>> *************** >>> *** 71,75 **** >>> this.terminator= terminator; >>> terLen= terminator.length(); >>> ! minLen= terLen >= 2 ? 2 : terLen; >>> for (int i= 0, terLines= 0; i < terLen; i++) >>> if (terminator.charAt(i) == '\n') >>> --- 71,75 ---- >>> this.terminator= terminator; >>> terLen= terminator.length(); >>> ! minLen= terLen <= 2 ? 2 : terLen; >>> for (int i= 0, terLines= 0; i < terLen; i++) >>> if (terminator.charAt(i) == '\n') >>> *************** >>> *** 135,139 **** >>> while (true) { >>> // if(Monitor.logLevel>3) Monitor.log("strLen=" + >>> strLen + " toCopy=" + toCopy + " i=" + i); >>> ! if (i > strLen - minLen) { >>> try { >>> numRead= br.read(cBuf, 0, bufLen); >>> --- 135,139 ---- >>> while (true) { >>> // if(Monitor.logLevel>3) Monitor.log("strLen=" + >>> strLen + " toCopy=" + toCopy + " i=" + i); >>> ! if (i > strLen - minLen) { >>> try { >>> numRead= br.read(cBuf, 0, bufLen); >>> *************** >>> *** 206,210 **** >>> if (Util.even(numEscapes)) { // line comment starts! >>> curTok += strBuf.substring(toCopy, i - >>> numEscapes / 2); >>> ! ongoingComment= true; >>> } else // escpaed, part of token >>> curTok >>> --- 206,210 ---- >>> if (Util.even(numEscapes)) { // line comment starts! >>> curTok += strBuf.substring(toCopy, i - >>> numEscapes / 2); >>> ! lineComment= true; >>> } else // escpaed, part of token >>> curTok >>> >>> >>> ------------------------------------------------------------------------- >>> This SF.net email is sponsored by: Microsoft >>> Defy all challenges. Microsoft(R) Visual Studio 2008. >>> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ >>> _______________________________________________ >>> jboost-cvs mailing list >>> jbo...@li... >>> https://lists.sourceforge.net/lists/listinfo/jboost-cvs > > -william > > ------------ > William Beaver > wb...@cs... > > > |
From: William B. <wb...@cs...> - 2008-07-22 17:49:57
|
Hello Yoav, There is no automatic way to get from the examples in boosting.info back to the source of the example. Using the example ID in boosting.info (first column) to get the row number of the example in the .data file, you then parse out the comment you've placed in the data file. This comment is application specific and points you to the source of that example. For example, in dros work the comment contains a [stack id, slice id, object id] tuple. For dc audio i store [audio sourcepath, sample start, sample length]. The comments are C style: '//' line comments and '/*' '*/' inline comments. You can place them anywhere now, as long as the .spec structure is maintained. I place the comments after the example terminator and end the whole thing with a '\n' (just to make it more human friendly). I have some matlab parsing code for the boosting.info file; it's mostly a hack but have on my todo list to build a nicer, object-based general purpose parser. In the meantime can send you the paring snippets if you'd like. from somewhere in Oregon, -William On Jul 20, 2008, at 8:33 AM, Yoav Freund wrote: > Hi William, > > I would like to use comments to trace back examples with small > margins. I see that you fixed a bug in that regard, > but I am not sure what is the specification for comments, it is not > documented in > > http://jboost.sourceforge.net/doc.html#input > > Is a comment anything that appears after the example terminator > symbol in the line? Does it need to have // in front of it (lines > that start with // are ignored). Does jboost store the comment > somewhere or can you retrieve the comment based on the example index > number in the jboost log file? > > Yoav > > On May 16, 2008, at 2:50 PM, william beaver wrote: > >> Update of /cvsroot/jboost/jboost/src/jboost/tokenizer >> In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv10384/src/ >> jboost/tokenizer >> >> Modified Files: >> LTStreamTokenizer.java >> Log Message: >> fixed legacy bugs that prevented comments from being parsed >> reliably, or at all. >> >> Index: LTStreamTokenizer.java >> =================================================================== >> RCS file: /cvsroot/jboost/jboost/src/jboost/tokenizer/ >> LTStreamTokenizer.java,v >> retrieving revision 1.1.1.1 >> retrieving revision 1.2 >> diff -C2 -d -r1.1.1.1 -r1.2 >> *** LTStreamTokenizer.java 16 May 2007 04:06:02 -0000 1.1.1.1 >> --- LTStreamTokenizer.java 16 May 2008 18:50:01 -0000 1.2 >> *************** >> *** 71,75 **** >> this.terminator= terminator; >> terLen= terminator.length(); >> ! minLen= terLen >= 2 ? 2 : terLen; >> for (int i= 0, terLines= 0; i < terLen; i++) >> if (terminator.charAt(i) == '\n') >> --- 71,75 ---- >> this.terminator= terminator; >> terLen= terminator.length(); >> ! minLen= terLen <= 2 ? 2 : terLen; >> for (int i= 0, terLines= 0; i < terLen; i++) >> if (terminator.charAt(i) == '\n') >> *************** >> *** 135,139 **** >> while (true) { >> // if(Monitor.logLevel>3) Monitor.log("strLen=" + >> strLen + " toCopy=" + toCopy + " i=" + i); >> ! if (i > strLen - minLen) { >> try { >> numRead= br.read(cBuf, 0, bufLen); >> --- 135,139 ---- >> while (true) { >> // if(Monitor.logLevel>3) Monitor.log("strLen=" + >> strLen + " toCopy=" + toCopy + " i=" + i); >> ! if (i > strLen - minLen) { >> try { >> numRead= br.read(cBuf, 0, bufLen); >> *************** >> *** 206,210 **** >> if (Util.even(numEscapes)) { // line comment starts! >> curTok += strBuf.substring(toCopy, i - >> numEscapes / 2); >> ! ongoingComment= true; >> } else // escpaed, part of token >> curTok >> --- 206,210 ---- >> if (Util.even(numEscapes)) { // line comment starts! >> curTok += strBuf.substring(toCopy, i - >> numEscapes / 2); >> ! lineComment= true; >> } else // escpaed, part of token >> curTok >> >> >> ------------------------------------------------------------------------- >> This SF.net email is sponsored by: Microsoft >> Defy all challenges. Microsoft(R) Visual Studio 2008. >> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ >> _______________________________________________ >> jboost-cvs mailing list >> jbo...@li... >> https://lists.sourceforge.net/lists/listinfo/jboost-cvs -william ------------ William Beaver wb...@cs... |
From: Yoav F. <yoa...@gm...> - 2008-07-20 15:33:45
|
Hi William, I would like to use comments to trace back examples with small margins. I see that you fixed a bug in that regard, but I am not sure what is the specification for comments, it is not documented in http://jboost.sourceforge.net/doc.html#input Is a comment anything that appears after the example terminator symbol in the line? Does it need to have // in front of it (lines that start with // are ignored). Does jboost store the comment somewhere or can you retrieve the comment based on the example index number in the jboost log file? Yoav On May 16, 2008, at 2:50 PM, william beaver wrote: > Update of /cvsroot/jboost/jboost/src/jboost/tokenizer > In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv10384/src/ > jboost/tokenizer > > Modified Files: > LTStreamTokenizer.java > Log Message: > fixed legacy bugs that prevented comments from being parsed > reliably, or at all. > > Index: LTStreamTokenizer.java > =================================================================== > RCS file: /cvsroot/jboost/jboost/src/jboost/tokenizer/ > LTStreamTokenizer.java,v > retrieving revision 1.1.1.1 > retrieving revision 1.2 > diff -C2 -d -r1.1.1.1 -r1.2 > *** LTStreamTokenizer.java 16 May 2007 04:06:02 -0000 1.1.1.1 > --- LTStreamTokenizer.java 16 May 2008 18:50:01 -0000 1.2 > *************** > *** 71,75 **** > this.terminator= terminator; > terLen= terminator.length(); > ! minLen= terLen >= 2 ? 2 : terLen; > for (int i= 0, terLines= 0; i < terLen; i++) > if (terminator.charAt(i) == '\n') > --- 71,75 ---- > this.terminator= terminator; > terLen= terminator.length(); > ! minLen= terLen <= 2 ? 2 : terLen; > for (int i= 0, terLines= 0; i < terLen; i++) > if (terminator.charAt(i) == '\n') > *************** > *** 135,139 **** > while (true) { > // if(Monitor.logLevel>3) Monitor.log("strLen=" + > strLen + " toCopy=" + toCopy + " i=" + i); > ! if (i > strLen - minLen) { > try { > numRead= br.read(cBuf, 0, bufLen); > --- 135,139 ---- > while (true) { > // if(Monitor.logLevel>3) Monitor.log("strLen=" + > strLen + " toCopy=" + toCopy + " i=" + i); > ! if (i > strLen - minLen) { > try { > numRead= br.read(cBuf, 0, bufLen); > *************** > *** 206,210 **** > if (Util.even(numEscapes)) { // line comment starts! > curTok += strBuf.substring(toCopy, i - > numEscapes / 2); > ! ongoingComment= true; > } else // escpaed, part of token > curTok > --- 206,210 ---- > if (Util.even(numEscapes)) { // line comment starts! > curTok += strBuf.substring(toCopy, i - > numEscapes / 2); > ! lineComment= true; > } else // escpaed, part of token > curTok > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > jboost-cvs mailing list > jbo...@li... > https://lists.sourceforge.net/lists/listinfo/jboost-cvs |
From: Aaron A. <aa...@us...> - 2008-07-04 22:35:01
|
Update of /cvsroot/jboost/jboost/src/jboost/monitor In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv19628 Modified Files: Monitor.java Log Message: Fixed bug relating to .info filename Index: Monitor.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/monitor/Monitor.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Monitor.java 3 Jun 2008 03:17:39 -0000 1.9 --- Monitor.java 4 Jul 2008 22:34:57 -0000 1.10 *************** *** 108,112 **** infoStream= new PrintWriter( ! new BufferedWriter(new FileWriter(outputStem + ".info"))); infoStream.println("Command line parameters: " + config.getString("args")); infoStream.println(); --- 108,112 ---- infoStream= new PrintWriter( ! new BufferedWriter(new FileWriter(infoFilename))); infoStream.println("Command line parameters: " + config.getString("args")); infoStream.println(); |
From: Aaron A. <aa...@us...> - 2008-06-03 03:17:43
|
Update of /cvsroot/jboost/jboost/src/jboost/controller In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv32711/controller Modified Files: Controller.java ControllerConfiguration.java Log Message: Moved ExampleSets from the ControllerConfig to the Controller. --Aaron Index: ControllerConfiguration.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/controller/ControllerConfiguration.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ControllerConfiguration.java 24 Jan 2008 22:48:53 -0000 1.4 --- ControllerConfiguration.java 3 Jun 2008 03:17:39 -0000 1.5 *************** *** 8,12 **** import java.io.*; - import jboost.examples.ExampleSet; import jboost.monitor.Monitor; --- 8,11 ---- *************** *** 14,22 **** /** ! * The ControllerConfiguration holds all the configurable data used by the * Controller, Monitor, and anything else that needs to get access to it. * Using this configuration object allows us to reduce the exposure of the * Controller to other classes that may need to share data with it. ! * * The data that this class maintains are: * <li> specFileName --- 13,21 ---- /** ! * The ControllerConfiguration holds all the configurable data used by the * Controller, Monitor, and anything else that needs to get access to it. * Using this configuration object allows us to reduce the exposure of the * Controller to other classes that may need to share data with it. ! * * The data that this class maintains are: * <li> specFileName *************** *** 30,35 **** * <li> trainSet * <li> testSet ! * ! * * @author cschavis */ --- 29,34 ---- * <li> trainSet * <li> testSet ! * ! * * @author cschavis */ *************** *** 68,84 **** public static final String BROWN_BOOST_POTENTIAL="brownBoostPotential"; public static final String BROWN_COST_SENSITIVE="costSensitive"; ! public static final String DEFAULT_BOOSTER = "AdaBoost"; - - // private data elements that are not stored in the Configuration vector - private ExampleSet trainSet; - private ExampleSet testSet; /** * Configure the specific entries that we need for the Controller */ ! public ControllerConfiguration(String manpage, String[] argv) throws BadCommandException, IOException { ! super(manpage, argv); String stem= getString("S", "default"); --- 67,79 ---- public static final String BROWN_BOOST_POTENTIAL="brownBoostPotential"; public static final String BROWN_COST_SENSITIVE="costSensitive"; ! public static final String DEFAULT_BOOSTER = "AdaBoost"; /** * Configure the specific entries that we need for the Controller */ ! public ControllerConfiguration(String manpage, String[] argv) throws BadCommandException, IOException { ! super(manpage, argv); String stem= getString("S", "default"); *************** *** 113,163 **** addOption(BROWN_COST_SENSITIVE, getString("costSensitive", null)); } ! /** ! * Check the values of all the parameters, e.g. make sure that * the filenames for the input files exist. ! * @return */ ! protected boolean checkCommandValues() throws BadCommandException { ! // check the input files ! try { ! if(getPrintVersion()){ ! System.out.println("JBoost version " + VERSION); ! System.exit(0); ! } ! String specname = getSpecFileName(); ! String testname = getTestFileName(); ! String trainname = getTrainFileName(); ! Monitor.log("Spec: " + specname + ", Test: " + testname + ", Train: " + trainname); ! if(specname == null || testname == null || trainname == null){ ! throw new BadCommandException("ERROR: Have not assigned all (spec,train,test) input file names yet!"); ! } ! File specfile = new File(specname); ! File testfile = new File(testname); ! File trainfile = new File(trainname); ! if (! (specfile.exists() && testfile.exists() && trainfile.exists()) ) { ! throw new BadCommandException("ERROR: Input file names (spec,train,test) do not exist!"); ! } ! } catch(Exception e) { ! System.err.println("ERROR: Input files do not exist or are unreadable for other reasons!"); ! throw new BadCommandException(e.getMessage()); ! } ! ! // Check the results output file parameters ! try { ! String fname = getResultOutputFileName(); ! if(fname == null){ ! throw new BadCommandException("ERROR: Have not assigned output file name yet!"); ! } ! } catch(Exception e) { ! System.err.println("ERROR: File either does not exist or is unreadable for other reasons!"); ! throw new BadCommandException(e.getMessage()); ! } ! ! return true; } ! ! /** * @return Returns the resultOutputFileName. --- 108,158 ---- addOption(BROWN_COST_SENSITIVE, getString("costSensitive", null)); } ! /** ! * Check the values of all the parameters, e.g. make sure that * the filenames for the input files exist. ! * @return */ ! protected boolean checkCommandValues() throws BadCommandException { ! // check the input files ! try { ! if(getPrintVersion()){ ! System.out.println("JBoost version " + VERSION); ! System.exit(0); ! } ! String specname = getSpecFileName(); ! String testname = getTestFileName(); ! String trainname = getTrainFileName(); ! Monitor.log("Spec: " + specname + ", Test: " + testname + ", Train: " + trainname); ! if(specname == null || testname == null || trainname == null){ ! throw new BadCommandException("ERROR: Have not assigned all (spec,train,test) input file names yet!"); ! } ! File specfile = new File(specname); ! File testfile = new File(testname); ! File trainfile = new File(trainname); ! if (! (specfile.exists() && testfile.exists() && trainfile.exists()) ) { ! throw new BadCommandException("ERROR: Input file names (spec,train,test) do not exist!"); ! } ! } catch(Exception e) { ! System.err.println("ERROR: Input files do not exist or are unreadable for other reasons!"); ! throw new BadCommandException(e.getMessage()); ! } ! ! // Check the results output file parameters ! try { ! String fname = getResultOutputFileName(); ! if(fname == null){ ! throw new BadCommandException("ERROR: Have not assigned output file name yet!"); ! } ! } catch(Exception e) { ! System.err.println("ERROR: File either does not exist or is unreadable for other reasons!"); ! throw new BadCommandException(e.getMessage()); ! } ! ! return true; } ! ! /** * @return Returns the resultOutputFileName. *************** *** 182,199 **** /** - * @param the test set - */ - public void setTestSet(ExampleSet set) { - testSet= set; - } - - /** - * @return Returns the testSet. - */ - public ExampleSet getTestSet() { - return testSet; - } - - /** * @return Returns the trainFileName. */ --- 177,180 ---- *************** *** 203,226 **** /** - * @param the training set - */ - public void setTrainSet(ExampleSet set) { - trainSet= set; - } - - /** - * @return Returns the trainSet. - */ - public ExampleSet getTrainSet() { - return trainSet; - } - - /** * @return Returns the name of the C output file */ public String getCoutputFileName() { ! return getString(C_OUTPUT_FILENAME); } ! /** * @return Returns the name of the Java output file --- 184,193 ---- /** * @return Returns the name of the C output file */ public String getCoutputFileName() { ! return getString(C_OUTPUT_FILENAME); } ! /** * @return Returns the name of the Java output file *************** *** 229,240 **** return getString(JAVA_OUTPUT_FILENAME); } ! /** * @return Returns the name of the Matlab output file */ ! public String getMatlabOutputFileName() { return getString(MATLAB_OUTPUT_FILENAME); } ! /** * @return Returns the name of the serialized output file --- 196,207 ---- return getString(JAVA_OUTPUT_FILENAME); } ! /** * @return Returns the name of the Matlab output file */ ! public String getMatlabOutputFileName() { return getString(MATLAB_OUTPUT_FILENAME); } ! /** * @return Returns the name of the serialized output file *************** *** 243,247 **** return getString(SERIALIZED_OUTPUT_FILENAME); } ! /** * @return Returns the name of the serialized input file --- 210,214 ---- return getString(SERIALIZED_OUTPUT_FILENAME); } ! /** * @return Returns the name of the serialized input file *************** *** 250,254 **** return getString(SERIALIZED_INPUT); } ! /** * @return Returns the specified number of threads --- 217,221 ---- return getString(SERIALIZED_INPUT); } ! /** * @return Returns the specified number of threads *************** *** 257,283 **** return getString(N_THREADS); } ! /** ! * @return the runtime of the boosting algorithm * (for adaptive versions of BBM) */ public double getRuntime() { ! String runStr = getString(BOOSTER_RUNTIME); ! if (runStr == null) { ! return 0; ! } ! return Double.parseDouble(runStr); } ! /** * @return should we print the version? */ public boolean getPrintVersion() { ! String str = getString(JBOOST_VERSION); ! if (str == null) { ! return false; ! } ! return true; } --- 224,250 ---- return getString(N_THREADS); } ! /** ! * @return the runtime of the boosting algorithm * (for adaptive versions of BBM) */ public double getRuntime() { ! String runStr = getString(BOOSTER_RUNTIME); ! if (runStr == null) { ! return 0; ! } ! return Double.parseDouble(runStr); } ! /** * @return should we print the version? */ public boolean getPrintVersion() { ! String str = getString(JBOOST_VERSION); ! if (str == null) { ! return false; ! } ! return true; } *************** *** 288,296 **** */ public boolean getPrintPotential() { ! String str = getString(BROWN_BOOST_POTENTIAL); ! if (str == null) { ! return false; ! } ! return true; } --- 255,263 ---- */ public boolean getPrintPotential() { ! String str = getString(BROWN_BOOST_POTENTIAL); ! if (str == null) { ! return false; ! } ! return true; } *************** *** 300,308 **** */ public boolean getCostSensitive() { ! String str = getString(BROWN_COST_SENSITIVE); ! if (str == null) { ! return false; ! } ! return true; } --- 267,275 ---- */ public boolean getCostSensitive() { ! String str = getString(BROWN_COST_SENSITIVE); ! if (str == null) { ! return false; ! } ! return true; } Index: Controller.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/controller/Controller.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Controller.java 24 Jan 2008 22:48:53 -0000 1.7 --- Controller.java 3 Jun 2008 03:17:39 -0000 1.8 *************** *** 48,52 **** * method will use configuration data to build a learner and read in the train * and test examples. ! * */ --- 48,52 ---- * method will use configuration data to build a learner and read in the train * and test examples. ! * */ [...1242 lines suppressed...] ! predictor.toJava( ! procedureName, ! m_config.getString("javaOutputMethod", "predict"), ! (m_config.getBool("javaStandAlone", false) ? null : m_config.getSpecFileName()), ! m_exampleDescription); ! else ! throw new RuntimeException( ! "Controller.generateCode: Unrecognized language:" + language); ! PrintWriter codeOutputStream= ! new PrintWriter(new BufferedWriter(new FileWriter(codeOutputFileName))); ! codeOutputStream.println(code); ! codeOutputStream.close(); ! } catch (Exception e) { ! System.err.println( ! "Exception occured while attempting to write " + language + " code"); ! System.err.println("Message:" + e); ! e.printStackTrace(); ! } } } |
From: Aaron A. <aa...@us...> - 2008-06-03 03:17:43
|
Update of /cvsroot/jboost/jboost/src/jboost/monitor In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv32711/monitor Modified Files: Monitor.java Log Message: Moved ExampleSets from the ControllerConfig to the Controller. --Aaron Index: Monitor.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/monitor/Monitor.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Monitor.java 23 Oct 2007 22:45:40 -0000 1.8 --- Monitor.java 3 Jun 2008 03:17:39 -0000 1.9 *************** *** 18,22 **** * A class whose responsibility is to generate the log files that will later be * analyzed with perl scripts that were written for the C++ version of Atrees ! * * @author Yoav Freund */ --- 18,22 ---- * A class whose responsibility is to generate the log files that will later be * analyzed with perl scripts that were written for the C++ version of Atrees ! * * @author Yoav Freund */ *************** *** 33,37 **** /** a high-level log of the program's progress. */ private String infoFilename; ! private PrintWriter infoStream; --- 33,37 ---- /** a high-level log of the program's progress. */ private String infoFilename; ! private PrintWriter infoStream; *************** *** 51,55 **** /** log file info */ private static String logOutputFilename; ! private static PrintWriter logStream; --- 51,55 ---- /** log file info */ private static String logOutputFilename; ! private static PrintWriter logStream; *************** *** 67,92 **** public static int logLevel= 0; public static void init_log(Configuration config) throws IOException { ! String stem= config.getString("S", "data"); ! logOutputFilename= config.getString("log", stem + ".log"); ! logLevel= config.getInt("loglevel", 2); ! if (logLevel < 2) { ! logStream= new PrintWriter(System.out); ! } else { ! logStream= ! new PrintWriter(new BufferedWriter(new FileWriter(logOutputFilename))); ! } ! startTime= new Date(); // remember time at start to report it later } /** a central place to print debugging logs */ public static void log(Object message) { ! logStream.println(message); } /** close the logging file */ public static void closeLog() { ! logStream.close(); } /** * The constructor ! * * @param config a configuration object with the run-time parameters * @param trainSet the training set (to calcualte training error) --- 67,92 ---- public static int logLevel= 0; public static void init_log(Configuration config) throws IOException { ! String stem= config.getString("S", "data"); ! logOutputFilename= config.getString("log", stem + ".log"); ! logLevel= config.getInt("loglevel", 2); ! if (logLevel < 2) { ! logStream= new PrintWriter(System.out); ! } else { ! logStream= ! new PrintWriter(new BufferedWriter(new FileWriter(logOutputFilename))); ! } ! startTime= new Date(); // remember time at start to report it later } /** a central place to print debugging logs */ public static void log(Object message) { ! logStream.println(message); } /** close the logging file */ public static void closeLog() { ! logStream.close(); } /** * The constructor ! * * @param config a configuration object with the run-time parameters * @param trainSet the training set (to calcualte training error) *************** *** 94,179 **** * @param m_booster the m_booster (to compute m_margins) */ ! public Monitor(Booster booster, ControllerConfiguration config) { ! trainSet= config.getTrainSet(); ! testSet= config.getTestSet(); ! m_booster= booster; ! outputStem= config.getString("S", "noname_out"); ! infoFilename= config.getString("info", outputStem + ".info"); ! trainBoostingFilename = outputStem + ".train.boosting.info"; ! testBoostingFilename = outputStem + ".test.boosting.info"; ! try { ! infoStream= ! new PrintWriter( ! new BufferedWriter(new FileWriter(outputStem + ".info"))); ! infoStream.println("Command line parameters: " + config.getString("args")); ! infoStream.println(); ! infoStream.println("Configuration parameters:\n" + config); ! infoStream.println(""); ! infoStream.println("FILENAMES"); ! infoStream.println("specFilename = " + config.getSpecFileName()); ! 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(""); ! infoStream.println("Train set size = " + trainSet.getExampleNo()); ! 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(); ! infoStream.println("Init Start time = " + startTime); ! infoStream.println("Learn Start time = " + afterInitTime); ! infoStream.println("iter \tbound \ttrain \ttest"); ! infoStream.flush(); ! } catch (IOException e) { ! throw new RuntimeException( ! "monitor failed to open file for output\n" + e.getMessage()); ! } } ! /** print the m_labels of trainSet and testSet onto samplingStream */ /* private void logLabels() { ! ArrayList labels= trainSet.getBinaryLabels(); ! samplingStream.println("train labels, elements=" + labels.size()); ! for (int i= 0; i < labels.size(); i++) { ! samplingStream.println(((Boolean) labels.get(i)).booleanValue() ? "+1" : "-1"); ! } ! labels.clear(); // release memory ! labels= testSet.getBinaryLabels(); ! samplingStream.println("test labels, elements=" + labels.size()); ! for (int i= 0; i < labels.size(); i++) { ! samplingStream.println(((Boolean) labels.get(i)).booleanValue() ? "+1" : "-1"); ! } ! labels.clear(); // release memory ! labels= null; } */ ! /** generate logs for current boosting iteration */ public void logIteration(int iter, Predictor combined, Predictor base) { ! double trainError= trainSet.calcError(iter, combined, base); ! double testError= testSet.calcError(iter, combined, base); ! double theoryBound= m_booster.getTheoryBound(); ! NumberFormat f= new DecimalFormat("0.0000"); ! infoStream.print(iter + "\t" + f.format(theoryBound) + "\t" ! + f.format(trainError) + "\t" + f.format(testError)); ! infoStream.flush(); ! logBoosting(iter, combined, base); ! infoStream.println(""); } --- 94,180 ---- * @param m_booster the m_booster (to compute m_margins) */ ! public Monitor(Booster booster, ExampleSet training, ! ExampleSet testing, ControllerConfiguration config) { ! trainSet= training; ! testSet= testing; ! m_booster= booster; ! outputStem= config.getString("S", "noname_out"); ! infoFilename= config.getString("info", outputStem + ".info"); ! trainBoostingFilename = outputStem + ".train.boosting.info"; ! testBoostingFilename = outputStem + ".test.boosting.info"; ! try { ! infoStream= ! new PrintWriter( ! new BufferedWriter(new FileWriter(outputStem + ".info"))); ! infoStream.println("Command line parameters: " + config.getString("args")); ! infoStream.println(); ! infoStream.println("Configuration parameters:\n" + config); ! infoStream.println(""); ! infoStream.println("FILENAMES"); ! infoStream.println("specFilename = " + config.getSpecFileName()); ! 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(""); ! infoStream.println("Train set size = " + trainSet.getExampleNo()); ! 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(); ! infoStream.println("Init Start time = " + startTime); ! infoStream.println("Learn Start time = " + afterInitTime); ! infoStream.println("iter \tbound \ttrain \ttest"); ! infoStream.flush(); ! } catch (IOException e) { ! throw new RuntimeException( ! "monitor failed to open file for output\n" + e.getMessage()); ! } } ! /** print the m_labels of trainSet and testSet onto samplingStream */ /* private void logLabels() { ! ArrayList labels= trainSet.getBinaryLabels(); ! samplingStream.println("train labels, elements=" + labels.size()); ! for (int i= 0; i < labels.size(); i++) { ! samplingStream.println(((Boolean) labels.get(i)).booleanValue() ? "+1" : "-1"); ! } ! labels.clear(); // release memory ! labels= testSet.getBinaryLabels(); ! samplingStream.println("test labels, elements=" + labels.size()); ! for (int i= 0; i < labels.size(); i++) { ! samplingStream.println(((Boolean) labels.get(i)).booleanValue() ? "+1" : "-1"); ! } ! labels.clear(); // release memory ! labels= null; } */ ! /** generate logs for current boosting iteration */ public void logIteration(int iter, Predictor combined, Predictor base) { ! double trainError= trainSet.calcError(iter, combined, base); ! double testError= testSet.calcError(iter, combined, base); ! double theoryBound= m_booster.getTheoryBound(); ! NumberFormat f= new DecimalFormat("0.0000"); ! infoStream.print(iter + "\t" + f.format(theoryBound) + "\t" ! + f.format(trainError) + "\t" + f.format(testError)); ! infoStream.flush(); ! logBoosting(iter, combined, base); ! infoStream.println(""); } *************** *** 183,275 **** */ private void logBoostingTrainTest(PrintWriter boostingStream, ExampleSet tSet, int iter, Predictor combined, Predictor base) { ! // Output the training data ! boostingStream.println("iteration=" + iter + FIELD_SEPARATOR + ! "elements=" + tSet.size() + FIELD_SEPARATOR + ! "boosting_params=" + m_booster.getParamString() + FIELD_SEPARATOR ! ); ! ! // 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.00000"); ! double[] tmp = null; ! Boolean[] labeltmp = null; ! int j = 0; ! for (int i=0; i < tMargin.size(); i++) { ! // output the example number ! boostingStream.print("" + i + FIELD_SEPARATOR); ! // output the margins ! 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(SEPARATOR); ! } ! boostingStream.print(FIELD_SEPARATOR); ! ! // output the scores ! 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(SEPARATOR); ! } ! boostingStream.print(FIELD_SEPARATOR); ! if (boostingStream.equals(trainBoostingStream)) { ! // 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); ! } ! boostingStream.print(FIELD_SEPARATOR); ! ! ! ! // output the potentials ! for (j= 0; j < tPotentials[i].length; j++){ ! boostingStream.print(f.format(tPotentials[i][j])); ! if (j != tmp.length -1) ! boostingStream.print(SEPARATOR); ! } ! boostingStream.print(FIELD_SEPARATOR); ! ! ! } ! - // output the labels - 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(SEPARATOR); - } - boostingStream.print(FIELD_SEPARATOR); - boostingStream.println(""); - } ! ! // release memory ! tMargin.clear(); ! tScores.clear(); ! tLabelIndices.clear(); ! tMargin= null; ! tScores= null; ! tLabelIndices = null; ! tWeights = null; ! tPotentials = null; } --- 184,276 ---- */ private void logBoostingTrainTest(PrintWriter boostingStream, ExampleSet tSet, int iter, Predictor combined, Predictor base) { ! // Output the training data ! boostingStream.println("iteration=" + iter + FIELD_SEPARATOR + ! "elements=" + tSet.size() + FIELD_SEPARATOR + ! "boosting_params=" + m_booster.getParamString() + FIELD_SEPARATOR ! ); ! // 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.00000"); ! double[] tmp = null; ! Boolean[] labeltmp = null; ! int j = 0; ! for (int i=0; i < tMargin.size(); i++) { ! // output the example number ! boostingStream.print("" + i + FIELD_SEPARATOR); ! // output the margins ! 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(SEPARATOR); ! } ! boostingStream.print(FIELD_SEPARATOR); ! // output the scores ! 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(SEPARATOR); ! } ! boostingStream.print(FIELD_SEPARATOR); ! if (boostingStream.equals(trainBoostingStream)) { ! // 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); ! } ! boostingStream.print(FIELD_SEPARATOR); ! ! ! ! // output the potentials ! for (j= 0; j < tPotentials[i].length; j++){ ! boostingStream.print(f.format(tPotentials[i][j])); ! if (j != tmp.length -1) ! boostingStream.print(SEPARATOR); ! } ! boostingStream.print(FIELD_SEPARATOR); ! ! ! } ! ! ! // output the labels ! 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(SEPARATOR); ! } ! boostingStream.print(FIELD_SEPARATOR); ! boostingStream.println(""); ! } ! ! ! // release memory ! tMargin.clear(); ! tScores.clear(); ! tLabelIndices.clear(); ! tMargin= null; ! tScores= null; ! tLabelIndices = null; ! tWeights = null; ! tPotentials = null; } *************** *** 277,301 **** /** 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= ! 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; ! } ! logBoostingTrainTest(trainBoostingStream, trainSet, iter, combined, base); ! logBoostingTrainTest(testBoostingStream, testSet, iter, combined, base); ! trainBoostingStream.flush(); ! testBoostingStream.flush(); ! infoStream.print(" \t# output boosting data #"); } ! --- 278,302 ---- /** 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= ! 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; ! } ! logBoostingTrainTest(trainBoostingStream, trainSet, iter, combined, base); ! logBoostingTrainTest(testBoostingStream, testSet, iter, combined, base); ! trainBoostingStream.flush(); ! testBoostingStream.flush(); ! infoStream.print(" \t# output boosting data #"); } ! *************** *** 303,314 **** /** 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"); } } --- 304,315 ---- /** 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"); } } |
From: william b. <wil...@us...> - 2008-05-16 18:50:21
|
Update of /cvsroot/jboost/jboost/src/jboost/tokenizer In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv10384/src/jboost/tokenizer Modified Files: LTStreamTokenizer.java Log Message: fixed legacy bugs that prevented comments from being parsed reliably, or at all. Index: LTStreamTokenizer.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/tokenizer/LTStreamTokenizer.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** LTStreamTokenizer.java 16 May 2007 04:06:02 -0000 1.1.1.1 --- LTStreamTokenizer.java 16 May 2008 18:50:01 -0000 1.2 *************** *** 71,75 **** this.terminator= terminator; terLen= terminator.length(); ! minLen= terLen >= 2 ? 2 : terLen; for (int i= 0, terLines= 0; i < terLen; i++) if (terminator.charAt(i) == '\n') --- 71,75 ---- this.terminator= terminator; terLen= terminator.length(); ! minLen= terLen <= 2 ? 2 : terLen; for (int i= 0, terLines= 0; i < terLen; i++) if (terminator.charAt(i) == '\n') *************** *** 135,139 **** while (true) { // if(Monitor.logLevel>3) Monitor.log("strLen=" + strLen + " toCopy=" + toCopy + " i=" + i); ! if (i > strLen - minLen) { try { numRead= br.read(cBuf, 0, bufLen); --- 135,139 ---- while (true) { // if(Monitor.logLevel>3) Monitor.log("strLen=" + strLen + " toCopy=" + toCopy + " i=" + i); ! if (i > strLen - minLen) { try { numRead= br.read(cBuf, 0, bufLen); *************** *** 206,210 **** if (Util.even(numEscapes)) { // line comment starts! curTok += strBuf.substring(toCopy, i - numEscapes / 2); ! ongoingComment= true; } else // escpaed, part of token curTok --- 206,210 ---- if (Util.even(numEscapes)) { // line comment starts! curTok += strBuf.substring(toCopy, i - numEscapes / 2); ! lineComment= true; } else // escpaed, part of token curTok |
From: Daniel H. <dh...@us...> - 2008-04-10 07:54:21
|
Update of /cvsroot/jboost/jboost/src/jboost/booster In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv20362/src/jboost/booster Modified Files: AdaBoost.java Booster.java BrownBoost.java YabaBoost.java AbstractBooster.java Log Message: Merged from jboost_unstable. Index: AbstractBooster.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/AbstractBooster.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** AbstractBooster.java 25 Mar 2008 01:00:27 -0000 1.8 --- AbstractBooster.java 10 Apr 2008 07:54:17 -0000 1.9 *************** *** 3,8 **** import java.io.Serializable; import jboost.controller.Configuration; - import jboost.controller.ControllerConfiguration; - import jboost.monitor.Monitor; /** --- 3,6 ---- *************** *** 21,235 **** public abstract class AbstractBooster implements Booster, Serializable { ! protected static final String PREFIX= "booster_"; ! ! /** ! * Factory method to build a booster instance according to ! * given configuration. Uses reflection to do this. ! * ! * @param c set of options for the booster ! * @param num_labels the number of m_labels in the data ! * @param isMultiLabel true if multilabled data ! * @return Booster ! */ ! public static Booster getInstance(Configuration c, int num_labels, ! boolean isMultiLabel) ! throws ClassNotFoundException, InstantiationException, ! IllegalAccessException, Exception { ! ! AbstractBooster result = null; ! ! // Get the booster type from configuration and ! // create a class of that type. ! String boosterType= c.getString(PREFIX + "type", ! "jboost.booster.AdaBoost"); ! System.out.println("Booster type: " + boosterType); ! Class boosterClass = Class.forName(boosterType); ! result = (AbstractBooster) boosterClass.newInstance(); ! result.init(c); ! ! // Get the runtime of the booster (if applicable). ! // If the booster is a discrete iterative scheme, the ! // number of iterations is dealt with elsewhere. ! if (result instanceof jboost.booster.BrownBoost) { ! double eps = 0.001; ! double runtime = Double.parseDouble(c.getString("boostingRuntime", ! "0.0")); ! if (runtime <= eps) { ! String str = "Need to specify runtime for m_booster " + result ! + ". Runtime must be larger than " + eps + "."; ! Monitor.log(str); ! throw new Exception(str); ! } ! ! jboost.booster.BrownBoost brown = (jboost.booster.BrownBoost) result; ! brown.setRuntime(runtime); ! result = brown; ! if (result instanceof jboost.booster.YabaBoost) { ! jboost.booster.YabaBoost yaba = (jboost.booster.YabaBoost) result; ! double c1=0, c2=0, theta=0, nc=0; ! double rpos=0, c1pos=0, c2pos=0, thetapos=0, ncpos=0; ! double rneg=0, c1neg=0, c2neg=0, thetaneg=0, ncneg=0; ! ControllerConfiguration conf = (ControllerConfiguration)c; ! try { ! c1 = Double.parseDouble(c.getString("c1", "Z1.0")); ! c2 = Double.parseDouble(c.getString("c2", "Z1.0")); ! theta = Double.parseDouble(c.getString("theta", "Z0.15")); ! nc = Double.parseDouble(c.getString("nc", "Z0.15")); ! yaba.setParams(c1,c2,theta,nc); ! if (conf.getCostSensitive()) { ! /* ! System.out.println(" runtime: " + rpos + "," + rneg + ! " c1: " + c1pos + "," + c1neg + ! " c2: " + c2pos + "," + c2neg + ! " theta: " + thetapos + "," + thetaneg + ! " nc: " + ncpos + "," + ncneg ! ); ! */ ! rpos = Double.parseDouble(c.getString("pos_c","Z")); ! rneg = Double.parseDouble(c.getString("neg_c","Z")); ! c1pos = Double.parseDouble(c.getString("pos_c1","Z")); ! c1neg = Double.parseDouble(c.getString("neg_c1","Z")); ! /* ! System.out.println(" runtime: " + rpos + "," + rneg + ! " c1: " + c1pos + "," + c1neg + ! " c2: " + c2pos + "," + c2neg + ! " theta: " + thetapos + "," + thetaneg + ! " nc: " + ncpos + "," + ncneg ! ); ! */ ! c2pos = Double.parseDouble(c.getString("pos_c2","Z")); ! c2neg = Double.parseDouble(c.getString("neg_c2","Z")); ! thetapos = Double.parseDouble(c.getString("pos_theta","Z")); ! thetaneg = Double.parseDouble(c.getString("neg_theta","Z")); ! ncpos = Double.parseDouble(c.getString("pos_nc","Z")); ! ncneg = Double.parseDouble(c.getString("neg_nc","Z")); ! /* ! System.out.println(" runtime: " + rpos + "," + rneg + ! " c1: " + c1pos + "," + c1neg + ! " c2: " + c2pos + "," + c2neg + ! " theta: " + thetapos + "," + thetaneg + ! " nc: " + ncpos + "," + ncneg ! ); ! */ ! yaba.setCostSensitiveParams(rpos, c1pos, c2pos, thetapos, ncpos, ! rneg, c1neg, c2neg, thetaneg, ncneg); ! } ! } catch (NumberFormatException e) { ! System.err.println("Need to supply appropriate parameters!"); ! System.err.println("For YabaBoost normal, we need r, c1, c2, nc, and theta!"); ! System.err.println("For YabaBoost cost sensitive, we need neg_c, pos_c, neg_c1, pos_c1, neg_c2, pos_c2, neg_theta, pos_theta, neg_nc, pos_nc"); ! throw new InstantiationException("Need more params for yaba"); ! } ! result = yaba; ! } ! } ! // If we have a multilable or multiclass problem, we need to wrap it. ! if (num_labels > 2 || isMultiLabel) { ! result= new MulticlassWrapMH(result, num_labels, isMultiLabel); ! } ! // If we are debugging, then wrap in paranoia ! boolean paranoid= c.getBool(PREFIX + "paranoid", false); ! if (paranoid) { ! result= new DebugWrap(result); ! } ! return result; } ! public int getNumExamples(){ ! return 0; } ! public String getParamString() { ! return "No parameters defined"; ! } - /** - * Create and return a new Bag which initially contains the - * elements in the list. - * - * @param list initial items to add to the Bag - */ - public Bag newBag(int[] list) { - Bag bag= newBag(); - bag.addExampleList(list); - return bag; - } ! /** ! * Clone a bag ! * ! * @param orig the bag to clone ! * @return new bag ! */ ! public Bag newBag(Bag orig) { ! Bag newbag= newBag(); ! newbag.copyBag(orig); ! return newbag; ! } - /** - * Find the best binary split for a sorted list of example indices - * with given split points. - * @param l an array of example indices, sorted. - * @param sp an array with true in position i when a split between - * positions i-1 and i should be checked - * @param b0 - a bag with all points below the best split (upon return) - * @param b1 - a bag with all points at or above the best split (upon return) - * @return the index in l where the best split occurred (possibly - * 0 if the best split puts all points on one side) - */ - public int findBestSplit(Bag b0, Bag b1, int[] l, boolean[] sp) { - Bag[] bags= new Bag[2]; ! bags[0]= newBag(); // init an empty bag ! bags[1]= newBag(l); // init a full bag ! b0.reset(); ! b1.copyBag(bags[1]); ! if (l.length == 0) ! return 0; ! double bestLoss= getLoss(bags); ! int bestIndex= 0; ! double loss; ! for (int i= 0; i < l.length - 1; i++) { ! bags[1].subtractExample(l[i]); ! bags[0].addExample(l[i]); ! if (sp[i + 1]) { // if this is a potential split point ! if ((loss= getLoss(bags)) < bestLoss) { ! bestLoss= loss; ! bestIndex= i + 1; ! b0.copyBag(bags[0]); ! b1.copyBag(bags[1]); ! } ! } } ! return bestIndex; } ! /** ! * Compute the loss associated with an array of bags where small ! * loss is considered "better". We assume that loss is additive ! * for a set of bags. ! * ! * @param bags array of bags whose losses will be added up and returned ! * @return loss the sum of the losses for all the bags ! */ ! public double getLoss(Bag[] bags) { ! double loss = 0; ! for (int i=0; i < bags.length; i++) { ! loss += bags[i].getLoss(); ! } ! return loss; } } --- 19,157 ---- public abstract class AbstractBooster implements Booster, Serializable { ! protected static final String PREFIX= "booster_"; + /** + * Factory method to build a booster instance according to + * given configuration. Uses reflection to do this. + * + * @param c set of options for the booster + * @param num_labels the number of m_labels in the data + * @param isMultiLabel true if multilabled data + * @return Booster + */ + public static Booster getInstance(Configuration c, int num_labels, + boolean isMultiLabel) + throws ClassNotFoundException, InstantiationException, + IllegalAccessException, Exception { + AbstractBooster result = null; ! // Get the booster type from configuration and ! // create a class of that type. ! String boosterType= c.getString(PREFIX + "type", ! "jboost.booster.AdaBoost"); ! System.out.println("Booster type: " + boosterType); ! Class boosterClass = Class.forName(boosterType); ! result = (AbstractBooster) boosterClass.newInstance(); ! result.init(c); ! // Get the runtime of the booster (if applicable). ! // If the booster is a discrete iterative scheme, the ! // number of iterations is dealt with elsewhere. ! // If we have a multilable or multiclass problem, we need to wrap it. ! if (num_labels > 2 || isMultiLabel) { ! result= new MulticlassWrapMH(result, num_labels, isMultiLabel); } ! // If we are debugging, then wrap in paranoia ! boolean paranoid= c.getBool(PREFIX + "paranoid", false); ! if (paranoid) { ! result= new DebugWrap(result); } + return result; + } ! public int getNumExamples(){ ! return 0; ! } + public String getParamString() { + return "No parameters defined"; + } ! /** ! * Create and return a new Bag which initially contains the ! * elements in the list. ! * ! * @param list initial items to add to the Bag ! */ ! public Bag newBag(int[] list) { ! Bag bag= newBag(); ! bag.addExampleList(list); ! return bag; ! } + /** + * Clone a bag + * + * @param orig the bag to clone + * @return new bag + */ + public Bag newBag(Bag orig) { + Bag newbag= newBag(); + newbag.copyBag(orig); + return newbag; + } ! /** ! * Find the best binary split for a sorted list of example indices ! * with given split points. ! * @param l an array of example indices, sorted. ! * @param sp an array with true in position i when a split between ! * positions i-1 and i should be checked ! * @param b0 - a bag with all points below the best split (upon return) ! * @param b1 - a bag with all points at or above the best split (upon return) ! * @return the index in l where the best split occurred (possibly ! * 0 if the best split puts all points on one side) ! */ ! public int findBestSplit(Bag b0, Bag b1, int[] l, boolean[] sp) { ! Bag[] bags= new Bag[2]; ! bags[0]= newBag(); // init an empty bag ! bags[1]= newBag(l); // init a full bag ! b0.reset(); ! b1.copyBag(bags[1]); ! if (l.length == 0) ! return 0; ! double bestLoss= getLoss(bags); ! int bestIndex= 0; ! double loss; ! ! for (int i= 0; i < l.length - 1; i++) { ! bags[1].subtractExample(l[i]); ! bags[0].addExample(l[i]); ! if (sp[i + 1]) { // if this is a potential split point ! if ((loss= getLoss(bags)) < bestLoss) { ! bestLoss= loss; ! bestIndex= i + 1; ! b0.copyBag(bags[0]); ! b1.copyBag(bags[1]); } ! } } + return bestIndex; + } ! /** ! * Compute the loss associated with an array of bags where small ! * loss is considered "better". We assume that loss is additive ! * for a set of bags. ! * ! * @param bags array of bags whose losses will be added up and returned ! * @return loss the sum of the losses for all the bags ! */ ! public double getLoss(Bag[] bags) { ! double loss = 0; ! for (int i=0; i < bags.length; i++) { ! loss += bags[i].getLoss(); } + return loss; + } } Index: YabaBoost.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/YabaBoost.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** YabaBoost.java 25 Mar 2008 01:00:28 -0000 1.8 --- YabaBoost.java 10 Apr 2008 07:54:17 -0000 1.9 *************** *** 1,21 **** package jboost.booster; - import java.io.BufferedWriter; - import java.io.FileWriter; import java.io.*; - import java.io.IOException; - import java.io.PrintWriter; - - import java.text.DecimalFormat; - import java.text.NumberFormat; [...1566 lines suppressed...] ! } ! public Bag newBag(Bag bag) { ! return new YabaBag((YabaBag) bag); ! } ! /** ! * Returns the prediction associated with a bag representing a subset of the ! * data. ! */ ! protected Prediction getPrediction(Bag b) { ! return ((YabaBag) b).calcPrediction(); ! } ! protected MixedBinaryPrediction getZeroPred() { ! return new MixedBinaryPrediction(0,0); ! } Index: AdaBoost.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/AdaBoost.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** AdaBoost.java 25 Mar 2008 01:00:27 -0000 1.6 --- AdaBoost.java 10 Apr 2008 07:54:16 -0000 1.7 *************** *** 28,32 **** protected double[] m_margins; /** permanent storage for old m_margins */ ! protected double[] m_oldMargins; /** permanent storage for example m_weights */ protected double[] m_weights; --- 28,32 ---- protected double[] m_margins; /** permanent storage for old m_margins */ ! protected double[] m_oldMargins; // XXX DJH: this is never used in AdaBoost (e.g. not cleared in clear()) /** permanent storage for example m_weights */ protected double[] m_weights; *************** *** 73,77 **** /** temporary location for storing the examples as they are read in */ ! protected List m_tmpList; --- 73,77 ---- /** temporary location for storing the examples as they are read in */ ! protected List<TmpData> m_tmpList; *************** *** 90,94 **** */ AdaBoost(double smooth) { ! m_tmpList= new ArrayList(); m_numExamples= 0; m_smooth= smooth; --- 90,94 ---- */ AdaBoost(double smooth) { ! m_tmpList= new ArrayList<TmpData>(); m_numExamples= 0; m_smooth= smooth; *************** *** 104,113 **** } ! /** ! * Add an example to the data set of this booster ! * @param index ! * @param label ! * @param weight ! */ public void addExample(int index, Label label, double weight) { int l= label.getSingleValue(); --- 104,113 ---- } ! /** ! * Add an example to the data set of this booster ! * @param index ! * @param label ! * @param weight ! */ public void addExample(int index, Label label, double weight) { int l= label.getSingleValue(); *************** *** 119,128 **** if (l==POSITIVE_LABEL) m_numPosExamples++; } else { ! failed= "AdaBoost.addExample received index " + index + ", when it expected index " + ! m_numExamples; } } else { ! failed= "Adaboost.addExample expected a label which is either 0 or 1. It received " + ! l; } --- 119,128 ---- if (l==POSITIVE_LABEL) m_numPosExamples++; } else { ! // XXX DJH: determine class name at runtime ! failed= getClass().getName() + ".addExample received index " + index + ", when it expected index " + m_numExamples; } } else { ! // XXX DJH: determine class name at runtime ! failed= getClass().getName() + ".addExample expected a label which is either 0 or 1. It received " + l; } *************** *** 181,185 **** m_negExamples[m_negIndex++] = index; else { ! System.err.println("Label of example is unknown to adaboost"); System.exit(2); } --- 181,186 ---- m_negExamples[m_negIndex++] = index; else { ! // XXX DJH: determine class name at runtime ! System.err.println("Label of example is unknown to " + this.getClass().getName()); System.exit(2); } *************** *** 248,278 **** ! /** ! * Returns a string with all the weights, margins, etc ! */ ! public String getExampleData() { ! StringBuffer ret = new StringBuffer(""); ! ret.append(getParamString()); ! for (int i=0; i<m_margins.length; i++){ ! ret.append(String.format("[%d];[%.4f];[%.4f];[%.4f];\n", ! m_labels[i], m_margins[i], m_weights[i], ! m_potentials[i])); ! } ! return ret.toString(); } ! public String getParamString() { ! String ret = String.format("None (AdaBoost)"); ! return ret; ! } /** output AdaBoost contents as a human-readable string */ public String toString() { String s= ! "Adaboost. No of examples = " ! + m_numExamples ! + ", m_epsilon = " ! + m_epsilon; s += "\nindex\tmargin\tweight\told weight\tlabel\n"; NumberFormat f= new DecimalFormat("0.00"); --- 249,282 ---- ! /** ! * Returns a string with all the weights, margins, etc ! */ ! public String getExampleData() { ! StringBuffer ret = new StringBuffer(""); ! ret.append(getParamString()); ! for (int i=0; i<m_margins.length; i++){ ! ret.append(String.format("[%d];[%.4f];[%.4f];[%.4f];\n", ! m_labels[i], m_margins[i], m_weights[i], ! m_potentials[i])); } + return ret.toString(); + } ! public String getParamString() { ! // XXX DJH: determine class name at runtime ! String ret = String.format("None (" + getClass().getName() + ")"); ! return ret; ! } /** output AdaBoost contents as a human-readable string */ public String toString() { + // XXX DJH: determine class name at runtime String s= ! getClass().getName() + ! ". No of examples = " ! + m_numExamples ! + ", m_epsilon = " ! + m_epsilon; s += "\nindex\tmargin\tweight\told weight\tlabel\n"; NumberFormat f= new DecimalFormat("0.00"); *************** *** 289,293 **** + f.format(m_sampleWeights[i]) + "\t\t" + m_labels[i] ! + "\n"; } return s; --- 293,297 ---- + f.format(m_sampleWeights[i]) + "\t\t" + m_labels[i] ! + "\n"; } return s; *************** *** 353,357 **** * @return +1 if label matches hyp, -1 if label doesn't match hyp, 0 if no hyp */ ! public double getStep(short simple_label, double hyp_pred) { double step = getLabel(simple_label)*hyp_pred; double EPS = 0.000001; --- 357,362 ---- * @return +1 if label matches hyp, -1 if label doesn't match hyp, 0 if no hyp */ ! // XXX DJH: changed from 'public' to 'protected' ! protected double getStep(short simple_label, double hyp_pred) { double step = getLabel(simple_label)*hyp_pred; double EPS = 0.000001; *************** *** 360,364 **** } ! public double getLabel(short simple_label) { return sign(-simple_label+0.5); } --- 365,370 ---- } ! // XXX DJH: changed from 'public' to 'protected' ! protected double getLabel(short simple_label) { return sign(-simple_label+0.5); } *************** *** 369,373 **** double total_weight = 0.0; ! // Keep track of which hypotheses had hypotheses associated with them. boolean[] examplesWithHyp = new boolean[m_margins.length]; m_hypPredictions = new double[m_margins.length]; --- 375,379 ---- double total_weight = 0.0; ! // Keep track of which examples had hypotheses associated with them. boolean[] examplesWithHyp = new boolean[m_margins.length]; m_hypPredictions = new double[m_margins.length]; *************** *** 378,384 **** int example = index[j]; if (this instanceof BrownBoost) ! m_hypPredictions[example] = ((BrownBag)b).calcPrediction(1.0,1.0).getClassScores()[0]; ! else ! m_hypPredictions[example] = b.calcPrediction().getClassScores()[0]; } } --- 384,390 ---- int example = index[j]; if (this instanceof BrownBoost) ! m_hypPredictions[example] = ((BrownBag)b).calcPrediction(1.0,1.0).getClassScores()[0]; ! else ! m_hypPredictions[example] = b.calcPrediction().getClassScores()[0]; } } *************** *** 386,390 **** int numExamplesWithHyps = 0; - double weight; // Get all examples that have a hypothesis associated with them for (int i= 0; i < exampleIndex.length; i++) { --- 392,395 ---- *************** *** 442,446 **** } }*/ - double gamma = getHypErr(bags, exampleIndex); return getPredictions(bags); } --- 447,450 ---- *************** *** 452,456 **** */ public double calculateWeight(double margin) { ! return Math.exp(-1 * margin); } --- 456,460 ---- */ public double calculateWeight(double margin) { ! return Math.exp(-1 * margin); } *************** *** 579,583 **** double EPS = 0.0000001; if (m_w[0] < EPS && m_w[1] < EPS) { ! return true; } return false; --- 583,587 ---- double EPS = 0.0000001; if (m_w[0] < EPS && m_w[1] < EPS) { ! return true; } return false; *************** *** 665,672 **** BinaryPrediction p = new BinaryPrediction( ! m_w[1] == m_w[0] ! ? 0.0 ! : // handle case that w0=w1=0 ! 0.5 * Math.log((m_w[1] + smoothFactor) / (m_w[0] + smoothFactor))); return p; } --- 669,676 ---- BinaryPrediction p = new BinaryPrediction( ! m_w[1] == m_w[0] ! ? 0.0 ! : // handle case that w0=w1=0 ! 0.5 * Math.log((m_w[1] + smoothFactor) / (m_w[0] + smoothFactor))); return p; } Index: Booster.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/Booster.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Booster.java 25 Mar 2008 01:00:27 -0000 1.4 --- Booster.java 10 Apr 2008 07:54:17 -0000 1.5 *************** *** 71,79 **** ! public abstract double[][] getWeights(); ! public abstract double[][] getPotentials(); ! public abstract double getTotalWeight(); ! public int getNumExamples(); ! public abstract String getParamString(); --- 71,79 ---- ! public abstract double[][] getWeights(); ! public abstract double[][] getPotentials(); ! public abstract double getTotalWeight(); ! public int getNumExamples(); ! public abstract String getParamString(); *************** *** 93,96 **** --- 93,99 ---- * partition of the data. */ + // XXX DJH: What is 'partition'? Similar to 'elements' below? + // XXX YF: I think you are probably correct in your interpretation, need to check the inplementation, verify, and update the + // XXX Description of this method and change "examples" to "elements" in the javadoc for "update". public abstract Prediction[] getPredictions(Bag[] b, int[][] partition); Index: BrownBoost.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/BrownBoost.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** BrownBoost.java 25 Mar 2008 01:00:27 -0000 1.11 --- BrownBoost.java 10 Apr 2008 07:54:17 -0000 1.12 *************** *** 3,13 **** import java.text.DecimalFormat; import java.text.NumberFormat; - import java.util.ArrayList; - import java.util.List; - import jboost.booster.AdaBoost.BinaryBag; import jboost.controller.Configuration; ! import jboost.examples.Label; ! import jboost.NotSupportedException; [...1462 lines suppressed...] ! super(); ! } ! /** constructor that copies an existing bag */ ! protected BrownBag(BrownBag bag) { ! super(bag); ! } ! /** Output the weights in the bag */ ! public String toString() { ! String s= "BrownBag.\t w0=" + m_w[0] + "\t w1=" + m_w[1] + "\n"; ! return s; ! } ! } /* End BrownBag */ |
From: Daniel H. <dh...@us...> - 2008-04-10 07:47:10
|
Update of /cvsroot/jboost/jboost/src/jboost/booster In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv17104/src/jboost/booster Modified Files: Tag: jboost_unstable AbstractBooster.java Log Message: Removed unused imports. Index: AbstractBooster.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/AbstractBooster.java,v retrieving revision 1.8.2.2 retrieving revision 1.8.2.3 diff -C2 -d -r1.8.2.2 -r1.8.2.3 *** AbstractBooster.java 9 Apr 2008 07:24:05 -0000 1.8.2.2 --- AbstractBooster.java 10 Apr 2008 07:46:57 -0000 1.8.2.3 *************** *** 3,8 **** import java.io.Serializable; import jboost.controller.Configuration; - import jboost.controller.ControllerConfiguration; - import jboost.monitor.Monitor; /** --- 3,6 ---- |
From: Daniel H. <dh...@us...> - 2008-04-10 07:32:44
|
Update of /cvsroot/jboost/jboost/src/jboost/booster In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv10894/src/jboost/booster Modified Files: Tag: jboost_unstable YabaBoost.java Log Message: Changed 'init()' to use 'config.getDouble()' instead of 'config.getString()' and check class before casting 'config'. Index: YabaBoost.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/YabaBoost.java,v retrieving revision 1.8.2.1 retrieving revision 1.8.2.2 diff -C2 -d -r1.8.2.1 -r1.8.2.2 *** YabaBoost.java 9 Apr 2008 07:24:04 -0000 1.8.2.1 --- YabaBoost.java 10 Apr 2008 07:32:29 -0000 1.8.2.2 *************** *** 99,118 **** double rneg=0, c1neg=0, c2neg=0, thetaneg=0, ncneg=0; try { ! c1 = Double.parseDouble(config.getString("c1", "Z1.0")); ! c2 = Double.parseDouble(config.getString("c2", "Z1.0")); ! theta = Double.parseDouble(config.getString("theta", "Z0.15")); ! nc = Double.parseDouble(config.getString("nc", "Z0.15")); setParams(c1,c2,theta,nc); ! if (((ControllerConfiguration) config).getCostSensitive()) { ! rpos = Double.parseDouble(config.getString("pos_c","Z")); ! rneg = Double.parseDouble(config.getString("neg_c","Z")); ! c1pos = Double.parseDouble(config.getString("pos_c1","Z")); ! c1neg = Double.parseDouble(config.getString("neg_c1","Z")); ! c2pos = Double.parseDouble(config.getString("pos_c2","Z")); ! c2neg = Double.parseDouble(config.getString("neg_c2","Z")); ! thetapos = Double.parseDouble(config.getString("pos_theta","Z")); ! thetaneg = Double.parseDouble(config.getString("neg_theta","Z")); ! ncpos = Double.parseDouble(config.getString("pos_nc","Z")); ! ncneg = Double.parseDouble(config.getString("neg_nc","Z")); setCostSensitiveParams(rpos, c1pos, c2pos, thetapos, ncpos, rneg, c1neg, c2neg, thetaneg, ncneg); } --- 99,119 ---- double rneg=0, c1neg=0, c2neg=0, thetaneg=0, ncneg=0; try { ! c1 = config.getDouble("c1", 1.0); ! c2 = config.getDouble("c2", 1.0); ! theta = config.getDouble("theta", 0.15);; ! nc = config.getDouble("nc", 0.15); setParams(c1,c2,theta,nc); ! if (config instanceof ControllerConfiguration && ! ((ControllerConfiguration) config).getCostSensitive()) { ! rpos = config.getDouble("pos_c",1.0); ! rneg = config.getDouble("neg_c",1.0); ! c1pos = config.getDouble("pos_c1",1.0); ! c1neg = config.getDouble("neg_c1",1.0); ! c2pos = config.getDouble("pos_c2",1.0); ! c2neg = config.getDouble("neg_c2",1.0); ! thetapos = config.getDouble("pos_theta",1.0); ! thetaneg = config.getDouble("neg_theta",1.0); ! ncpos = config.getDouble("pos_nc",1.0); ! ncneg = config.getDouble("neg_nc",1.0); setCostSensitiveParams(rpos, c1pos, c2pos, thetapos, ncpos, rneg, c1neg, c2neg, thetaneg, ncneg); } |
From: Daniel H. <dh...@us...> - 2008-04-09 07:24:29
|
Update of /cvsroot/jboost/jboost/src/jboost/booster In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv26281/src/jboost/booster Modified Files: Tag: jboost_unstable BrownBoost.java YabaBoost.java AbstractBooster.java Log Message: Cleaned up AbstractBooster (moved config code to BrownBoost and YabaBoost). Index: YabaBoost.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/YabaBoost.java,v retrieving revision 1.8 retrieving revision 1.8.2.1 diff -C2 -d -r1.8 -r1.8.2.1 *** YabaBoost.java 25 Mar 2008 01:00:28 -0000 1.8 --- YabaBoost.java 9 Apr 2008 07:24:04 -0000 1.8.2.1 *************** *** 1,21 **** package jboost.booster; - import java.io.BufferedWriter; - import java.io.FileWriter; import java.io.*; - import java.io.IOException; - import java.io.PrintWriter; - - import java.text.DecimalFormat; - import java.text.NumberFormat; [...1565 lines suppressed...] ! } ! public Bag newBag(Bag bag) { ! return new YabaBag((YabaBag) bag); ! } ! /** ! * Returns the prediction associated with a bag representing a subset of the ! * data. ! */ ! protected Prediction getPrediction(Bag b) { ! return ((YabaBag) b).calcPrediction(); ! } ! protected MixedBinaryPrediction getZeroPred() { ! return new MixedBinaryPrediction(0,0); ! } Index: AbstractBooster.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/AbstractBooster.java,v retrieving revision 1.8.2.1 retrieving revision 1.8.2.2 diff -C2 -d -r1.8.2.1 -r1.8.2.2 *** AbstractBooster.java 7 Apr 2008 17:19:55 -0000 1.8.2.1 --- AbstractBooster.java 9 Apr 2008 07:24:05 -0000 1.8.2.2 *************** *** 51,132 **** // If the booster is a discrete iterative scheme, the // number of iterations is dealt with elsewhere. - // XXX DJH: Why isn't this done in BrownBoost/YABA.init()? - // XXX YF: I also think this should not be done in AbstractBooster. - if (result instanceof jboost.booster.BrownBoost) { - double eps = 0.001; - double runtime = Double.parseDouble(c.getString("boostingRuntime", - "0.0")); - if (runtime <= eps) { - String str = "Need to specify runtime for m_booster " + result - + ". Runtime must be larger than " + eps + "."; - Monitor.log(str); - throw new Exception(str); - } - - jboost.booster.BrownBoost brown = (jboost.booster.BrownBoost) result; - brown.setRuntime(runtime); - result = brown; - - - - if (result instanceof jboost.booster.YabaBoost) { - jboost.booster.YabaBoost yaba = (jboost.booster.YabaBoost) result; - double c1=0, c2=0, theta=0, nc=0; - double rpos=0, c1pos=0, c2pos=0, thetapos=0, ncpos=0; - double rneg=0, c1neg=0, c2neg=0, thetaneg=0, ncneg=0; - ControllerConfiguration conf = (ControllerConfiguration)c; - try { - c1 = Double.parseDouble(c.getString("c1", "Z1.0")); - c2 = Double.parseDouble(c.getString("c2", "Z1.0")); - theta = Double.parseDouble(c.getString("theta", "Z0.15")); - nc = Double.parseDouble(c.getString("nc", "Z0.15")); - yaba.setParams(c1,c2,theta,nc); - if (conf.getCostSensitive()) { - /* - System.out.println(" runtime: " + rpos + "," + rneg + - " c1: " + c1pos + "," + c1neg + - " c2: " + c2pos + "," + c2neg + - " theta: " + thetapos + "," + thetaneg + - " nc: " + ncpos + "," + ncneg - ); - */ - rpos = Double.parseDouble(c.getString("pos_c","Z")); - rneg = Double.parseDouble(c.getString("neg_c","Z")); - c1pos = Double.parseDouble(c.getString("pos_c1","Z")); - c1neg = Double.parseDouble(c.getString("neg_c1","Z")); - /* - System.out.println(" runtime: " + rpos + "," + rneg + - " c1: " + c1pos + "," + c1neg + - " c2: " + c2pos + "," + c2neg + - " theta: " + thetapos + "," + thetaneg + - " nc: " + ncpos + "," + ncneg - ); - */ - c2pos = Double.parseDouble(c.getString("pos_c2","Z")); - c2neg = Double.parseDouble(c.getString("neg_c2","Z")); - thetapos = Double.parseDouble(c.getString("pos_theta","Z")); - thetaneg = Double.parseDouble(c.getString("neg_theta","Z")); - ncpos = Double.parseDouble(c.getString("pos_nc","Z")); - ncneg = Double.parseDouble(c.getString("neg_nc","Z")); - /* - System.out.println(" runtime: " + rpos + "," + rneg + - " c1: " + c1pos + "," + c1neg + - " c2: " + c2pos + "," + c2neg + - " theta: " + thetapos + "," + thetaneg + - " nc: " + ncpos + "," + ncneg - ); - */ - yaba.setCostSensitiveParams(rpos, c1pos, c2pos, thetapos, ncpos, - rneg, c1neg, c2neg, thetaneg, ncneg); - } - } catch (NumberFormatException e) { - System.err.println("Need to supply appropriate parameters!"); - System.err.println("For YabaBoost normal, we need r, c1, c2, nc, and theta!"); - System.err.println("For YabaBoost cost sensitive, we need neg_c, pos_c, neg_c1, pos_c1, neg_c2, pos_c2, neg_theta, pos_theta, neg_nc, pos_nc"); - throw new InstantiationException("Need more params for yaba"); - } - result = yaba; - } - } // If we have a multilable or multiclass problem, we need to wrap it. --- 51,54 ---- Index: BrownBoost.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/BrownBoost.java,v retrieving revision 1.11 retrieving revision 1.11.2.1 diff -C2 -d -r1.11 -r1.11.2.1 *** BrownBoost.java 25 Mar 2008 01:00:27 -0000 1.11 --- BrownBoost.java 9 Apr 2008 07:24:03 -0000 1.11.2.1 *************** *** 3,13 **** import java.text.DecimalFormat; import java.text.NumberFormat; - import java.util.ArrayList; - import java.util.List; - import jboost.booster.AdaBoost.BinaryBag; import jboost.controller.Configuration; ! import jboost.examples.Label; ! import jboost.NotSupportedException; [...1462 lines suppressed...] ! super(); ! } ! /** constructor that copies an existing bag */ ! protected BrownBag(BrownBag bag) { ! super(bag); ! } ! /** Output the weights in the bag */ ! public String toString() { ! String s= "BrownBag.\t w0=" + m_w[0] + "\t w1=" + m_w[1] + "\n"; ! return s; ! } ! } /* End BrownBag */ |
From: Daniel H. <dh...@us...> - 2008-04-07 17:23:52
|
Update of /cvsroot/jboost/jboost/src/jboost/booster In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv24857/src/jboost/booster Added Files: Tag: jboost_unstable NormalBoost.java Log Message: initial version; nothing implemented yet. --- NEW FILE: NormalBoost.java --- package jboost.booster; import jboost.controller.Configuration; /** * * @author djhsu * @version $Header: /cvsroot/jboost/jboost/src/jboost/booster/Attic/NormalBoost.java,v 1.1.2.1 2008/04/07 17:23:43 dhsu Exp $ */ public class NormalBoost extends AdaBoost { // XXX DJH: I do not understand how this is used outside of the booster // package (e.g. in Controller.java) public double calculateWeight(double margin) { // TODO Auto-generated method stub return 0; } public void clear() { // TODO Auto-generated method stub } protected void finalizeData(double defaultWeight) { // TODO Auto-generated method stub } public Prediction[] getPredictions(Bag[] b) { // TODO Auto-generated method stub return null; } public Prediction[] getPredictions(Bag[] b, int[][] partition) { // TODO Auto-generated method stub return null; } public double getTheoryBound() { // TODO Auto-generated method stub return 0; } public void init(Configuration config) { // TODO Auto-generated method stub } public Bag newBag() { // TODO Auto-generated method stub return null; } public void update(Prediction[] predictions, int[][] elements) { // TODO Auto-generated method stub } } |
From: Daniel H. <dh...@us...> - 2008-04-07 17:21:51
|
Update of /cvsroot/jboost/jboost/src/jboost/booster In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv23957/src/jboost/booster Modified Files: Tag: jboost_unstable AdaBoost.java Log Message: clean-up Index: AdaBoost.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/AdaBoost.java,v retrieving revision 1.6 retrieving revision 1.6.2.1 diff -C2 -d -r1.6 -r1.6.2.1 *** AdaBoost.java 25 Mar 2008 01:00:27 -0000 1.6 --- AdaBoost.java 7 Apr 2008 17:21:47 -0000 1.6.2.1 *************** *** 28,32 **** protected double[] m_margins; /** permanent storage for old m_margins */ ! protected double[] m_oldMargins; /** permanent storage for example m_weights */ protected double[] m_weights; --- 28,32 ---- protected double[] m_margins; /** permanent storage for old m_margins */ ! protected double[] m_oldMargins; // XXX DJH: this is never used in AdaBoost (e.g. not cleared in clear()) /** permanent storage for example m_weights */ protected double[] m_weights; *************** *** 73,77 **** /** temporary location for storing the examples as they are read in */ ! protected List m_tmpList; --- 73,77 ---- /** temporary location for storing the examples as they are read in */ ! protected List<TmpData> m_tmpList; *************** *** 90,94 **** */ AdaBoost(double smooth) { ! m_tmpList= new ArrayList(); m_numExamples= 0; m_smooth= smooth; --- 90,94 ---- */ AdaBoost(double smooth) { ! m_tmpList= new ArrayList<TmpData>(); m_numExamples= 0; m_smooth= smooth; *************** *** 104,113 **** } ! /** ! * Add an example to the data set of this booster ! * @param index ! * @param label ! * @param weight ! */ public void addExample(int index, Label label, double weight) { int l= label.getSingleValue(); --- 104,113 ---- } ! /** ! * Add an example to the data set of this booster ! * @param index ! * @param label ! * @param weight ! */ public void addExample(int index, Label label, double weight) { int l= label.getSingleValue(); *************** *** 119,128 **** if (l==POSITIVE_LABEL) m_numPosExamples++; } else { ! failed= "AdaBoost.addExample received index " + index + ", when it expected index " + ! m_numExamples; } } else { ! failed= "Adaboost.addExample expected a label which is either 0 or 1. It received " + ! l; } --- 119,128 ---- if (l==POSITIVE_LABEL) m_numPosExamples++; } else { ! // XXX DJH: determine class name at runtime ! failed= getClass().getName() + ".addExample received index " + index + ", when it expected index " + m_numExamples; } } else { ! // XXX DJH: determine class name at runtime ! failed= getClass().getName() + ".addExample expected a label which is either 0 or 1. It received " + l; } *************** *** 181,185 **** m_negExamples[m_negIndex++] = index; else { ! System.err.println("Label of example is unknown to adaboost"); System.exit(2); } --- 181,186 ---- m_negExamples[m_negIndex++] = index; else { ! // XXX DJH: determine class name at runtime ! System.err.println("Label of example is unknown to " + this.getClass().getName()); System.exit(2); } *************** *** 248,278 **** ! /** ! * Returns a string with all the weights, margins, etc ! */ ! public String getExampleData() { ! StringBuffer ret = new StringBuffer(""); ! ret.append(getParamString()); ! for (int i=0; i<m_margins.length; i++){ ! ret.append(String.format("[%d];[%.4f];[%.4f];[%.4f];\n", ! m_labels[i], m_margins[i], m_weights[i], ! m_potentials[i])); ! } ! return ret.toString(); } ! public String getParamString() { ! String ret = String.format("None (AdaBoost)"); ! return ret; ! } /** output AdaBoost contents as a human-readable string */ public String toString() { String s= ! "Adaboost. No of examples = " ! + m_numExamples ! + ", m_epsilon = " ! + m_epsilon; s += "\nindex\tmargin\tweight\told weight\tlabel\n"; NumberFormat f= new DecimalFormat("0.00"); --- 249,282 ---- ! /** ! * Returns a string with all the weights, margins, etc ! */ ! public String getExampleData() { ! StringBuffer ret = new StringBuffer(""); ! ret.append(getParamString()); ! for (int i=0; i<m_margins.length; i++){ ! ret.append(String.format("[%d];[%.4f];[%.4f];[%.4f];\n", ! m_labels[i], m_margins[i], m_weights[i], ! m_potentials[i])); } + return ret.toString(); + } ! public String getParamString() { ! // XXX DJH: determine class name at runtime ! String ret = String.format("None (" + getClass().getName() + ")"); ! return ret; ! } /** output AdaBoost contents as a human-readable string */ public String toString() { + // XXX DJH: determine class name at runtime String s= ! getClass().getName() + ! ". No of examples = " ! + m_numExamples ! + ", m_epsilon = " ! + m_epsilon; s += "\nindex\tmargin\tweight\told weight\tlabel\n"; NumberFormat f= new DecimalFormat("0.00"); *************** *** 289,293 **** + f.format(m_sampleWeights[i]) + "\t\t" + m_labels[i] ! + "\n"; } return s; --- 293,297 ---- + f.format(m_sampleWeights[i]) + "\t\t" + m_labels[i] ! + "\n"; } return s; *************** *** 353,357 **** * @return +1 if label matches hyp, -1 if label doesn't match hyp, 0 if no hyp */ ! public double getStep(short simple_label, double hyp_pred) { double step = getLabel(simple_label)*hyp_pred; double EPS = 0.000001; --- 357,362 ---- * @return +1 if label matches hyp, -1 if label doesn't match hyp, 0 if no hyp */ ! // XXX DJH: changed from 'public' to 'protected' ! protected double getStep(short simple_label, double hyp_pred) { double step = getLabel(simple_label)*hyp_pred; double EPS = 0.000001; *************** *** 360,364 **** } ! public double getLabel(short simple_label) { return sign(-simple_label+0.5); } --- 365,370 ---- } ! // XXX DJH: changed from 'public' to 'protected' ! protected double getLabel(short simple_label) { return sign(-simple_label+0.5); } *************** *** 369,373 **** double total_weight = 0.0; ! // Keep track of which hypotheses had hypotheses associated with them. boolean[] examplesWithHyp = new boolean[m_margins.length]; m_hypPredictions = new double[m_margins.length]; --- 375,379 ---- double total_weight = 0.0; ! // Keep track of which examples had hypotheses associated with them. boolean[] examplesWithHyp = new boolean[m_margins.length]; m_hypPredictions = new double[m_margins.length]; *************** *** 378,384 **** int example = index[j]; if (this instanceof BrownBoost) ! m_hypPredictions[example] = ((BrownBag)b).calcPrediction(1.0,1.0).getClassScores()[0]; ! else ! m_hypPredictions[example] = b.calcPrediction().getClassScores()[0]; } } --- 384,390 ---- int example = index[j]; if (this instanceof BrownBoost) ! m_hypPredictions[example] = ((BrownBag)b).calcPrediction(1.0,1.0).getClassScores()[0]; ! else ! m_hypPredictions[example] = b.calcPrediction().getClassScores()[0]; } } *************** *** 386,390 **** int numExamplesWithHyps = 0; - double weight; // Get all examples that have a hypothesis associated with them for (int i= 0; i < exampleIndex.length; i++) { --- 392,395 ---- *************** *** 442,446 **** } }*/ - double gamma = getHypErr(bags, exampleIndex); return getPredictions(bags); } --- 447,450 ---- *************** *** 452,456 **** */ public double calculateWeight(double margin) { ! return Math.exp(-1 * margin); } --- 456,460 ---- */ public double calculateWeight(double margin) { ! return Math.exp(-1 * margin); } *************** *** 579,583 **** double EPS = 0.0000001; if (m_w[0] < EPS && m_w[1] < EPS) { ! return true; } return false; --- 583,587 ---- double EPS = 0.0000001; if (m_w[0] < EPS && m_w[1] < EPS) { ! return true; } return false; *************** *** 665,672 **** BinaryPrediction p = new BinaryPrediction( ! m_w[1] == m_w[0] ! ? 0.0 ! : // handle case that w0=w1=0 ! 0.5 * Math.log((m_w[1] + smoothFactor) / (m_w[0] + smoothFactor))); return p; } --- 669,676 ---- BinaryPrediction p = new BinaryPrediction( ! m_w[1] == m_w[0] ! ? 0.0 ! : // handle case that w0=w1=0 ! 0.5 * Math.log((m_w[1] + smoothFactor) / (m_w[0] + smoothFactor))); return p; } |
From: Daniel H. <dh...@us...> - 2008-04-07 17:20:01
|
Update of /cvsroot/jboost/jboost/src/jboost/booster In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv22970/src/jboost/booster Modified Files: Tag: jboost_unstable Booster.java MixedBinaryPrediction.java AbstractBooster.java Log Message: clean-up Index: Booster.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/Booster.java,v retrieving revision 1.4 retrieving revision 1.4.2.1 diff -C2 -d -r1.4 -r1.4.2.1 *** Booster.java 25 Mar 2008 01:00:27 -0000 1.4 --- Booster.java 7 Apr 2008 17:19:55 -0000 1.4.2.1 *************** *** 71,79 **** ! public abstract double[][] getWeights(); ! public abstract double[][] getPotentials(); ! public abstract double getTotalWeight(); ! public int getNumExamples(); ! public abstract String getParamString(); --- 71,79 ---- ! public abstract double[][] getWeights(); ! public abstract double[][] getPotentials(); ! public abstract double getTotalWeight(); ! public int getNumExamples(); ! public abstract String getParamString(); *************** *** 93,96 **** --- 93,99 ---- * partition of the data. */ + // XXX DJH: What is 'partition'? Similar to 'elements' below? + // XXX YF: I think you are probably correct in your interpretation, need to check the inplementation, verify, and update the + // XXX Description of this method and change "examples" to "elements" in the javadoc for "update". public abstract Prediction[] getPredictions(Bag[] b, int[][] partition); Index: MixedBinaryPrediction.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/MixedBinaryPrediction.java,v retrieving revision 1.6 retrieving revision 1.6.2.1 diff -C2 -d -r1.6 -r1.6.2.1 *** MixedBinaryPrediction.java 25 Mar 2008 01:00:27 -0000 1.6 --- MixedBinaryPrediction.java 7 Apr 2008 17:19:55 -0000 1.6.2.1 *************** *** 1,5 **** package jboost.booster; - import jboost.examples.Label; import jboost.booster.NotNormalizedPredException; --- 1,4 ---- *************** *** 11,146 **** class MixedBinaryPrediction extends BinaryPrediction implements NormalizedPrediction{ ! protected double deltaT; ! protected double normalizingConstant; ! public MixedBinaryPrediction() {super();} ! public MixedBinaryPrediction(double p) ! throws NotNormalizedPredException { ! (new Exception("asdf")).printStackTrace(); ! throw new NotNormalizedPredException("MixedBinaryPrediction: Need to normalize based on time!"); ! } ! public static double updateMargin(double currentMargin, double stepSize, double step, double dt, double nc) { ! //System.out.println("cm: " + currentMargin + ", deltax: " + stepSize*step + ", dt: " + dt + ", nc: " + nc); ! //System.out.println(Math.exp(-dt*nc)*currentMargin + stepSize*step); ! return Math.exp(-dt*nc)*currentMargin + stepSize*step; ! } ! public MixedBinaryPrediction(double p, double dt, double nc) ! throws NotNormalizedPredException { ! super(); ! deltaT = dt; ! prediction=p; ! normalizingConstant = nc; ! } ! public MixedBinaryPrediction(double p, double dt) ! throws NotNormalizedPredException { ! super(); ! deltaT = dt; ! prediction=p; ! normalizingConstant = 1; ! } ! public Object clone(){ ! Object a = new MixedBinaryPrediction(prediction, deltaT); ! return a; ! } ! /** ! * Be very careful with how this is used. See NormalizedPrediction ! * for details. ! */ ! public Prediction add(Prediction p) throws NotNormalizedPredException{ ! if (! (p instanceof MixedBinaryPrediction)) { ! throw new NotNormalizedPredException("Must use MixedBinaryPrediction when adding to a MixedBinaryPrediction."); ! } ! // H_t = (1-alpha)H_{t-1} + alpha h_t ! // The prediction p is for h_t ! double alpha = ((MixedBinaryPrediction) p).prediction; ! prediction = Math.exp(-normalizingConstant*deltaT) * prediction + alpha; ! /* if (Math.abs(alpha) > 1 || Math.abs(prediction) > 1) { throw new NotNormalizedPredException("Prediction may result in unnormalized " + "prediction! p is: " + p); } - */ - return this; - } - - /** - * This is not well defined for normalized predictions. However, we - * do allow it. */ ! public Prediction scale(double w) throws NotNormalizedPredException{ ! if (Math.abs(w) > 1) { ! throw new NotNormalizedPredException("Scalar may result in unnormalized " ! + "prediction! w is: " + w); ! } ! prediction *= w; ! return this; ! } ! ! public double getDeltaT() { ! return deltaT; ! } ! ! public double getNormConstant() { ! return normalizingConstant; ! } ! ! public Prediction add(double w, Prediction p) { ! ((MixedBinaryPrediction) p).scale(w); ! this.add( (MixedBinaryPrediction) p ); ! return this; ! } ! ! public boolean equals(Prediction other) { ! MixedBinaryPrediction bp= (MixedBinaryPrediction) other; ! return (prediction == bp.prediction && deltaT == bp.deltaT && normalizingConstant == bp.normalizingConstant); ! } ! ! public String toString() { ! return "MixedBinaryPrediction. p(1)= " + prediction; ! } ! ! public String cPreamble() { ! System.out.println("Prediction::cPreamble not supported for 'mixed' or normalized predictions."); ! System.exit(2); ! return ! "typedef double Prediction_t;\n" + ! "#define reset_pred() {p = 0.0;}\n" + ! "#define add_pred(X) {p = (1-(X))*p + (X);}\n" + ! "#define finalize_pred()" + ! " ((r) ? (r[1] = p , r[0] = -p) : -p)\n"; ! } ! public String javaPreamble() { ! System.out.println("Prediction::javaPreamble not supported for 'mixed' or normalized predictions."); ! System.exit(2); ! return "" ! + " static private double p;\n" ! + " static private void reset_pred() { p = 0.0; }\n" ! + " static private void add_pred(double x) { p = (1-x)*p + x; }\n" ! + " static private double[] finalize_pred() {\n" ! + " return new double[] {-p, p};\n" ! + " }\n"; } ! public double[] toCodeArray() { ! return new double[] {prediction}; ! } ! } --- 10,138 ---- class MixedBinaryPrediction extends BinaryPrediction implements NormalizedPrediction{ ! protected double deltaT; ! protected double normalizingConstant; ! public MixedBinaryPrediction() {super();} ! public MixedBinaryPrediction(double p) ! throws NotNormalizedPredException { ! (new Exception("asdf")).printStackTrace(); ! throw new NotNormalizedPredException("MixedBinaryPrediction: Need to normalize based on time!"); ! } ! public static double updateMargin(double currentMargin, double stepSize, double step, double dt, double nc) { ! //System.out.println("cm: " + currentMargin + ", deltax: " + stepSize*step + ", dt: " + dt + ", nc: " + nc); ! //System.out.println(Math.exp(-dt*nc)*currentMargin + stepSize*step); ! return Math.exp(-dt*nc)*currentMargin + stepSize*step; ! } ! public MixedBinaryPrediction(double p, double dt, double nc) ! throws NotNormalizedPredException { ! super(); ! deltaT = dt; ! prediction=p; ! normalizingConstant = nc; ! } ! public MixedBinaryPrediction(double p, double dt) ! throws NotNormalizedPredException { ! super(); ! deltaT = dt; ! prediction=p; ! normalizingConstant = 1; ! } ! public Object clone(){ ! Object a = new MixedBinaryPrediction(prediction, deltaT); ! return a; ! } ! /** ! * Be very careful with how this is used. See NormalizedPrediction ! * for details. ! */ ! public Prediction add(Prediction p) throws NotNormalizedPredException{ ! if (! (p instanceof MixedBinaryPrediction)) { ! throw new NotNormalizedPredException("Must use MixedBinaryPrediction when adding to a MixedBinaryPrediction."); ! } ! // H_t = (1-alpha)H_{t-1} + alpha h_t ! // The prediction p is for h_t ! double alpha = ((MixedBinaryPrediction) p).prediction; ! prediction = Math.exp(-normalizingConstant*deltaT) * prediction + alpha; ! /* if (Math.abs(alpha) > 1 || Math.abs(prediction) > 1) { throw new NotNormalizedPredException("Prediction may result in unnormalized " + "prediction! p is: " + p); } */ ! return this; ! } ! /** ! * This is not well defined for normalized predictions. However, we ! * do allow it. ! */ ! public Prediction scale(double w) throws NotNormalizedPredException{ ! if (Math.abs(w) > 1) { ! throw new NotNormalizedPredException("Scalar may result in unnormalized " ! + "prediction! w is: " + w); } + prediction *= w; + return this; + } ! public double getDeltaT() { ! return deltaT; ! } ! public double getNormConstant() { ! return normalizingConstant; ! } + public Prediction add(double w, Prediction p) { + ((MixedBinaryPrediction) p).scale(w); + this.add( (MixedBinaryPrediction) p ); + return this; + } + public boolean equals(Prediction other) { + MixedBinaryPrediction bp= (MixedBinaryPrediction) other; + return (prediction == bp.prediction && deltaT == bp.deltaT && normalizingConstant == bp.normalizingConstant); + } + public String toString() { + return "MixedBinaryPrediction. p(1)= " + prediction; + } + public String cPreamble() { + System.out.println("Prediction::cPreamble not supported for 'mixed' or normalized predictions."); + System.exit(2); + return + "typedef double Prediction_t;\n" + + "#define reset_pred() {p = 0.0;}\n" + + "#define add_pred(X) {p = (1-(X))*p + (X);}\n" + + "#define finalize_pred()" + + " ((r) ? (r[1] = p , r[0] = -p) : -p)\n"; + } + public String javaPreamble() { + System.out.println("Prediction::javaPreamble not supported for 'mixed' or normalized predictions."); + System.exit(2); + return "" + + " static private double p;\n" + + " static private void reset_pred() { p = 0.0; }\n" + + " static private void add_pred(double x) { p = (1-x)*p + x; }\n" + + " static private double[] finalize_pred() {\n" + + " return new double[] {-p, p};\n" + + " }\n"; + } + public double[] toCodeArray() { + return new double[] {prediction}; + } + } Index: AbstractBooster.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/AbstractBooster.java,v retrieving revision 1.8 retrieving revision 1.8.2.1 diff -C2 -d -r1.8 -r1.8.2.1 *** AbstractBooster.java 25 Mar 2008 01:00:27 -0000 1.8 --- AbstractBooster.java 7 Apr 2008 17:19:55 -0000 1.8.2.1 *************** *** 21,85 **** public abstract class AbstractBooster implements Booster, Serializable { ! protected static final String PREFIX= "booster_"; ! /** ! * Factory method to build a booster instance according to ! * given configuration. Uses reflection to do this. ! * ! * @param c set of options for the booster ! * @param num_labels the number of m_labels in the data ! * @param isMultiLabel true if multilabled data ! * @return Booster ! */ ! public static Booster getInstance(Configuration c, int num_labels, ! boolean isMultiLabel) ! throws ClassNotFoundException, InstantiationException, ! IllegalAccessException, Exception { ! AbstractBooster result = null; ! // Get the booster type from configuration and ! // create a class of that type. ! String boosterType= c.getString(PREFIX + "type", ! "jboost.booster.AdaBoost"); ! System.out.println("Booster type: " + boosterType); ! Class boosterClass = Class.forName(boosterType); ! result = (AbstractBooster) boosterClass.newInstance(); ! result.init(c); ! // Get the runtime of the booster (if applicable). ! // If the booster is a discrete iterative scheme, the ! // number of iterations is dealt with elsewhere. ! if (result instanceof jboost.booster.BrownBoost) { ! double eps = 0.001; ! double runtime = Double.parseDouble(c.getString("boostingRuntime", ! "0.0")); ! if (runtime <= eps) { ! String str = "Need to specify runtime for m_booster " + result ! + ". Runtime must be larger than " + eps + "."; ! Monitor.log(str); ! throw new Exception(str); ! } ! jboost.booster.BrownBoost brown = (jboost.booster.BrownBoost) result; ! brown.setRuntime(runtime); ! result = brown; ! if (result instanceof jboost.booster.YabaBoost) { ! jboost.booster.YabaBoost yaba = (jboost.booster.YabaBoost) result; ! double c1=0, c2=0, theta=0, nc=0; ! double rpos=0, c1pos=0, c2pos=0, thetapos=0, ncpos=0; ! double rneg=0, c1neg=0, c2neg=0, thetaneg=0, ncneg=0; ! ControllerConfiguration conf = (ControllerConfiguration)c; ! try { ! c1 = Double.parseDouble(c.getString("c1", "Z1.0")); ! c2 = Double.parseDouble(c.getString("c2", "Z1.0")); ! theta = Double.parseDouble(c.getString("theta", "Z0.15")); ! nc = Double.parseDouble(c.getString("nc", "Z0.15")); ! yaba.setParams(c1,c2,theta,nc); ! if (conf.getCostSensitive()) { ! /* System.out.println(" runtime: " + rpos + "," + rneg + " c1: " + c1pos + "," + c1neg + --- 21,87 ---- public abstract class AbstractBooster implements Booster, Serializable { ! protected static final String PREFIX= "booster_"; ! /** ! * Factory method to build a booster instance according to ! * given configuration. Uses reflection to do this. ! * ! * @param c set of options for the booster ! * @param num_labels the number of m_labels in the data ! * @param isMultiLabel true if multilabled data ! * @return Booster ! */ ! public static Booster getInstance(Configuration c, int num_labels, ! boolean isMultiLabel) ! throws ClassNotFoundException, InstantiationException, ! IllegalAccessException, Exception { ! AbstractBooster result = null; ! // Get the booster type from configuration and ! // create a class of that type. ! String boosterType= c.getString(PREFIX + "type", ! "jboost.booster.AdaBoost"); ! System.out.println("Booster type: " + boosterType); ! Class boosterClass = Class.forName(boosterType); ! result = (AbstractBooster) boosterClass.newInstance(); ! result.init(c); ! // Get the runtime of the booster (if applicable). ! // If the booster is a discrete iterative scheme, the ! // number of iterations is dealt with elsewhere. ! // XXX DJH: Why isn't this done in BrownBoost/YABA.init()? ! // XXX YF: I also think this should not be done in AbstractBooster. ! if (result instanceof jboost.booster.BrownBoost) { ! double eps = 0.001; ! double runtime = Double.parseDouble(c.getString("boostingRuntime", ! "0.0")); ! if (runtime <= eps) { ! String str = "Need to specify runtime for m_booster " + result ! + ". Runtime must be larger than " + eps + "."; ! Monitor.log(str); ! throw new Exception(str); ! } ! jboost.booster.BrownBoost brown = (jboost.booster.BrownBoost) result; ! brown.setRuntime(runtime); ! result = brown; ! if (result instanceof jboost.booster.YabaBoost) { ! jboost.booster.YabaBoost yaba = (jboost.booster.YabaBoost) result; ! double c1=0, c2=0, theta=0, nc=0; ! double rpos=0, c1pos=0, c2pos=0, thetapos=0, ncpos=0; ! double rneg=0, c1neg=0, c2neg=0, thetaneg=0, ncneg=0; ! ControllerConfiguration conf = (ControllerConfiguration)c; ! try { ! c1 = Double.parseDouble(c.getString("c1", "Z1.0")); ! c2 = Double.parseDouble(c.getString("c2", "Z1.0")); ! theta = Double.parseDouble(c.getString("theta", "Z0.15")); ! nc = Double.parseDouble(c.getString("nc", "Z0.15")); ! yaba.setParams(c1,c2,theta,nc); ! if (conf.getCostSensitive()) { ! /* System.out.println(" runtime: " + rpos + "," + rneg + " c1: " + c1pos + "," + c1neg + *************** *** 88,97 **** " nc: " + ncpos + "," + ncneg ); ! */ ! rpos = Double.parseDouble(c.getString("pos_c","Z")); ! rneg = Double.parseDouble(c.getString("neg_c","Z")); ! c1pos = Double.parseDouble(c.getString("pos_c1","Z")); ! c1neg = Double.parseDouble(c.getString("neg_c1","Z")); ! /* System.out.println(" runtime: " + rpos + "," + rneg + " c1: " + c1pos + "," + c1neg + --- 90,99 ---- " nc: " + ncpos + "," + ncneg ); ! */ ! rpos = Double.parseDouble(c.getString("pos_c","Z")); ! rneg = Double.parseDouble(c.getString("neg_c","Z")); ! c1pos = Double.parseDouble(c.getString("pos_c1","Z")); ! c1neg = Double.parseDouble(c.getString("neg_c1","Z")); ! /* System.out.println(" runtime: " + rpos + "," + rneg + " c1: " + c1pos + "," + c1neg + *************** *** 100,111 **** " nc: " + ncpos + "," + ncneg ); ! */ ! c2pos = Double.parseDouble(c.getString("pos_c2","Z")); ! c2neg = Double.parseDouble(c.getString("neg_c2","Z")); ! thetapos = Double.parseDouble(c.getString("pos_theta","Z")); ! thetaneg = Double.parseDouble(c.getString("neg_theta","Z")); ! ncpos = Double.parseDouble(c.getString("pos_nc","Z")); ! ncneg = Double.parseDouble(c.getString("neg_nc","Z")); ! /* System.out.println(" runtime: " + rpos + "," + rneg + " c1: " + c1pos + "," + c1neg + --- 102,113 ---- " nc: " + ncpos + "," + ncneg ); ! */ ! c2pos = Double.parseDouble(c.getString("pos_c2","Z")); ! c2neg = Double.parseDouble(c.getString("neg_c2","Z")); ! thetapos = Double.parseDouble(c.getString("pos_theta","Z")); ! thetaneg = Double.parseDouble(c.getString("neg_theta","Z")); ! ncpos = Double.parseDouble(c.getString("pos_nc","Z")); ! ncneg = Double.parseDouble(c.getString("neg_nc","Z")); ! /* System.out.println(" runtime: " + rpos + "," + rneg + " c1: " + c1pos + "," + c1neg + *************** *** 114,235 **** " nc: " + ncpos + "," + ncneg ); ! */ ! yaba.setCostSensitiveParams(rpos, c1pos, c2pos, thetapos, ncpos, ! rneg, c1neg, c2neg, thetaneg, ncneg); ! } ! } catch (NumberFormatException e) { ! System.err.println("Need to supply appropriate parameters!"); ! System.err.println("For YabaBoost normal, we need r, c1, c2, nc, and theta!"); ! System.err.println("For YabaBoost cost sensitive, we need neg_c, pos_c, neg_c1, pos_c1, neg_c2, pos_c2, neg_theta, pos_theta, neg_nc, pos_nc"); ! throw new InstantiationException("Need more params for yaba"); ! } ! result = yaba; ! } ! } ! ! // If we have a multilable or multiclass problem, we need to wrap it. ! if (num_labels > 2 || isMultiLabel) { ! result= new MulticlassWrapMH(result, num_labels, isMultiLabel); ! } ! ! // If we are debugging, then wrap in paranoia ! boolean paranoid= c.getBool(PREFIX + "paranoid", false); ! if (paranoid) { ! result= new DebugWrap(result); } - return result; } ! public int getNumExamples(){ ! return 0; } ! public String getParamString() { ! return "No parameters defined"; } ! /** ! * Create and return a new Bag which initially contains the ! * elements in the list. ! * ! * @param list initial items to add to the Bag ! */ ! public Bag newBag(int[] list) { ! Bag bag= newBag(); ! bag.addExampleList(list); ! return bag; ! } - /** - * Clone a bag - * - * @param orig the bag to clone - * @return new bag - */ - public Bag newBag(Bag orig) { - Bag newbag= newBag(); - newbag.copyBag(orig); - return newbag; - } ! /** ! * Find the best binary split for a sorted list of example indices ! * with given split points. ! * @param l an array of example indices, sorted. ! * @param sp an array with true in position i when a split between ! * positions i-1 and i should be checked ! * @param b0 - a bag with all points below the best split (upon return) ! * @param b1 - a bag with all points at or above the best split (upon return) ! * @return the index in l where the best split occurred (possibly ! * 0 if the best split puts all points on one side) ! */ ! public int findBestSplit(Bag b0, Bag b1, int[] l, boolean[] sp) { ! Bag[] bags= new Bag[2]; - bags[0]= newBag(); // init an empty bag - bags[1]= newBag(l); // init a full bag ! b0.reset(); ! b1.copyBag(bags[1]); ! if (l.length == 0) ! return 0; ! double bestLoss= getLoss(bags); ! int bestIndex= 0; ! double loss; ! for (int i= 0; i < l.length - 1; i++) { ! bags[1].subtractExample(l[i]); ! bags[0].addExample(l[i]); ! if (sp[i + 1]) { // if this is a potential split point ! if ((loss= getLoss(bags)) < bestLoss) { ! bestLoss= loss; ! bestIndex= i + 1; ! b0.copyBag(bags[0]); ! b1.copyBag(bags[1]); ! } ! } } ! return bestIndex; } ! /** ! * Compute the loss associated with an array of bags where small ! * loss is considered "better". We assume that loss is additive ! * for a set of bags. ! * ! * @param bags array of bags whose losses will be added up and returned ! * @return loss the sum of the losses for all the bags ! */ ! public double getLoss(Bag[] bags) { ! double loss = 0; ! for (int i=0; i < bags.length; i++) { ! loss += bags[i].getLoss(); ! } ! return loss; } } --- 116,237 ---- " nc: " + ncpos + "," + ncneg ); ! */ ! yaba.setCostSensitiveParams(rpos, c1pos, c2pos, thetapos, ncpos, ! rneg, c1neg, c2neg, thetaneg, ncneg); ! } ! } catch (NumberFormatException e) { ! System.err.println("Need to supply appropriate parameters!"); ! System.err.println("For YabaBoost normal, we need r, c1, c2, nc, and theta!"); ! System.err.println("For YabaBoost cost sensitive, we need neg_c, pos_c, neg_c1, pos_c1, neg_c2, pos_c2, neg_theta, pos_theta, neg_nc, pos_nc"); ! throw new InstantiationException("Need more params for yaba"); ! } ! result = yaba; } } ! // If we have a multilable or multiclass problem, we need to wrap it. ! if (num_labels > 2 || isMultiLabel) { ! result= new MulticlassWrapMH(result, num_labels, isMultiLabel); } ! // If we are debugging, then wrap in paranoia ! boolean paranoid= c.getBool(PREFIX + "paranoid", false); ! if (paranoid) { ! result= new DebugWrap(result); } + return result; + } + public int getNumExamples(){ + return 0; + } ! public String getParamString() { ! return "No parameters defined"; ! } + /** + * Create and return a new Bag which initially contains the + * elements in the list. + * + * @param list initial items to add to the Bag + */ + public Bag newBag(int[] list) { + Bag bag= newBag(); + bag.addExampleList(list); + return bag; + } ! /** ! * Clone a bag ! * ! * @param orig the bag to clone ! * @return new bag ! */ ! public Bag newBag(Bag orig) { ! Bag newbag= newBag(); ! newbag.copyBag(orig); ! return newbag; ! } ! /** ! * Find the best binary split for a sorted list of example indices ! * with given split points. ! * @param l an array of example indices, sorted. ! * @param sp an array with true in position i when a split between ! * positions i-1 and i should be checked ! * @param b0 - a bag with all points below the best split (upon return) ! * @param b1 - a bag with all points at or above the best split (upon return) ! * @return the index in l where the best split occurred (possibly ! * 0 if the best split puts all points on one side) ! */ ! public int findBestSplit(Bag b0, Bag b1, int[] l, boolean[] sp) { ! Bag[] bags= new Bag[2]; ! bags[0]= newBag(); // init an empty bag ! bags[1]= newBag(l); // init a full bag ! b0.reset(); ! b1.copyBag(bags[1]); ! if (l.length == 0) ! return 0; ! ! double bestLoss= getLoss(bags); ! int bestIndex= 0; ! double loss; ! ! for (int i= 0; i < l.length - 1; i++) { ! bags[1].subtractExample(l[i]); ! bags[0].addExample(l[i]); ! if (sp[i + 1]) { // if this is a potential split point ! if ((loss= getLoss(bags)) < bestLoss) { ! bestLoss= loss; ! bestIndex= i + 1; ! b0.copyBag(bags[0]); ! b1.copyBag(bags[1]); } ! } } + return bestIndex; + } ! /** ! * Compute the loss associated with an array of bags where small ! * loss is considered "better". We assume that loss is additive ! * for a set of bags. ! * ! * @param bags array of bags whose losses will be added up and returned ! * @return loss the sum of the losses for all the bags ! */ ! public double getLoss(Bag[] bags) { ! double loss = 0; ! for (int i=0; i < bags.length; i++) { ! loss += bags[i].getLoss(); } + return loss; + } } |
From: Daniel H. <dh...@us...> - 2008-04-07 17:09:20
|
Update of /cvsroot/jboost/jboost/src/jboost/atree In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv18586/src/jboost/atree Modified Files: PredictorNode.java Log Message: Index: PredictorNode.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/atree/PredictorNode.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PredictorNode.java 2 Oct 2007 02:28:06 -0000 1.2 --- PredictorNode.java 7 Apr 2008 17:09:06 -0000 1.3 *************** *** 1,7 **** package jboost.atree; - import java.io.IOException; - import java.io.ObjectInputStream; - import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.Vector; --- 1,4 ---- *************** *** 21,103 **** class PredictorNode implements Serializable { ! /** the prediction value associated with this node. */ ! protected Prediction prediction; ! /** A textual identifier, has the format <parentSplitterNodeID>:index ! * The id of the root predictor node is "R". */ ! protected String id; ! /** An index signifying the iteration in which this node was added ! * to the tree. */ ! protected int index; ! /** ! * The parent splitter node (or null if root) ! */ ! SplitterNode parent; ! /** ! * The branch index (as a value returned by Splitter) of the ! * parent split that leads to this predictor node. ! */ ! int branchIndex; ! /** constructor */ ! public PredictorNode(Prediction p,String ID,int ind,Vector sp, ! SplitterNode parent, int branchIndex) throws Error { ! prediction=p; ! id=ID; ! index=ind; ! this.parent = parent; ! this.branchIndex = branchIndex; ! if(sp==null) splitterNodes=new Vector(); ! else splitterNodes=sp; ! } ! /** calculate the prediction of the subtree starting at this node. */ ! protected Prediction predict(Instance instance) throws IncompAttException { ! Prediction retval=(Prediction)prediction.clone(); ! Prediction tmp=null; ! if(splitterNodes==null) return(retval); ! for(int i=0;i<splitterNodes.size();i++){ ! tmp=((SplitterNode)splitterNodes.elementAt(i)).predict(instance); ! if(tmp!=null) retval.add(tmp); ! } ! return(retval); ! } ! /** ! * Calculate the prediction of the subtree starting at this node in ! * order of iteration. This is important for normalized predictors ! * such as NormalBoost. This function can only be called on the ! * root node. ! * @author Aaron Arvey ! */ ! protected Prediction orderPredict(Instance instance, int numIterations) throws IncompAttException, RuntimeException { ! // Are we the root node? ! if (parent!=null || id!="R") { ! throw new RuntimeException("Cannot perform ordered prediction on a node other then the root"); ! } ! ! Prediction retval=(Prediction)prediction.clone(); ! Prediction tmp=null; ! for (int i=0; i < numIterations; i++) { ! PredictorNode p = findPrediction(instance, i, this); ! if (p==null) { // we could not get to this iteration, so we continue to the next iteration ! continue; ! //throw new Exception("Cannot find prediction for iteration " + i); ! } ! retval.add(p.prediction); ! } ! ! /* if (numIterations > 3 && numIterations < 5) { System.out.println("Doing ordered prediction"); } ! if (numIterations > 3 && numIterations < 5) { try { --- 18,100 ---- class PredictorNode implements Serializable { ! /** the prediction value associated with this node. */ ! protected Prediction prediction; ! /** A textual identifier, has the format <parentSplitterNodeID>:index ! * The id of the root predictor node is "R". */ ! protected String id; ! /** An index signifying the iteration in which this node was added ! * to the tree. */ ! protected int index; ! /** ! * The parent splitter node (or null if root) ! */ ! SplitterNode parent; ! /** ! * The branch index (as a value returned by Splitter) of the ! * parent split that leads to this predictor node. ! */ ! int branchIndex; ! /** constructor */ ! public PredictorNode(Prediction p,String ID,int ind,Vector sp, ! SplitterNode parent, int branchIndex) throws Error { ! prediction=p; ! id=ID; ! index=ind; ! this.parent = parent; ! this.branchIndex = branchIndex; ! if(sp==null) splitterNodes=new Vector(); ! else splitterNodes=sp; ! } ! /** calculate the prediction of the subtree starting at this node. */ ! protected Prediction predict(Instance instance) throws IncompAttException { ! Prediction retval=(Prediction)prediction.clone(); ! Prediction tmp=null; ! if(splitterNodes==null) return(retval); ! for(int i=0;i<splitterNodes.size();i++){ ! tmp=((SplitterNode)splitterNodes.elementAt(i)).predict(instance); ! if(tmp!=null) retval.add(tmp); ! } ! return(retval); ! } ! /** ! * Calculate the prediction of the subtree starting at this node in ! * order of iteration. This is important for normalized predictors ! * such as NormalBoost. This function can only be called on the ! * root node. ! * @author Aaron Arvey ! */ ! protected Prediction orderPredict(Instance instance, int numIterations) throws IncompAttException, RuntimeException { ! // Are we the root node? ! if (parent!=null || id!="R") { ! throw new RuntimeException("Cannot perform ordered prediction on a node other then the root"); ! } ! ! Prediction retval=(Prediction)prediction.clone(); ! Prediction tmp=null; ! for (int i=0; i < numIterations; i++) { ! PredictorNode p = findPrediction(instance, i, this); ! if (p==null) { // we could not get to this iteration, so we continue to the next iteration ! continue; ! //throw new Exception("Cannot find prediction for iteration " + i); ! } ! retval.add(p.prediction); ! } ! ! /* if (numIterations > 3 && numIterations < 5) { System.out.println("Doing ordered prediction"); } ! if (numIterations > 3 && numIterations < 5) { try { *************** *** 107,233 **** } } ! */ ! - return retval; - } ! private PredictorNode findPrediction(Instance instance, int iter, PredictorNode pn) { ! if(pn.splitterNodes==null && pn.index != iter) return null; ! if(pn.splitterNodes==null && pn.index == iter) return pn; ! ! // Search for the SplitterNode/PredictorNode of interest ! for(int i=0;i<pn.splitterNodes.size();i++){ ! if ( ((SplitterNode)pn.splitterNodes.elementAt(i)).getIndex() == iter ) { ! return ((SplitterNode)pn.splitterNodes.elementAt(i)).predictNode(instance); ! } ! } ! // We couldn't find the node of interest, so continue with search ! PredictorNode tmp = null; ! for(int i=0;i<pn.splitterNodes.size();i++){ ! tmp = ((SplitterNode)pn.splitterNodes.elementAt(i)).predictNode(instance); ! tmp = findPrediction(instance, iter, tmp); ! if (tmp==null) { ! // The node is not down there or this instance does ! // not fulfill the predicate. Search down the other ! // paths ! } else { ! return tmp; ! } ! } ! return null; } ! /** Generate a textual explanation of the prediction */ ! public String explain(Instance instance) throws IncompAttException { ! // describe own contribution ! String s = "\tP="+prediction.shortText()+"\n"; ! // describe contributions of child SplitterNodes ! if(splitterNodes==null) return s; ! for(int i=0;i<splitterNodes.size();i++) ! s+=((SplitterNode)splitterNodes.elementAt(i)).explain(instance); ! return s; ! } - public void addSplitterNode(SplitterNode sn) { - splitterNodes.add(sn); - } ! /** output self in human-readable format. */ ! public String toString() { ! String s=new String(); ! s+=index+"\t["+id+"] prediction = "; ! s+=prediction+"\n"; ! if(splitterNodes==null) return(s); ! for(int i=0;i<splitterNodes.size();i++) { ! s+=(SplitterNode)splitterNodes.get(i); ! } ! return(s); } ! ! /** Converts this predictor node to Java. */ ! public String toJava(String fname) { ! int i=0; ! String retval="\tprivate Prediction "+fname+"(Instance ins){\n"; ! retval+="\t\tPrediction retval=null;\n"; ! SplitterNode sn=null; ! if(splitterNodes.size()>0) ! retval+="\t\tretval="+fname+"_"+i+"(ins);\n"; ! for(i=1;i<splitterNodes.size();i++) ! retval+="\t\tretval.add("+fname+"_"+i+"(ins));\n"; ! retval+="\t\treturn(retval);\n"; ! retval+="\t}\n\n"; ! for(i=0;i<splitterNodes.size();i++) { ! sn=(SplitterNode)splitterNodes.get(i); ! retval+=sn.toJava(fname+"_"+i); ! } ! return(retval); } ! /** Add a prediction to its prediction value */ ! public void addToPrediction(Prediction p) { ! if (p instanceof NormalizedPrediction) { ! System.err.println("Cannot add normalized prediction to existing node"); ! System.exit(2); ! } ! prediction.add(p); } ! /** The splitter nodes that are the children of this node. In predicting, the algorithm follows all the children, and sums their predictions */ ! protected Vector splitterNodes; ! public Vector getSplitterNodes() { ! return splitterNodes; ! } ! /** ! * Returns the number of child splitternodes. ! */ ! int getSplitterNodeNo(){ ! return(splitterNodes.size()); ! } ! /** ! * Return the ID of this PredictorNode ! * @return id of this node ! */ ! public String getID() { ! return id; ! } ! ! /** ! * Return the index of this PredictorNode ! * @return index of this node ! */ ! public int getIndex() { ! return index; ! } } --- 104,230 ---- } } ! */ ! return retval; ! } ! private PredictorNode findPrediction(Instance instance, int iter, PredictorNode pn) { ! if(pn.splitterNodes==null && pn.index != iter) return null; ! if(pn.splitterNodes==null && pn.index == iter) return pn; ! // Search for the SplitterNode/PredictorNode of interest ! for(int i=0;i<pn.splitterNodes.size();i++){ ! if ( ((SplitterNode)pn.splitterNodes.elementAt(i)).getIndex() == iter ) { ! return ((SplitterNode)pn.splitterNodes.elementAt(i)).predictNode(instance); ! } } + // We couldn't find the node of interest, so continue with search + PredictorNode tmp = null; + for(int i=0;i<pn.splitterNodes.size();i++){ + tmp = ((SplitterNode)pn.splitterNodes.elementAt(i)).predictNode(instance); + tmp = findPrediction(instance, iter, tmp); + if (tmp==null) { + // The node is not down there or this instance does + // not fulfill the predicate. Search down the other + // paths + } else { + return tmp; + } + } ! return null; ! } + /** Generate a textual explanation of the prediction */ + public String explain(Instance instance) throws IncompAttException { + // describe own contribution + String s = "\tP="+prediction.shortText()+"\n"; + // describe contributions of child SplitterNodes + if(splitterNodes==null) return s; + for(int i=0;i<splitterNodes.size();i++) + s+=((SplitterNode)splitterNodes.elementAt(i)).explain(instance); + return s; + } ! public void addSplitterNode(SplitterNode sn) { ! splitterNodes.add(sn); ! } ! ! ! /** output self in human-readable format. */ ! public String toString() { ! String s=new String(); ! s+=index+"\t["+id+"] prediction = "; ! s+=prediction+"\n"; ! if(splitterNodes==null) return(s); ! for(int i=0;i<splitterNodes.size();i++) { ! s+=(SplitterNode)splitterNodes.get(i); } + return(s); + } ! ! /** Converts this predictor node to Java. */ ! public String toJava(String fname) { ! int i=0; ! String retval="\tprivate Prediction "+fname+"(Instance ins){\n"; ! retval+="\t\tPrediction retval=null;\n"; ! SplitterNode sn=null; ! if(splitterNodes.size()>0) ! retval+="\t\tretval="+fname+"_"+i+"(ins);\n"; ! for(i=1;i<splitterNodes.size();i++) ! retval+="\t\tretval.add("+fname+"_"+i+"(ins));\n"; ! retval+="\t\treturn(retval);\n"; ! retval+="\t}\n\n"; ! for(i=0;i<splitterNodes.size();i++) { ! sn=(SplitterNode)splitterNodes.get(i); ! retval+=sn.toJava(fname+"_"+i); } + return(retval); + } ! /** Add a prediction to its prediction value */ ! public void addToPrediction(Prediction p) { ! if (p instanceof NormalizedPrediction) { ! System.err.println("Cannot add normalized prediction to existing node"); ! System.exit(2); } + prediction.add(p); + } ! /** The splitter nodes that are the children of this node. In predicting, the algorithm follows all the children, and sums their predictions */ ! protected Vector splitterNodes; ! public Vector getSplitterNodes() { ! return splitterNodes; ! } ! /** ! * Returns the number of child splitternodes. ! */ ! int getSplitterNodeNo(){ ! return(splitterNodes.size()); ! } ! /** ! * Return the ID of this PredictorNode ! * @return id of this node ! */ ! public String getID() { ! return id; ! } ! ! /** ! * Return the index of this PredictorNode ! * @return index of this node ! */ ! public int getIndex() { ! return index; ! } } |
From: Daniel H. <dh...@us...> - 2008-04-07 16:29:39
|
Update of /cvsroot/jboost/jboost/src/jboost/learner In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv1426/src/jboost/learner Modified Files: EqualitySplitterBuilder.java Log Message: Index: EqualitySplitterBuilder.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/learner/EqualitySplitterBuilder.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** EqualitySplitterBuilder.java 16 May 2007 04:06:02 -0000 1.1.1.1 --- EqualitySplitterBuilder.java 7 Apr 2008 16:29:27 -0000 1.2 *************** *** 4,8 **** import java.util.Vector; ! import sun.tools.tree.CastExpression; import jboost.CandidateSplit; --- 4,8 ---- import java.util.Vector; ! //import sun.tools.tree.CastExpression; import jboost.CandidateSplit; |