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...> - 2007-10-23 22:44:58
|
Update of /cvsroot/jboost/jboost/src/jboost/examples In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv4508 Modified Files: AttributeDescription.java Added Files: IdDescription.java IntegerAttribute.java IntegerDescription.java Log Message: The beginnings of integer fields (shrink datasize by half) and ID attribute Index: AttributeDescription.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/examples/AttributeDescription.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** AttributeDescription.java 2 Oct 2007 20:34:56 -0000 1.2 --- AttributeDescription.java 23 Oct 2007 22:44:54 -0000 1.3 *************** *** 33,36 **** --- 33,37 ---- if (name.equals(DataStream.LABELS_ATTR)) retval=new LabelDescription(name,options,okValues); else if (name.equals(DataStream.WEIGHT_ATTR)) retval= new WeightDescription(name, options); + //else if (name.equals(DataStream.ID_ATTR)) retval= new IdDescription(name, options); else if(type.equals("number")) retval=new NumberDescription(name,options); else if(type.equals("string")) retval=new StringDescription(name,options); --- NEW FILE: IdDescription.java --- package jboost.examples; import jboost.controller.Configuration; import jboost.tokenizer.BadAttException; /** * The description for a private weight of each example. */ public class IdDescription extends IntegerDescription { public static final int MAX_ID = Integer.MAX_VALUE; IdDescription(String name, Configuration config, int default_val) throws ClassNotFoundException { super(name,config); } /** * Reads an id * If no value is specified, default to 1 * If the value is negative, return 0 as the weight. * If the value is greater than 1, return 1. * @param weight the string representation of the weight * @return Attribute the RealAttribute corresponding to the weight */ public Attribute str2Att(String id) throws BadAttException { double att = 1.0; // initialized because try complains otherwise. if (id != null) { id= id.trim(); if (id.length() != 0) { try { att= Double.parseDouble(id); } catch (NumberFormatException nfe) { throw new BadAttException(id + " is not a float",0,0); } if (att < 0) { att= 0; throw new BadAttException("The id: " + id + " is less than 0",0,0); } if (att > MAX_ID) { throw new BadAttException("The id: " + id + " is larger than MAX_ID=" + MAX_ID,0,0); } } } return new RealAttribute (att); } } --- NEW FILE: IntegerDescription.java --- package jboost.examples; import jboost.controller.Configuration; import jboost.tokenizer.BadAttException; /** * the description for number attributes. */ class IntegerDescription extends AttributeDescription { IntegerDescription(String name, Configuration c) throws ClassNotFoundException { attributeName = name; attributeClass = Class.forName("jboost.examples.IntegerAttribute"); // Need to make a SAFE version of configuration, which implements an error() function, which // can return and error message. crucial=c.getBool("crucial",false); ignoreAttribute=c.getBool("ignoreAttribute",false); existence=c.getBool("existence",false); existence=c.getBool("order",true); } /** checks format of string in datafile and converts to float * * If the attribute is missing it creates a new * real attribute, that is not defined. */ public Attribute str2Att(String string) throws BadAttException { if(string == null) return(new RealAttribute()); string=string.trim(); if(string.length()==0) return(new RealAttribute()); double att = 0.; // initialized because try complains otherwise. try { att = Double.parseDouble(string); } catch (NumberFormatException e) { System.err.println(string + " is not a float."); throw new BadAttException(string+" is not a float",0,0); } return new RealAttribute (att); } public String toString() { String retval=new String(attributeName); retval+=" "+attributeClass.getName(); retval+=" crucial: "+crucial; retval+=" ignoreAttribute: "+ignoreAttribute; retval+=" existence: "+existence; retval+=" order: "+order; return(retval); } public String toString(Attribute attr) { String retval=new String(); if(attr==null) return("undefined"); retval+=((RealAttribute)attr).toString(); return(retval); } } --- NEW FILE: IntegerAttribute.java --- package jboost.examples; /** Represents a single real valued attribute */ public class IntegerAttribute extends Attribute { private int value; public IntegerAttribute(int value) {this.value=value; setDefined();} public IntegerAttribute() {defined=false;} public int getValue() {return value;} public String toString() { return this.isDefined() ? String.valueOf(value) : "undefined"; } } |
From: Aaron A. <aa...@us...> - 2007-10-16 02:02:31
|
Update of /cvsroot/jboost/jboost/scripts In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv1395 Modified Files: atree2dot2ps.pl Log Message: dirname bug fixed Index: atree2dot2ps.pl =================================================================== RCS file: /cvsroot/jboost/jboost/scripts/atree2dot2ps.pl,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** atree2dot2ps.pl 10 Jul 2007 01:38:38 -0000 1.4 --- atree2dot2ps.pl 16 Oct 2007 02:02:27 -0000 1.5 *************** *** 71,74 **** --- 71,76 ---- $graphtitle .= " | "; + $filename= $dirname . "/" . $filename; + open(FILE,$filename) || die "could not open $file \n"; $filename =~ s/.output.tree//; |
From: Aaron A. <aa...@us...> - 2007-10-13 04:32:33
|
Update of /cvsroot/jboost/jboost/src/jboost/atree In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv490/atree Modified Files: InstrumentedAlternatingTree.java Log Message: Fixed underflow bug in weights and outputting more information with InequalitySplitter NaN bug Index: InstrumentedAlternatingTree.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/atree/InstrumentedAlternatingTree.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** InstrumentedAlternatingTree.java 2 Oct 2007 02:28:06 -0000 1.3 --- InstrumentedAlternatingTree.java 13 Oct 2007 04:32:27 -0000 1.4 *************** *** 624,627 **** --- 624,639 ---- return b.isFinished(); } + + double EPS = 1e-50; + double w = m_booster.getTotalWeight(); + if ((w < EPS) || Double.isNaN(w)) { + System.out.println("JBoost boosting process is completed."); + System.out.println("\tThe boosting has finished early."); + System.out.println("\tThis is a result of too little weight being placed on examples"); + System.out.println("\t(which will cause an underflow error)."); + System.out.println("\tThis is not necessarily a bad thing. Look at the margin curve to find out more."); + return true; + } + return false; } |
From: Aaron A. <aa...@us...> - 2007-10-13 04:32:33
|
Update of /cvsroot/jboost/jboost/src/jboost/booster In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv490/booster Modified Files: AdaBoost.java Booster.java DebugWrap.java MulticlassWrapMH.java Log Message: Fixed underflow bug in weights and outputting more information with InequalitySplitter NaN bug Index: MulticlassWrapMH.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/MulticlassWrapMH.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** MulticlassWrapMH.java 18 Sep 2007 03:25:58 -0000 1.4 --- MulticlassWrapMH.java 13 Oct 2007 04:32:28 -0000 1.5 *************** *** 181,184 **** --- 181,189 ---- return 0.5 * m_numLabels * m_booster.getTheoryBound(); } + + + public double getTotalWeight() { + return m_booster.getTotalWeight(); + } /** Index: Booster.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/Booster.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Booster.java 18 Sep 2007 03:25:58 -0000 1.2 --- Booster.java 13 Oct 2007 04:32:28 -0000 1.3 *************** *** 73,76 **** --- 73,77 ---- public abstract double[][] getWeights(); public abstract double[][] getPotentials(); + public abstract double getTotalWeight(); public int getNumExamples(); public abstract String getParamString(); Index: AdaBoost.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/AdaBoost.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** AdaBoost.java 18 Sep 2007 03:25:58 -0000 1.2 --- AdaBoost.java 13 Oct 2007 04:32:28 -0000 1.3 *************** *** 201,204 **** --- 201,211 ---- } + /** + * + */ + public double getTotalWeight() { + return m_totalWeight; + } + /** *************** *** 504,512 **** public BinaryPrediction calcPrediction() { double smoothFactor= m_epsilon * m_totalWeight; ! return 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))); } --- 511,526 ---- public BinaryPrediction calcPrediction() { double smoothFactor= m_epsilon * m_totalWeight; ! double EPS = 1e-50; ! if (Double.isNaN(smoothFactor) || (Math.abs(m_totalWeight)<EPS) || ! (Math.abs(smoothFactor)<EPS) || Double.isNaN(m_totalWeight)) { ! return new BinaryPrediction(0.0); ! } ! ! 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: DebugWrap.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/DebugWrap.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** DebugWrap.java 18 Sep 2007 03:25:58 -0000 1.2 --- DebugWrap.java 13 Oct 2007 04:32:28 -0000 1.3 *************** *** 147,150 **** --- 147,154 ---- } + public double getTotalWeight() { + return booster.getTotalWeight(); + } + public double[][] getPotentials(){ return new double[1][1]; |
From: Aaron A. <aa...@us...> - 2007-10-13 04:32:33
|
Update of /cvsroot/jboost/jboost/src/jboost/learner In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv490/learner Modified Files: InequalitySplitterBuilder.java Log Message: Fixed underflow bug in weights and outputting more information with InequalitySplitter NaN bug Index: InequalitySplitterBuilder.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/learner/InequalitySplitterBuilder.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** InequalitySplitterBuilder.java 16 May 2007 04:06:02 -0000 1.1.1.1 --- InequalitySplitterBuilder.java 13 Oct 2007 04:32:28 -0000 1.2 *************** *** 248,251 **** --- 248,255 ---- } } + if (cutIndex==-1) { + cutIndex=-1; + System.out.println(this); + } result[0]= new int[cutIndex]; // create first list int noGreater= j; |
From: Aaron A. <aa...@us...> - 2007-10-07 02:15:41
|
Update of /cvsroot/jboost/jboost/scripts In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv12669 Modified Files: nfold.py Log Message: booster option added, resample removed Index: nfold.py =================================================================== RCS file: /cvsroot/jboost/jboost/scripts/nfold.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** nfold.py 10 Jul 2007 01:38:38 -0000 1.5 --- nfold.py 7 Oct 2007 02:15:35 -0000 1.6 *************** *** 10,14 **** def usage(): ! print 'Usage: nfold.py <--folds=number> [--generate | --dir=dir] [--data=filename --spec=filename] [--rounds=number --tree=treetype]' print '\t--folds=N create N files for N fold cross validation (required)' print '\t--data=DATAFILE DATAFILE contains the data to be divided into test/train sets (required)' --- 10,15 ---- def usage(): ! print 'Usage: nfold.py <--booster=boosttype> <--folds=number> [--generate | --dir=dir] [--data=file --spec=file] [--rounds=number --tree=treetype]' ! print '\t--booster=TYPE AdaBoost, LogLossBoost, BrownBoost, etc (required)' print '\t--folds=N create N files for N fold cross validation (required)' print '\t--data=DATAFILE DATAFILE contains the data to be divided into test/train sets (required)' *************** *** 23,31 **** ! def learner(atreeoption, k, rounds): # XXX: put in description! config= os.getenv('JBOOST_CONFIG') command = 'java -Xmx1000M -cp ' + os.getenv('CLASSPATH') \ ! + ' jboost.controller.Controller -b LogLossBoost -p 3 -a -1 -S trial' + str(k) \ + ' -n trial.spec -ATreeType '+ atreeoption +' -numRounds ' + str(rounds) if (config != None): --- 24,32 ---- ! def learner(atreeoption, k, rounds, booster): # XXX: put in description! config= os.getenv('JBOOST_CONFIG') command = 'java -Xmx1000M -cp ' + os.getenv('CLASSPATH') \ ! + ' jboost.controller.Controller -b ' + booster + ' -p 3 -a -1 -S trial' + str(k) \ + ' -n trial.spec -ATreeType '+ atreeoption +' -numRounds ' + str(rounds) if (config != None): *************** *** 78,82 **** testfile.close() trainfile.close() ! os.system('./resample.py --k=128 --label=" 1" --train=' + trainfilename); --- 79,83 ---- testfile.close() trainfile.close() ! #os.system('./resample.py --k=128 --label=" 1" --train=' + trainfilename); *************** *** 92,96 **** try: opts, args = getopt.getopt(sys.argv[1:],'' , ! ['folds=','data=','spec=','dir=','rounds=','tree=','generate']) except getopt.GetoptError: print 'nfold.py: Illegal argument\n' --- 93,97 ---- try: opts, args = getopt.getopt(sys.argv[1:],'' , ! ['booster=','folds=','data=','spec=','dir=','rounds=','tree=','generate']) except getopt.GetoptError: print 'nfold.py: Illegal argument\n' *************** *** 99,103 **** # parse options ! datafile = specfile = folds = dirname = generateData = rounds = tree = None for opt,arg in opts: if (opt == '--data'): --- 100,104 ---- # parse options ! booster = datafile = specfile = folds = dirname = generateData = rounds = tree = None for opt,arg in opts: if (opt == '--data'): *************** *** 105,108 **** --- 106,111 ---- elif (opt == '--spec'): specfile= arg + elif (opt == '--booster'): + booster= arg elif (opt == '--folds'): folds = int(arg) *************** *** 128,131 **** --- 131,139 ---- sys.exit(2) + if (booster == None): + print 'nfold.py: --booster is a required parameter.\n' + usage() + sys.exit(2) + if (datafile != None and specfile == None): print 'nfold.py: --data option requies --spec option.\n' *************** *** 194,198 **** print '* Fold ' + str(k) + ' |' print '*============' ! learner(treetype, k, rounds) print '*=---------------------------------------------------------------------=-*' moveresults(treetype) --- 202,206 ---- print '* Fold ' + str(k) + ' |' print '*============' ! learner(treetype, k, rounds, booster) print '*=---------------------------------------------------------------------=-*' moveresults(treetype) |
From: Aaron A. <aa...@us...> - 2007-10-02 20:36:47
|
Update of /cvsroot/jboost/jboost/src/jboost/controller In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv3790/controller Modified Files: Configuration.java Controller.java Log Message: Change of version, iterations counting method, and spelling errors Index: Controller.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/controller/Controller.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Controller.java 14 Jun 2007 16:38:57 -0000 1.4 --- Controller.java 2 Oct 2007 20:36:43 -0000 1.5 *************** *** 75,95 **** try { // read the command line ! try { ! configuration= new ControllerConfiguration(DEFAULT_MANPAGE, argv); ! Monitor.init_log(configuration); ! configuration.checkCommandValues(); ! controller = new Controller(configuration); ! } catch (BadCommandException e) { ! configuration.printUsage(); ! System.err.println("JBoost Exception: " + e.getMessage()); ! } catch (Exception e) { ! configuration.printUsage(); ! System.err.println("JBoost Exception: " + e.getMessage()); ! } ! // the rest of the code can be called from an external main controller.startLearning(); controller.outputLearningResults(); shutdown(); } catch (Exception e) { System.err.println(e.getMessage()); --- 75,91 ---- try { // read the command line ! configuration= new ControllerConfiguration(DEFAULT_MANPAGE, argv); ! Monitor.init_log(configuration); ! configuration.checkCommandValues(); ! controller = new Controller(configuration); ! ! // the rest of the code can be called from an external main controller.startLearning(); controller.outputLearningResults(); shutdown(); + } catch (BadCommandException e) { + configuration.printUsage(); + System.err.println("JBoost Exception: " + e.getMessage()); } catch (Exception e) { System.err.println(e.getMessage()); *************** *** 210,213 **** --- 206,210 ---- m_learningTree= new InstrumentedAlternatingTree(m_splitterBuilderVector, m_booster, m_trainSetIndices,m_config); + System.out.println("Finished creating root (iteration -1)"); } *************** *** 349,353 **** Executor pe=ExecutorSinglet.getExecutor(); - iterNo++; // first iteration shouldn't really count for (int iter= 0; iter < iterNo && !m_learningTree.boosterIsFinished(); iter++) { if (Monitor.logLevel > 1) { --- 346,349 ---- *************** *** 399,402 **** --- 395,403 ---- // run through the losses results to determine the best split int best=0; + if (losses.length==0) { + System.err.println("ERROR: There are no candidate weak hypotheses to add to the tree."); + System.err.println("This is likely a bug in JBoost; please report to JBoost developers."); + System.exit(2); + } double bestLoss=losses[best]; double tmpLoss; *************** *** 421,425 **** + iter); } ! System.out.println("finished learning iteration " + iter); if(m_booster instanceof BrownBoost){ iterNo++; --- 422,426 ---- + iter); } ! System.out.println("Finished learning iteration " + iter); if(m_booster instanceof BrownBoost){ iterNo++; *************** *** 579,585 **** } } ! // the default behavior is to accept each example ! // an example is only refused if we are sampling and its ! // weight is set to zero if (accepted) { addTrainingExample(counter, example, exampleWeight); --- 580,586 ---- } } ! // The default behavior is to accept each example. An ! // example is only refused if we are sampling and its ! // weight is set to zero. if (accepted) { addTrainingExample(counter, example, exampleWeight); *************** *** 588,592 **** if ((counter % 100) == 0) { ! System.out.print("Fead " + counter + " training examples\n"); } } --- 589,593 ---- if ((counter % 100) == 0) { ! System.out.print("Read " + counter + " training examples\n"); } } Index: Configuration.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/controller/Configuration.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Configuration.java 14 Jun 2007 16:40:41 -0000 1.5 --- Configuration.java 2 Oct 2007 20:36:43 -0000 1.6 *************** *** 54,58 **** private Vector m_validCommands; private String m_unSpecified; ! public final static String VERSION="1.3.1"; private final static String m_usage = "" + "jboost Version " + VERSION + "\n" --- 54,58 ---- private Vector m_validCommands; private String m_unSpecified; ! public final static String VERSION="1.4"; private final static String m_usage = "" + "jboost Version " + VERSION + "\n" |
From: Aaron A. <aa...@us...> - 2007-10-02 20:35:00
|
Update of /cvsroot/jboost/jboost/src/jboost/examples In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv2954/examples Modified Files: AttributeDescription.java ExampleDescription.java MultiDiscreteAttribute.java WeightDescription.java Log Message: Some misc small changes Index: ExampleDescription.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/examples/ExampleDescription.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** ExampleDescription.java 16 May 2007 04:06:02 -0000 1.1.1.1 --- ExampleDescription.java 2 Oct 2007 20:34:56 -0000 1.2 *************** *** 10,13 **** --- 10,34 ---- public class ExampleDescription { + /** An AttributeDescription for the labels */ + private LabelDescription label; + + /** An AttributeDescription for the example weights */ + private WeightDescription weight; + + /** a description of each attribute */ + private Vector attribute; + + /** the index of the example attribute that contains the label */ + private int m_labelIndex; + + /** the index of the example attribute that contains the weight */ + private int m_weightIndex; + + /** Flag for using private sampling weights */ + private boolean m_useSamplingWeights; + + + + /** * Defaul constructor *************** *** 147,168 **** - /** An AttributeDescription for the labels */ - private LabelDescription label; - - /** An AttributeDescription for the example weights */ - private WeightDescription weight; - - /** a description of each attribute */ - private Vector attribute; - - /** the index of the example attribute that contains the label */ - private int m_labelIndex; - - /** the index of the example attribute that contains the weight */ - private int m_weightIndex; - - /** Flag for using private sampling weights */ - private boolean m_useSamplingWeights; - - } --- 168,170 ---- Index: WeightDescription.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/examples/WeightDescription.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** WeightDescription.java 16 May 2007 04:06:02 -0000 1.1.1.1 --- WeightDescription.java 2 Oct 2007 20:34:56 -0000 1.2 *************** *** 8,11 **** --- 8,13 ---- */ public class WeightDescription extends NumberDescription { + + public static final double MAX_WEIGHT = 1; WeightDescription(String name, Configuration config) *************** *** 25,29 **** public Attribute str2Att(String weight) throws BadAttException { double att = 1.0; // initialized because try complains otherwise. ! if (weight != null) { weight= weight.trim(); --- 27,31 ---- public Attribute str2Att(String weight) throws BadAttException { double att = 1.0; // initialized because try complains otherwise. ! if (weight != null) { weight= weight.trim(); *************** *** 35,42 **** } if (att < 0) { ! att= 0; } ! if (att > 1) { ! att= 1; } } --- 37,46 ---- } if (att < 0) { ! att= 0; ! throw new BadAttException("The weight: " + weight + " is less than 0",0,0); } ! if (att > MAX_WEIGHT) { ! att= MAX_WEIGHT; ! throw new BadAttException("The weight: " + weight + " is larger than MAX_WEIGHT=" + MAX_WEIGHT,0,0); } } Index: MultiDiscreteAttribute.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/examples/MultiDiscreteAttribute.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** MultiDiscreteAttribute.java 16 May 2007 04:06:02 -0000 1.1.1.1 --- MultiDiscreteAttribute.java 2 Oct 2007 20:34:56 -0000 1.2 *************** *** 89,92 **** --- 89,107 ---- } + public int[] getValues() { + int[] ret = null; + if(values == null) { + ret = new int[1]; + ret[0] = value; + } else { + ret = new int[values.length]; + int j = 0; + for(int i=0; i<values.length; i++) + if (values[i]) + ret[j++] = i; + } + return ret; + } + public static void main(String[] args) { MultiDiscreteAttribute[] a = new MultiDiscreteAttribute[5]; Index: AttributeDescription.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/examples/AttributeDescription.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** AttributeDescription.java 16 May 2007 04:06:02 -0000 1.1.1.1 --- AttributeDescription.java 2 Oct 2007 20:34:56 -0000 1.2 *************** *** 31,35 **** AttributeDescription retval=null; ! if (name.equals("labels")) retval=new LabelDescription(name,options,okValues); else if (name.equals(DataStream.WEIGHT_ATTR)) retval= new WeightDescription(name, options); else if(type.equals("number")) retval=new NumberDescription(name,options); --- 31,35 ---- AttributeDescription retval=null; ! if (name.equals(DataStream.LABELS_ATTR)) retval=new LabelDescription(name,options,okValues); else if (name.equals(DataStream.WEIGHT_ATTR)) retval= new WeightDescription(name, options); else if(type.equals("number")) retval=new NumberDescription(name,options); |
From: Aaron A. <aa...@us...> - 2007-10-02 02:32:51
|
Update of /cvsroot/jboost/jboost/src/jboost/booster In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv12857 Added Files: MixedBinaryPredictionTest.java Log Message: MixedBinaryPredictionTest added... ooops --- NEW FILE: MixedBinaryPredictionTest.java --- package jboost.booster; import jboost.booster.NotNormalizedPredException; import junit.framework.TestCase; /** * @author Aaron Arvey * * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments */ public class MixedBinaryPredictionTest extends TestCase { //protected MixedBinaryPrediction p; /** * Constructor for * @param arg0 */ public MixedBinaryPredictionTest(String arg0) { super(arg0); System.out.println("Making MixedPred class"); } final public void testAdd() { System.out.println("test add"); Prediction p = new MixedBinaryPrediction(); assertEquals(true, Prediction.isNormPred(p)); MixedBinaryPrediction np = new MixedBinaryPrediction(); assertEquals(true, Prediction.isNormPred(np)); } protected void setUp() { System.out.println("set up "); } protected void tearDown() { System.out.println("tear down"); } final public void testCodeOutput() { System.out.println("test code output"); } final public void testIsNormPred() { System.out.println("is norm pred"); BinaryPrediction bp = new BinaryPrediction(); assertEquals(false, Prediction.isNormPred(bp)); Prediction p = new MixedBinaryPrediction(); assertEquals(true, Prediction.isNormPred(p)); MixedBinaryPrediction np = new MixedBinaryPrediction(); assertEquals(true, Prediction.isNormPred(np)); } final public void testConstructor() { System.out.println("test constructor"); MixedBinaryPrediction p; boolean exceptionThrown = false; try { p = new MixedBinaryPrediction(5); } catch (NotNormalizedPredException e) { exceptionThrown = true; } if (!exceptionThrown) { assertEquals(1,0); } try { p = new MixedBinaryPrediction(-5); } catch (NotNormalizedPredException e) { exceptionThrown = true; } if (!exceptionThrown) { assertEquals(1,0); } try { p = new MixedBinaryPrediction(0.0); p = new MixedBinaryPrediction(0.3); p = new MixedBinaryPrediction(0.99); p = new MixedBinaryPrediction(1.0); } catch (NotNormalizedPredException e) { assertEquals(1,0); } } } // public MixedBinaryPrediction(double p) throws NotNormalizedPredException{ // super(); // if (Math.abs(p) > 1) { // throw new NotNormalizedPredException("Prediction is unnormalized " // + "prediction! p is: " + p); // } // prediction=p; // } // public Object clone(){ // Object a = new MixedBinaryPrediction(prediction); // 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 = (1-Math.abs(alpha)) * 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 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); // } // public String toString() { // return "MixedBinaryPrediction. p(1)= " + prediction; // } // public String cPreamble() { // System.out.println("Prediction::cPreamble not supported."); // 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."); // 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}; // } // } |
From: Aaron A. <aa...@us...> - 2007-10-02 02:32:11
|
Update of /cvsroot/jboost/jboost/src/jboost/booster In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv12745 Modified Files: BoosterTestSuite.java BrownBoost.java LogLossBoost.java MixedBinaryPrediction.java Prediction.java YabaBoost.java Added Files: NormalizedPrediction.java Log Message: MixedBinaryPrediction and tests added, confidence rated predictions switch, cost sensative params in place --- NEW FILE: NormalizedPrediction.java --- package jboost.booster; /** * A normalized predictor. When a prediction is added, we * ensure that the margin is normalized. This normalization is done * by "mixing" in the new prediction. * * @author Aaron Arvey **/ public interface NormalizedPrediction { /** * Must be used very carefully. An example: * * Prediction return_value = new MixedBinaryPrediction(Prediction root_value); * for (pi in iteration_ordered_predictions) * return_value.add(pi) * * There are two important parts to the above example. * 1) the add method is called on return_value * 2) iteration ordered predictions */ public Prediction add(Prediction p); /* public static boolean isNormPred(Prediction p); */ } Index: MixedBinaryPrediction.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/MixedBinaryPrediction.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** MixedBinaryPrediction.java 14 Jun 2007 16:35:43 -0000 1.2 --- MixedBinaryPrediction.java 2 Oct 2007 02:32:07 -0000 1.3 *************** *** 5,18 **** /** ! * A normalized predictor. When a prediction is added, we ! * ensure that the margin is normalized. This normalization is done ! * by "mixing" in the new prediction. * * @author Aaron Arvey **/ ! class MixedBinaryPrediction extends BinaryPrediction{ public MixedBinaryPrediction() {super();} public MixedBinaryPrediction(double p) throws NotNormalizedPredException{ super(); --- 5,23 ---- /** ! * A binary normalized predictor. See NoramlizedPrediction * * @author Aaron Arvey **/ ! class MixedBinaryPrediction extends BinaryPrediction implements NormalizedPrediction{ public MixedBinaryPrediction() {super();} + + /* + public static boolean isNormPred(Prediction p) { + return (p instanceof NormalizedPrediction); + } + */ + public MixedBinaryPrediction(double p) throws NotNormalizedPredException{ super(); *************** *** 30,40 **** /** ! * This may not be well defined for normalized predictions. However, ! * since we have symmetry (i.e. (1-x)y+y = (1-y)x+x ) we allow this operation. */ public Prediction add(Prediction p) throws NotNormalizedPredException{ ! double other_p = ((MixedBinaryPrediction) p).prediction; ! prediction = (1-Math.abs(prediction)) * other_p + prediction; ! if (Math.abs(other_p) > 1 || Math.abs(prediction) > 1) { throw new NotNormalizedPredException("Prediction may result in unnormalized " + "prediction! p is: " + p); --- 35,51 ---- /** ! * 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 = (1-Math.abs(alpha)) * prediction + alpha; ! if (Math.abs(alpha) > 1 || Math.abs(prediction) > 1) { throw new NotNormalizedPredException("Prediction may result in unnormalized " + "prediction! p is: " + p); Index: BrownBoost.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/BrownBoost.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** BrownBoost.java 18 Sep 2007 03:25:58 -0000 1.6 --- BrownBoost.java 2 Oct 2007 02:32:07 -0000 1.7 *************** *** 62,65 **** --- 62,66 ---- } + public void setRuntime(double runtime){ m_c = runtime; *************** *** 426,429 **** --- 427,432 ---- */ + + public String getParamString() { String ret = String.format("BrownBoost Params: %.4f %.4f", m_c, m_s); Index: BoosterTestSuite.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/BoosterTestSuite.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** BoosterTestSuite.java 27 May 2007 11:23:23 -0000 1.2 --- BoosterTestSuite.java 2 Oct 2007 02:32:07 -0000 1.3 *************** *** 25,28 **** --- 25,29 ---- //suite.addTest(new TestSuite(YabaBoostTest.class)); suite.addTest(new TestSuite(BrownBoostTest.class)); + suite.addTest(new TestSuite(MixedBinaryPredictionTest.class)); //suite.addTest(new TestSuite(MulticlassWrapMHTest.class)); //$JUnit-END$ Index: YabaBoost.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/YabaBoost.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** YabaBoost.java 10 Jul 2007 01:32:52 -0000 1.4 --- YabaBoost.java 2 Oct 2007 02:32:07 -0000 1.5 *************** *** 34,37 **** --- 34,44 ---- /** + * This is true if and only if we are cost sensitive boosting. If + * this is set, then m_{pos,neg}c{1,2} and m_{pos,neg}Theta must + * be set. + */ + protected boolean m_isCostSensitive; + + /** * Parameter for yaba that allows for decrease of potential * by translation of potential curve. *************** *** 40,43 **** --- 47,52 ---- */ protected double m_c1; + protected double m_posc1; + protected double m_negc1; *************** *** 48,51 **** --- 57,63 ---- */ protected double m_c2; + protected double m_posc2; + protected double m_negc2; + /** *************** *** 54,57 **** --- 66,71 ---- */ protected double m_theta; + protected double m_posTheta; + protected double m_negTheta; /** *************** *** 60,63 **** --- 74,79 ---- */ protected double m_origTheta; + protected double m_posOrigTheta; + protected double m_negOrigTheta; *************** *** 70,73 **** --- 86,98 ---- protected static final double FINISH_GAME_NOW = 0.05; + + /** + * A parameter indicating whether we should use confidence rated + * predictions. + */ + protected static final boolean USE_CONFIDENCE = false; + + + /** * A parameter indicating when we should stop the game. *************** *** 76,80 **** * an approximation of the 0/1 loss instead of the exact 0/1 loss. */ ! protected static final double THETA_UPDATE_STEP = 0.05; /** --- 101,105 ---- * an approximation of the 0/1 loss instead of the exact 0/1 loss. */ ! protected static final double THETA_UPDATE_STEP = 0.02; /** *************** *** 84,93 **** public YabaBoost() { super(); - /* - m_c = 1; - m_c1 = 2; - m_c2 = 1; - m_theta = 0.5; - */ } --- 109,112 ---- *************** *** 114,126 **** m_initialPotential = calculatePotential(0,m_c); } public String surfingData() { ! String ret = new String(""); ! ret += String.format("YabaBoost Params: %.4f %.4f %4f %4f %4f\n", m_c, m_s, m_c1, m_c2, m_theta); for (int i=0; i<m_margins.length; i++){ ! ret += String.format("%.4f\t%.4f\t%.4f\n", m_margins[i], m_weights[i], m_potentials[i]); } ! return ret; } --- 133,159 ---- m_initialPotential = calculatePotential(0,m_c); } + + + public void setCostSensativeParams(double pc1, double pc2, double ptheta, + double nc1, double nc2, double ntheta) { + m_posc1 = pc1; + m_posc2 = pc2; + m_posTheta = ptheta; + m_posOrigTheta = ptheta; + + m_negc1 = pc1; + m_negc2 = pc2; + m_negTheta = ptheta; + m_negOrigTheta = ptheta; + } public String surfingData() { ! StringBuffer ret = new StringBuffer(""); ! ret.append(String.format("YabaBoost Params: %.4f %.4f %4f %4f %4f\n", m_c, m_s, m_c1, m_c2, m_theta)); for (int i=0; i<m_margins.length; i++){ ! ret.append(String.format("%.4f\t%.4f\t%.4f\n", m_margins[i], m_weights[i], m_potentials[i])); } ! return ret.toString(); } *************** *** 166,180 **** double totalWeight = 0; for (int i= 0; i < m_hypPredictions.length; i++) { ! int example = i; ! double margin = m_margins[example]; ! double orig_margin = margin; ! ! // m_labels are 0 or 1, this moves it to +-1 ! double step = getStep(m_labels[example], m_hypPredictions[example]); ! double new_margin; ! double EPS = 0.0001; if (Math.abs(step) > EPS) { new_margin = (1-alpha)*margin + alpha*step; --- 199,214 ---- double totalWeight = 0; + double EPS = 0.0001; + double margin, orig_margin, step, new_margin, new_weight, new_pot, orig_pot; + int example; for (int i= 0; i < m_hypPredictions.length; i++) { ! example = i; ! margin = m_margins[example]; ! orig_margin = margin; ! // m_labels are 0 or 1, this moves it to in margin space +-1 ! step = getStep(m_labels[example], m_hypPredictions[example]); ! EPS = 0.0001; if (Math.abs(step) > EPS) { new_margin = (1-alpha)*margin + alpha*step; *************** *** 183,189 **** } ! double new_weight = calculateWeight(new_margin, new_time_remaining); ! double new_pot = calculatePotential(new_margin, new_time_remaining); ! double orig_pot = calculatePotential(orig_margin, orig_time_remaining); vars.B += new_weight*step; --- 217,223 ---- } ! new_weight = calculateWeight(new_margin, new_time_remaining); ! new_pot = calculatePotential(new_margin, new_time_remaining); ! orig_pot = calculatePotential(orig_margin, orig_time_remaining); vars.B += new_weight*step; *************** *** 394,404 **** * constant potential. */ ! double CONSTRAINT_EPS = 0.001; double EPS = 0.001; if (m_s > FINISH_GAME_NOW && Math.abs(vars.Potential-m_initialPotential)>CONSTRAINT_EPS) { - m_s = m_oldS; - dump_everything(vars); System.err.println("Average potential difference is too big!"); System.err.println("Outputting all data to outfile!"); s = m_c - m_s; --- 428,439 ---- * constant potential. */ ! double CONSTRAINT_EPS = 0.01; double EPS = 0.001; if (m_s > FINISH_GAME_NOW && Math.abs(vars.Potential-m_initialPotential)>CONSTRAINT_EPS) { 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; *************** *** 426,433 **** System.out.println("New theta is:" + m_theta); return solve_constraints(hyp_err); } if (Math.abs(vars.B) > CONSTRAINT_EPS) { - System.err.println("CORRELATION IS TOO BIG!!!"); } --- 461,469 ---- System.out.println("New theta is:" + m_theta); return solve_constraints(hyp_err); + + */ } if (Math.abs(vars.B) > CONSTRAINT_EPS) { System.err.println("CORRELATION IS TOO BIG!!!"); } *************** *** 539,543 **** double sd = Math.sqrt(m_c2*(Math.exp(-2*s) - Math.exp(-2*m_c))) + FINISH_GAME_NOW; double norm = 1 / Math.sqrt(Math.PI * sd * sd); ! return norm * Math.exp(- Math.pow((margin-mu)/sd,2)); } --- 575,588 ---- double sd = Math.sqrt(m_c2*(Math.exp(-2*s) - Math.exp(-2*m_c))) + FINISH_GAME_NOW; double norm = 1 / Math.sqrt(Math.PI * sd * sd); ! double ret = norm * Math.exp(- Math.pow((margin-mu)/sd,2)); ! ! if (USE_CONFIDENCE) { ! if (margin < mu) ! ret = 0; ! else ! ret = 2*ret; ! } ! ! return ret; } *************** *** 552,555 **** --- 597,603 ---- 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; + if (USE_CONFIDENCE) { + pot = Math.min(2*pot, 1.0); + } /* System.out.println("S:"+s); *************** *** 569,572 **** --- 617,626 ---- + public String getParamString() { + String ret = String.format("s=%.4f,c=%.4f,c1=%.4f,c2=%.4f,theta=%.4f,confidence=%b", m_s, m_c, m_c1, m_c2, m_theta, USE_CONFIDENCE); + return ret; + } + + /** Index: LogLossBoost.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/LogLossBoost.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** LogLossBoost.java 16 May 2007 04:06:02 -0000 1.1.1.1 --- LogLossBoost.java 2 Oct 2007 02:32:07 -0000 1.2 *************** *** 52,55 **** --- 52,62 ---- return oneOverLog2 * Z / m_margins.length; } + + + public String getParamString() { + String ret = String.format("None (LogLossBoost)"); + return ret; + } + /** Index: Prediction.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/Prediction.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** Prediction.java 16 May 2007 04:06:02 -0000 1.1.1.1 --- Prediction.java 2 Oct 2007 02:32:07 -0000 1.2 *************** *** 24,27 **** --- 24,35 ---- public abstract Prediction add(Prediction p); + + /** + * Returns true iff this prediction is normalized + */ + public static boolean isNormPred(Prediction p) { + return (p instanceof NormalizedPrediction); + } + /** |
From: Aaron A. <aa...@us...> - 2007-10-02 02:28:10
|
Update of /cvsroot/jboost/jboost/src/jboost/atree In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv11031 Modified Files: AlternatingTree.java AtreePredictor.java AtreeTestSuite.java InstrumentedAlternatingTree.java PredictorNode.java SplitterNode.java Added Files: AlternatingTreeTest.java Log Message: Added ordered prediction capabilities, currenlty set as the default Index: PredictorNode.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/atree/PredictorNode.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** PredictorNode.java 16 May 2007 04:06:02 -0000 1.1.1.1 --- PredictorNode.java 2 Oct 2007 02:28:06 -0000 1.2 *************** *** 8,11 **** --- 8,12 ---- import jboost.booster.Prediction; + import jboost.booster.NormalizedPrediction; import jboost.examples.Instance; import jboost.learner.IncompAttException; *************** *** 19,22 **** --- 20,48 ---- */ 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, *************** *** 42,45 **** --- 68,145 ---- 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 { + Thread.currentThread().sleep(9999); + } catch (Exception e) { + // do nothing + } + } + */ + + + 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 { *************** *** 57,89 **** } - /** returns the number of child splitternodes. */ - int getSplitterNodeNo(){ - return(splitterNodes.size()); - } - - /** 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; - /** - * Return the ID of this PredictorNode - * @return id of this node - */ - public String getID() { - return id; - } - - - public int getIndex() { - return index; - } - /** output self in human-readable format. */ public String toString() { --- 157,161 ---- *************** *** 120,123 **** --- 192,199 ---- /** 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); } *************** *** 127,145 **** sums their predictions */ protected Vector splitterNodes; ! public Vector getSplitterNodes() { return splitterNodes; } /** ! * 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; } --- 203,233 ---- 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; ! } } Index: AtreePredictor.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/atree/AtreePredictor.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** AtreePredictor.java 16 May 2007 04:06:02 -0000 1.1.1.1 --- AtreePredictor.java 2 Oct 2007 02:28:06 -0000 1.2 *************** *** 30,33 **** --- 30,38 ---- AtreePredictor(Splitter s, PredictorNode p, Prediction[] pred, Booster b) { splitter = s; + + if (p==null){ + System.err.println("Predictor node given to constructor is null"); + System.err.println(s); + } pNode = p; this.pred = pred; *************** *** 35,42 **** zeroPred = b.getPredictions(new Bag[] {b.newBag()} , new int[0][])[0]; } ! public Prediction predict(Instance x) throws IncompAttException { if (isConstant) return pred[0]; for(PredictorNode p = pNode; p.parent != null; p = p.parent.parent) { if (p.parent.splitter.eval(x) != p.branchIndex) --- 40,70 ---- zeroPred = b.getPredictions(new Bag[] {b.newBag()} , new int[0][])[0]; } ! ! /** ! * Check to see if we get to this node. If we reach this node, ! * return the prediction for it. ! */ public Prediction predict(Instance x) throws IncompAttException { + // if this is the root, we have no parent + if (pNode==null) { + return predict(x,0); + } else { + return predict(x,pNode.index); + } + } + + + /** + * Check to see if we get to this node and this node is iteration + * iter. If we reach this node, return the prediction for it. + */ + public Prediction predict(Instance x, int iter) throws IncompAttException { if (isConstant) return pred[0]; + + if (pNode.index != iter) + return zeroPred; + + // If we don't reach this node, then return zero for(PredictorNode p = pNode; p.parent != null; p = p.parent.parent) { if (p.parent.splitter.eval(x) != p.branchIndex) *************** *** 46,49 **** --- 74,78 ---- return (v < 0 ? zeroPred : pred[v]); } + } Index: AlternatingTree.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/atree/AlternatingTree.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** AlternatingTree.java 16 May 2007 04:06:02 -0000 1.1.1.1 --- AlternatingTree.java 2 Oct 2007 02:28:06 -0000 1.2 *************** *** 52,55 **** --- 52,67 ---- } + /** Make a prediction */ + public Prediction predict(Instance instance, int numIters) throws IncompAttException { + //return predict(instance); + return orderPredict(instance, numIters); + } + + /** Make a iteration orderd prediction */ + public Prediction orderPredict(Instance instance, int numIters) throws IncompAttException { + Prediction retval=root.orderPredict(instance, numIters); + return(retval); + } + /** Generate a textual explanation of the prediction */ public String explain(Instance instance) throws IncompAttException { --- NEW FILE: AlternatingTreeTest.java --- /* * */ package jboost.atree; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.Vector; import jboost.CandidateSplit; import jboost.Predictor; import jboost.booster.AdaBoost; import jboost.booster.Booster; import jboost.controller.Configuration; import jboost.examples.Attribute; import jboost.examples.AttributeDescription; import jboost.examples.DiscreteAttribute; import jboost.examples.Example; import jboost.examples.ExampleDescription; import jboost.examples.ExampleSet; import jboost.examples.Instance; import jboost.examples.Label; import jboost.learner.EqualitySplitterBuilder; import jboost.learner.IncompAttException; import jboost.learner.SplitterBuilder; import jboost.tokenizer.DataStream; import jboost.tokenizer.jboost_DataStream; import junit.framework.TestCase; /** * */ public class AlternatingTreeTest extends TestCase { DataStream m_datastream; Booster m_booster; Booster m_booster2; int m_numRounds; int[] m_trainLabels; int[] m_trainFeature1; int[] m_trainFeature2; int[] m_testLabels; int[] m_testValues; int[] m_exampleIndices= new int[12]; ExampleSet m_examples; SplitterBuilder m_builder; Vector m_builders; /* * @see TestCase#setUp() */ protected void setUp() throws Exception { super.setUp(); // build examples m_datastream= new jboost_DataStream(false,"feature1 (zero,one,two)\n labels (one,two)\n"); ExampleDescription description= m_datastream.getExampleDescription(); m_examples= new ExampleSet(description); m_booster= new AdaBoost(); m_booster2= new AdaBoost(); m_builder= new EqualitySplitterBuilder(0, m_booster, new AttributeDescription[] {description.getAttributeDescription(0)}); m_trainLabels= new int[] { 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0}; m_trainFeature1= new int[] { 0, 2, 2, 2, 1, 2, 0, 1, 0, 0, 2, 1}; m_testLabels= new int[] { 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0}; m_testValues= new int[] { 0, 2, 2, 2, 1, 2, 0, 1, 0, 0, 2, 1}; Example x; Attribute[] attributes= new Attribute[1]; Label l; m_exampleIndices= new int[m_trainLabels.length]; for (int i= 0; i < m_trainLabels.length; i++) { l= new Label(m_trainLabels[i]); attributes[0]= new DiscreteAttribute(m_trainFeature1[i]); x= new Example(attributes, l); try { m_builder.addExample(i, x); m_booster.addExample(i, l); m_booster2.addExample(i, l); m_examples.addExample(i, x); m_exampleIndices[i]= i; } catch (IncompAttException e) { } } m_builder.finalizeData(); m_booster.finalizeData(); m_booster2.finalizeData(); m_examples.finalizeData(); m_builders= new Vector(); m_builders.add(m_builder); } /* * @see TestCase#tearDown() */ protected void tearDown() throws Exception { super.tearDown(); } public final void testGetCandidates() { //TODO Implement getCandidates(). InstrumentedAlternatingTree iat; try { iat= new InstrumentedAlternatingTree(m_builders, m_booster, m_exampleIndices, new Configuration()); m_numRounds= 2; for (int j=0; j < m_numRounds; j++) { Vector cand= iat.getCandidates(); CandidateSplit bC= null; for (int i= 0; i < cand.size(); i++) { bC= (CandidateSplit) cand.get(i); iat.addCandidate(bC); } } Predictor c= iat.getCombinedPredictor(); } catch(Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } public final void testInstrumentAlternatingTree() { // create an instrumented tree InstrumentedAlternatingTree first= null; try { first= new InstrumentedAlternatingTree(m_builders, m_booster, m_exampleIndices, new Configuration()); m_numRounds= 100; for (int j=0; j < m_numRounds; j++) { Vector cand= first.getCandidates(); CandidateSplit bC= null; // This piece should be replaced by a more general tool to measure the // goodness of a // split. int best= 0; double bestLoss= ((CandidateSplit) cand.get(0)).getLoss(); double tmpLoss; for (int i= 1; i < cand.size(); i++) { if ((tmpLoss= ((CandidateSplit) cand.get(i)).getLoss()) < bestLoss) { bestLoss= tmpLoss; best= i; } } bC= (CandidateSplit) cand.get(best); first.addCandidate(bC); } // turn the instrumented tree into an alternating tree AlternatingTree tree= (AlternatingTree) first.getCombinedPredictor(); // serialize the tree ByteArrayOutputStream bos= new ByteArrayOutputStream(); ObjectOutputStream os; os= new ObjectOutputStream(bos); os.writeObject(tree); os.flush(); os.close(); // de-serialize ByteArrayInputStream bis= new ByteArrayInputStream(bos.toByteArray()); ObjectInputStream is; AlternatingTree newTree= null; is= new ObjectInputStream(bis); newTree= (AlternatingTree) is.readObject(); is.close(); InstrumentedAlternatingTree second= new InstrumentedAlternatingTree(newTree, m_builders, m_booster2, m_exampleIndices, new Configuration()); AlternatingTree secondTree= (AlternatingTree) second.getCombinedPredictor(); for (int i=0; i < m_trainLabels.length; i++) { Instance test= m_examples.getExample(i).getInstance(); assertTrue(tree.predict(test).equals(secondTree.predict(test))); } testPredict(tree, secondTree); // assert that the boosters are equivalent assertTrue(m_booster.toString().equals(m_booster2.toString())); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); fail(); } } protected final void testPredict(AlternatingTree t1, AlternatingTree t2) { for (int i=0; i < m_trainLabels.length; i++) { Instance test= m_examples.getExample(i).getInstance(); System.out.println(t1.predict(test)); System.out.println(t1.predict(test).getClassScores()[0]); System.out.println(t1.predict(test).getClassScores()[1]); System.out.println(t1.orderPredict(test,m_numRounds-1)); System.out.println(t2.predict(test)); System.out.println(t2.orderPredict(test,m_numRounds-1)); System.out.flush(); double EPS = 0.000001; assertEquals(t1.predict(test).getClassScores()[0], t1.orderPredict(test,m_numRounds-1).getClassScores()[0], EPS); assertEquals(t1.predict(test).getClassScores()[1], t1.orderPredict(test,m_numRounds-1).getClassScores()[1], EPS); assertEquals(t2.predict(test).getClassScores()[0], t2.orderPredict(test,m_numRounds-1).getClassScores()[0], EPS); assertEquals(t2.predict(test).getClassScores()[1], t2.orderPredict(test,m_numRounds-1).getClassScores()[1], EPS); } } } Index: AtreeTestSuite.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/atree/AtreeTestSuite.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** AtreeTestSuite.java 16 May 2007 04:06:02 -0000 1.1.1.1 --- AtreeTestSuite.java 2 Oct 2007 02:28:06 -0000 1.2 *************** *** 18,21 **** --- 18,22 ---- //$JUnit-BEGIN$ suite.addTestSuite(InstrumentedAlternatingTreeTest.class); + suite.addTestSuite(AlternatingTreeTest.class); //$JUnit-END$ return suite; Index: SplitterNode.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/atree/SplitterNode.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** SplitterNode.java 16 May 2007 04:06:02 -0000 1.1.1.1 --- SplitterNode.java 2 Oct 2007 02:28:06 -0000 1.2 *************** *** 24,37 **** class SplitterNode implements Serializable{ ! /** Calculate the prediction of the subtree starting at this node. ! Depends on the fact that all splits are binary.*/ protected Prediction predict(Instance instance) throws IncompAttException { ! if(splitter==null) throw(new RuntimeException("Splitter node: "+id+" has no splitter.")); int which_branch=splitter.eval(instance); ! if(which_branch<0) return(null); ! if(predictorNodes==null) throw(new RuntimeException("Splitter node: "+id+" has no predictor nodes.")); return(predictorNodes[which_branch].predict(instance)); } /** Generate a textual explanation of the prediction */ protected String explain(Instance instance) throws IncompAttException { --- 24,56 ---- class SplitterNode implements Serializable{ ! /** ! * Calculate the prediction of the subtree starting at this node. ! * Depends on the fact that all splits are binary. ! */ protected Prediction predict(Instance instance) throws IncompAttException { ! if(splitter==null) ! throw(new RuntimeException("Splitter node: "+id+" has no splitter.")); int which_branch=splitter.eval(instance); ! if(which_branch<0) ! return(null); ! if(predictorNodes==null) ! throw(new RuntimeException("Splitter node: "+id+" has no predictor nodes.")); return(predictorNodes[which_branch].predict(instance)); } + /** + * Return the prediction node that comes next for this instance + */ + protected PredictorNode predictNode(Instance instance) throws IncompAttException { + if(splitter==null) + throw(new RuntimeException("Splitter node: "+id+" has no splitter.")); + int which_branch=splitter.eval(instance); + if(which_branch<0) + return(null); + if(predictorNodes==null) + throw(new RuntimeException("Splitter node: "+id+" has no predictor nodes.")); + return(predictorNodes[which_branch]); + } + /** Generate a textual explanation of the prediction */ protected String explain(Instance instance) throws IncompAttException { Index: InstrumentedAlternatingTree.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/atree/InstrumentedAlternatingTree.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** InstrumentedAlternatingTree.java 27 May 2007 11:24:07 -0000 1.2 --- InstrumentedAlternatingTree.java 2 Oct 2007 02:28:06 -0000 1.3 *************** *** 15,18 **** --- 15,19 ---- import jboost.booster.BrownBoost; import jboost.booster.Prediction; + import jboost.booster.NormalizedPrediction; import jboost.controller.Configuration; import jboost.controller.ConfigurationException; *************** *** 112,116 **** // Use the number of boosting iterations as the default // size for the internal lists used by this tree ! int listSize= config.getInt("numRounds", 25); // initialize the data structures used by the tree --- 113,117 ---- // Use the number of boosting iterations as the default // size for the internal lists used by this tree ! int listSize= config.getInt("numRounds", 200); // initialize the data structures used by the tree *************** *** 215,220 **** Vector splitters=new Vector(m_splitterBuilders.size()); ! for(Iterator i=m_splitterBuilders.iterator();i.hasNext();) { PredictorNodeSB pSB=(PredictorNodeSB)i.next(); if (m_treeType == AtreeType.ADD_ROOT && pSB.pNode != 0) { while(sbCount.currentCount()!=0) { --- 216,223 ---- Vector splitters=new Vector(m_splitterBuilders.size()); ! for (Iterator i = m_splitterBuilders.iterator(); i.hasNext(); ) { ! PredictorNodeSB pSB=(PredictorNodeSB)i.next(); + if (m_treeType == AtreeType.ADD_ROOT && pSB.pNode != 0) { while(sbCount.currentCount()!=0) { *************** *** 318,323 **** Prediction[] pred= m_booster.getPredictions(bags, partition); m_booster.update(pred, partition); ! ((PredictorNode) m_predictors.get(0)).addToPrediction(pred[0]); lastBasePredictor= new AtreePredictor(pred); } --- 321,334 ---- Prediction[] pred= m_booster.getPredictions(bags, partition); m_booster.update(pred, partition); ! ! if (pred.length > 0 && pred[0] instanceof NormalizedPrediction) { ! System.err.println("Cannot update root with mixed binary pred"); ! System.exit(2); ! } ! ((PredictorNode) m_predictors.get(0)).addToPrediction(pred[0]); + if (pred==null) { + System.err.println("Updating root pred is null!"); + } lastBasePredictor= new AtreePredictor(pred); } *************** *** 351,355 **** * @param partition */ ! private void insert(Bag[] bags, PredictorNode parent, Splitter splitter, SplitterBuilder[] parentArray, Prediction[] predictions, int[][] partition) { --- 362,366 ---- * @param partition */ ! private SplitterNode insert(Bag[] bags, PredictorNode parent, Splitter splitter, SplitterBuilder[] parentArray, Prediction[] predictions, int[][] partition) { *************** *** 384,387 **** --- 395,399 ---- parent.addSplitterNode(sNode); m_splitters.add(pInt); + return sNode; } *************** *** 393,396 **** --- 405,409 ---- public void addCandidate(CandidateSplit candidate) throws InstrumentException { AtreeCandidateSplit acand= null; + SplitterNode node= null; try { acand= (AtreeCandidateSplit) candidate; *************** *** 410,416 **** Prediction[] predictions= m_booster.getPredictions(bags, partition); m_booster.update(predictions, partition); lastBasePredictor= new AtreePredictor(splitter, parent, predictions, m_booster); ! SplitterNode node= findSplitter(parent, splitter); ! if (node != null) { for (int i=0; i < node.predictorNodes.length; i++) { node.predictorNodes[i].addToPrediction(predictions[i]); --- 423,432 ---- Prediction[] predictions= m_booster.getPredictions(bags, partition); m_booster.update(predictions, partition); + if (parent==null) { + System.err.println("Parent is null!"); + } lastBasePredictor= new AtreePredictor(splitter, parent, predictions, m_booster); ! node= findSplitter(parent, splitter); ! if (node != null && (predictions.length > 0 && !(predictions[0] instanceof NormalizedPrediction)) ) { for (int i=0; i < node.predictorNodes.length; i++) { node.predictorNodes[i].addToPrediction(predictions[i]); *************** *** 418,424 **** } else { SplitterBuilder[] parentArray= ((PredictorNodeSB) m_splitterBuilders.get(acand.getPredictorNode())).SB; ! insert(bags, parent, splitter, parentArray, predictions, partition); } } } --- 434,463 ---- } else { SplitterBuilder[] parentArray= ((PredictorNodeSB) m_splitterBuilders.get(acand.getPredictorNode())).SB; ! node = insert(bags, parent, splitter, parentArray, predictions, partition); } } + /* + System.out.println("Adding Candidate: " + candidate); + + System.out.println("Node being added:" ); + System.out.println("" + node ); + + System.out.println("m_predictors:"); + for (int i=0; i<m_predictors.size(); i++) { + System.out.println("i: "+ i + m_predictors.get(i)); + } + System.out.println("m_predictors.index:"); + for (int i=0; i<m_predictors.size(); i++) { + System.out.println("i: "+ i + ((PredictorNode)(m_predictors.get(i))).getIndex()); + } + System.out.println("m_splitters:\n"); + for (int i=0; i<m_splitters.size(); i++) { + System.out.println("i: "+i+m_splitters.get(i)); + } + System.out.println("m_splitterBuilders:\n"); + for (int i=0; i<m_splitterBuilders.size(); i++) { + System.out.println("i: "+i+m_splitterBuilders.get(i)); + } + */ } *************** *** 449,452 **** --- 488,494 ---- m_booster.update(predictions, partition); + if (parent==null) { + System.err.println("Adding candidate and the parent is null!"); + } lastBasePredictor= new AtreePredictor(splitter, parent, predictions, m_booster); SplitterNode node= findSplitter(parent, splitter); |
From: Aaron A. <aa...@us...> - 2007-10-02 02:22:35
|
Update of /cvsroot/jboost/jboost/src/jboost In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv8688 Modified Files: Predictor.java Log Message: Predict now takes the number of iterations (for order predict) Index: Predictor.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/Predictor.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** Predictor.java 16 May 2007 04:06:02 -0000 1.1.1.1 --- Predictor.java 2 Oct 2007 02:22:32 -0000 1.2 *************** *** 11,18 **** public interface Predictor { ! /** Given an <code>Instance</code>, generate a <code>Prediction<\code> */ - public abstract Prediction predict(Instance instance) throws IncompAttException; } --- 11,23 ---- public interface Predictor { ! /** ! * Given an <code>Instance</code>, generate a <code>Prediction<\code> */ public abstract Prediction predict(Instance instance) throws IncompAttException; + + /** + * Given an <code>Instance</code>, generate a <code>Prediction<\code>. + */ + public abstract Prediction predict(Instance instance, int numIters) throws IncompAttException; } |
From: Aaron A. <aa...@us...> - 2007-10-02 02:17:21
|
Update of /cvsroot/jboost/jboost/src/jboost In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv6594 Modified Files: AllTests.java Log Message: Added AtreeTestSuite to tests Index: AllTests.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/AllTests.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** AllTests.java 16 May 2007 04:06:02 -0000 1.1.1.1 --- AllTests.java 2 Oct 2007 02:17:14 -0000 1.2 *************** *** 7,10 **** --- 7,11 ---- import jboost.booster.BoosterTestSuite; import jboost.controller.ControllerTestSuite; + import jboost.atree.AtreeTestSuite; import junit.framework.Test; import junit.framework.TestSuite; *************** *** 21,24 **** --- 22,26 ---- suite.addTest(BoosterTestSuite.suite()); suite.addTest(ControllerTestSuite.suite()); + suite.addTest(AtreeTestSuite.suite()); //$JUnit-END$ return suite; |
From: Aaron A. <aa...@us...> - 2007-09-18 03:26:04
|
Update of /cvsroot/jboost/jboost/src/jboost/monitor In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv9842/monitor Modified Files: Monitor.java Log Message: New log file format. Index: Monitor.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/monitor/Monitor.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Monitor.java 10 Jul 2007 01:33:31 -0000 1.6 --- Monitor.java 18 Sep 2007 03:25:59 -0000 1.7 *************** *** 26,56 **** private static Date endTime; private String outputStem; ! private PrintWriter infoStream; // the stream for providing private String infoFilename; ! // a high-level log of the program's progress. - - /** parameter that controls when scores are printed */ - private int scoresPrintRate; - private PrintWriter testScoresStream; // a stream for the test data scores - private String testScoresOutputFilename; - private PrintWriter trainScoresStream; // a stream for the training data scores - private String trainScoresOutputFilename; ! /** margin streams and varialbes */ ! private int marginPrintRate; ! private PrintWriter testMarginStream; // a stream for the test data scores ! private String testMarginOutputFilename; ! private PrintWriter trainMarginStream; // a stream for the training data scores ! private String trainMarginOutputFilename; - /** surfing streams and varialbes */ - private int surfPrintRate; - private PrintWriter surfStream; // a stream for the training data scores - private String surfOutputFilename; ! /** a stream for logging resampling activity */ private PrintWriter samplingStream; private String samplingOutputFilename; /** log file info */ --- 26,47 ---- private static Date endTime; private String outputStem; ! ! /** a high-level log of the program's progress. */ private String infoFilename; ! private PrintWriter infoStream; ! /** training and testing streams and variables */ ! private int boostingPrintRate; ! private PrintWriter trainBoostingStream; ! private String trainBoostingFilename; ! private PrintWriter testBoostingStream; ! private String testBoostingFilename; ! /** a stream for logging resampling activity private PrintWriter samplingStream; private String samplingOutputFilename; + */ /** log file info */ *************** *** 106,116 **** infoFilename= config.getString("info", outputStem + ".info"); ! trainScoresOutputFilename= outputStem + ".train.scores"; ! testScoresOutputFilename= outputStem + ".test.scores"; ! trainMarginOutputFilename= outputStem + ".train.margin"; ! testMarginOutputFilename= outputStem + ".test.margin"; ! surfOutputFilename= outputStem + ".surfing"; - samplingOutputFilename= outputStem + ".sampling"; try { infoStream= --- 97,103 ---- infoFilename= config.getString("info", outputStem + ".info"); ! trainBoostingFilename = outputStem + ".train.boosting.info"; ! testBoostingFilename = outputStem + ".test.boosting.info"; try { infoStream= *************** *** 125,139 **** infoStream.println("trainFilename = " + config.getTrainFileName()); infoStream.println("testFilename = " + config.getTestFileName()); ! infoStream.println("trainScoresOutputFilename = " ! +trainScoresOutputFilename); ! infoStream.println("testScoresOutputFilename = " + ! testScoresOutputFilename); ! infoStream.println("trainMarginOutputFilename = " ! +trainMarginOutputFilename); ! infoStream.println("testMarginOutputFilename = " ! +testMarginOutputFilename); infoStream.println("resultOutputFilename = " + config.getResultOutputFileName()); - infoStream.println("samplingOutputFilename = " + samplingOutputFilename); infoStream.println("logOutputFilename = " + logOutputFilename); infoStream.println(""); --- 112,119 ---- infoStream.println("trainFilename = " + config.getTrainFileName()); infoStream.println("testFilename = " + config.getTestFileName()); ! infoStream.println("trainBoostingInfo = " + trainBoostingFilename); ! infoStream.println("testBoostingInfo = " + testBoostingFilename); infoStream.println("resultOutputFilename = " + config.getResultOutputFileName()); infoStream.println("logOutputFilename = " + logOutputFilename); infoStream.println(""); *************** *** 141,170 **** infoStream.println("Test set size = " + testSet.getExampleNo()); infoStream.println(""); ! scoresPrintRate= config.getInt("a", 0); ! marginPrintRate= scoresPrintRate; ! surfPrintRate= scoresPrintRate; ! if (scoresPrintRate != 0) { ! trainScoresStream= new PrintWriter(new BufferedWriter( ! new FileWriter(trainScoresOutputFilename))); ! testScoresStream= new PrintWriter(new BufferedWriter( ! new FileWriter(testScoresOutputFilename))); ! samplingStream= new PrintWriter(new BufferedWriter( ! new FileWriter(samplingOutputFilename))); ! logLabels(); ! // output train and test m_labels onto the samplingStream ! samplingStream.close(); ! } ! if (marginPrintRate != 0) { ! trainMarginStream= new PrintWriter( new BufferedWriter( ! new FileWriter(trainMarginOutputFilename))); ! testMarginStream= new PrintWriter( ! new BufferedWriter( ! new FileWriter(testMarginOutputFilename))); ! } ! if (marginPrintRate != 0) { ! surfStream = new PrintWriter( new BufferedWriter( ! new FileWriter(surfOutputFilename))); } afterInitTime= new Date(); --- 121,133 ---- infoStream.println("Test set size = " + testSet.getExampleNo()); infoStream.println(""); ! boostingPrintRate= config.getInt("a", 0); ! ! if (boostingPrintRate != 0) { ! trainBoostingStream = new PrintWriter( new BufferedWriter( ! new FileWriter(trainBoostingFilename))); ! testBoostingStream = new PrintWriter( new BufferedWriter( ! new FileWriter(testBoostingFilename))); } afterInitTime= new Date(); *************** *** 180,183 **** --- 143,147 ---- /** print the m_labels of trainSet and testSet onto samplingStream */ + /* private void logLabels() { ArrayList labels= trainSet.getBinaryLabels(); *************** *** 195,198 **** --- 159,163 ---- labels= null; } + */ /** generate logs for current boosting iteration */ *************** *** 205,289 **** + f.format(trainError) + "\t" + f.format(testError)); infoStream.flush(); ! logScores(iter, combined, base); ! logMargins(iter, combined, base); ! logSurfing(iter, combined, base); ! infoStream.println(); ! } ! ! /** output the scores distribution of the training set */ ! private void logScores(int iter, Predictor combined, Predictor base) { ! if (scoresPrintRate == 0 || // never print scores ! (scoresPrintRate > 0 && scoresPrintRate != iter)) ! // or print scores only on iteration scoresPrintRate ! return; ! if (scoresPrintRate == -1) { ! // print score when highest order digit in iter changes. ! double m= ! java.lang.Math.floor( ! java.lang.Math.log(iter) / java.lang.Math.log(10.0)); ! int t= (int) java.lang.Math.pow(10.0, m); ! if (iter == 0) ! t= 1; // fix bug in "pow" ! if ((iter % t) != 0) ! return; ! } ! infoStream.print(" \t# output scores #"); ! // output training scores ! // double m_margins[] = m_booster.getMargins(); // get m_margins from the ! // m_booster ! ArrayList trainScores= trainSet.calcScores(iter, combined, base); ! trainScoresStream.println( ! "iteration=" + iter + ", elements=" + trainScores.size()); ! for (int i= 0; i < trainScores.size(); i++) ! trainScoresStream.println((Double) trainScores.get(i)); ! trainScores= null; // release memory ! // output test scores ! ArrayList testScores= testSet.calcScores(iter, combined, base); ! testScoresStream.println( ! "iteration=" + iter + ", elements=" + testScores.size()); ! for (int i= 0; i < testScores.size(); i++) ! testScoresStream.println((Double) testScores.get(i)); ! testScores.clear(); // release memory ! testScores= null; } ! ! ! /** output the scores distribution of the training set */ ! private void logSurfing(int iter, Predictor combined, Predictor base) { ! if (surfPrintRate == 0 || // never print surf ! (surfPrintRate > 0 && surfPrintRate != iter)) ! // or print surf only on iteration surfPrintRate ! return; ! if (surfPrintRate == -1) { ! // print score when highest order digit in iter changes. ! double m= ! java.lang.Math.floor( ! java.lang.Math.log(iter) / java.lang.Math.log(10.0)); ! int t= (int) java.lang.Math.pow(10.0, m); ! if (iter == 0) ! t= 1; // fix bug in "pow" ! if ((iter % t) != 0) ! return; } - infoStream.print(" \t# output surf #"); - // output training surf - // double m_margins[] = m_booster.getMargins(); // get m_margins from the - // m_booster ! surfStream.println("iteration=" + iter + ", elements=" + trainSet.getExampleNo()); ! if(m_booster instanceof BrownBoost) { ! surfStream.print(((BrownBoost)m_booster).surfingData()); } } - /** output the scores distribution of the training set */ ! private void logMargins(int iter, Predictor combined, Predictor base) { ! if (marginPrintRate == 0 || // never print scores ! (marginPrintRate > 0 && scoresPrintRate != iter)) ! // or print scores only on iteration scoresPrintRate return; ! if (marginPrintRate == -1) { // print score when highest order digit in iter changes. double m= --- 170,287 ---- + f.format(trainError) + "\t" + f.format(testError)); infoStream.flush(); ! logBoosting(iter, combined, base); ! infoStream.println(""); } ! ! ! /** ! * Provides logging for both the train and test sets. ! */ ! private void logBoostingTrainTest(PrintWriter boostingStream, ExampleSet tSet, int iter, Predictor combined, Predictor base) { ! // Output the training data ! boostingStream.println("iteration=" + iter + ! ", elements=" + tSet.size() + ! ", boosting_params=" + m_booster.getParamString() ! ); ! ! // Get the relavant data structures (arrays and lists) ! ArrayList tMargin = tSet.calcMargins(iter, combined, base); ! ArrayList tScores = tSet.calcScores(iter, combined, base); ! ArrayList tLabelIndices = tSet.getBinaryLabels(); ! double[][] tWeights = null; ! double[][] tPotentials = null; ! if (boostingStream.equals(trainBoostingStream)) { ! tWeights = m_booster.getWeights(); ! tPotentials = m_booster.getPotentials(); } ! NumberFormat f= new DecimalFormat("0.0000"); ! double[] tmp = null; ! Boolean[] labeltmp = null; ! int j = 0; ! for (int i=0; i < tMargin.size(); i++) { ! // output the example number ! boostingStream.print("[" +i + "]; "); ! ! // output the margins ! boostingStream.print("["); ! tmp = ((double[]) tMargin.get(i)); ! for (j= 0; j < tmp.length; j++){ ! boostingStream.print(f.format(tmp[j])); ! if (j != tmp.length -1) ! boostingStream.print(","); ! } ! boostingStream.print("]; "); ! ! ! // output the scores ! boostingStream.print("["); ! tmp = ((double[]) tScores.get(i)); ! for (j= 0; j < tmp.length; j++){ ! boostingStream.print(f.format(tmp[j])); ! if (j != tmp.length -1) ! boostingStream.print(","); ! } ! boostingStream.print("]; "); ! ! ! ! if (boostingStream.equals(trainBoostingStream)) { ! ! // output the weights ! boostingStream.print("["); ! for (j= 0; j < tWeights[i].length; j++){ ! boostingStream.print(f.format(tWeights[i][j])); ! if (j != tmp.length -1) ! boostingStream.print(","); ! } ! boostingStream.print("]; "); ! ! ! // output the potentials ! boostingStream.print("["); ! for (j= 0; j < tPotentials[i].length; j++){ ! boostingStream.print(f.format(tPotentials[i][j])); ! if (j != tmp.length -1) ! boostingStream.print(","); ! } ! boostingStream.print("]; "); ! ! ! } ! ! ! // output the labels ! boostingStream.print("["); ! labeltmp = ((Boolean[]) tLabelIndices.get(i)); ! for (j= 0; j < labeltmp.length; j++){ ! boostingStream.print(labeltmp[j].booleanValue() ? "+1" : "-1"); ! if (j != tmp.length -1) ! boostingStream.print(","); ! } ! boostingStream.print("]; "); ! ! boostingStream.println(""); } + + + // release memory + tMargin.clear(); + tScores.clear(); + tLabelIndices.clear(); + tMargin= null; + tScores= null; + tLabelIndices = null; + tWeights = null; + tPotentials = null; } /** output the scores distribution of the training set */ ! private void logBoosting(int iter, Predictor combined, Predictor base) { ! if (boostingPrintRate == 0 || ! (boostingPrintRate > 0 && boostingPrintRate != iter)) return; ! if (boostingPrintRate == -1) { // print score when highest order digit in iter changes. double m= *************** *** 296,317 **** return; } ! infoStream.print(" \t# output margins #"); ! // output training scores ! // double m_margins[] = m_booster.getMargins(); // get m_margins from the ! // m_booster ! ArrayList trainMargin= trainSet.calcMargins(iter, combined, base); ! trainMarginStream.println( ! "iteration=" + iter + ", elements=" + trainMargin.size()); ! for (int i= 0; i < trainMargin.size(); i++) ! trainMarginStream.println((Double) trainMargin.get(i)); ! trainMargin= null; // release memory ! // output test scores ! ArrayList testMargin= testSet.calcMargins(iter, combined, base); ! testMarginStream.println( ! "iteration=" + iter + ", elements=" + testMargin.size()); ! for (int i= 0; i < testMargin.size(); i++) ! testMarginStream.println((Double) testMargin.get(i)); ! testMargin.clear(); // release memory ! testMargin= null; } --- 294,302 ---- return; } ! logBoostingTrainTest(trainBoostingStream, trainSet, iter, combined, base); ! logBoostingTrainTest(testBoostingStream, testSet, iter, combined, base); ! trainBoostingStream.flush(); ! testBoostingStream.flush(); ! infoStream.print(" \t# output boosting data #"); } *************** *** 324,337 **** infoStream.println("End time=" + endTime); infoStream.close(); ! if (trainScoresStream != null) ! trainScoresStream.close(); ! if (testScoresStream != null) ! testScoresStream.close(); ! if (trainMarginStream != null) ! trainMarginStream.close(); ! if (testMarginStream != null) ! testMarginStream.close(); ! if (surfStream != null) ! surfStream.close(); log("finished closing output files"); } --- 309,316 ---- infoStream.println("End time=" + endTime); infoStream.close(); ! if (trainBoostingStream != null) ! trainBoostingStream.close(); ! if (testBoostingStream != null) ! testBoostingStream.close(); log("finished closing output files"); } |
Update of /cvsroot/jboost/jboost/src/jboost/booster In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv9842/booster Modified Files: MulticlassWrapMH.java AbstractBooster.java AdaBoost.java Booster.java DebugWrap.java BrownBoost.java Log Message: New log file format. Index: MulticlassWrapMH.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/MulticlassWrapMH.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** MulticlassWrapMH.java 30 May 2007 07:41:55 -0000 1.3 --- MulticlassWrapMH.java 18 Sep 2007 03:25:58 -0000 1.4 *************** *** 74,77 **** --- 74,80 ---- } + + + public void finalizeData() { m_booster.finalizeData(); *************** *** 85,88 **** --- 88,129 ---- return new MultiBag(); } + + + /** + * + */ + public double[][] getWeights() { + int numExamples = m_booster.getNumExamples() / m_numLabels; + double[][] r= new double[numExamples][m_numLabels]; + double[][] weights = m_booster.getWeights(); + for (int i= 0; i < numExamples; i++) + for (int j=0; j < m_numLabels; j++) + r[i][j]= weights[i*m_numLabels+j][0]; + return r; + } + + /** + * + */ + public double[][] getPotentials() { + int numExamples = m_booster.getNumExamples() / m_numLabels; + double[][] r= new double[numExamples][m_numLabels]; + double[][] potentials = m_booster.getPotentials(); + for (int i= 0; i < numExamples; i++) + for (int j=0; j < m_numLabels; j++) + r[i][j]= potentials[i*m_numLabels+j][0]; + return r; + } + + + /** + * + * + */ + public String getParamString() { + return m_booster.getParamString(); + } + + /** *************** *** 91,94 **** --- 132,140 ---- * extend the abstract booster" * + * According to Aaron: It seems that multiclass booster should + * certainly extend AbstractBooster. MulticlassWrap becomes the + * booster and merely insulates the true booster via an Adaptor + * design pattern. + * * Not sure what context this function would be inappropriate. */ *************** *** 140,144 **** * train the underlying booster. */ ! public double[] getMargins() { return m_booster.getMargins(); } --- 186,190 ---- * train the underlying booster. */ ! public double[][] getMargins() { return m_booster.getMargins(); } *************** *** 314,321 **** } /** * This is the prediction class associated with this booster. * Each prediction is composed of an array of predictions from the ! * underlying booster, one for each class. */ class MultiPrediction extends Prediction { /** --- 360,370 ---- } + + /** * This is the prediction class associated with this booster. * Each prediction is composed of an array of predictions from the ! * underlying booster, one for each class. ! */ class MultiPrediction extends Prediction { /** Index: AdaBoost.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/AdaBoost.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** AdaBoost.java 16 May 2007 04:06:02 -0000 1.1.1.1 --- AdaBoost.java 18 Sep 2007 03:25:58 -0000 1.2 *************** *** 1,2 **** --- 1,3 ---- + /* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ package jboost.booster; *************** *** 30,33 **** --- 31,37 ---- /** permanent storage for example's old m_weights */ protected double[] m_oldWeights; + /** Records the potentials. Similar to m_margins and m_weights. */ + protected double[] m_potentials; + /** sampling weights for the examples */ protected double[] m_sampleWeights; *************** *** 118,121 **** --- 122,126 ---- m_labels= null; m_margins= null; + m_potentials= null; m_weights= null; m_oldWeights= null; *************** *** 126,133 **** protected void finalizeData(double defaultWeight) { ! m_margins= new double[m_numExamples]; ! m_oldMargins= new double[m_numExamples]; m_weights= new double[m_numExamples]; m_oldWeights= new double[m_numExamples]; m_labels= new short[m_numExamples]; m_sampleWeights= new double[m_numExamples]; --- 131,139 ---- protected void finalizeData(double defaultWeight) { ! m_margins= new double[m_numExamples]; ! m_oldMargins= new double[m_numExamples]; m_weights= new double[m_numExamples]; m_oldWeights= new double[m_numExamples]; + m_potentials= new double[m_numExamples]; m_labels= new short[m_numExamples]; m_sampleWeights= new double[m_numExamples]; *************** *** 150,153 **** --- 156,160 ---- } + /** * Return the theoretical bound on the training error. *************** *** 160,170 **** * Returns the margin values of the training examples. */ ! public double[] getMargins() { ! double[] r= new double[m_numExamples]; for (int i= 0; i < m_numExamples; i++) ! r[i]= m_margins[i]; return r; } /** output AdaBoost contents as a human-readable string */ public String toString() { --- 167,225 ---- * Returns the margin values of the training examples. */ ! public double[][] getMargins() { ! double[][] r= new double[m_numExamples][1]; for (int i= 0; i < m_numExamples; i++) ! r[i][0]= m_margins[i]; return r; } + /** + * + */ + public double[][] getWeights() { + double[][] r= new double[m_numExamples][1]; + for (int i= 0; i < m_numExamples; i++) + r[i][0]= m_weights[i]; + return r; + } + + /** + * + */ + public double[][] getPotentials() { + double[][] r= new double[m_numExamples][1]; + for (int i= 0; i < m_numExamples; i++) + r[i][0]= m_potentials[i]; + return r; + } + + /** + * + */ + public int getNumExamples() { + return m_numExamples; + } + + + /** + * 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() { Index: Booster.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/Booster.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** Booster.java 16 May 2007 04:06:02 -0000 1.1.1.1 --- Booster.java 18 Sep 2007 03:25:58 -0000 1.2 *************** *** 68,72 **** * for statistical purposes only (e.g., plotting all margin values). */ ! public abstract double[] getMargins(); /** --- 68,79 ---- * for statistical purposes only (e.g., plotting all margin values). */ ! public abstract double[][] getMargins(); ! ! ! public abstract double[][] getWeights(); ! public abstract double[][] getPotentials(); ! public int getNumExamples(); ! public abstract String getParamString(); ! /** Index: BrownBoost.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/BrownBoost.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** BrownBoost.java 10 Jul 2007 01:32:52 -0000 1.5 --- BrownBoost.java 18 Sep 2007 03:25:58 -0000 1.6 *************** *** 44,52 **** * Records the potentials. Similar to m_margins and m_weights. */ - protected double[] m_potentials; - - /** - * Records the potentials. Similar to m_margins and m_weights. - */ protected double m_totalPotential; --- 44,47 ---- *************** *** 62,66 **** public void finalizeData() { super.finalizeData(); - m_potentials = new double[m_numExamples]; for (int i=0; i<m_numExamples; i++) { m_potentials[i] = calculatePotential(0,m_c); --- 57,60 ---- *************** *** 421,430 **** } public String surfingData() { ! String ret = new String(""); ! ret += String.format("BrownBoost Params: %.4f %.4f\n", m_c, m_s); for (int i=0; i<m_margins.length; i++){ ! ret += String.format("%.4f\t%.4f\t%.4f\n", m_margins[i], m_weights[i], m_potentials[i]); } return ret; } --- 415,431 ---- } + /* public String surfingData() { ! StringBuffer ret = new StringBuffer(""); ! ret.append(String.format("BrownBoost Params: %.4f %.4f\n", m_c, m_s)); for (int i=0; i<m_margins.length; i++){ ! ret.append(String.format("%.4f\t%.4f\t%.4f\n", m_margins[i], m_weights[i], m_potentials[i])); } + return ret.toString(); + } + */ + + public String getParamString() { + String ret = String.format("BrownBoost Params: %.4f %.4f", m_c, m_s); return ret; } Index: DebugWrap.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/DebugWrap.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** DebugWrap.java 16 May 2007 04:06:02 -0000 1.1.1.1 --- DebugWrap.java 18 Sep 2007 03:25:58 -0000 1.2 *************** *** 140,143 **** --- 140,155 ---- return booster.calculateWeight(margin); } + + + + public double[][] getWeights() { + return new double[1][1]; + } + + public double[][] getPotentials(){ + return new double[1][1]; + } + + *************** *** 239,243 **** } ! public double[] getMargins() { return booster.getMargins(); } --- 251,255 ---- } ! public double[][] getMargins() { return booster.getMargins(); } Index: AbstractBooster.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/AbstractBooster.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** AbstractBooster.java 14 Jun 2007 16:33:51 -0000 1.4 --- AbstractBooster.java 18 Sep 2007 03:25:58 -0000 1.5 *************** *** 69,79 **** double c1 = Double.parseDouble(c.getString("c1", "1.0")); double c2 = Double.parseDouble(c.getString("c2", "1.0")); ! double theta = Double.parseDouble(c.getString("theta", "0.2")); jboost.booster.YabaBoost yaba = (jboost.booster.YabaBoost) result; yaba.setParams(c1,c2,theta); result = yaba; } - - } --- 69,77 ---- double c1 = Double.parseDouble(c.getString("c1", "1.0")); double c2 = Double.parseDouble(c.getString("c2", "1.0")); ! double theta = Double.parseDouble(c.getString("theta", "0.15")); jboost.booster.YabaBoost yaba = (jboost.booster.YabaBoost) result; yaba.setParams(c1,c2,theta); result = yaba; } } *************** *** 91,94 **** --- 89,101 ---- } + public int getNumExamples(){ + return 0; + } + + public String getParamString() { + return "No parameters defined"; + } + + /** * Create and return a new Bag which initially contains the |
From: Aaron A. <aa...@us...> - 2007-09-18 03:26:03
|
Update of /cvsroot/jboost/jboost/src/jboost/examples In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv9842/examples Modified Files: ExampleSet.java Log Message: New log file format. Index: ExampleSet.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/examples/ExampleSet.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** ExampleSet.java 16 May 2007 04:06:02 -0000 1.1.1.1 --- ExampleSet.java 18 Sep 2007 03:25:59 -0000 1.2 *************** *** 1,2 **** --- 1,3 ---- + /* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ package jboost.examples; *************** *** 32,35 **** --- 33,40 ---- private boolean isBinary=true; // identifies the data as binary-labeled + /** last iteration on which calc* was called */ + private int lastIter = -2; + private Prediction[] prediction = null; + /** default constructor */ public ExampleSet(){ *************** *** 76,79 **** --- 81,89 ---- else return exampleSet.length; } + + /** get no of examples */ + public int size() { + return getExampleNo(); + } /** get example no. i */ *************** *** 137,142 **** Example x = exampleSet[i]; double[] tmp = prediction[i].getMargins(x.getLabel()); ! for(int j=0; j<tmp.length; j++) ! margins.add(new Double(tmp[j])); } } --- 147,151 ---- Example x = exampleSet[i]; double[] tmp = prediction[i].getMargins(x.getLabel()); ! margins.add(tmp); } } *************** *** 162,173 **** int i=0; try{ for(i=0; i<size; i++) { ! double[] tmp = prediction[i].getClassScores(); ! if(isBinary) // for binary m_labels, keep only one score ! scores.add(new Double(tmp[0])); ! else ! for(int j=0; j<tmp.length; j++) ! scores.add(new Double(tmp[j])); } } --- 171,185 ---- int i=0; + double[] tmp = null; + double tmp0 = 0; try{ for(i=0; i<size; i++) { ! tmp = prediction[i].getClassScores(); ! if(isBinary) { // for binary m_labels, keep only one score ! tmp0 = tmp[0]; ! tmp = new double[1]; ! tmp[0] = tmp0; ! } ! scores.add(tmp); } } *************** *** 182,187 **** } ! private int lastIter = -2; // last iteration on which calc* was called ! private Prediction[] prediction = null; /** updates the saved predictions --- 194,199 ---- } ! ! /** updates the saved predictions *************** *** 191,194 **** --- 203,208 ---- Predictor combined, Predictor base) { + + if (base != null) { if (curIter == lastIter) *************** *** 202,208 **** } } for (int i = 0; i < exampleSet.length; i++) prediction[i] = ! combined.predict(exampleSet[i].getInstance()); lastIter = curIter; } --- 216,225 ---- } } + + for (int i = 0; i < exampleSet.length; i++) prediction[i] = ! combined.predict(exampleSet[i].getInstance(),curIter); ! lastIter = curIter; } *************** *** 219,230 **** int i=0; try{ for(i=0; i<size; i++) { Label l = exampleSet[i].getLabel(); ! if(isBinary) ! labels.add(new Boolean(l.getMultiValue(0))); ! else ! for(int j=0; j<noOfLabels; j++) ! labels.add(new Boolean(l.getMultiValue(j))); } } --- 236,253 ---- int i=0; + Boolean[] tmp = null; try{ for(i=0; i<size; i++) { Label l = exampleSet[i].getLabel(); ! if(isBinary) { ! tmp = new Boolean[1]; ! tmp[0] = new Boolean(l.getMultiValue(0)); ! } else { ! tmp = new Boolean[noOfLabels]; ! for(int j=0; j<noOfLabels; j++) { ! tmp[j] = new Boolean(l.getMultiValue(j)); ! } ! } ! labels.add(tmp); } } |
From: Aaron A. <aa...@us...> - 2007-07-12 16:23:13
|
Update of /cvsroot/jboost/jboost/scripts In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv3389 Modified Files: surfing.py Log Message: minor updates Index: surfing.py =================================================================== RCS file: /cvsroot/jboost/jboost/scripts/surfing.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** surfing.py 10 Jul 2007 01:34:17 -0000 1.1 --- surfing.py 12 Jul 2007 16:07:26 -0000 1.2 *************** *** 67,70 **** --- 67,71 ---- y = math.exp(-math.pow(x-mu,2)/(var)) * max_bin p = (1 - erf((x-mu)/math.sqrt(var)))/2 + p = min(2*p, 1) weights.append((x,y,p)) x += step *************** *** 76,80 **** num_bins = 0 if is_cum: ! num_bins = 100 else: num_bins = 30 --- 77,81 ---- num_bins = 0 if is_cum: ! num_bins = 200 else: num_bins = 30 *************** *** 154,158 **** epsoutlines.append('set terminal post\n') epsoutlines.append('set output \'surfing%05d.eps\'\n' % (iter)) ! epsoutlines.append('set title "'+ params[0] + 'boost ' + datafile + ' Surfing: Iteration ' + str(iter) + '" font "Times,20"\n') epsoutlines.append('set key left top\n') epsoutlines.append('set yzeroaxis lt -1\n') --- 155,159 ---- epsoutlines.append('set terminal post\n') epsoutlines.append('set output \'surfing%05d.eps\'\n' % (iter)) ! epsoutlines.append('set title "'+ params[0] + 'boost ' + datafile + ' Surfing: Time Remaining ' + str(params[2]) + '" font "Times,20"\n') epsoutlines.append('set key left top\n') epsoutlines.append('set yzeroaxis lt -1\n') *************** *** 165,170 **** --- 166,176 ---- epsoutlines.append('set xlabel "Margin" font "Times,20"\n') epsoutlines.append('set ylabel "Cumulative Distribution" font "Times,20"\n') + # epsoutlines.append('EPS = 0.00001\n') + # epsoutlines.append('theta = %.5f\n' % (params[5])) + # epsoutlines.append('set parametric \n') + # epsoutlines.append('delta(t) = (x<=theta+EPS ? x>=theta-EPS ? 1.0 : 0 : 0 )\n') epsoutlines.append('plot "surfing_hist.dat" using 1:2 title "Margin CDF" with lines, ' + \ '"surfing_weight.dat" using 1:2 title "Potential" with lines \n') + # 'delta(t) with lines \n') # if params[0]=='normal': # epsoutlines.append('set parametric\n') |
From: Aaron A. <aa...@us...> - 2007-07-10 01:38:43
|
Update of /cvsroot/jboost/jboost/scripts In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv23831/scripts Modified Files: atree2dot2ps.pl nfold.py Log Message: added 'truncate' and 'flip label' options Index: atree2dot2ps.pl =================================================================== RCS file: /cvsroot/jboost/jboost/scripts/atree2dot2ps.pl,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** atree2dot2ps.pl 19 May 2007 21:42:41 -0000 1.3 --- atree2dot2ps.pl 10 Jul 2007 01:38:38 -0000 1.4 *************** *** 16,24 **** print "\t -t (--tree) file.tree \t File containing the ADTree in text format (required) \n"; print "\t -d (--dir) directiory\t Directory to use (optional, defaults to '.') \n"; print "\t --threshold num \t A given depth to stop the tree from becoming too large. (optional) \n"; print "\t -h (--help) \t Print this usage information \n"; print "\n"; print "This script uses the 'dot' program, which must be in your path.\n"; ! print "'dot' is part of the graphviz package from at&t research.\n"; exit($exit_code); } --- 16,26 ---- print "\t -t (--tree) file.tree \t File containing the ADTree in text format (required) \n"; print "\t -d (--dir) directiory\t Directory to use (optional, defaults to '.') \n"; + print "\t -l (--labels) \t Flip the labels (-1 becomes +1) (optional)\n"; + print "\t --truncate \t Truncate threshold values to increase readability\n"; print "\t --threshold num \t A given depth to stop the tree from becoming too large. (optional) \n"; print "\t -h (--help) \t Print this usage information \n"; print "\n"; print "This script uses the 'dot' program, which must be in your path.\n"; ! print "'dot' is part of the graphviz package from AT&T research.\n"; exit($exit_code); } *************** *** 30,33 **** --- 32,37 ---- $threshold = 0; $gethelp = 0; + $fliplabels = 0; + $truncatesplits = 0; if ( @ARGV > 0 ) { *************** *** 36,39 **** --- 40,45 ---- 'd|dir=s' => \$dirname, 'h|help' => \$gethelp, + 'l|labels' => \$fliplabels, + 'truncate' => \$truncatesplits, 'threshold=i' => \$threshold) or print_usage(2); *************** *** 90,94 **** $splitType = $1; } ! print "$type, $index, $label, $splitType\n"; } elsif($line =~ /^(\d*)\t\[([^\]]*)\].*p\(1\)= (.*)/) { --- 96,109 ---- $splitType = $1; } ! if ($splitType =~ /InequalitySplitter/ && $truncatesplits) { ! $label =~ /([a-zA-Z0-9\-\s]*)\s*(<|>)\s*(-*[0-9]*(\.)?[0-9]?[0-9]?[0-9]?).*/; ! $var = $1; ! $ineq = $2; ! $val = $3; ! print "$type, $index, $var, $ineq, $val, $splitType\n"; ! $label = "$var $ineq $val" ! } else { ! print "$type, $index, $label, $splitType\n"; ! } } elsif($line =~ /^(\d*)\t\[([^\]]*)\].*p\(1\)= (.*)/) { *************** *** 98,101 **** --- 113,119 ---- $label = $3; $label =~ s/(\d\.\d{3}).*/$1/; + if($fliplabels) { + $label = -$label; + } print "$type, $index, $label\n"; } *************** *** 142,146 **** system("dot -Tpng $filename.$threshold.dot -o $filename.$threshold.png"); system("dot -Tgif $filename.$threshold.dot -o $filename.$threshold.gif"); ! system("dot -Tps2 $filename.$threshold.dot -o $filename.$threshold.ps"); system("ps2pdf $filename.$threshold.ps"); --- 160,166 ---- system("dot -Tpng $filename.$threshold.dot -o $filename.$threshold.png"); system("dot -Tgif $filename.$threshold.dot -o $filename.$threshold.gif"); ! #system("dot -Tps2 $filename.$threshold.dot -o $filename.$threshold.eps"); ! system("dot -Tps $filename.$threshold.dot -o $filename.$threshold.ps"); system("ps2pdf $filename.$threshold.ps"); + system("pstoimg -antialias -aaliastext -density 400 $filename.$threshold.ps"); Index: nfold.py =================================================================== RCS file: /cvsroot/jboost/jboost/scripts/nfold.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** nfold.py 27 May 2007 11:19:49 -0000 1.4 --- nfold.py 10 Jul 2007 01:38:38 -0000 1.5 *************** *** 27,31 **** config= os.getenv('JBOOST_CONFIG') command = 'java -Xmx1000M -cp ' + os.getenv('CLASSPATH') \ ! + ' jboost.controller.Controller -p 3 -a -2 -S trial' + str(k) \ + ' -n trial.spec -ATreeType '+ atreeoption +' -numRounds ' + str(rounds) if (config != None): --- 27,31 ---- config= os.getenv('JBOOST_CONFIG') command = 'java -Xmx1000M -cp ' + os.getenv('CLASSPATH') \ ! + ' jboost.controller.Controller -b LogLossBoost -p 3 -a -1 -S trial' + str(k) \ + ' -n trial.spec -ATreeType '+ atreeoption +' -numRounds ' + str(rounds) if (config != None): *************** *** 69,72 **** --- 69,74 ---- print 'k: ' + str(k) + ' start:' + str(start) +' end:' + str(end) # create test/train files + trainfilename = fileprefix + str(k) + trainsuffix; + testfilename = fileprefix + str(k) + testsuffix; testfile= file(fileprefix + str(k)+ testsuffix, 'w') trainfile= file(fileprefix + str(k) + trainsuffix, 'w') *************** *** 76,79 **** --- 78,82 ---- testfile.close() trainfile.close() + os.system('./resample.py --k=128 --label=" 1" --train=' + trainfilename); |
From: Aaron A. <aa...@us...> - 2007-07-10 01:34:20
|
Update of /cvsroot/jboost/jboost/scripts In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv21939/scripts Added Files: surfing.py Log Message: added --- NEW FILE: surfing.py --- #! /usr/bin/env python import string import getopt import sys import pickle import os import re import math def usage(): print 'Usage: margin.py ' print '\t--surfing=filename surfing file as output by jboost (-a -2 switch)' print '\t--scores=filename scores file as output by jboost (-a -2 switch)' print '\t--data=filename train/test filename' print '\t--spec=filename spec filename' print '\t--booster=type type={normal, brown}' print '\t--framerate=num an integer specifying framerate' def erf(z): t = 1.0 / (1.0 + 0.5 * abs(z)); ans = 1 - t * math.exp( -z*z - 1.26551223 + \ t * ( 1.00002368 + \ t * ( 0.37409196 + \ t * ( 0.09678418 + \ t * (-0.18628806 + \ t * ( 0.27886807 + \ t * (-1.13520398 + \ t * ( 1.48851587 + \ t * (-0.82215223 + \ t * ( 0.17087277)))))))))) if z < 0: ans = - ans return ans; def get_weight_line(params, start, end, max_bin): weights = [] s = c= c1 = c2 = theta = 0 if(params[0] == 'brown'): c = float(params[1]) s = float(params[2]) #time remaining elif(params[0] == 'normal'): c = float(params[1]) s = c-float(params[2]) #time played start = -1.0 end = 1.0 c1 = float(params[3]) c2 = float(params[4]) theta = float(params[5]) num_steps = 100 step = (end - start) / num_steps x = start for i in range(0,num_steps): mu = var = 0 if params[0] == 'brown': mu = -s var = c elif params[0] == 'normal': mu = theta - c1 * (math.exp(-s) - math.exp(-c)) var = c2 * (math.exp(-2*s) - math.exp(-2*c)) + 0.05 norm = 1 / math.sqrt(var*math.pi) y = math.exp(-math.pow(x-mu,2)/(var)) * max_bin p = (1 - erf((x-mu)/math.sqrt(var)))/2 weights.append((x,y,p)) x += step return weights def get_margin_hist(margins, is_cum): num_bins = 0 if is_cum: num_bins = 100 else: num_bins = 30 marg_max = max(margins) marg_min = min(margins) bin_size = (marg_max - marg_min) / num_bins b = marg_min i = 0 hist = [] x_axis = [] j = 0 EPS = bin_size / 10000 total_seen = 0 while b <= marg_max: hist.append(0) while i < len(margins) and (margins[i] <= b + bin_size + EPS): i += 1 hist[j] += 1 x_axis.append(b + bin_size) if is_cum: tmp = hist[j] hist[j] += total_seen total_seen += tmp b += bin_size j += 1 s = 0 if is_cum: s = max(hist) else: s = sum(hist) return [(x, float(h) / s) for (x,h) in zip(x_axis,hist)] def paste_gnuplot(num_iterations, framerate): print 'Starting animated gif creation' os.system('convert -rotate 90 -delay 5 -loop 0 surfing*.eps surfing.gif') print 'Finished gif creation' print 'See surfing.gif for animation' line_compare = lambda x,y : cmp(float(string.split(x,'\t')[0]), float(string.split(y,'\t')[0])) def write_gnuplot(lines, iter, datafile, params): lines.sort(line_compare); margins = [ float(string.split(x,'\t')[0]) for x in lines] weights = [ float(string.split(x,'\t')[1]) for x in lines] potentials = [ float(string.split(x,'\t')[2]) for x in lines] marg_max = max(margins); marg_min = min(margins); lines = get_margin_hist(margins, 1); max_bin = max([l[1] for l in lines]) lines = [str(l[0]) + ' ' + str(l[1]) + '\n' for l in lines] f= open('surfing_hist.dat', 'w') f.writelines(lines) f.close() weight_line = get_weight_line(params, marg_min, marg_max, max_bin) # lines = [ str(m) + ' ' + str(p) + ' ' + str(w) + '\n' for (m,w,p) in weight_line] lines = [ str(m) + ' ' + str(p) + '\n' for (m,w,p) in weight_line] f= open('surfing_weight.dat', 'w') f.writelines(lines) f.close() xrange = max([abs(marg_min), abs(marg_max)]) yrange = max_bin epsoutlines = [] epsoutlines.append('set terminal post\n') epsoutlines.append('set output \'surfing%05d.eps\'\n' % (iter)) epsoutlines.append('set title "'+ params[0] + 'boost ' + datafile + ' Surfing: Iteration ' + str(iter) + '" font "Times,20"\n') epsoutlines.append('set key left top\n') epsoutlines.append('set yzeroaxis lt -1\n') if params[0]=='normal': epsoutlines.append('set xrange [-1:1]\n') epsoutlines.append('set yrange [0:1]\n') else: epsoutlines.append('set xrange [%0.2f:%0.2f]\n' % (-xrange, xrange)) epsoutlines.append('set yrange [0:1]\n') epsoutlines.append('set xlabel "Margin" font "Times,20"\n') epsoutlines.append('set ylabel "Cumulative Distribution" font "Times,20"\n') epsoutlines.append('plot "surfing_hist.dat" using 1:2 title "Margin CDF" with lines, ' + \ '"surfing_weight.dat" using 1:2 title "Potential" with lines \n') # if params[0]=='normal': # epsoutlines.append('set parametric\n') # epsoutlines.append('set trange [0:1]\n') # epsoutlines.append('replot ' + str(params[5]) + ', t \n') pngoutlines = epsoutlines[:] pngoutlines[0] = 'set terminal png notransparent small\n' pngoutlines[1] = ('set output \'surfing%05d.png\'\n' % (iter)) gifoutlines = epsoutlines[:] gifoutlines[0] = 'set terminal gif notransparent\n' gifoutlines[1] = ('set output \'surfing%05d.gif\'\n' % (iter)) f = open('surfing.png.gnuplot', 'w') f.writelines(pngoutlines) f.close() f = open('surfing.eps.gnuplot', 'w') f.writelines(epsoutlines) f.close() f = open('surfing.gif.gnuplot', 'w') f.writelines(gifoutlines) f.close() os.system('gnuplot surfing.eps.gnuplot') print 'Finished with iteration ' + str(iter) def main(): # Usage: see usage() # Looks at all the examples that have negative margins # the output can be used to find the examples that are probably mislabeled # and also the examples that might need more features try: opts, args= getopt.getopt(sys.argv[1:], '', ['surfing=', 'scores=','data=','spec=','labels=', 'iteration=', 'framerate=', 'booster=', 'sample']) except getopt.GetoptError, inst: print 'Received an illegal argument:', inst usage() sys.exit(2) surffile = scoresfile = datafile = framerate = specfile = labelsfile = sample = iteration = booster = None for opt,arg in opts: if (opt == '--surfing'): surffile = arg if (opt == '--booster'): booster = arg if (opt == '--framerate'): framerate = int(arg) if (opt == '--scores'): scoresfile = arg if (opt == '--spec'): specfile = arg if (opt == '--data'): datafile = arg if(surffile == None or scoresfile == None or datafile == None or specfile == None): print 'Need score, data, and spec file.' usage() sys.exit(2) if(framerate==None): print 'Need frame rate.' usage() sys.exit(2) if(booster==None or (booster!='normal' and booster!='brown')): print 'Only accepts `normal` and `brown` boost.' usage() sys.exit(2) print 'Reading surfing file' f= open(surffile,'r') data= f.readlines() f.close() num_elements= int((string.split(data[0],'='))[2]) num_iterations = int(string.split(string.split(data[-num_elements-2], ',')[0], '=')[1]) os.system('rm surfing*.eps surfing*.png') for iter in range(0, num_iterations+1, framerate): if (booster=='brown'): total_time = string.split(data[iter*(num_elements+2)+1], ' ')[2] time_left = string.split(data[iter*(num_elements+2)+1], ' ')[3] params = ('brown', total_time, time_left) if (booster=='normal'): total_time = string.split(data[iter*(num_elements+2)+1], ' ')[2] time_left = string.split(data[iter*(num_elements+2)+1], ' ')[3] c1 = 1.818 c2 = 1 theta = 0.1 #c1 = string.split(data[iter*(num_elements+2)+1], ' ')[4] #c2 = string.split(data[iter*(num_elements+2)+1], ' ')[5] #theta = string.split(data[iter*(num_elements+2)+1], ' ')[6] params = ('normal', total_time, time_left, c1, c2, theta) lines = [x for x in data[iter*(num_elements+2)+2:(iter+1)*(num_elements+2)]] write_gnuplot(lines, iter, datafile, params) paste_gnuplot(num_iterations, framerate) if __name__ == "__main__": main() |
From: Aaron A. <aa...@us...> - 2007-07-10 01:33:39
|
Update of /cvsroot/jboost/jboost/src/jboost/monitor In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv21507/src/jboost/monitor Modified Files: Monitor.java Log Message: close surf stream Index: Monitor.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/monitor/Monitor.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Monitor.java 14 Jun 2007 16:21:13 -0000 1.5 --- Monitor.java 10 Jul 2007 01:33:31 -0000 1.6 *************** *** 332,335 **** --- 332,337 ---- if (testMarginStream != null) testMarginStream.close(); + if (surfStream != null) + surfStream.close(); log("finished closing output files"); } |
From: Aaron A. <aa...@us...> - 2007-07-10 01:32:57
|
Update of /cvsroot/jboost/jboost/src/jboost/booster In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv21044/src/jboost/booster Modified Files: BrownBoost.java BrownBoostTest.java YabaBoost.java Log Message: corrected erf bug and added surfing data to yaba Index: YabaBoost.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/YabaBoost.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** YabaBoost.java 14 Jun 2007 16:37:46 -0000 1.3 --- YabaBoost.java 10 Jul 2007 01:32:52 -0000 1.4 *************** *** 115,118 **** --- 115,129 ---- } + + public String surfingData() { + String ret = new String(""); + ret += String.format("YabaBoost Params: %.4f %.4f %4f %4f %4f\n", m_c, m_s, m_c1, m_c2, m_theta); + for (int i=0; i<m_margins.length; i++){ + ret += String.format("%.4f\t%.4f\t%.4f\n", m_margins[i], m_weights[i], m_potentials[i]); + } + return ret; + } + + public void finalizeData() { *************** *** 486,489 **** --- 497,503 ---- + if (m_hypPredictions.length != m_margins.length) { + System.err.println("WARNING: m_hypPredictions is not the same length as the margins"); + } for (int i=0; i < m_hypPredictions.length; i++) { m_oldWeights[i]= m_weights[i]; Index: BrownBoost.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/BrownBoost.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** BrownBoost.java 14 Jun 2007 16:45:52 -0000 1.4 --- BrownBoost.java 10 Jul 2007 01:32:52 -0000 1.5 *************** *** 109,113 **** t * (-0.82215223 + t * ( 0.17087277)))))))))); ! return Math.abs(ans); } --- 109,114 ---- t * (-0.82215223 + t * ( 0.17087277)))))))))); ! ! return sign(z)*Math.abs(ans); } *************** *** 422,425 **** --- 423,427 ---- public String surfingData() { String ret = new String(""); + ret += String.format("BrownBoost Params: %.4f %.4f\n", m_c, m_s); for (int i=0; i<m_margins.length; i++){ ret += String.format("%.4f\t%.4f\t%.4f\n", m_margins[i], m_weights[i], m_potentials[i]); Index: BrownBoostTest.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/BrownBoostTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** BrownBoostTest.java 27 May 2007 11:23:23 -0000 1.2 --- BrownBoostTest.java 10 Jul 2007 01:32:52 -0000 1.3 *************** *** 183,186 **** --- 183,190 ---- assertEquals(BrownBoost.erf(1.0), .8427007, 0.0001); assertEquals(BrownBoost.erf(2.0), .9953222, 0.0001); + + assertEquals(BrownBoost.erf(-0.5), -.5204998, 0.0001); + assertEquals(BrownBoost.erf(-1.0), -.8427007, 0.0001); + assertEquals(BrownBoost.erf(-2.0), -.9953222, 0.0001); } |
From: Aaron A. <aa...@us...> - 2007-06-14 16:45:54
|
Update of /cvsroot/jboost/jboost/src/jboost/booster In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv24459/src/jboost/booster Modified Files: BrownBoost.java Log Message: Bug fix for weight and potential updates when hypothesis abstains Index: BrownBoost.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/BrownBoost.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** BrownBoost.java 4 Jun 2007 07:24:38 -0000 1.3 --- BrownBoost.java 14 Jun 2007 16:45:52 -0000 1.4 *************** *** 41,44 **** --- 41,54 ---- protected double[] m_hypPredictions; + /** + * Records the potentials. Similar to m_margins and m_weights. + */ + protected double[] m_potentials; + + /** + * Records the potentials. Similar to m_margins and m_weights. + */ + protected double m_totalPotential; + /** * Default constructor just calls AdaBoost to *************** *** 49,52 **** --- 59,71 ---- } + + public void finalizeData() { + super.finalizeData(); + m_potentials = new double[m_numExamples]; + for (int i=0; i<m_numExamples; i++) { + m_potentials[i] = calculatePotential(0,m_c); + } + } + public void setRuntime(double runtime){ m_c = runtime; *************** *** 316,320 **** int count_t_over_s = 0; double lastE = 0; ! double STEP_EPS = 0.00001; double CORR_EPS = 0.001; boolean first_iter = true; --- 335,339 ---- int count_t_over_s = 0; double lastE = 0; ! double STEP_EPS = 0.0001; double CORR_EPS = 0.001; boolean first_iter = true; *************** *** 365,375 **** if(sign(vars.B) != sign(alpha_step)) alpha_step /= -2; if(Math.abs(vars.B) < CORR_EPS) break; - /* - if (alpha > 5) { - alpha = 0.1; - vars = calc_constraints (alpha, t); - break; - } - */ } --- 384,387 ---- *************** *** 388,399 **** double bs_t = t; - - /* - System.out.println("\nBinary Search gives alpha=" + bs_alpha - + ", t=" + bs_t + ", s=" + m_s - + ", pot_diff=" + vars.E - + ", pot=" + vars.Potential); - */ - alpha = bs_alpha; t = bs_t; --- 400,403 ---- *************** *** 415,421 **** return alpha; } - - /** --- 419,430 ---- return alpha; } + public String surfingData() { + String ret = new String(""); + for (int i=0; i<m_margins.length; i++){ + ret += String.format("%.4f\t%.4f\t%.4f\n", m_margins[i], m_weights[i], m_potentials[i]); + } + return ret; + } /** *************** *** 432,445 **** return; } - - // save old m_weights - for (int i= 0; i < m_weights.length; i++){ - m_oldWeights[i]= m_weights[i]; - } - - // save old m_margins - for (int i= 0; i < m_margins.length; i++){ - m_oldMargins[i] = m_margins[i]; - } for (int i= 0; i < exampleIndex.length; i++) { --- 441,444 ---- *************** *** 449,460 **** for (int j= 0; j < indexes.length; j++) { int example = indexes[j]; m_margins[example] += value[m_labels[example]]; } } for (int i=0; i < m_hypPredictions.length; i++) { ! m_totalWeight -= m_weights[i]; m_weights[i] = calculateWeight(m_margins[i]); m_totalWeight += m_weights[i]; } } --- 448,467 ---- for (int j= 0; j < indexes.length; j++) { int example = indexes[j]; + m_oldMargins[example] = m_margins[example]; m_margins[example] += value[m_labels[example]]; } } + + m_totalWeight = 0; + m_totalPotential = 0; for (int i=0; i < m_hypPredictions.length; i++) { ! m_oldWeights[i]= m_weights[i]; ! m_weights[i] = calculateWeight(m_margins[i]); m_totalWeight += m_weights[i]; + + m_potentials[i] = calculatePotential(m_margins[i]); + m_totalPotential += m_potentials[i]; } } *************** *** 605,623 **** gamma /= total_weight; potential /= m_margins.length; - /* - System.out.println("---------------------------------------"); - System.out.println("---------------------------------------"); - System.out.print("gamma (weighted correlation):" + gamma); - System.out.print(", potential (unweighted):" + potential); - System.out.print(", hyp error (unweighted):" + hyp_err + "\n"); - System.out.println(""); - */ /* ! if (total_err < m_initialPotential) { ! System.err.println("WARNING: the 'weak' hypothesis was too good!"); ! System.err.println("You were aiming for an error rate of: " + m_initialPotential); ! System.err.println("With this hypothesis, you were able to achieve an error rate of: " + total_err); ! } */ --- 612,621 ---- gamma /= total_weight; potential /= m_margins.length; /* ! System.out.println("\tTotal number of examples: " + m_margins.length); ! System.out.println("\tNumber of predictions made: " + num_predictions); ! String out = "\tgamma (weighted correlation):" + gamma + ", potential (unweighted):" + potential + ", hyp error (unweighted):" + hyp_err; ! System.out.println(out); */ |
From: Aaron A. <aa...@us...> - 2007-06-14 16:40:47
|
Update of /cvsroot/jboost/jboost/src/jboost/controller In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv22461/src/jboost/controller Modified Files: Configuration.java Log Message: version is now 1.3.1 Index: Configuration.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/controller/Configuration.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Configuration.java 29 May 2007 05:05:47 -0000 1.4 --- Configuration.java 14 Jun 2007 16:40:41 -0000 1.5 *************** *** 54,58 **** private Vector m_validCommands; private String m_unSpecified; ! public final static String VERSION="1.3"; private final static String m_usage = "" + "jboost Version " + VERSION + "\n" --- 54,58 ---- private Vector m_validCommands; private String m_unSpecified; ! public final static String VERSION="1.3.1"; private final static String m_usage = "" + "jboost Version " + VERSION + "\n" |
From: Aaron A. <aa...@us...> - 2007-06-14 16:38:59
|
Update of /cvsroot/jboost/jboost/src/jboost/controller In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv21625/src/jboost/controller Modified Files: Controller.java Log Message: Added in some more error messages when we get an exception Index: Controller.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/controller/Controller.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Controller.java 27 May 2007 11:20:23 -0000 1.3 --- Controller.java 14 Jun 2007 16:38:57 -0000 1.4 *************** *** 87,91 **** System.err.println("JBoost Exception: " + e.getMessage()); } - // the rest of the code can be called from an external main --- 87,90 ---- *************** *** 96,99 **** --- 95,100 ---- System.err.println(e.getMessage()); configuration.printUsage(); + e.printStackTrace(); + e.getMessage(); } finally { Monitor.closeLog(); |
From: Aaron A. <aa...@us...> - 2007-06-14 16:37:50
|
Update of /cvsroot/jboost/jboost/src/jboost/booster In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv21194/src/jboost/booster Modified Files: YabaBoost.java Log Message: can now move the paramter 'theta' to save potential Index: YabaBoost.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/YabaBoost.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** YabaBoost.java 31 May 2007 10:03:23 -0000 1.2 --- YabaBoost.java 14 Jun 2007 16:37:46 -0000 1.3 *************** *** 55,64 **** protected double m_theta; - /** ! * The average potential of the set of examples. ! protected double m_avgPotential; */ ! /** * A parameter indicating when we should stop the game. --- 55,65 ---- protected double m_theta; /** ! * This paramter cannot be changed and contains the original value ! * for theta. */ ! protected double m_origTheta; ! ! /** * A parameter indicating when we should stop the game. *************** *** 68,71 **** --- 69,80 ---- */ protected static final double FINISH_GAME_NOW = 0.05; + + /** + * A parameter indicating when we should stop the game. + * Technically, this should be 0; however due to numerical instability + * we finish the game slightly earlier then we should. This leads to + * an approximation of the 0/1 loss instead of the exact 0/1 loss. + */ + protected static final double THETA_UPDATE_STEP = 0.05; /** *************** *** 90,98 **** m_c = runtime; m_s = m_c; } public void setParams(double c1, double c2, double theta) throws Exception { double EPS = 0.01; ! if (c1 < EPS || c2 < EPS || theta < EPS) { throw new Exception("Yaba params are bad!\nc1:"+c1+"\nc2:" +c2+"\ntheta:"+theta+"\n"); --- 99,108 ---- m_c = runtime; m_s = m_c; + m_initialPotential = calculatePotential(0,m_c); } public void setParams(double c1, double c2, double theta) throws Exception { double EPS = 0.01; ! if (c1 < EPS || c2 < EPS || theta < EPS || m_c < EPS) { throw new Exception("Yaba params are bad!\nc1:"+c1+"\nc2:" +c2+"\ntheta:"+theta+"\n"); *************** *** 101,104 **** --- 111,116 ---- m_c2 = c2; m_theta = theta; + m_origTheta = theta; + m_initialPotential = calculatePotential(0,m_c); } *************** *** 129,149 **** protected ErfVars calc_constraints(double alpha, double t) { - /* - * Make sure that all examples are passed in. Not just the ones that - * have predictions this round. - - int num_examples = 0; - for (int i=0; i < exampleIndex.length; i++) { - num_examples += exampleIndex[i].length; - } - if (num_examples != m_margins.length) { - System.err.println("YabaBoost.calc_constraints: " - + "Not all examples are given"); - System.err.println("YabaBoost.calc_constraints: " - + "num example given is " + num_examples); - System.exit(2); - } - */ - ErfVars vars = new ErfVars(); --- 141,144 ---- *************** *** 168,174 **** double step = getStep(m_labels[example], m_hypPredictions[example]); ! double new_margin = (1-alpha)*margin + alpha*step; ! double new_weight = calculateWeight(new_margin, new_time_remaining); double new_pot = calculatePotential(new_margin, new_time_remaining); double orig_pot = calculatePotential(orig_margin, orig_time_remaining); --- 163,176 ---- double step = getStep(m_labels[example], m_hypPredictions[example]); ! double new_margin; ! ! double EPS = 0.0001; ! if (Math.abs(step) > EPS) { ! new_margin = (1-alpha)*margin + alpha*step; ! } else { ! new_margin = margin; ! } + double new_weight = calculateWeight(new_margin, new_time_remaining); double new_pot = calculatePotential(new_margin, new_time_remaining); double orig_pot = calculatePotential(orig_margin, orig_time_remaining); *************** *** 176,180 **** vars.B += new_weight*step; vars.E += orig_pot - new_pot; ! vars.Potential += new_pot / m_hypPredictions.length; totalWeight += new_weight; --- 178,182 ---- vars.B += new_weight*step; vars.E += orig_pot - new_pot; ! vars.Potential += new_pot; totalWeight += new_weight; *************** *** 184,187 **** --- 186,191 ---- } vars.B /= totalWeight; + vars.E /= m_hypPredictions.length; + vars.Potential /= m_hypPredictions.length; return vars; } *************** *** 202,207 **** System.err.println(""); System.err.println("Dumping everything"); - System.err.println("% " + v.Potential + ", " + m_initialPotential); - dumpfile.println("% Avg Diff Potential, Gamma correlation"); dumpfile.println("% " + v.E + ", " + v.B); --- 206,209 ---- *************** *** 286,292 **** double lastE = 0; ! ! ! double STEP_EPS = 0.00001; boolean first_iter = true; while(Math.abs(t_step) > STEP_EPS) { --- 288,292 ---- double lastE = 0; ! double STEP_EPS = 0.0001; boolean first_iter = true; while(Math.abs(t_step) > STEP_EPS) { *************** *** 304,310 **** * become as large as it needs to be. If it is too large, * we trim it down after the fact. Or maybe we do want to ! * do this. If we let t>m_s then we wind up with NaN. */ if (t >= m_s) { ! t = m_s - STEP_EPS; t_step = -t_step; count_t_over_s++; --- 304,311 ---- * become as large as it needs to be. If it is too large, * we trim it down after the fact. Or maybe we do want to ! * do this. If we let t>m_s then we wind up with NaN. ! */ if (t >= m_s) { ! t = m_s - 0.001; t_step = -t_step; count_t_over_s++; *************** *** 316,321 **** continue; } ! ! if (t < STEP_EPS) { t = STEP_EPS; --- 317,321 ---- continue; } ! if (t < STEP_EPS) { t = STEP_EPS; *************** *** 347,354 **** } ! System.out.format("\tYabaBoost: (alpha=%.4f, t=%.4f) -> (corr=%.6f, pot_diff=%.6f), " ! + "potential=%.6f\n", alpha, t, vars.B, vars.E, vars.Potential); // reverse t search direction if(sign(vars.E) != sign(t_step)) t_step /= -2; } --- 347,357 ---- } ! System.out.format("\tYabaBoost: (alpha=%.4f, t=%.4f) -> " ! + "(corr=%.6f, pot_diff=%.6f, pot_diff=%.6f), " ! + "potential=%.6f\n", alpha, t, vars.B, vars.E, ! m_initialPotential - vars.Potential, vars.Potential); // reverse t search direction + vars.E = m_initialPotential - vars.Potential; if(sign(vars.E) != sign(t_step)) t_step /= -2; } *************** *** 358,386 **** double bs_t = t; - // We use the binary search alpha and t alpha = bs_alpha; t = bs_t; - - System.out.format("YabaBoost: alpha=%.4f, t=%.4f, time left=%.4f, " - + "potential=%.4f\n", alpha, t, m_s, vars.Potential); - - - m_oldS = m_s; m_s -= t; ! /* Weird things happen towards the end of the game ! * (underflow/overflow). So we cheat a little and terminate ! * before the actual end of the game. */ ! if (m_s < FINISH_GAME_NOW) { ! m_s = -1; ! } - if (m_s < 0) { - alpha = 0; - } - System.out.println("Binary Search gives alpha=" + bs_alpha + ", t=" + bs_t); System.out.println("We use binary searchalpha=" + alpha + ", t=" + t); --- 361,374 ---- double bs_t = t; // We use the binary search alpha and t alpha = bs_alpha; t = bs_t; m_oldS = m_s; m_s -= t; ! System.out.format("YabaBoost: alpha=%.4f, t=%.4f, time left=%.4f, " ! + "potential=%.4f, theta=%.4f\n", alpha, t, m_s, vars.Potential, m_theta); System.out.println("Binary Search gives alpha=" + bs_alpha + ", t=" + bs_t); System.out.println("We use binary searchalpha=" + alpha + ", t=" + t); *************** *** 390,404 **** ! ! double CONSTRAINT_EPS = 0.001; ! if (t < m_s && ! (Math.abs(vars.Potential-m_initialPotential)>CONSTRAINT_EPS ! || Math.abs(vars.B)>CONSTRAINT_EPS)) { ! m_s = m_oldS; dump_everything(vars); ! System.err.println("Average potential difference or correlation is too big!"); System.err.println("Outputting all data to outfile!"); ! System.exit(2); } --- 378,423 ---- ! /* ! * When we can't obtain the potential we wanted, we need to ! * adjust the paramters. We adjust theta and c1 to maintain a ! * constant potential. ! */ double CONSTRAINT_EPS = 0.001; ! double EPS = 0.001; ! if (m_s > FINISH_GAME_NOW && Math.abs(vars.Potential-m_initialPotential)>CONSTRAINT_EPS) { ! m_s = m_oldS; dump_everything(vars); ! System.err.println("Average potential difference is too big!"); System.err.println("Outputting all data to outfile!"); ! ! 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); ! } ! ! if (Math.abs(vars.B) > CONSTRAINT_EPS) { ! ! System.err.println("CORRELATION IS TOO BIG!!!"); } *************** *** 410,417 **** } ! ! ! ! m_lastAlpha = alpha; --- 429,440 ---- } ! /* ! * Weird things happen towards the end of the game ! * (underflow/overflow). So we cheat a little and terminate ! * before the actual end of the game. ! */ ! if (m_s < FINISH_GAME_NOW) { ! m_s = -1; ! } m_lastAlpha = alpha; *************** *** 431,444 **** return; } - - // save old m_weights - for (int i= 0; i < m_weights.length; i++){ - m_oldWeights[i]= m_weights[i]; - } - - // save old m_margins - for (int i= 0; i < m_margins.length; i++){ - m_oldMargins[i] = m_margins[i]; - } for (int i= 0; i < exampleIndex.length; i++) { --- 454,457 ---- *************** *** 461,464 **** --- 474,478 ---- System.err.println("prediction is: " + Math.abs(p)); } + m_oldMargins[example] = m_margins[example]; m_margins[example] = (1-alpha)*m_margins[example] + value[m_labels[example]]; *************** *** 468,489 **** + m_margins[example] + " greater than 1!!!!"); } - - m_totalWeight -= m_weights[example]; - m_weights[example] = calculateWeight(m_margins[example]); - m_totalWeight += m_weights[example]; } } ! // print all margins. ! /* ! for (int i= 0; i < m_margins.length; i++){ ! System.out.println("Margin: " + (m_margins[i] >= 0 ? " " : "") + m_margins[i] ); ! } ! */ } - /** --- 482,501 ---- + m_margins[example] + " greater than 1!!!!"); } } } ! for (int i=0; i < m_hypPredictions.length; i++) { ! m_oldWeights[i]= m_weights[i]; ! m_totalWeight -= m_weights[i]; ! m_weights[i] = calculateWeight(m_margins[i]); ! m_totalWeight += m_weights[i]; + m_totalPotential -= m_potentials[i]; + m_potentials[i] = calculatePotential(m_margins[i]); + m_totalPotential += m_potentials[i]; + } } /** *************** *** 511,515 **** double s = m_c - time_remaining; 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))); double norm = 1 / Math.sqrt(Math.PI * sd * sd); return norm * Math.exp(- Math.pow((margin-mu)/sd,2)); --- 523,527 ---- double s = m_c - time_remaining; 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 norm = 1 / Math.sqrt(Math.PI * sd * sd); return norm * Math.exp(- Math.pow((margin-mu)/sd,2)); *************** *** 524,528 **** double s = m_c - time_remaining; 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))); double pot = (1 - erf((margin-mu)/sd)) / 2; /* --- 536,540 ---- double s = m_c - time_remaining; 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; /* *************** *** 575,579 **** /** Place holder to ensure that this function is not used in BrownBoost. */ public MixedBinaryPrediction calcPrediction(){ ! //System.err.println("Need to have alpha for prediction in BrownBag.calcPrediction()!"); return new MixedBinaryPrediction(0); } --- 587,592 ---- /** Place holder to ensure that this function is not used in BrownBoost. */ public MixedBinaryPrediction calcPrediction(){ ! System.err.println("Need to have alpha for prediction in BrownBag.calcPrediction()!"); ! System.exit(2); return new MixedBinaryPrediction(0); } |