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
|
Update of /cvsroot/jboost/jboost/src/jboost/booster In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv8493 Modified Files: AbstractBooster.java AbstractBoosterTest.java AdaBoost.java AdaBoostTest.java Bag.java BinaryPrediction.java Booster.java BoosterTestSuite.java BrownBoost.java BrownBoostTest.java DebugWrap.java LogLossBoost.java LogLossBoostTest.java MixedBinaryPrediction.java MixedBinaryPredictionTest.java MulticlassWrapMH.java MulticlassWrapOC.java NormalizedPrediction.java NotNormalizedPredException.java Prediction.java YabaBoost.java YabaBoostTest.java Log Message: Small comments and sed commands to reformat Index: Bag.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/Bag.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Bag.java 24 Jan 2008 22:30:16 -0000 1.2 --- Bag.java 25 Mar 2008 01:00:27 -0000 1.3 *************** *** 21,26 **** */ public abstract void reset(); ! ! /** * Get the weights of the bag. */ --- 21,26 ---- */ public abstract void reset(); ! ! /** * Get the weights of the bag. */ *************** *** 28,32 **** return m_w; } ! /** * If the bag has no weight, then it is considered to be weightless. --- 28,32 ---- return m_w; } ! /** * If the bag has no weight, then it is considered to be weightless. *************** *** 106,110 **** * When data splitting is used, this is the same as getLoss() but * computed using only examples in part s of the split. s<0 ! * indicates that the entire dataset should be used. * * The default implementation of this method simply throws an --- 106,110 ---- * When data splitting is used, this is the same as getLoss() but * computed using only examples in part s of the split. s<0 ! * indicates that the entire dataset should be used. * * The default implementation of this method simply throws an *************** *** 114,118 **** throw new NotSupportedException("getLoss",this.getClass().toString()); } ! /* * Computes a non-default loss for this bag. The loss types are --- 114,118 ---- throw new NotSupportedException("getLoss",this.getClass().toString()); } ! /* * Computes a non-default loss for this bag. The loss types are *************** *** 122,126 **** */ /* public abstract double getSpecialLoss(int lossType); */ ! /* * When data splitting is used, this is the same as --- 122,126 ---- */ /* public abstract double getSpecialLoss(int lossType); */ ! /* * When data splitting is used, this is the same as *************** *** 135,139 **** } */ ! /** * Checks if a given loss type is allowed for this bag. --- 135,139 ---- } */ ! /** * Checks if a given loss type is allowed for this bag. Index: MulticlassWrapOC.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/MulticlassWrapOC.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** MulticlassWrapOC.java 16 May 2007 04:06:02 -0000 1.1.1.1 --- MulticlassWrapOC.java 25 Mar 2008 01:00:28 -0000 1.2 *************** *** 14,16 **** MulticlassWrapOC(AbstractBooster booster) {} ! } --- 14,16 ---- MulticlassWrapOC(AbstractBooster booster) {} ! } Index: BoosterTestSuite.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/BoosterTestSuite.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** BoosterTestSuite.java 2 Oct 2007 02:32:07 -0000 1.3 --- BoosterTestSuite.java 25 Mar 2008 01:00:27 -0000 1.4 *************** *** 30,33 **** return suite; } ! } --- 30,33 ---- return suite; } ! } Index: AdaBoostTest.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/AdaBoostTest.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** AdaBoostTest.java 16 May 2007 04:06:02 -0000 1.1.1.1 --- AdaBoostTest.java 25 Mar 2008 01:00:27 -0000 1.2 *************** *** 74,78 **** //TODO Implement newBag(). } ! public final void testUpdate() { //TODO Implement update(). --- 74,78 ---- //TODO Implement newBag(). } ! public final void testUpdate() { //TODO Implement update(). *************** *** 103,107 **** } } ! for (int i=0; i < ones.length; i++) { ones[i]= indices[COUNT/2 + i]; --- 103,107 ---- } } ! for (int i=0; i < ones.length; i++) { ones[i]= indices[COUNT/2 + i]; *************** *** 116,120 **** } } ! final public void testGetPredictions() { //TODO Implement getPredictions(). --- 116,120 ---- } } ! final public void testGetPredictions() { //TODO Implement getPredictions(). Index: NormalizedPrediction.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/NormalizedPrediction.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** NormalizedPrediction.java 24 Jan 2008 22:30:16 -0000 1.2 --- NormalizedPrediction.java 25 Mar 2008 01:00:28 -0000 1.3 *************** *** 2,6 **** /** ! * 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. --- 2,6 ---- /** ! * 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. *************** *** 10,14 **** public interface NormalizedPrediction { ! /** * Must be used very carefully. An example: * --- 10,14 ---- public interface NormalizedPrediction { ! /** * Must be used very carefully. An example: * *************** *** 22,28 **** */ public Prediction add(Prediction p); ! /* public static boolean isNormPred(Prediction p); */ ! public double getDeltaT(); } --- 22,28 ---- */ public Prediction add(Prediction p); ! /* public static boolean isNormPred(Prediction p); */ ! public double getDeltaT(); } Index: LogLossBoost.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/LogLossBoost.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** LogLossBoost.java 2 Oct 2007 02:32:07 -0000 1.2 --- LogLossBoost.java 25 Mar 2008 01:00:27 -0000 1.3 *************** *** 6,10 **** * AdaBoost-like implementation for the Log-Loss. The only differnece is weight * update. ! * * @author Yoram Singer * @version $Header: --- 6,10 ---- * AdaBoost-like implementation for the Log-Loss. The only differnece is weight * update. ! * * @author Yoram Singer * @version $Header: *************** *** 17,21 **** /** * Default constructors call AdaBoost constructors ! * Uses a value of 0.0 for the smoothing term */ public LogLossBoost() { --- 17,21 ---- /** * Default constructors call AdaBoost constructors ! * Uses a value of 0.0 for the smoothing term */ public LogLossBoost() { *************** *** 59,63 **** } ! /** * The LogLoss example weight is set to 1/(1 + e^(margin)) --- 59,63 ---- } ! /** * The LogLoss example weight is set to 1/(1 + e^(margin)) *************** *** 67,71 **** } ! /** * Update the examples m_margins and m_weights using the * logistic loss computation --- 67,71 ---- } ! /** * Update the examples m_margins and m_weights using the * logistic loss computation *************** *** 78,82 **** m_oldWeights[i]= m_weights[i]; } ! // update m_weights and m_margins for (int i= 0; i < exampleIndex.length; i++) { --- 78,82 ---- m_oldWeights[i]= m_weights[i]; } ! // update m_weights and m_margins for (int i= 0; i < exampleIndex.length; i++) { Index: BinaryPrediction.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/BinaryPrediction.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** BinaryPrediction.java 16 May 2007 04:06:02 -0000 1.1.1.1 --- BinaryPrediction.java 25 Mar 2008 01:00:27 -0000 1.2 *************** *** 13,17 **** public BinaryPrediction(double p) {prediction=p;} public BinaryPrediction() {prediction=0.0;} ! public Object clone(){ Object a = new BinaryPrediction(prediction); --- 13,17 ---- public BinaryPrediction(double p) {prediction=p;} public BinaryPrediction() {prediction=0.0;} ! public Object clone(){ Object a = new BinaryPrediction(prediction); *************** *** 28,37 **** return this; } ! public Prediction add(double w, Prediction p) { prediction += w * ((BinaryPrediction) p).prediction; return this; } ! public double[] getClassScores() { double[] a = {-prediction,prediction}; --- 28,37 ---- return this; } ! public Prediction add(double w, Prediction p) { prediction += w * ((BinaryPrediction) p).prediction; return this; } ! public double[] getClassScores() { double[] a = {-prediction,prediction}; *************** *** 55,61 **** public boolean equals(Prediction other) { BinaryPrediction bp= (BinaryPrediction) other; ! return (prediction == bp.prediction); } ! /** * computes margin as absolute value of prediction. --- 55,61 ---- public boolean equals(Prediction other) { BinaryPrediction bp= (BinaryPrediction) other; ! return (prediction == bp.prediction); } ! /** * computes margin as absolute value of prediction. Index: Booster.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/Booster.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Booster.java 13 Oct 2007 04:32:28 -0000 1.3 --- Booster.java 25 Mar 2008 01:00:27 -0000 1.4 *************** *** 1,5 **** /* * Created on Jan 12, 2004 ! * */ package jboost.booster; --- 1,5 ---- /* * Created on Jan 12, 2004 ! * */ package jboost.booster; *************** *** 9,13 **** /** ! * This is the definition of the required interface for a booster. * A skeletal implementation is provided by AbstractBooster. * --- 9,13 ---- /** ! * This is the definition of the required interface for a booster. * A skeletal implementation is provided by AbstractBooster. * *************** *** 15,44 **** */ public interface Booster { ! /** * Factory method to create an instance of a Booster * @param configuration ! */ public abstract void init(Configuration config); ! /** * Create and return a new Bag which initially contains the elements in the * list 'defaults'. ! * * @param defaults the initial items to add to the Bag */ public abstract Bag newBag(int[] defaults); ! /** * Create and return a new Bag which is a clone of 'original' ! * * @param original the bag to copy into a new Bag */ public abstract Bag newBag(Bag original); ! /** * Find the best binary split for a sorted list of example indices with given * split points. ! * * @param l an array of example indices, sorted. * @param sp an array with true in position i when a split between positions --- 15,44 ---- */ public interface Booster { ! /** * Factory method to create an instance of a Booster * @param configuration ! */ public abstract void init(Configuration config); ! /** * Create and return a new Bag which initially contains the elements in the * list 'defaults'. ! * * @param defaults the initial items to add to the Bag */ public abstract Bag newBag(int[] defaults); ! /** * Create and return a new Bag which is a clone of 'original' ! * * @param original the bag to copy into a new Bag */ public abstract Bag newBag(Bag original); ! /** * Find the best binary split for a sorted list of example indices with given * split points. ! * * @param l an array of example indices, sorted. * @param sp an array with true in position i when a split between positions *************** *** 50,64 **** */ public abstract int findBestSplit(Bag b0, Bag b1, int[] l, boolean[] sp); ! /** * Compute the loss associated with an array of bags where small loss is * considered "better". The default implementation of this procedure assumes * that the loss is additive across bags. ! * * @param bags array of bags whose losses will be added up and returned * @return loss the sum of the losses for all the bags */ public abstract double getLoss(Bag[] bags); ! /** * Returns a list of margin values for the training data. The actual number --- 50,64 ---- */ public abstract int findBestSplit(Bag b0, Bag b1, int[] l, boolean[] sp); ! /** * Compute the loss associated with an array of bags where small loss is * considered "better". The default implementation of this procedure assumes * that the loss is additive across bags. ! * * @param bags array of bags whose losses will be added up and returned * @return loss the sum of the losses for all the bags */ public abstract double getLoss(Bag[] bags); ! /** * Returns a list of margin values for the training data. The actual number *************** *** 77,86 **** public abstract String getParamString(); ! /** * Returns the current theoretical bound on the training error. */ public abstract double getTheoryBound(); ! /** * Returns the predictions associated with a list of bags representing a --- 77,86 ---- public abstract String getParamString(); ! /** * Returns the current theoretical bound on the training error. */ public abstract double getTheoryBound(); ! /** * Returns the predictions associated with a list of bags representing a *************** *** 94,102 **** */ public abstract Prediction[] getPredictions(Bag[] b, int[][] partition); ! /** * Updates training set data structures to reflect the addition of a new base * classifier. ! * * @param predictions an array of predictions * @param examples an array of arrays of example indexes for which the --- 94,102 ---- */ public abstract Prediction[] getPredictions(Bag[] b, int[][] partition); ! /** * Updates training set data structures to reflect the addition of a new base * classifier. ! * * @param predictions an array of predictions * @param examples an array of arrays of example indexes for which the *************** *** 105,111 **** * predictions</i>. the second index runs over the examples * indices that correspond to that part. ! */ public abstract void update(Prediction[] predictions, int[][] elements); ! /** * Use the margin value to calculate the weight for the example --- 105,111 ---- * predictions</i>. the second index runs over the examples * indices that correspond to that part. ! */ public abstract void update(Prediction[] predictions, int[][] elements); ! /** * Use the margin value to calculate the weight for the example *************** *** 114,128 **** */ public double calculateWeight(double margin); ! /** * Create and return a new Bag which contains no elements */ public abstract Bag newBag(); ! /** * Clear the examples list */ public abstract void clear(); ! /** * Finalize the data structures of the booster. Execute after the constructor --- 114,128 ---- */ public double calculateWeight(double margin); ! /** * Create and return a new Bag which contains no elements */ public abstract Bag newBag(); ! /** * Clear the examples list */ public abstract void clear(); ! /** * Finalize the data structures of the booster. Execute after the constructor *************** *** 130,138 **** */ public abstract void finalizeData(); ! /** * Add an example to location index in the list of examples handled by the * booster. ! * * @param index the position where the example should be added * @param label the label to add --- 130,138 ---- */ public abstract void finalizeData(); ! /** * Add an example to location index in the list of examples handled by the * booster. ! * * @param index the position where the example should be added * @param label the label to add *************** *** 140,144 **** public abstract void addExample(int index, Label label); public abstract void addExample(int index, Label label, double weight); ! } --- 140,144 ---- public abstract void addExample(int index, Label label); public abstract void addExample(int index, Label label, double weight); ! } Index: AdaBoost.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/AdaBoost.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** AdaBoost.java 24 Jan 2008 22:30:16 -0000 1.5 --- AdaBoost.java 25 Mar 2008 01:00:27 -0000 1.6 *************** *** 9,12 **** --- 9,14 ---- import jboost.controller.Configuration; import jboost.examples.Label; + import jboost.booster.BrownBoost; + import jboost.booster.BrownBoost.BrownBag; *************** *** 14,18 **** * The simplest possible implementation of a booster. confidence-rated adaboost * based on equality/inequality of m_labels ! * * @author Yoav Freund * @version $Header: --- 16,20 ---- * The simplest possible implementation of a booster. confidence-rated adaboost * based on equality/inequality of m_labels ! * * @author Yoav Freund * @version $Header: *************** *** 34,37 **** --- 36,46 ---- protected double[] m_potentials; + /** + * The predictions from a hypothesis for an iteration. + * HACK: This should eventually be removed for efficiency concerns. + */ + protected double[] m_hypPredictions; + + /** */ protected int[] m_posExamples; *************** *** 55,59 **** /** if false, then assume all sample weights are 1 */ //protected boolean m_useSampleWeights; ! protected double m_totalWeight; // total weight of all examples protected int m_numExamples= 0; // number of examples in training set --- 64,68 ---- /** if false, then assume all sample weights are 1 */ //protected boolean m_useSampleWeights; ! protected double m_totalWeight; // total weight of all examples protected int m_numExamples= 0; // number of examples in training set *************** *** 67,72 **** ! /** ! * default constructor * */ --- 76,81 ---- ! /** ! * default constructor * */ *************** *** 77,81 **** /** * Constructor which takes a smoothing factor ! * * @param smooth "smoothing" factor */ --- 86,90 ---- /** * Constructor which takes a smoothing factor ! * * @param smooth "smoothing" factor */ *************** *** 94,100 **** m_smooth= config.getDouble(PREFIX + "smooth", 0.5); } ! /** ! * Add an example to the data set of this booster * @param index * @param label --- 103,109 ---- m_smooth= config.getDouble(PREFIX + "smooth", 0.5); } ! /** ! * Add an example to the data set of this booster * @param index * @param label *************** *** 114,118 **** } } else { ! failed= "Adaboost.addExample expected a label which is either 0 or 1. It received " + l; } --- 123,127 ---- } } else { ! failed= "Adaboost.addExample expected a label which is either 0 or 1. It received " + l; } *************** *** 122,129 **** } } ! /** * Add an example to the dataset ! * Default the weight for this example to 1 * If this method is used, then this booster will assume * that all the sample weights are 1 --- 131,138 ---- } } ! /** * Add an example to the dataset ! * Default the weight for this example to 1 * If this method is used, then this booster will assume * that all the sample weights are 1 *************** *** 167,179 **** m_weights[index]= m_oldWeights[index]= defaultWeight; m_labels[index]= a.getLabel(); ! if (a.getLabel()==POSITIVE_LABEL) ! m_posExamples[m_posIndex++] = index; else if (a.getLabel()==NEGATIVE_LABEL) ! m_negExamples[m_negIndex++] = index; else { System.err.println("Label of example is unknown to adaboost"); System.exit(2); } ! m_sampleWeights[index]= a.getWeight(); } --- 176,188 ---- m_weights[index]= m_oldWeights[index]= defaultWeight; m_labels[index]= a.getLabel(); ! if (a.getLabel()==POSITIVE_LABEL) ! m_posExamples[m_posIndex++] = index; else if (a.getLabel()==NEGATIVE_LABEL) ! m_negExamples[m_negIndex++] = index; else { System.err.println("Label of example is unknown to adaboost"); System.exit(2); } ! m_sampleWeights[index]= a.getWeight(); } *************** *** 181,185 **** m_tmpList.clear(); // free the memory } ! public void finalizeData() { finalizeData(1.0); --- 190,194 ---- m_tmpList.clear(); // free the memory } ! public void finalizeData() { finalizeData(1.0); *************** *** 213,217 **** return r; } ! /** * --- 222,226 ---- return r; } ! /** * *************** *** 230,234 **** return m_numExamples; } ! /** * --- 239,243 ---- return m_numExamples; } ! /** * *************** *** 237,242 **** return m_totalWeight; } ! ! /** * Returns a string with all the weights, margins, etc --- 246,251 ---- return m_totalWeight; } ! ! /** * Returns a string with all the weights, margins, etc *************** *** 246,251 **** 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])); } --- 255,260 ---- 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])); } *************** *** 318,321 **** --- 327,426 ---- + + /** + * @param z - any double + * @return If z is negative return -1 else return 1 + */ + public static double sign(double z){ + if( Double.compare(z, 0.0) == 0 ){ + return 1.0; + } else if( Double.compare(z, -0.0) == 0 ){ + return -1.0; + } + + if(z > 0){ + return 1.0; + } else { + return -1.0; + } + } + + /** + * Get the "step" of the hypothesis on an example. The step is + * defined as $y_j * h_i(x_j)$ for example j and hypothesis i. + * @param simple_label - The label of the example as given by m_labels + * @param hyp_pred - The hypothesized value of the example + * @return +1 if label matches hyp, -1 if label doesn't match hyp, 0 if no hyp + */ + public double getStep(short simple_label, double hyp_pred) { + double step = getLabel(simple_label)*hyp_pred; + double EPS = 0.000001; + if(Math.abs(step) < EPS) return 0.0; + return sign(step); + } + + public double getLabel(short simple_label) { + return sign(-simple_label+0.5); + } + + protected double getHypErr(Bag[] bags, int[][] exampleIndex) { + double hyp_err = 0.0; + double gamma = 0.0; + double total_weight = 0.0; + + // Keep track of which hypotheses had hypotheses associated with them. + boolean[] examplesWithHyp = new boolean[m_margins.length]; + m_hypPredictions = new double[m_margins.length]; + for (int i=0; i < exampleIndex.length; i++){ + int[] index = exampleIndex[i]; + BinaryBag b = (BinaryBag) bags[i]; + for (int j=0; j < index.length; j++){ + int example = index[j]; + if (this instanceof BrownBoost) + m_hypPredictions[example] = ((BrownBag)b).calcPrediction(1.0,1.0).getClassScores()[0]; + else + m_hypPredictions[example] = b.calcPrediction().getClassScores()[0]; + } + } + + + int numExamplesWithHyps = 0; + double weight; + // Get all examples that have a hypothesis associated with them + for (int i= 0; i < exampleIndex.length; i++) { + int[] indexes= exampleIndex[i]; + for (int j= 0; j < indexes.length; j++) { + int example = indexes[j]; + examplesWithHyp[example] = true; + numExamplesWithHyps += 1; + + double step = getStep(m_labels[example], m_hypPredictions[example]); + gamma += m_weights[example]*step; + if (step < 0) // We got it wrong + hyp_err += 1; + } + } + + // Get all examples that have no hypothesis associated with them. + for (int i=0; i < m_margins.length; i++) { + total_weight += m_weights[i]; + if(!examplesWithHyp[i]){ + m_hypPredictions[i] = 0; + //System.out.println("m_hypPredictions[" + i + "," + example + "]: " + 0 + " (No hyp for example " + example + ")"); + } + } + + hyp_err /= numExamplesWithHyps; + gamma /= (double)total_weight; + + if (numExamplesWithHyps > 0) { + System.out.println("Num Examples with predictions: " + numExamplesWithHyps + "/" + m_margins.length); + System.out.println("Gamma: " + gamma); + } + return gamma; + } + + + /** * Returns the predictions associated with a list of bags representing a *************** *** 337,345 **** } }*/ return getPredictions(bags); } ! ! /** * AdaBoost uses e^(-margin) as the weight calculation --- 442,451 ---- } }*/ + double gamma = getHypErr(bags, exampleIndex); return getPredictions(bags); } ! ! /** * AdaBoost uses e^(-margin) as the weight calculation *************** *** 348,358 **** return Math.exp(-1 * margin); } ! /** ! * Update the examples m_margins and m_weights using the * exponential update * @param predictions values for examples * @param exampleIndex the list of examples to update ! */ public void update(Prediction[] predictions, int[][] exampleIndex) { // save old m_weights --- 454,464 ---- return Math.exp(-1 * margin); } ! /** ! * Update the examples m_margins and m_weights using the * exponential update * @param predictions values for examples * @param exampleIndex the list of examples to update ! */ public void update(Prediction[] predictions, int[][] exampleIndex) { // save old m_weights *************** *** 375,380 **** } ! /** ! * Defines the state of an example * Inner class used to store a list of Examples * The list is converted into the internal data structures for the --- 481,486 ---- } ! /** ! * Defines the state of an example * Inner class used to store a list of Examples * The list is converted into the internal data structures for the *************** *** 385,389 **** short m_label; double m_weight; ! /** * Ctor for a TmpData object --- 491,495 ---- short m_label; double m_weight; ! /** * Ctor for a TmpData object *************** *** 397,401 **** m_weight= weight; } ! /** * Get the index for this example --- 503,507 ---- m_weight= weight; } ! /** * Get the index for this example *************** *** 405,409 **** return m_index; } ! /** * Get the label for this example --- 511,515 ---- return m_index; } ! /** * Get the label for this example *************** *** 413,417 **** return m_label; } ! /** * Get the weigh for this example --- 519,523 ---- return m_label; } ! /** * Get the weigh for this example *************** *** 423,427 **** } ! /** * This is the definition of a bag for AdaBoost. The two m_labels are --- 529,533 ---- } ! /** * This is the definition of a bag for AdaBoost. The two m_labels are *************** *** 482,487 **** * Update the weights in this bag using the weights from the booster * The example index is used to find the label and weight for this example ! * ! * @param index the example that is being added to this bag. The index refers to the booster's * internal data structures */ --- 588,593 ---- * Update the weights in this bag using the weights from the booster * The example index is used to find the label and weight for this example ! * ! * @param index the example that is being added to this bag. The index refers to the booster's * internal data structures */ *************** *** 553,561 **** 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] --- 659,667 ---- 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] *************** *** 568,572 **** /** * Compare a bag to this bag and output true if they are equal ! * * @param other * bag to compare to this bag --- 674,678 ---- /** * Compare a bag to this bag and output true if they are equal ! * * @param other * bag to compare to this bag Index: NotNormalizedPredException.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/NotNormalizedPredException.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** NotNormalizedPredException.java 16 May 2007 04:06:02 -0000 1.1.1.1 --- NotNormalizedPredException.java 25 Mar 2008 01:00:28 -0000 1.2 *************** *** 1,11 **** package jboost.booster; ! /** * This exception gets thrown if a prediction that is supposed to be ! * normalized, becomes unnormalized. * @author Aaron Arvey */ public class NotNormalizedPredException extends RuntimeException { ! NotNormalizedPredException (String m) { message = m; } --- 1,11 ---- package jboost.booster; ! /** * This exception gets thrown if a prediction that is supposed to be ! * normalized, becomes unnormalized. * @author Aaron Arvey */ public class NotNormalizedPredException extends RuntimeException { ! NotNormalizedPredException (String m) { message = m; } Index: BrownBoostTest.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/BrownBoostTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** BrownBoostTest.java 10 Jul 2007 01:32:52 -0000 1.3 --- BrownBoostTest.java 25 Mar 2008 01:00:27 -0000 1.4 *************** *** 76,83 **** //TODO Implement newBag(). } ! ! /** ! * This test indicates whether or not the update algorithm in * BrownBoost is producing the correct weights. This is the core * of the BrownBoost algorithm and is thus the most important to test. --- 76,83 ---- //TODO Implement newBag(). } ! ! /** ! * This test indicates whether or not the update algorithm in * BrownBoost is producing the correct weights. This is the core * of the BrownBoost algorithm and is thus the most important to test. *************** *** 123,127 **** } } ! for (int i=0; i < ones.length; i++) { ones[i]= indices[COUNT/2 + i]; --- 123,127 ---- } } ! for (int i=0; i < ones.length; i++) { ones[i]= indices[COUNT/2 + i]; *************** *** 146,150 **** */ } ! final public void testGetPredictions() { //TODO Implement getPredictions(). --- 146,150 ---- */ } ! final public void testGetPredictions() { //TODO Implement getPredictions(). Index: LogLossBoostTest.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/LogLossBoostTest.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** LogLossBoostTest.java 16 May 2007 04:06:02 -0000 1.1.1.1 --- LogLossBoostTest.java 25 Mar 2008 01:00:27 -0000 1.2 *************** *** 10,16 **** */ public class LogLossBoostTest extends AbstractBoosterTest { ! LogLossBoost m_logLoss; ! /** * @param arg0 --- 10,16 ---- */ public class LogLossBoostTest extends AbstractBoosterTest { ! LogLossBoost m_logLoss; ! /** * @param arg0 *************** *** 37,42 **** m_logLoss= new LogLossBoost(); } ! ! public final void testFinalizeData() { //TODO Implement finalizeData(). --- 37,42 ---- m_logLoss= new LogLossBoost(); } ! ! public final void testFinalizeData() { //TODO Implement finalizeData(). *************** *** 71,75 **** } } ! for (int i=0; i < ones.length; i++) { ones[i]= indices[COUNT/2 + i]; --- 71,75 ---- } } ! for (int i=0; i < ones.length; i++) { ones[i]= indices[COUNT/2 + i]; Index: MixedBinaryPrediction.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/MixedBinaryPrediction.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** MixedBinaryPrediction.java 24 Jan 2008 22:30:16 -0000 1.5 --- MixedBinaryPrediction.java 25 Mar 2008 01:00:27 -0000 1.6 *************** *** 16,20 **** public MixedBinaryPrediction() {super();} ! public MixedBinaryPrediction(double p) throws NotNormalizedPredException { (new Exception("asdf")).printStackTrace(); --- 16,20 ---- public MixedBinaryPrediction() {super();} ! public MixedBinaryPrediction(double p) throws NotNormalizedPredException { (new Exception("asdf")).printStackTrace(); *************** *** 28,32 **** } ! public MixedBinaryPrediction(double p, double dt, double nc) throws NotNormalizedPredException { super(); --- 28,32 ---- } ! public MixedBinaryPrediction(double p, double dt, double nc) throws NotNormalizedPredException { super(); *************** *** 35,41 **** normalizingConstant = nc; } - ! public MixedBinaryPrediction(double p, double dt) throws NotNormalizedPredException { super(); --- 35,41 ---- normalizingConstant = nc; } ! ! public MixedBinaryPrediction(double p, double dt) throws NotNormalizedPredException { super(); *************** *** 44,48 **** normalizingConstant = 1; } ! --- 44,48 ---- normalizingConstant = 1; } ! *************** *** 52,56 **** } ! /** * Be very careful with how this is used. See NormalizedPrediction * for details. --- 52,56 ---- } ! /** * Be very careful with how this is used. See NormalizedPrediction * for details. *************** *** 94,98 **** return normalizingConstant; } ! public Prediction add(double w, Prediction p) { ((MixedBinaryPrediction) p).scale(w); --- 94,98 ---- return normalizingConstant; } ! public Prediction add(double w, Prediction p) { ((MixedBinaryPrediction) p).scale(w); *************** *** 100,109 **** return this; } ! public boolean equals(Prediction other) { MixedBinaryPrediction bp= (MixedBinaryPrediction) other; ! return (prediction == bp.prediction && deltaT == bp.deltaT && normalizingConstant == bp.normalizingConstant); } ! public String toString() { return "MixedBinaryPrediction. p(1)= " + prediction; --- 100,109 ---- return this; } ! public boolean equals(Prediction other) { MixedBinaryPrediction bp= (MixedBinaryPrediction) other; ! return (prediction == bp.prediction && deltaT == bp.deltaT && normalizingConstant == bp.normalizingConstant); } ! public String toString() { return "MixedBinaryPrediction. p(1)= " + prediction; Index: MulticlassWrapMH.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/MulticlassWrapMH.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** MulticlassWrapMH.java 13 Oct 2007 04:32:28 -0000 1.5 --- MulticlassWrapMH.java 25 Mar 2008 01:00:28 -0000 1.6 *************** *** 11,15 **** * no knowledge of the surrounding wrapper. * ! * The multiclass problem is reduce to a binary problem using a * "one-against-all" reduction. This reduction maps a multiclass * example to k (the # of classes) binary examples. Namely, example --- 11,15 ---- * no knowledge of the surrounding wrapper. * ! * The multiclass problem is reduce to a binary problem using a * "one-against-all" reduction. This reduction maps a multiclass * example to k (the # of classes) binary examples. Namely, example *************** *** 25,36 **** /** The underlying m_booster */ ! private AbstractBooster m_booster; /** The number of labels */ ! private int m_numLabels; ! /** The number of labels */ ! private boolean m_isMultiLabel; ! /** * constructor --- 25,36 ---- /** The underlying m_booster */ ! private AbstractBooster m_booster; /** The number of labels */ ! private int m_numLabels; ! /** The number of labels */ ! private boolean m_isMultiLabel; ! /** * constructor *************** *** 43,47 **** m_isMultiLabel = isMultiLabel; } ! public String toString() { if (m_booster==null) { --- 43,47 ---- m_isMultiLabel = isMultiLabel; } ! public String toString() { if (m_booster==null) { *************** *** 52,64 **** System.err.println(msg); } ! return ("MulticlassWrapMH. # of classes = " + m_numLabels + ".\nUnderlying m_booster:\n" + m_booster); } ! public void addExample(int index, Label l) { addExample(index, l, 1.0); } ! /** * @see jboost.booster.Booster#addExample(int, jboost.examples.Label, double) --- 52,64 ---- System.err.println(msg); } ! return ("MulticlassWrapMH. # of classes = " + m_numLabels + ".\nUnderlying m_booster:\n" + m_booster); } ! public void addExample(int index, Label l) { addExample(index, l, 1.0); } ! /** * @see jboost.booster.Booster#addExample(int, jboost.examples.Label, double) *************** *** 80,88 **** m_booster.finalizeData(); } ! public void clear() { m_booster.clear(); } ! public Bag newBag() { return new MultiBag(); --- 80,88 ---- m_booster.finalizeData(); } ! public void clear() { m_booster.clear(); } ! public Bag newBag() { return new MultiBag(); *************** *** 98,102 **** 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; --- 98,102 ---- 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; *************** *** 126,130 **** ! /** * According to Rob: "This method should never be called. We need --- 126,130 ---- ! /** * According to Rob: "This method should never be called. We need *************** *** 142,147 **** return m_booster.calculateWeight(margin); } ! ! public void update(Prediction[] preds, int[][] index) { int num_preds = preds.length; --- 142,147 ---- return m_booster.calculateWeight(margin); } ! ! public void update(Prediction[] preds, int[][] index) { int num_preds = preds.length; *************** *** 149,153 **** int[][] uindex = new int[index.length * m_numLabels][]; int i, j, t, k; ! // create array of predictions to pass to underlying booster --- 149,153 ---- int[][] uindex = new int[index.length * m_numLabels][]; int i, j, t, k; ! // create array of predictions to pass to underlying booster *************** *** 159,163 **** } } ! // create array of indices to pass to underlying booster t = 0; --- 159,163 ---- } } ! // create array of indices to pass to underlying booster t = 0; *************** *** 172,176 **** m_booster.update(upreds, uindex); } ! /** * computes theoretical bound as (m_numLabels/2) * theoretical --- 172,176 ---- m_booster.update(upreds, uindex); } ! /** * computes theoretical bound as (m_numLabels/2) * theoretical *************** *** 186,190 **** return m_booster.getTotalWeight(); } ! /** * returns the margin values of all of the "examples" used to --- 186,190 ---- return m_booster.getTotalWeight(); } ! /** * returns the margin values of all of the "examples" used to *************** *** 194,198 **** return m_booster.getMargins(); } ! /** * Returns the predictions associated with a list of bags representing a --- 194,198 ---- return m_booster.getMargins(); } ! /** * Returns the predictions associated with a list of bags representing a *************** *** 201,220 **** public Prediction[] getPredictions(Bag[] b, int[][] exampleIndex) { Bag[] ubags = new Bag[b.length * m_numLabels]; ! for (int i = 0; i < b.length; i++) for (int j = 0; j < m_numLabels; j++) ubags[i * m_numLabels + j] = ((MultiBag) b[i]).bags[j]; ! Prediction[] upreds = m_booster.getPredictions(ubags, exampleIndex); Prediction[] preds = new Prediction[b.length]; ! for (int i = 0; i < b.length; i++) { preds[i] = new MultiPrediction(); for (int j = 0; j < m_numLabels; j++) ! ((MultiPrediction) preds[i]).preds[j] = upreds[i * m_numLabels + j]; } return preds; ! } public Prediction[] getPredictions(Bag[] b) { --- 201,220 ---- public Prediction[] getPredictions(Bag[] b, int[][] exampleIndex) { Bag[] ubags = new Bag[b.length * m_numLabels]; ! for (int i = 0; i < b.length; i++) for (int j = 0; j < m_numLabels; j++) ubags[i * m_numLabels + j] = ((MultiBag) b[i]).bags[j]; ! Prediction[] upreds = m_booster.getPredictions(ubags, exampleIndex); Prediction[] preds = new Prediction[b.length]; ! for (int i = 0; i < b.length; i++) { preds[i] = new MultiPrediction(); for (int j = 0; j < m_numLabels; j++) ! ((MultiPrediction) preds[i]).preds[j] = upreds[i * m_numLabels + j]; } return preds; ! } public Prediction[] getPredictions(Bag[] b) { *************** *** 223,238 **** return nothing; } ! ! public double getLoss(Bag[] b) { Bag[] ubags = new Bag[b.length * m_numLabels]; ! for (int i = 0; i < b.length; i++) for (int j = 0; j < m_numLabels; j++) ubags[i * m_numLabels + j] = ((MultiBag) b[i]).bags[j]; ! return m_booster.getLoss(ubags); } ! /** * This is the bag class associated with this booster. Each bag --- 223,238 ---- return nothing; } ! ! public double getLoss(Bag[] b) { Bag[] ubags = new Bag[b.length * m_numLabels]; ! for (int i = 0; i < b.length; i++) for (int j = 0; j < m_numLabels; j++) ubags[i * m_numLabels + j] = ((MultiBag) b[i]).bags[j]; ! return m_booster.getLoss(ubags); } ! /** * This is the bag class associated with this booster. Each bag *************** *** 241,247 **** */ class MultiBag extends Bag { ! private Bag[] bags; // underlying bags ! private MultiBag() { bags = new Bag[m_numLabels]; --- 241,247 ---- */ class MultiBag extends Bag { ! private Bag[] bags; // underlying bags ! private MultiBag() { bags = new Bag[m_numLabels]; *************** *** 249,253 **** bags[j] = m_booster.newBag(); } ! public String toString() { String s = "MultiBag.\n"; --- 249,253 ---- bags[j] = m_booster.newBag(); } ! public String toString() { String s = "MultiBag.\n"; *************** *** 256,265 **** return s; } ! public void reset() { for (int j = 0; j < m_numLabels; j++) bags[j].reset(); } ! public boolean isWeightless() { for (int j = 0; j < m_numLabels; j++) --- 256,265 ---- return s; } ! public void reset() { for (int j = 0; j < m_numLabels; j++) bags[j].reset(); } ! public boolean isWeightless() { for (int j = 0; j < m_numLabels; j++) *************** *** 275,279 **** bags[j].addExample(s + j); } ! public void subtractExample(int index) { int s = index * m_numLabels; --- 275,279 ---- bags[j].addExample(s + j); } ! public void subtractExample(int index) { int s = index * m_numLabels; *************** *** 281,285 **** bags[j].subtractExample(s + j); } ! public void addExampleList(int[] l) { int i; --- 281,285 ---- bags[j].subtractExample(s + j); } ! public void addExampleList(int[] l) { int i; *************** *** 294,298 **** } } ! public void subtractExampleList(int[] l) { int i; --- 294,298 ---- } } ! public void subtractExampleList(int[] l) { int i; *************** *** 307,311 **** } } ! public void addBag(Bag b) { MultiBag other = (MultiBag) b; --- 307,311 ---- } } ! public void addBag(Bag b) { MultiBag other = (MultiBag) b; *************** *** 313,317 **** bags[j].addBag(other.bags[j]); } ! public void subtractBag(Bag b) { MultiBag other = (MultiBag) b; --- 313,317 ---- bags[j].addBag(other.bags[j]); } ! public void subtractBag(Bag b) { MultiBag other = (MultiBag) b; *************** *** 319,323 **** bags[j].subtractBag(other.bags[j]); } ! public void copyBag(Bag b) { MultiBag other = (MultiBag) b; --- 319,323 ---- bags[j].subtractBag(other.bags[j]); } ! public void copyBag(Bag b) { MultiBag other = (MultiBag) b; *************** *** 325,329 **** bags[j].copyBag(other.bags[j]); } ! public void refresh(int index) { int s = index * m_numLabels; --- 325,329 ---- bags[j].copyBag(other.bags[j]); } ! public void refresh(int index) { int s = index * m_numLabels; *************** *** 331,335 **** bags[j].refresh(s + j); } ! public void refreshList(int[] l) { int i; --- 331,335 ---- bags[j].refresh(s + j); } ! public void refreshList(int[] l) { int i; *************** *** 344,348 **** } } ! /** * Computes the loss for this bag. This loss is only meaningful for --- 344,348 ---- } } ! /** * Computes the loss for this bag. This loss is only meaningful for *************** *** 355,359 **** return loss; } ! public double getLoss(int s) throws jboost.NotSupportedException { --- 355,359 ---- return loss; } ! public double getLoss(int s) throws jboost.NotSupportedException { *************** *** 364,368 **** } } ! --- 364,368 ---- } } ! *************** *** 370,374 **** * 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 { --- 370,374 ---- * 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 { *************** *** 377,381 **** */ private Prediction[] preds; ! /** * Constructor. --- 377,381 ---- */ private Prediction[] preds; ! /** * Constructor. *************** *** 384,391 **** preds = new Prediction[m_numLabels]; } ! public Object clone() { MultiPrediction newpred = new MultiPrediction(); ! for (int j = 0; j < m_numLabels; j++) { newpred.preds[j] = (Prediction) preds[j].clone(); --- 384,391 ---- preds = new Prediction[m_numLabels]; } ! public Object clone() { MultiPrediction newpred = new MultiPrediction(); ! for (int j = 0; j < m_numLabels; j++) { newpred.preds[j] = (Prediction) preds[j].clone(); *************** *** 393,397 **** return newpred; } ! public Prediction add(Prediction p) { for (int j = 0; j < m_numLabels; j++) { --- 393,397 ---- return newpred; } ! public Prediction add(Prediction p) { for (int j = 0; j < m_numLabels; j++) { *************** *** 400,404 **** return this; } ! public Prediction scale(double w) { for (int j = 0; j < m_numLabels; j++) --- 400,404 ---- return this; } ! public Prediction scale(double w) { for (int j = 0; j < m_numLabels; j++) *************** *** 406,410 **** return this; } ! public Prediction add(double w, Prediction p) { for (int j = 0; j < m_numLabels; j++) { --- 406,410 ---- return this; } ! public Prediction add(double w, Prediction p) { for (int j = 0; j < m_numLabels; j++) { *************** *** 413,417 **** return this; } ! public double[] getMarginsSingleLabel(Label l) { int maxClass = -1; --- 413,417 ---- return this; } ! public double[] getMarginsSingleLabel(Label l) { int maxClass = -1; *************** *** 433,437 **** return ret; } ! public double[] getMarginsMultiLabel(Label l) { double[] ret = new double[m_numLabels]; --- 433,437 ---- return ret; } ! public double[] getMarginsMultiLabel(Label l) { double[] ret = new double[m_numLabels]; *************** *** 444,457 **** public double[] getMargins(Label l) { ! if (m_isMultiLabel) return getMarginsMultiLabel(l); return getMarginsSingleLabel(l); } ! public double[] getClassScores() { double[] scores = new double[m_numLabels]; double[] uscore; ! for (int j = 0; j < m_numLabels; j++) { uscore = preds[j].getClassScores(); --- 444,457 ---- public double[] getMargins(Label l) { ! if (m_isMultiLabel) return getMarginsMultiLabel(l); return getMarginsSingleLabel(l); } ! public double[] getClassScores() { double[] scores = new double[m_numLabels]; double[] uscore; ! for (int j = 0; j < m_numLabels; j++) { uscore = preds[j].getClassScores(); *************** *** 460,464 **** return scores; } ! /** * Check to see if this MultiPrediction is the same as the other --- 460,464 ---- return scores; } ! /** * Check to see if this MultiPrediction is the same as the other *************** *** 476,480 **** return retval; } ! public String toString() { String s = "MultiPrediction.\n"; --- 476,480 ---- return retval; } ! public String toString() { String s = "MultiPrediction.\n"; *************** *** 483,487 **** return s; } ! public String shortText() { String s = "[,"+preds[0]; --- 483,487 ---- return s; } ! public String shortText() { String s = "[,"+preds[0]; *************** *** 490,504 **** return s+"]"; } ! public String cPreamble() { String code = ""; ! code += "typedef double Prediction_t[" + m_numLabels + "];\n"; ! code += "#define reset_pred() { \\\n"; for (int i = 0; i < m_numLabels; i++) code += " p["+i+"] = 0.0; \\\n"; code += " }\n"; ! code += "#define add_pred("; for (int i = 0; i < m_numLabels; i++) --- 490,504 ---- return s+"]"; } ! public String cPreamble() { String code = ""; ! code += "typedef double Prediction_t[" + m_numLabels + "];\n"; ! code += "#define reset_pred() { \\\n"; for (int i = 0; i < m_numLabels; i++) code += " p["+i+"] = 0.0; \\\n"; code += " }\n"; ! code += "#define add_pred("; for (int i = 0; i < m_numLabels; i++) *************** *** 508,512 **** code += " p["+i+"] += X"+i+"; \\\n"; code += " }\n"; ! code += "#define finalize_pred() \\\n"; code += " (r ? ( \\\n"; --- 508,512 ---- code += " p["+i+"] += X"+i+"; \\\n"; code += " }\n"; ! code += "#define finalize_pred() \\\n"; code += " (r ? ( \\\n"; *************** *** 514,524 **** code += " r["+i+"] = p["+i+"], \\\n"; code += " p[0]) : p[0])\n"; ! return code; } ! public String javaPreamble() { String code = ""; ! code += "" + " static private double[] p = new double[" + m_numLabels + "];\n" --- 514,524 ---- code += " r["+i+"] = p["+i+"], \\\n"; code += " p[0]) : p[0])\n"; ! return code; } ! public String javaPreamble() { String code = ""; ! code += "" + " static private double[] p = new double[" + m_numLabels + "];\n" *************** *** 539,548 **** return code; } ! public double[] toCodeArray() { return getClassScores(); } } ! /** a main for testing */ public static void main(String[] argv) { --- 539,548 ---- return code; } ! public double[] toCodeArray() { return getClassScores(); } } ! /** a main for testing */ public static void main(String[] argv) { *************** *** 550,561 **** AbstractBooster ada = new DebugWrap(new MulticlassWrapMH(new DebugWrap(new AdaBoost(0.0)), 2, true)); ! for(int i=0; i< 10; i++) { ada.addExample(i,new Label(i % 2)); } ! ada.finalizeData(); if(Monitor.logLevel>3) Monitor.log(ada); ! int[] elements = {1,2,6,3,4}; String s="\n Generating a bag with elements:\n" +elements[0]; --- 550,561 ---- AbstractBooster ada = new DebugWrap(new MulticlassWrapMH(new DebugWrap(new AdaBoost(0.0)), 2, true)); ! for(int i=0; i< 10; i++) { ada.addExample(i,new Label(i % 2)); } ! ada.finalizeData(); if(Monitor.logLevel>3) Monitor.log(ada); ! int[] elements = {1,2,6,3,4}; String s="\n Generating a bag with elements:\n" +elements[0]; *************** *** 564,573 **** Bag bag = ada.newBag(elements); if(Monitor.logLevel>3) Monitor.log(bag); ! Prediction[] p; p = ada.getPredictions(new Bag[] {bag}); // calc optimal prediction for this bag ! if(Monitor.logLevel>3) Monitor.log("best prediction for this bag is " + p[0].getClassScores()[1]); ! int[][] exampleList = new int[1][]; exampleList[0] = elements; --- 564,573 ---- Bag bag = ada.newBag(elements); if(Monitor.logLevel>3) Monitor.log(bag); ! Prediction[] p; p = ada.getPredictions(new Bag[] {bag}); // calc optimal prediction for this bag ! if(Monitor.logLevel>3) Monitor.log("best prediction for this bag is " + p[0].getClassScores()[1]); ! int[][] exampleList = new int[1][]; exampleList[0] = elements; *************** *** 579,583 **** if(Monitor.logLevel>3) Monitor.log("now best prediction for this bag is "+ (ada.getPredictions(new Bag[] {bag})[0]).getClassScores()[1]); ! } catch(Exception e) { --- 579,583 ---- if(Monitor.logLevel>3) Monitor.log("now best prediction for this bag is "+ (ada.getPredictions(new Bag[] {bag})[0]).getClassScores()[1]); ! } catch(Exception e) { *************** *** 585,592 **** e.printStackTrace(); } ! ! } ! /* (non-Javadoc) * @see jboost.booster.Booster#init(jboost.controller.Configuration) --- 585,592 ---- e.printStackTrace(); } ! ! } ! /* (non-Javadoc) * @see jboost.booster.Booster#init(jboost.controller.Configuration) *************** *** 594,598 **** public void init(Configuration config) { // TODO Auto-generated method stub ! } } --- 594,598 ---- public void init(Configuration config) { // TODO Auto-generated method stub ! } } Index: MixedBinaryPredictionTest.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/MixedBinaryPredictionTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MixedBinaryPredictionTest.java 2 Oct 2007 02:32:48 -0000 1.1 --- MixedBinaryPredictionTest.java 25 Mar 2008 01:00:27 -0000 1.2 *************** *** 15,19 **** /** ! * Constructor for * @param arg0 */ --- 15,19 ---- /** ! * Constructor for * @param arg0 */ *************** *** 22,26 **** System.out.println("Making MixedPred class"); } ! final public void testAdd() { System.out.println("test add"); --- 22,26 ---- System.out.println("Making MixedPred class"); } ! final public void testAdd() { System.out.println("test add"); *************** *** 29,33 **** MixedBinaryPrediction np = new MixedBinaryPrediction(); assertEquals(true, Prediction.isNormPred(np)); ! } --- 29,33 ---- MixedBinaryPrediction np = new MixedBinaryPrediction(); assertEquals(true, Prediction.isNormPred(np)); ! } *************** *** 68,75 **** boolean exceptionThrown = false; try { ! p = new MixedBinaryPrediction(5); } catch (NotNormalizedPredException e) { ... [truncated message content] |
From: Aaron A. <aa...@us...> - 2008-02-16 00:02:24
|
Update of /cvsroot/jboost/jboost/src/jboost/examples In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv31648 Modified Files: TextDescription.java Log Message: Put in a hack for text processing (ngrams are removed) Index: TextDescription.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/examples/TextDescription.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** TextDescription.java 16 May 2007 04:06:02 -0000 1.1.1.1 --- TextDescription.java 16 Feb 2008 00:02:19 -0000 1.2 *************** *** 102,107 **** st = new FixedNgram(string, ngramsize); try { ! while ( st.hasMoreElements()) { ! word = (String) st.nextElement(); // if(Monitor.logLevel>3) Monitor.log("DIAG TextAttReader.str2Att: word=" +word); if (wt.frozen && !wt.map.containsKey(word)) --- 102,110 ---- st = new FixedNgram(string, ngramsize); try { ! String[] wordArr = string.split(" "); ! //while ( st.hasMoreElements()) { ! for (int i=0; i<wordArr.length; i++) { ! //word = (String) st.nextElement(); ! word = wordArr[i]; // if(Monitor.logLevel>3) Monitor.log("DIAG TextAttReader.str2Att: word=" +word); if (wt.frozen && !wt.map.containsKey(word)) |
From: Aaron A. <aa...@us...> - 2008-01-24 22:48:59
|
Update of /cvsroot/jboost/jboost/src/jboost/learner In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv26189/learner Modified Files: InequalitySplitter.java InequalitySplitterBuilder.java StumpSplitterBuilderFamily.java Log Message: Cost sensitive normalboost, fixed compile bug in BooleanAttribute Index: StumpSplitterBuilderFamily.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/learner/StumpSplitterBuilderFamily.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** StumpSplitterBuilderFamily.java 16 May 2007 04:06:02 -0000 1.1.1.1 --- StumpSplitterBuilderFamily.java 24 Jan 2008 22:48:54 -0000 1.2 *************** *** 9,12 **** --- 9,13 ---- import jboost.examples.RealAttribute; import jboost.examples.SetAttribute; + import jboost.examples.*; import jboost.monitor.Monitor; *************** *** 43,46 **** --- 44,49 ---- DiscreteAttribute discreteAttribute=new DiscreteAttribute(0); SetAttribute setAttribute=new SetAttribute(); + IntegerAttribute integerAttribute=new IntegerAttribute(); + BooleanAttribute booleanAttribute=new BooleanAttribute(); Vector retval=new Vector(); *************** *** 57,60 **** --- 60,66 ---- tmpSB= new InequalitySplitterBuilder(attr[i], booster, new AttributeDescription[] {attrDesc[attr[i]]}); + } else if (attributeClass.equals(integerAttribute.getClass())) { + tmpSB= new InequalitySplitterBuilder(attr[i], booster, + new AttributeDescription[] {attrDesc[attr[i]]}); } else if (attributeClass.equals(discreteAttribute.getClass())) { tmpSB= new EqualitySplitterBuilder(attr[i], booster, Index: InequalitySplitterBuilder.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/learner/InequalitySplitterBuilder.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** InequalitySplitterBuilder.java 13 Oct 2007 04:32:28 -0000 1.2 --- InequalitySplitterBuilder.java 24 Jan 2008 22:48:54 -0000 1.3 *************** *** 12,15 **** --- 12,16 ---- import jboost.examples.Example; import jboost.examples.Label; + import jboost.examples.*; import jboost.examples.RealAttribute; import jboost.monitor.Monitor; *************** *** 290,297 **** throw new RuntimeException("Attempt to addExample() to non-root or finalized SplitterBuilder"); RealAttribute a= null; Attribute t= example.getAttribute(attributeIndex); // check that attribute is of the correct class try { ! a= (RealAttribute) t; // try downcasting } catch (ClassCastException e) { throw new IncompAttException( --- 291,319 ---- throw new RuntimeException("Attempt to addExample() to non-root or finalized SplitterBuilder"); RealAttribute a= null; + IntegerAttribute b= null; Attribute t= example.getAttribute(attributeIndex); + Label l= example.getLabel(); // check that attribute is of the correct class try { ! if (t instanceof RealAttribute) { ! a = (RealAttribute) t; ! if (a.isDefined() && (l != null)) { ! IVL ivl= new IVL(index, a.getValue(), l); ! tempList.add(ivl); ! } ! } else if (t instanceof IntegerAttribute) { ! b = (IntegerAttribute) t; ! if (b.isDefined() && (l != null)) { ! IVL ivl= new IVL(index, b.getValue(), l); ! tempList.add(ivl); ! } ! } else { ! throw new IncompAttException( ! index, ! attributeIndex, ! "IntegerAttribute or RealAttribute", ! t.getClass()); ! } ! // check if attribute and label are defined } catch (ClassCastException e) { throw new IncompAttException( *************** *** 301,314 **** t.getClass()); } - Label l= example.getLabel(); largestIndex= (largestIndex > index) ? largestIndex : index; // remember the largest index seen // if(Monitor.logLevel>3) Monitor.log("In RootInequalitySplitterBuilder: a="+a+" t="+t // +" example="+example); - if (a.isDefined() - && (l != null)) { // check if attribute and label are defined - IVL ivl= new IVL(index, a.getValue(), l); - tempList.add(ivl); // add item to list - } // if(Monitor.logLevel>3) Monitor.log("at end of addExample("+index+")\n"+tempList); } --- 323,330 ---- *************** *** 397,400 **** --- 413,417 ---- of the previous (unmasked) example in sortedIndices */ protected boolean[] potentialSplits; + //----------------------------- Private Members -------------------------------------// /** an internal class defining the elements of {@link tempList} */ *************** *** 405,408 **** --- 422,430 ---- label= l; } + IVL(int i, int v, Label l) { + index= i; + value= v; + label= l; + } public int compareTo(Object o) { // defined so that we can use "Collections.sort" double value2= ((IVL) o).value; Index: InequalitySplitter.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/learner/InequalitySplitter.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** InequalitySplitter.java 16 May 2007 04:06:02 -0000 1.1.1.1 --- InequalitySplitter.java 24 Jan 2008 22:48:54 -0000 1.2 *************** *** 5,8 **** --- 5,9 ---- import jboost.examples.Instance; import jboost.examples.RealAttribute; + import jboost.examples.*; /** *************** *** 59,64 **** if(t == null) {return(-1);} try { ! RealAttribute a= (RealAttribute) t; // try downcasting ! return((a.getValue() > threshold)?1:0); } catch (ClassCastException e) { --- 60,74 ---- if(t == null) {return(-1);} try { ! ! if (t instanceof RealAttribute) { ! RealAttribute a= (RealAttribute) t; // try downcasting ! return((a.getValue() > threshold)?1:0); ! } else if (t instanceof IntegerAttribute) { ! IntegerAttribute a= (IntegerAttribute) t; // try downcasting ! return((a.getValue() > threshold)?1:0); ! } else { ! throw new IncompAttException("InequalitySplitter Error:",index ! ,t.getClass()); ! } } catch (ClassCastException e) { |
From: Aaron A. <aa...@us...> - 2008-01-24 22:48:59
|
Update of /cvsroot/jboost/jboost/src/jboost/tokenizer In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv26189/tokenizer Modified Files: jboost_DataStream.java Log Message: Cost sensitive normalboost, fixed compile bug in BooleanAttribute Index: jboost_DataStream.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/tokenizer/jboost_DataStream.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** jboost_DataStream.java 23 Oct 2007 23:52:26 -0000 1.2 --- jboost_DataStream.java 24 Jan 2008 22:48:54 -0000 1.3 *************** *** 298,303 **** } // make sure the type is one of the three supported ! if (!(type.equals("finite") || type.equals("text") || type.equals("number") ! || type.equals("string"))) { throw new SpecFileException("Type not valid for attribute " + line); } --- 298,308 ---- } // make sure the type is one of the three supported ! if (!(type.equals("finite") || ! type.equals("text") || ! type.equals("number") || ! type.equals("string") || ! type.equals("int") || ! type.equals("bool") ! )) { throw new SpecFileException("Type not valid for attribute " + line); } *************** *** 357,367 **** if (attribute != null) { if (name.equals(DataStream.LABELS_ATTR)) { ! ed.setLabel(attribute, lineCount); } else if (name.equals(DataStream.WEIGHT_ATTR)) { ! ed.setWeight(attribute, lineCount);/* } else if (name.equals(DataStream.ID_ATTR)) { ! ed.setId(attribute, lineCount);*/ } else { ! ed.addAttribute(attribute); } --- 362,372 ---- if (attribute != null) { if (name.equals(DataStream.LABELS_ATTR)) { ! ed.setLabel(attribute, lineCount); } else if (name.equals(DataStream.WEIGHT_ATTR)) { ! ed.setWeight(attribute, lineCount); } else if (name.equals(DataStream.ID_ATTR)) { ! //ed.setId(attribute, lineCount); } else { ! ed.addAttribute(attribute); } |
From: Aaron A. <aa...@us...> - 2008-01-24 22:48:59
|
Update of /cvsroot/jboost/jboost/src/jboost/examples In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv26189/examples Modified Files: BooleanAttribute.java Log Message: Cost sensitive normalboost, fixed compile bug in BooleanAttribute Index: BooleanAttribute.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/examples/BooleanAttribute.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** BooleanAttribute.java 17 Dec 2007 00:36:31 -0000 1.1 --- BooleanAttribute.java 24 Jan 2008 22:48:54 -0000 1.2 *************** *** 7,11 **** public BooleanAttribute(boolean value) {this.value=value; setDefined();} ! public BooleanAttribute() { setDefined(false);} public boolean getValue() {return value;} --- 7,11 ---- public BooleanAttribute(boolean value) {this.value=value; setDefined();} ! public BooleanAttribute() { defined=false;} public boolean getValue() {return value;} |
From: Aaron A. <aa...@us...> - 2008-01-24 22:48:59
|
Update of /cvsroot/jboost/jboost/src/jboost/controller In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv26189/controller Modified Files: Controller.java ControllerConfiguration.java Log Message: Cost sensitive normalboost, fixed compile bug in BooleanAttribute Index: ControllerConfiguration.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/controller/ControllerConfiguration.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ControllerConfiguration.java 23 Oct 2007 22:46:32 -0000 1.3 --- ControllerConfiguration.java 24 Jan 2008 22:48:53 -0000 1.4 *************** *** 54,67 **** public static final String YABA_C1="c1"; public static final String YABA_C2="c2"; public static final String YABA_THETA="theta"; ! public static final String YABA_POS_C="pos_r"; public static final String YABA_POS_C1="pos_c1"; public static final String YABA_POS_C2="pos_c2"; public static final String YABA_POS_THETA="pos_theta"; ! public static final String YABA_NEG_C="neg_r"; public static final String YABA_NEG_C1="neg_c1"; public static final String YABA_NEG_C2="neg_c2"; public static final String YABA_NEG_THETA="neg_theta"; public static final String BROWN_BOOST_POTENTIAL="brownBoostPotential"; public static final String DEFAULT_BOOSTER = "AdaBoost"; --- 54,71 ---- public static final String YABA_C1="c1"; public static final String YABA_C2="c2"; + public static final String YABA_NC="nc"; public static final String YABA_THETA="theta"; ! public static final String YABA_POS_C="pos_c"; public static final String YABA_POS_C1="pos_c1"; public static final String YABA_POS_C2="pos_c2"; public static final String YABA_POS_THETA="pos_theta"; ! public static final String YABA_POS_NC="pos_nc"; ! public static final String YABA_NEG_C="neg_c"; public static final String YABA_NEG_C1="neg_c1"; public static final String YABA_NEG_C2="neg_c2"; public static final String YABA_NEG_THETA="neg_theta"; + public static final String YABA_NEG_NC="neg_nc"; public static final String BROWN_BOOST_POTENTIAL="brownBoostPotential"; + public static final String BROWN_COST_SENSITIVE="costSensitive"; public static final String DEFAULT_BOOSTER = "AdaBoost"; *************** *** 94,107 **** addOption(YABA_C1, getString("c1", null)); addOption(YABA_C2, getString("c2", null)); addOption(YABA_THETA, getString("theta", null)); ! addOption(YABA_POS_C,"pos_r"); ! addOption(YABA_POS_C1,"pos_c1"); ! addOption(YABA_POS_C2,"pos_c2"); ! addOption(YABA_POS_THETA,"pos_theta"); ! addOption(YABA_NEG_C,"neg_r"); ! addOption(YABA_NEG_C1,"neg_c1"); ! addOption(YABA_NEG_C2,"neg_c2"); ! addOption(YABA_NEG_THETA,"neg_theta"); addOption(BROWN_BOOST_POTENTIAL, getString("potential", null)); } --- 98,115 ---- addOption(YABA_C1, getString("c1", null)); addOption(YABA_C2, getString("c2", null)); + addOption(YABA_NC, getString("nc", null)); addOption(YABA_THETA, getString("theta", null)); ! addOption(YABA_POS_C,getString("pos_c",null)); ! addOption(YABA_POS_C1,getString("pos_c1",null)); ! addOption(YABA_POS_C2,getString("pos_c2",null)); ! addOption(YABA_POS_THETA,getString("pos_theta",null)); ! addOption(YABA_POS_NC, getString("pos_nc", null)); ! addOption(YABA_NEG_C,getString("neg_c",null)); ! addOption(YABA_NEG_C1,getString("neg_c1",null)); ! addOption(YABA_NEG_C2,getString("neg_c2",null)); ! addOption(YABA_NEG_THETA,getString("neg_theta",null)); ! addOption(YABA_NEG_NC, getString("neg_nc", null)); addOption(BROWN_BOOST_POTENTIAL, getString("potential", null)); + addOption(BROWN_COST_SENSITIVE, getString("costSensitive", null)); } *************** *** 288,291 **** --- 296,311 ---- + /** + * @return should we print potential and exit? + */ + public boolean getCostSensitive() { + String str = getString(BROWN_COST_SENSITIVE); + if (str == null) { + return false; + } + return true; + } + + Index: Controller.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/controller/Controller.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Controller.java 5 Dec 2007 06:39:57 -0000 1.6 --- Controller.java 24 Jan 2008 22:48:53 -0000 1.7 *************** *** 92,96 **** configuration.printUsage(); e.printStackTrace(); - e.getMessage(); } finally { Monitor.closeLog(); --- 92,95 ---- *************** *** 143,146 **** --- 142,149 ---- BrownBoost b = (BrownBoost) m_booster; System.out.println("\tPotential loss of m_booster: " + b.getInitialPotential()); + if (b.isCostSensitive()) { + System.out.println("\tPotential loss of positive examples m_booster: " + b.getPositivePotential()); + System.out.println("\tPotential loss of negative examples m_booster: " + b.getNegativePotential()); + } System.exit(0); } |
From: Aaron A. <aa...@us...> - 2008-01-24 22:48:59
|
Update of /cvsroot/jboost/jboost/src/jboost/atree In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv26189/atree Modified Files: InstrumentedAlternatingTree.java Log Message: Cost sensitive normalboost, fixed compile bug in BooleanAttribute Index: InstrumentedAlternatingTree.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/atree/InstrumentedAlternatingTree.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** InstrumentedAlternatingTree.java 23 Oct 2007 23:52:26 -0000 1.5 --- InstrumentedAlternatingTree.java 24 Jan 2008 22:48:53 -0000 1.6 *************** *** 705,709 **** private int[] makeIndices(boolean[] exMask) { int[] examples= null; ! int count= 0; for (int j= 0; j < exMask.length; j++) if (exMask[j] == true) --- 705,709 ---- private int[] makeIndices(boolean[] exMask) { int[] examples= null; ! int count= 0; for (int j= 0; j < exMask.length; j++) if (exMask[j] == true) |
Update of /cvsroot/jboost/jboost/src/jboost/booster In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv19099 Modified Files: AbstractBooster.java AdaBoost.java Bag.java BrownBoost.java MixedBinaryPrediction.java NormalizedPrediction.java YabaBoost.java Log Message: Main changes: one sided prediction is optional (USE_ONE_SIDED), cost asymetric code in yababoost/normalboost, new parameters are optional (USE_BETA_RHO), several other changes as well Index: Bag.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/Bag.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** Bag.java 16 May 2007 04:06:02 -0000 1.1.1.1 --- Bag.java 24 Jan 2008 22:30:16 -0000 1.2 *************** *** 12,15 **** --- 12,19 ---- public abstract class Bag { + + /** total weight for examples of each label */ + protected double[] m_w; + /** * Resets the bag to empty (or to its default setting as defined by *************** *** 17,21 **** */ public abstract void reset(); ! /** * If the bag has no weight, then it is considered to be weightless. --- 21,32 ---- */ public abstract void reset(); ! ! /** ! * Get the weights of the bag. ! */ ! public double[] getWeights() { ! return m_w; ! } ! /** * If the bag has no weight, then it is considered to be weightless. Index: NormalizedPrediction.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/NormalizedPrediction.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** NormalizedPrediction.java 2 Oct 2007 02:32:07 -0000 1.1 --- NormalizedPrediction.java 24 Jan 2008 22:30:16 -0000 1.2 *************** *** 22,29 **** */ public Prediction add(Prediction p); - /* public static boolean isNormPred(Prediction p); */ ! } --- 22,28 ---- */ public Prediction add(Prediction p); /* public static boolean isNormPred(Prediction p); */ ! public double getDeltaT(); } Index: AbstractBooster.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/AbstractBooster.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** AbstractBooster.java 23 Oct 2007 22:45:40 -0000 1.6 --- AbstractBooster.java 24 Jan 2008 22:30:16 -0000 1.7 *************** *** 3,6 **** --- 3,7 ---- import java.io.Serializable; import jboost.controller.Configuration; + import jboost.controller.ControllerConfiguration; import jboost.monitor.Monitor; *************** *** 66,90 **** if (result instanceof jboost.booster.YabaBoost) { ! double c1=0, c2=0, theta=0; ! double rpos=0, c1pos=0, c2pos=0, thetapos=0; ! double rneg=0, c1neg=0, c2neg=0, thetaneg=0; try { c1 = Double.parseDouble(c.getString("c1", "Z1.0")); c2 = Double.parseDouble(c.getString("c2", "Z1.0")); theta = Double.parseDouble(c.getString("theta", "Z0.15")); ! //c1 = Double.parseDouble(c.getString("pos_r", "Z1.0")); ! //c1 = Double.parseDouble(c.getString("pos_c1", "Z1.0")); ! //c2 = Double.parseDouble(c.getString("pos_c2", "Z1.0")); ! //theta = Double.parseDouble(c.getString("pos_theta", "Z0.15")); } catch (NumberFormatException e) { ! String s = "Need to supply r, c1, c2, and theta!"; ! System.err.println(s); ! throw new InstantiationException(s); } - jboost.booster.YabaBoost yaba = (jboost.booster.YabaBoost) result; - yaba.setParams(c1,c2,theta); - yaba.setCostSensitiveParams(rpos, c1pos, c2pos, thetapos, - rneg, c1neg, c2neg, thetaneg); result = yaba; } --- 67,127 ---- + if (result instanceof jboost.booster.YabaBoost) { ! jboost.booster.YabaBoost yaba = (jboost.booster.YabaBoost) result; ! double c1=0, c2=0, theta=0, nc=0; ! double rpos=0, c1pos=0, c2pos=0, thetapos=0, ncpos=0; ! double rneg=0, c1neg=0, c2neg=0, thetaneg=0, ncneg=0; ! ControllerConfiguration conf = (ControllerConfiguration)c; try { c1 = Double.parseDouble(c.getString("c1", "Z1.0")); c2 = Double.parseDouble(c.getString("c2", "Z1.0")); theta = Double.parseDouble(c.getString("theta", "Z0.15")); ! nc = Double.parseDouble(c.getString("nc", "Z0.15")); ! yaba.setParams(c1,c2,theta,nc); ! if (conf.getCostSensitive()) { ! /* ! System.out.println(" runtime: " + rpos + "," + rneg + ! " c1: " + c1pos + "," + c1neg + ! " c2: " + c2pos + "," + c2neg + ! " theta: " + thetapos + "," + thetaneg + ! " nc: " + ncpos + "," + ncneg ! ); ! */ ! rpos = Double.parseDouble(c.getString("pos_c","Z")); ! rneg = Double.parseDouble(c.getString("neg_c","Z")); ! c1pos = Double.parseDouble(c.getString("pos_c1","Z")); ! c1neg = Double.parseDouble(c.getString("neg_c1","Z")); ! /* ! System.out.println(" runtime: " + rpos + "," + rneg + ! " c1: " + c1pos + "," + c1neg + ! " c2: " + c2pos + "," + c2neg + ! " theta: " + thetapos + "," + thetaneg + ! " nc: " + ncpos + "," + ncneg ! ); ! */ ! c2pos = Double.parseDouble(c.getString("pos_c2","Z")); ! c2neg = Double.parseDouble(c.getString("neg_c2","Z")); ! thetapos = Double.parseDouble(c.getString("pos_theta","Z")); ! thetaneg = Double.parseDouble(c.getString("neg_theta","Z")); ! ncpos = Double.parseDouble(c.getString("pos_nc","Z")); ! ncneg = Double.parseDouble(c.getString("neg_nc","Z")); ! /* ! System.out.println(" runtime: " + rpos + "," + rneg + ! " c1: " + c1pos + "," + c1neg + ! " c2: " + c2pos + "," + c2neg + ! " theta: " + thetapos + "," + thetaneg + ! " nc: " + ncpos + "," + ncneg ! ); ! */ ! yaba.setCostSensitiveParams(rpos, c1pos, c2pos, thetapos, ncpos, ! rneg, c1neg, c2neg, thetaneg, ncneg); ! } } catch (NumberFormatException e) { ! System.err.println("Need to supply appropriate parameters!"); ! System.err.println("For YabaBoost normal, we need r, c1, c2, nc, and theta!"); ! System.err.println("For YabaBoost cost sensitive, we need neg_c, pos_c, neg_c1, pos_c1, neg_c2, pos_c2, neg_theta, pos_theta, neg_nc, pos_nc"); ! throw new InstantiationException("Need more params for yaba"); } result = yaba; } Index: MixedBinaryPrediction.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/MixedBinaryPrediction.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** MixedBinaryPrediction.java 13 Dec 2007 07:41:39 -0000 1.4 --- MixedBinaryPrediction.java 24 Jan 2008 22:30:16 -0000 1.5 *************** *** 18,24 **** --- 18,31 ---- public MixedBinaryPrediction(double p) throws NotNormalizedPredException { + (new Exception("asdf")).printStackTrace(); throw new NotNormalizedPredException("MixedBinaryPrediction: Need to normalize based on time!"); } + public static double updateMargin(double currentMargin, double stepSize, double step, double dt, double nc) { + //System.out.println("cm: " + currentMargin + ", deltax: " + stepSize*step + ", dt: " + dt + ", nc: " + nc); + //System.out.println(Math.exp(-dt*nc)*currentMargin + stepSize*step); + return Math.exp(-dt*nc)*currentMargin + stepSize*step; + } + public MixedBinaryPrediction(double p, double dt, double nc) throws NotNormalizedPredException { *************** *** 30,33 **** --- 37,49 ---- + public MixedBinaryPrediction(double p, double dt) + throws NotNormalizedPredException { + super(); + deltaT = dt; + prediction=p; + normalizingConstant = 1; + } + + public Object clone(){ *************** *** 48,52 **** // The prediction p is for h_t double alpha = ((MixedBinaryPrediction) p).prediction; ! prediction = Math.exp(-dt) * prediction + alpha; /* if (Math.abs(alpha) > 1 || Math.abs(prediction) > 1) { --- 64,68 ---- // The prediction p is for h_t double alpha = ((MixedBinaryPrediction) p).prediction; ! prediction = Math.exp(-normalizingConstant*deltaT) * prediction + alpha; /* if (Math.abs(alpha) > 1 || Math.abs(prediction) > 1) { *************** *** 70,73 **** --- 86,97 ---- return this; } + + public double getDeltaT() { + return deltaT; + } + + public double getNormConstant() { + return normalizingConstant; + } public Prediction add(double w, Prediction p) { *************** *** 79,83 **** public boolean equals(Prediction other) { MixedBinaryPrediction bp= (MixedBinaryPrediction) other; ! return (prediction == bp.prediction && dt == bp.dt && normalizingConstant == bp.normalizingConstant); } --- 103,107 ---- public boolean equals(Prediction other) { MixedBinaryPrediction bp= (MixedBinaryPrediction) other; ! return (prediction == bp.prediction && deltaT == bp.deltaT && normalizingConstant == bp.normalizingConstant); } Index: BrownBoost.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/BrownBoost.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** BrownBoost.java 13 Dec 2007 07:21:05 -0000 1.9 --- BrownBoost.java 24 Jan 2008 22:30:16 -0000 1.10 *************** *** 72,76 **** */ protected int[] m_examples; ! /** * Default constructor just calls AdaBoost to --- 72,97 ---- */ protected int[] m_examples; ! ! /** ! * A parameter indicating whether we should use confidence rated ! * predictions. ! */ ! protected static final boolean USE_BETA_RHO = false; ! ! ! /** ! * A parameter indicating whether we should use confidence rated ! * predictions. ! */ ! protected static final boolean USE_CONFIDENCE = false; ! ! ! /** ! * A parameter indicating whether we should use confidence rated ! * predictions. ! */ ! protected static final boolean ONE_SIDED_PREDICTION = USE_CONFIDENCE; ! ! /** * Default constructor just calls AdaBoost to *************** *** 86,90 **** m_examples = new int[m_numExamples]; for (int i=0; i<m_numExamples; i++) { ! m_potentials[i] = calculatePotential(0,m_c); m_examples[i] = i; } --- 107,117 ---- m_examples = new int[m_numExamples]; for (int i=0; i<m_numExamples; i++) { ! if (m_isCostSensitive) { ! m_potentials[i] = calculatePotential(0,m_c,m_labels[i]); ! m_weights[i] = calculateWeight(0,m_c,m_labels[i]); ! } else { ! m_potentials[i] = calculatePotential(0,m_c); ! m_weights[i] = calculateWeight(0,m_c); ! } m_examples[i] = i; } *************** *** 98,105 **** //System.out.println("BrownBoost:\n \t m_c: " + m_c + "\n \t intial potential: " + m_initialPotential); } ! public double getInitialPotential(){ ! return m_initialPotential; } --- 125,160 ---- //System.out.println("BrownBoost:\n \t m_c: " + m_c + "\n \t intial potential: " + m_initialPotential); } ! /* ! public double getRuntime() { ! if (USE_BETA_RHO) { ! return 1.0; ! } else { ! return m_c; ! } ! } ! */ public double getInitialPotential(){ ! return calculatePotential(0.0, m_c); ! } ! ! public double getPositivePotential(){ ! return calculatePotential(0.0, m_posc, POSITIVE_LABEL); ! } ! ! public double getNegativePotential(){ ! return calculatePotential(0.0, m_negc, NEGATIVE_LABEL); ! } ! ! public double getTimeRemaining() { ! if (USE_BETA_RHO) { ! return 1.0 - m_s; ! } else { ! return m_c - m_s; ! } ! } ! ! public double getTimePlayed() { ! return m_s; } *************** *** 109,112 **** --- 164,171 ---- } + public boolean isCostSensitive(){ + return m_isCostSensitive; + } + /** * Checked results with Matlab, and correctness is sufficient. *************** *** 277,285 **** ! protected double solve_constraints(double hyp_err, int[] examples) { if( m_s < 0.001){ m_s = -1; ! return 0; } --- 336,344 ---- ! protected double[] solve_constraints(double hyp_err, int[] examples) { if( m_s < 0.001){ m_s = -1; ! return new double[] {0,0}; } *************** *** 386,394 **** System.err.println("ERROR: Bad solution for t<0"); m_s = m_oldS; ! return(0.0); } //System.out.println("\ns: " + m_s); ! return alpha; } --- 445,453 ---- System.err.println("ERROR: Bad solution for t<0"); m_s = m_oldS; ! return new double[] {0, 0}; } //System.out.println("\ns: " + m_s); ! return new double[] {alpha, t}; } *************** *** 452,455 **** --- 511,518 ---- } + public double calculateWeight(double margin, double time_remaining, short label) { + return calculateWeight(margin, m_s); + } + /** * BrownBoost uses (1-erf(-(margin+s)/c))/2 as the potential function *************** *** 459,462 **** --- 522,530 ---- } + public double calculatePotential(double margin, double time_remaining, short label) { + return calculatePotential(margin, m_s); + } + + /** * BrownBoost uses e^(-(margin+s)^2/c) as the weight calculation *************** *** 464,468 **** public double calculateWeight(double margin, double time_remaining) { double s = time_remaining; ! return Math.exp(-1 * Math.pow(margin+s,2)/m_c); } --- 532,544 ---- public double calculateWeight(double margin, double time_remaining) { double s = time_remaining; ! double mu = -s; ! double weight = Math.exp(-1 * Math.pow(margin+s,2)/m_c); ! if (USE_CONFIDENCE) { ! if (margin < mu) ! weight = 0; ! else ! weight = 2*weight; ! } ! return weight; } *************** *** 472,476 **** public double calculatePotential(double margin, double time_remaining) { double s = time_remaining; ! return (1-erf((margin+s)/Math.sqrt(m_c)))/2; } --- 548,556 ---- public double calculatePotential(double margin, double time_remaining) { double s = time_remaining; ! double pot = (1-erf((margin+s)/Math.sqrt(m_c)))/2; ! if (USE_CONFIDENCE) { ! pot = Math.min(2*pot, 1.0); ! } ! return pot; } *************** *** 504,573 **** - /** - * BrownBag is identical to BinaryBag, except for the method used to - * derive the value of prediction (alpha in the literature). BrownBag - * uses the value of alpha determined by BrownBoost and its variants. - * See comments for AdaBoost.BinaryBag. - * @author Aaron Arvey - */ - class BrownBag extends AdaBoost.BinaryBag{ - - protected BrownBag(int[] list) { - m_w= new double[2]; - reset(); - this.addExampleList(list); - } - - /** compute the binary prediction associated with this bag */ - public BinaryPrediction calcPrediction(double alpha) { - BinaryPrediction ret; - ret = new BinaryPrediction(m_w[1] > m_w[0] ? 1.0 : -1.0 ); - ret.scale(alpha); - return ret; - } - - /** compute the binary prediction associated with this bag */ - public BinaryPrediction calcPrediction(double posAlpha, double negAlpha) { - BinaryPrediction ret; - if (m_w[1] > m_w[0]) { - ret = new BinaryPrediction(1.0); - ret.scale(posAlpha); - } else { - ret = new BinaryPrediction(-1.0); - ret.scale(negAlpha); - } - return ret; - } - - - /** Place holder to ensure that this function is not used in BrownBoost. */ - public BinaryPrediction calcPrediction(){ - //System.err.println("Need to have alpha for prediction in BrownBag.calcPrediction()!"); - return new BinaryPrediction(0); - } - - - /** default constructor */ - protected BrownBag() { - super(); - } - - - /** constructor that copies an existing bag */ - protected BrownBag(BrownBag bag) { - super(bag); - } - - - /** Output the weights in the bag */ - public String toString() { - String s= "BrownBag.\t w0=" + m_w[0] + "\t w1=" + m_w[1] + "\n"; - return s; - } - - - } /* End BrownBag */ - - protected double getHypErr(Bag[] bags, int[][] exampleIndex) { --- 584,587 ---- *************** *** 583,595 **** boolean[] examplesWithHyp = new boolean[m_margins.length]; // Get all examples that have a hypothesis associated with them for (int i= 0; i < exampleIndex.length; i++) { int[] indexes= exampleIndex[i]; ! BinaryPrediction pred = ((BrownBag) bags[i]).calcPrediction(1.0); total += 1; for (int j= 0; j < indexes.length; j++) { int example = indexes[j]; examplesWithHyp[example] = true; double step = getStep(m_labels[example], m_hypPredictions[example]); --- 597,611 ---- boolean[] examplesWithHyp = new boolean[m_margins.length]; + int numExamplesWithHyps = 0; // Get all examples that have a hypothesis associated with them for (int i= 0; i < exampleIndex.length; i++) { int[] indexes= exampleIndex[i]; ! //BinaryPrediction pred = ((BrownBag) bags[i]).calcPrediction(1.0); total += 1; for (int j= 0; j < indexes.length; j++) { int example = indexes[j]; examplesWithHyp[example] = true; + numExamplesWithHyps += 1; double step = getStep(m_labels[example], m_hypPredictions[example]); *************** *** 611,615 **** for (int i=0; i < m_margins.length; i++) { if(!examplesWithHyp[i]){ ! int example = i; m_hypPredictions[example] = 0; double weight = m_weights[example]; --- 627,631 ---- for (int i=0; i < m_margins.length; i++) { if(!examplesWithHyp[i]){ ! int example = i; m_hypPredictions[example] = 0; double weight = m_weights[example]; *************** *** 619,622 **** --- 635,639 ---- potential += calculatePotential(m_margins[i]); } + System.out.println("Num Examples with predictions: " + numExamplesWithHyps); //updatePotential(exampleIndex); *************** *** 669,680 **** // Create a prediction array to accompany the exampleIndex array m_hypPredictions = new double[m_margins.length]; for (int i=0; i < exampleIndex.length; i++){ int[] index = exampleIndex[i]; BrownBag b = (BrownBag)bags[i]; for (int j=0; j < index.length; j++){ int example = index[j]; ! m_hypPredictions[example] = b.calcPrediction(1.0).getClassScores()[0]; } } --- 686,714 ---- + double[] totalWeights = new double[bags.length]; + int maxWeightIndex = 0; + double maxWeight = 0; + for (int i=0; i < bags.length; i++) { + double[] weights = bags[i].getWeights(); + for (int j=0; j < weights.length; j++) { + totalWeights[i] += weights[j]; + if (totalWeights[i] > maxWeight) { + maxWeight = totalWeights[i]; + maxWeightIndex = i; + } + } + } + + // Create a prediction array to accompany the exampleIndex array m_hypPredictions = new double[m_margins.length]; for (int i=0; i < exampleIndex.length; i++){ + if (ONE_SIDED_PREDICTION && i!= maxWeightIndex) + continue; int[] index = exampleIndex[i]; BrownBag b = (BrownBag)bags[i]; for (int j=0; j < index.length; j++){ int example = index[j]; ! m_hypPredictions[example] = b.calcPrediction(1.0,0.0).getClassScores()[0]; } } *************** *** 685,704 **** double gamma = getHypErr(bags, exampleIndex); ! if (m_isCostSensitive) { System.out.println("Solving positive example constraints"); ! double posAlpha = solve_constraints(gamma, m_posExamples); System.out.println("Solving negative example constraints"); ! double negAlpha = solve_constraints(gamma, m_negExamples); for (int i= 0; i < bags.length; i++) { ! p[i]= ((BrownBag) bags[i]).calcPrediction(posAlpha, negAlpha); System.out.println("p[" + i + "] = " + p[i]); } } else { ! double alpha = solve_constraints(gamma, m_examples); for (int i= 0; i < bags.length; i++) { ! p[i]= ((BrownBag) bags[i]).calcPrediction(alpha); ! System.out.println("p[" + i + "] = " + p[i]); } } return p; } --- 719,770 ---- double gamma = getHypErr(bags, exampleIndex); ! if (false) { //m_isCostSensitive) { System.out.println("Solving positive example constraints"); ! double[] sols = solve_constraints(gamma, m_posExamples); ! double posAlpha = sols[0]; ! double posDeltaT = sols[1]; ! System.out.println("Positive alpha, dt: " + posAlpha + "," + posDeltaT); System.out.println("Solving negative example constraints"); ! sols = solve_constraints(gamma, m_negExamples); ! double negAlpha = sols[0]; ! double negDeltaT = sols[1]; ! System.out.println("Negative alpha, dt: " + negAlpha + "," + negDeltaT); for (int i= 0; i < bags.length; i++) { ! p[i]= ((BrownBag) bags[i]).calcPrediction(posAlpha, posDeltaT, negAlpha, negDeltaT); System.out.println("p[" + i + "] = " + p[i]); } } else { ! double[] sols = solve_constraints(gamma, m_examples); ! double alpha = sols[0]; ! double dt = sols[1]; ! if (bags.length > 1) { ! BinaryBag [] bbags = new BinaryBag[2]; ! bbags[0] = (BinaryBag)bags[0]; ! bbags[1] = (BinaryBag)bags[1]; ! for (int i= 0; i < bags.length; i++) { ! if ( (bbags[0].getWeights()[0] > bbags[0].getWeights()[1] && bbags[1].getWeights()[0] > bbags[1].getWeights()[1]) ! || ! (bbags[0].getWeights()[0] < bbags[0].getWeights()[1] && bbags[1].getWeights()[0] < bbags[1].getWeights()[1]) ! || ! true ! ) ! System.out.print("Bag i: " + bags[i]); ! } ! } ! for (int i= 0; i < bags.length; i++) { ! if (i!=maxWeightIndex && ONE_SIDED_PREDICTION) { ! p[i]= ((BrownBag) bags[i]).calcPrediction(0,dt); ! } else { ! p[i]= ((BrownBag) bags[i]).calcPrediction(alpha,dt); ! } ! //System.out.print("Bag i: " + bags[i]); ! //System.out.println("p[" + i + "] = " + p[i]); } } + + for (int i=0; i<totalWeights.length; i++) + System.out.println("Totalweights[" + i + "]=" + totalWeights[i]); + return p; } *************** *** 725,727 **** --- 791,870 ---- } + + + + /** + * BrownBag is identical to BinaryBag, except for the method used to + * derive the value of prediction (alpha in the literature). BrownBag + * uses the value of alpha determined by BrownBoost and its variants. + * See comments for AdaBoost.BinaryBag. + * @author Aaron Arvey + */ + class BrownBag extends AdaBoost.BinaryBag{ + + protected BrownBag(int[] list) { + m_w= new double[2]; + reset(); + this.addExampleList(list); + } + + /** compute the binary prediction associated with this bag */ + public BinaryPrediction calcPrediction(double alpha) { + BinaryPrediction ret; + ret = new BinaryPrediction(m_w[1] > m_w[0] ? 1.0 : -1.0 ); + ret.scale(alpha); + return ret; + } + + /** compute the binary prediction associated with this bag */ + public BinaryPrediction calcPrediction(double alpha, double dt) { + //if (this instanceof BrownBag) + return calcPrediction(alpha); + //if (this instanceof BrownBag) + //return ((YabaBag)this).calcPrediction(alpha,dt); + } + + /** compute the binary prediction associated with this bag */ + public BinaryPrediction calcPrediction(double posAlpha, double posDeltaT, double negAlpha, double negDeltaT) { + BinaryPrediction ret; + if (m_w[1] > m_w[0]) { + ret = new BinaryPrediction(1.0); + ret.scale(posAlpha); + } else { + ret = new BinaryPrediction(-1.0); + ret.scale(negAlpha); + } + return ret; + } + + + /** Place holder to ensure that this function is not used in BrownBoost. */ + public BinaryPrediction calcPrediction(){ + //System.err.println("Need to have alpha for prediction in BrownBag.calcPrediction()!"); + return new BinaryPrediction(0); + } + + + /** default constructor */ + protected BrownBag() { + super(); + } + + + /** constructor that copies an existing bag */ + protected BrownBag(BrownBag bag) { + super(bag); + } + + + /** Output the weights in the bag */ + public String toString() { + String s= "BrownBag.\t w0=" + m_w[0] + "\t w1=" + m_w[1] + "\n"; + return s; + } + + + } /* End BrownBag */ + + } /* End BrownBoost Class */ Index: YabaBoost.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/YabaBoost.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** YabaBoost.java 23 Oct 2007 22:45:40 -0000 1.6 --- YabaBoost.java 24 Jan 2008 22:30:16 -0000 1.7 *************** *** 1,5 **** package jboost.booster; - import java.io.BufferedWriter; import java.io.FileWriter; --- 1,4 ---- *************** *** 72,75 **** --- 71,81 ---- /** + * The normalization constant for updating the score (might be alpha in Freund & Arvey 2008). + */ + protected double m_nc = 1.0; + protected double m_posNc = 1.0; + protected double m_negNc = 1.0; + + /** * A parameter indicating when we should stop the game. * Technically, this should be 0; however due to numerical instability *************** *** 77,89 **** * an approximation of the 0/1 loss instead of the exact 0/1 loss. */ ! 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; ! --- 83,87 ---- * an approximation of the 0/1 loss instead of the exact 0/1 loss. */ ! protected static final double FINISH_GAME_NOW = 0.02; *************** *** 95,102 **** */ protected static final double THETA_UPDATE_STEP = 0.02; /** ! * Default constructor just calls AdaBoost to ! * get everything initialized */ public YabaBoost() { --- 93,101 ---- */ protected static final double THETA_UPDATE_STEP = 0.02; + /** ! * Default constructor just calls AdaBoost to get everything ! * initialized */ public YabaBoost() { *************** *** 111,126 **** 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"); } m_c1 = c1; m_c2 = c2; m_theta = theta; m_origTheta = theta; m_initialPotential = calculatePotential(0,m_c); --- 110,127 ---- m_c = runtime; m_s = m_c; ! m_initialPotential = calculatePotential(0,m_c,NO_LABEL); } ! public void setParams(double c1, double c2, double theta, double nc) 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");*/ ! System.err.println("Bad yaba params!"); } m_c1 = c1; m_c2 = c2; m_theta = theta; + m_nc = nc; m_origTheta = theta; m_initialPotential = calculatePotential(0,m_c); *************** *** 128,164 **** ! public void setCostSensitiveParams(double pc, double pc1, double pc2, double ptheta, ! double nc, double nc1, double nc2, double ntheta) { m_posc = pc; m_posc1 = pc1; m_posc2 = pc2; m_posTheta = ptheta; m_posOrigTheta = ptheta; ! m_negc = pc; ! 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(); - } - - public void finalizeData() { double EPS = 0.01; ! if (m_c1 < EPS || m_c2 < EPS || m_theta < EPS || m_c < EPS) { System.err.println("Yaba params are bad!\nc:"+m_c+"\nc1:" +m_c1+"\nc2:"+m_c2+"\ntheta:"+m_theta+"\n"); ! System.exit(2); } m_initialPotential = calculatePotential(0,m_c); --- 129,169 ---- ! public void setCostSensitiveParams(double pc, double pc1, double pc2, double ptheta, double pnc, ! double nc, double nc1, double nc2, double ntheta, double nnc) { m_posc = pc; m_posc1 = pc1; m_posc2 = pc2; + m_posNc = pnc; m_posTheta = ptheta; m_posOrigTheta = ptheta; + m_posInitialPotential = calculatePotential(0.0,m_posc,POSITIVE_LABEL); + System.out.println("pc, pc1, pc2, pnc, ptheta, pos pot: " + pc + "," + pc1 + + "," + pc2 + "," + ptheta + "," + pnc + "," + + m_posInitialPotential); ! m_negc = nc; ! m_negc1 = nc1; ! m_negc2 = nc2; ! m_negNc = nnc; ! m_negTheta = ntheta; ! m_negOrigTheta = ntheta; ! m_negInitialPotential = calculatePotential(0.0,m_negc,NEGATIVE_LABEL); ! ! m_isCostSensitive = true; } public void finalizeData() { double EPS = 0.01; ! if (!m_isCostSensitive && (m_c1 < EPS || m_c2 < EPS || m_theta < EPS || m_c < EPS || m_nc < EPS)) { System.err.println("Yaba params are bad!\nc:"+m_c+"\nc1:" +m_c1+"\nc2:"+m_c2+"\ntheta:"+m_theta+"\n"); ! //System.exit(2); ! } else if (m_isCostSensitive && (m_posc1 < EPS || m_posc2 < EPS || m_posTheta < EPS || m_posc < EPS || m_posNc < EPS || ! m_negc1 < EPS || m_negc2 < EPS || m_negTheta < EPS || m_negc < EPS || m_negNc < EPS)) { ! System.err.println("Yaba cost sensitive params are bad!\nc:"+m_c+"\nc1:" ! +m_c1+"\nc2:"+m_c2+"\ntheta:"+m_theta+"\n"); ! ! //System.exit(2); } m_initialPotential = calculatePotential(0,m_c); *************** *** 168,172 **** + "\t m_c2: " + m_c2 + "\n" + "\t m_theta: " + m_theta + "\n" ! + "\t initial potential: " + m_initialPotential + "\n"; System.out.println(yabaout); --- 173,191 ---- + "\t m_c2: " + m_c2 + "\n" + "\t m_theta: " + m_theta + "\n" ! + "\t m_nc: " + m_nc + "\n" ! + "\t m_initialPotential: " + m_initialPotential + "\n" ! + "\t m_posc: " + m_posc + "\n" ! + "\t m_posc1: " + m_posc1 + "\n" ! + "\t m_posc2: " + m_posc2 + "\n" ! + "\t m_posTheta: " + m_posTheta + "\n" ! + "\t m_posNc: " + m_posNc + "\n" ! + "\t m_posInitialPotential: " + m_posInitialPotential + "\n" ! + "\t m_negc: " + m_negc + "\n" ! + "\t m_negc1: " + m_negc1 + "\n" ! + "\t m_negc2: " + m_negc2 + "\n" ! + "\t m_negTheta: " + m_negTheta + "\n" ! + "\t m_negNc: " + m_negNc + "\n" ! + "\t m_negInitialPotential: " + m_negInitialPotential + "\n" ! + "\t m_isCostSensitive: " + m_isCostSensitive + "\n" + "\n"; System.out.println(yabaout); *************** *** 205,218 **** step = getStep(m_labels[example], m_hypPredictions[example]); ! EPS = 0.0001; if (Math.abs(step) > EPS) { ! new_margin = (1-alpha)*margin + alpha*step; } else { new_margin = margin; } ! 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; --- 224,238 ---- step = getStep(m_labels[example], m_hypPredictions[example]); ! EPS = 0.000001; if (Math.abs(step) > EPS) { ! new_margin = MixedBinaryPrediction.updateMargin(margin, alpha, step, t, m_nc); } else { new_margin = margin; } ! new_weight = calculateWeight(new_margin, new_time_remaining, m_labels[example]); ! new_pot = calculatePotential(new_margin, new_time_remaining, m_labels[example]); ! orig_pot = calculatePotential(orig_margin, orig_time_remaining, m_labels[example]); ! //System.out.println("New weight is: " + new_weight); vars.B += new_weight*step; *************** *** 278,282 **** * @return alpha - An appropriate value of alpha that satisfies constraints. */ ! protected double solve_constraints(double hyp_err, int[] examples) { /* * If the game has a small amount of time remaining, quit now. --- 298,303 ---- * @return alpha - An appropriate value of alpha that satisfies constraints. */ ! protected double[] solve_constraints(double hyp_err, int[] examples) { ! /* * If the game has a small amount of time remaining, quit now. *************** *** 286,290 **** if( m_s < FINISH_GAME_NOW){ m_s = -1; ! return 0; } --- 307,311 ---- if( m_s < FINISH_GAME_NOW){ m_s = -1; ! return new double[] {0,0}; } *************** *** 308,311 **** --- 329,333 ---- double t=0.3; double alpha=0.1; + /* *************** *** 370,377 **** // Increment alpha alpha += alpha_step; - //System.out.print(" alpha: " + alpha); // Deal with boundary cases, keep margin normalized ! if(alpha < 0 || alpha > 1) { alpha = Math.round(alpha); alpha_step = -alpha_step; --- 392,398 ---- // Increment alpha alpha += alpha_step; // Deal with boundary cases, keep margin normalized ! if(alpha < -0.1 || alpha > 1) { alpha = Math.round(alpha); alpha_step = -alpha_step; *************** *** 464,470 **** if (t < 0) { - dump_everything(vars); System.err.println("The change in time is negtive!"); System.err.println("Outputting all data to outfile!"); System.exit(2); } --- 485,491 ---- if (t < 0) { System.err.println("The change in time is negtive!"); System.err.println("Outputting all data to outfile!"); + dump_everything(vars); System.exit(2); } *************** *** 480,484 **** m_lastAlpha = alpha; ! return alpha; } --- 501,505 ---- m_lastAlpha = alpha; ! return new double[] {alpha, t}; } *************** *** 503,514 **** double[] value = new double[] { -p, p }; int[] indexes = exampleIndex[i]; for (int j= 0; j < indexes.length; j++) { int example = indexes[j]; - double alpha = Math.abs(p); // Set margins to new margin // value[m_labels[example]] is equal to alpha*step double EPS = 0.0001; ! if (Math.abs(p) - m_lastAlpha > EPS) { System.err.println("Prediction was messed up!"); System.err.println("alpha was: " + m_lastAlpha); --- 524,537 ---- double[] value = new double[] { -p, p }; int[] indexes = exampleIndex[i]; + double alpha = Math.abs(p); + double dt = ((MixedBinaryPrediction)predictions[i]).getDeltaT(); + double step; for (int j= 0; j < indexes.length; j++) { int example = indexes[j]; // Set margins to new margin // value[m_labels[example]] is equal to alpha*step double EPS = 0.0001; ! if (Math.abs(Math.abs(p) - m_lastAlpha) > EPS) { System.err.println("Prediction was messed up!"); System.err.println("alpha was: " + m_lastAlpha); *************** *** 516,531 **** } m_oldMargins[example] = m_margins[example]; ! m_margins[example] = (1-alpha)*m_margins[example] ! + value[m_labels[example]]; ! ! if(Math.abs(m_margins[example]) > 1){ ! System.out.println("m_margins[" +example+ "]: " ! + m_margins[example] + " greater than 1!!!!"); ! } } } ! ! if (m_hypPredictions.length != m_margins.length || m_hypPredictions.length != m_numExamples) { System.err.println("WARNING: m_hypPredictions is not the same length as the margins"); } --- 539,549 ---- } m_oldMargins[example] = m_margins[example]; ! step = (value[m_labels[example]] >= 0) ? 1.0 : -1.0; ! m_margins[example] = MixedBinaryPrediction.updateMargin(m_margins[example], Math.abs(value[m_labels[example]]), step, dt, m_nc); } } ! ! if (m_hypPredictions == null || m_hypPredictions.length != m_margins.length || m_hypPredictions.length != m_numExamples) { System.err.println("WARNING: m_hypPredictions is not the same length as the margins"); } *************** *** 556,559 **** --- 574,578 ---- */ public double calculatePotential(double margin) { + //System.out.println("potential being called"); return calculatePotential(margin, m_s); } *************** *** 564,581 **** * @return weight of any example with the given margin */ ! public double calculateWeight(double margin, double time_remaining) { ! 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); ! 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; } --- 583,646 ---- * @return weight of any example with the given margin */ ! public double calculateWeight(double margin, double time_remaining){ ! return calculateWeight(margin, time_remaining, (short)NO_LABEL); ! } ! /** ! * @param margin ! * @param time time remaining in game ! * @param label the label of the example (for asymmetric weighting) ! * @return weight of any example with the given margin ! */ ! public double calculateWeight(double margin, double time_remaining, short label) { ! double ret; ! if (label==POSITIVE_LABEL && m_isCostSensitive) { ! ret = calculateWeight(margin, time_remaining, m_c, m_posc1, m_posc2, m_posTheta, m_posNc); ! } else if (label==NEGATIVE_LABEL && m_isCostSensitive) { ! ret = calculateWeight(margin, time_remaining, m_c, m_negc1, m_negc2, m_negTheta, m_negNc); ! } else { ! ret = calculateWeight(margin, time_remaining, m_c, m_c1, m_c2, m_theta, m_nc); ! } ! return ret; ! } ! ! ! ! /** ! * @param margin ! * @param time time remaining in game ! * @param c total time of game ! * @param c1 scale of mean ! * @param c2 scale of variance ! * @param theta mean of the final function ! * @param nc normalization constant ! * @return weight of any example with the given margin ! */ ! public double calculateWeight(double margin, double time_remaining, ! double c, double c1, double c2, ! double theta, double nc) { ! double s=0, mu=0, sd=0, norm=0, ret=0; ! s = c - time_remaining; ! mu = theta - c1* ( Math.exp(-s) - Math.exp(-c) ); ! sd = Math.sqrt(c2*(Math.exp(-2*s) - Math.exp(-2*c))) + FINISH_GAME_NOW; ! ! /** ! * To translate between notations (Freund & Arvey -> code ! * here): rho is c1, theta is theta, alpha is nc. ! */ ! if (USE_BETA_RHO) { ! double rho = c1; ! double alpha = nc; ! double t = s; ! mu = rho + Math.exp(-alpha*(1-t))*(theta - rho); ! sd = Math.sqrt( (Math.exp(2*alpha*(1-t)) - 1) / (2*alpha) ); } + norm = 1 / Math.sqrt(Math.PI * sd * sd); + ret = norm * Math.exp(- Math.pow((margin-mu)/sd,2)); + if (USE_CONFIDENCE) { + if (margin < mu) ret = 0; + else ret = 2*ret; + } return ret; } *************** *** 584,594 **** /** * @param margin * @return potential of example with given margin */ public double calculatePotential(double margin, double time_remaining) { ! 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; if (USE_CONFIDENCE) { pot = Math.min(2*pot, 1.0); --- 649,717 ---- /** * @param margin + * @param time_remaining * @return potential of example with given margin */ public double calculatePotential(double margin, double time_remaining) { ! return calculatePotential(margin, time_remaining, NO_LABEL); ! } ! ! /** ! * @param margin ! * @param time_remaining ! * @param label ! * @return potential of example with given margin ! */ ! public double calculatePotential(double margin, double time_remaining, short label) { ! double ret = 0; ! if (label==POSITIVE_LABEL && m_isCostSensitive) { ! ret = calculatePotential(margin, time_remaining, m_c, m_posc1, m_posc2, m_posTheta, m_posNc); ! } else if (label==NEGATIVE_LABEL && m_isCostSensitive) { ! ret = calculatePotential(margin, time_remaining, m_c, m_negc1, m_negc2, m_negTheta, m_negNc); ! } else { ! ret = calculatePotential(margin, time_remaining, m_c, m_c1, m_c2, m_theta, m_nc); ! } ! return ret; ! } ! ! /** ! * @param margin ! * @return potential of example with given margin ! */ ! double calculatePotential(double margin, double time_remaining, double c, double c1, double c2, double theta, double nc) { ! double s, mu, sd, pot; ! s = c - time_remaining; ! mu = theta - c1 * (Math.exp(-s) - Math.exp(-c)); ! sd = Math.sqrt(c2 * (Math.exp(-2*s) - Math.exp(-2*c))) + FINISH_GAME_NOW; ! ! /** ! * To translate between notations (Freund & Arvey -> code ! * here): rho is c1, theta is theta, alpha is nc. ! */ ! if (USE_BETA_RHO) { ! double rho = c1; ! double alpha = nc; ! double t = s; ! mu = rho + Math.exp(-alpha*(1-t))*(theta - rho); ! sd = Math.sqrt( (Math.exp(2*alpha*(1-t)) - 1) / (2*alpha) ); ! /* ! System.out.println("Using beta, rho potential"); ! System.out.println("Using beta, rho potentialb"); ! System.out.println("Using beta, rho potential"); ! System.out.println("Using beta, rho potentialb"); ! System.out.println("Using beta, rho potential"); ! System.out.println("Using beta, rho potentialb"); ! System.out.println("Using beta, rho potential"); ! System.out.println("Using beta, rho potentialb"); ! System.out.println("Using beta, rho potential"); ! System.out.println("Using beta, rho potentialb"); ! System.out.println("Using beta, rho potential"); ! System.out.println("Using beta, rho potentialb"); ! System.out.println("Using beta, rho potential"); ! System.out.println("Using beta, rho potentialb"); ! */ ! } ! ! pot = (1 - erf((margin-mu)/sd)) / 2; ! if (USE_CONFIDENCE) { pot = Math.min(2*pot, 1.0); *************** *** 612,616 **** public String getParamString() { ! String ret = String.format("YabaBoost 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; } --- 735,747 ---- public String getParamString() { ! String ret = String.format("YabaBoost s=%.4f c=%.4f c1=%.4f c2=%.4f theta=%.4f nc=%.4f " + ! "poss=%.4f negs=%.4f posc=%.4f negc=%.4f posc1=%.4f " + ! "negc1=%.4f posc2=%.4f negc2=%.4f posnc=%.4f negnc=%.4f " + ! "postheta=%.4f negtheta=%.4f confidence=%b " + ! "asymmetric=%b onesided=%b betarho=%b", ! m_s, m_c, m_c1, m_c2, m_theta, m_nc, ! -5.0, -5.0, m_posc, m_negc, m_posc1, m_negc1, m_posc2, m_negc2, ! m_posNc, m_negNc, m_posTheta, m_negTheta, ! USE_CONFIDENCE, m_isCostSensitive, ONE_SIDED_PREDICTION, USE_BETA_RHO); return ret; } *************** *** 635,640 **** public MixedBinaryPrediction calcPrediction(double alpha) { MixedBinaryPrediction ret = new MixedBinaryPrediction(0); try { ! ret = new MixedBinaryPrediction(m_w[1] > m_w[0] ? 1.0 : -1.0 ); } catch (NotNormalizedPredException e){ System.err.println(e.getStackTrace()); --- 766,777 ---- public MixedBinaryPrediction calcPrediction(double alpha) { MixedBinaryPrediction ret = new MixedBinaryPrediction(0); + return ret; + } + + /** compute the binary prediction associated with this bag */ + public MixedBinaryPrediction calcPrediction(double alpha, double dt) { + MixedBinaryPrediction ret = new MixedBinaryPrediction(0,0); try { ! ret = new MixedBinaryPrediction(m_w[1] > m_w[0] ? 1.0 : -1.0, dt); } catch (NotNormalizedPredException e){ System.err.println(e.getStackTrace()); *************** *** 695,699 **** protected MixedBinaryPrediction getZeroPred() { ! return new MixedBinaryPrediction(0); } --- 832,836 ---- protected MixedBinaryPrediction getZeroPred() { ! return new MixedBinaryPrediction(0,0); } Index: AdaBoost.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/AdaBoost.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** AdaBoost.java 23 Oct 2007 22:45:40 -0000 1.4 --- AdaBoost.java 24 Jan 2008 22:30:16 -0000 1.5 *************** *** 43,46 **** --- 43,53 ---- protected int m_numNegExamples; + /** Constant for positive label for cost sensitive stuff */ + protected final short POSITIVE_LABEL = 0; + /** Constant for negative label for cost sensitive stuff */ + protected final short NEGATIVE_LABEL = 1; + /** Constant for non cost sensitive stuff */ + protected final short NO_LABEL = -99; + /** sampling weights for the examples */ protected double[] m_sampleWeights; *************** *** 101,105 **** m_numExamples++; m_tmpList.add(new TmpData(index, (short) l, weight)); ! if (l==1) m_numPosExamples++; } else { failed= "AdaBoost.addExample received index " + index + ", when it expected index " + --- 108,112 ---- m_numExamples++; m_tmpList.add(new TmpData(index, (short) l, weight)); ! if (l==POSITIVE_LABEL) m_numPosExamples++; } else { failed= "AdaBoost.addExample received index " + index + ", when it expected index " + *************** *** 160,167 **** m_weights[index]= m_oldWeights[index]= defaultWeight; m_labels[index]= a.getLabel(); ! if (a.getLabel()==1) m_posExamples[m_posIndex++] = index; ! else m_negExamples[m_negIndex++] = index; m_sampleWeights[index]= a.getWeight(); } --- 167,179 ---- m_weights[index]= m_oldWeights[index]= defaultWeight; m_labels[index]= a.getLabel(); ! if (a.getLabel()==POSITIVE_LABEL) m_posExamples[m_posIndex++] = index; ! else if (a.getLabel()==NEGATIVE_LABEL) m_negExamples[m_negIndex++] = index; + else { + System.err.println("Label of example is unknown to adaboost"); + System.exit(2); + } + m_sampleWeights[index]= a.getWeight(); } *************** *** 311,314 **** --- 323,340 ---- */ public Prediction[] getPredictions(Bag[] bags, int[][] exampleIndex) { + // Code to see how often the splitting partition predicts the same way on both sides + /* + if (bags.length > 1) { + BinaryBag [] bbags = new BinaryBag[2]; + bbags[0] = (BinaryBag)bags[0]; + bbags[1] = (BinaryBag)bags[1]; + for (int i= 0; i < bags.length; i++) { + if ( (bbags[0].getWeights()[0] > bbags[0].getWeights()[1] && bbags[1].getWeights()[0] > bbags[1].getWeights()[1]) + || + (bbags[0].getWeights()[0] < bbags[0].getWeights()[1] && bbags[1].getWeights()[0] < bbags[1].getWeights()[1]) + ) + System.out.print("Bag i: " + bags[i]); + } + }*/ return getPredictions(bags); } *************** *** 408,414 **** class BinaryBag extends Bag { - /** total weight for examples of each label */ - protected double[] m_w; - /** default constructor */ protected BinaryBag() { --- 434,437 ---- |
From: Aaron A. <aa...@us...> - 2008-01-19 04:13:53
|
Update of /cvsroot/jboost/jboost/scripts In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv30878 Modified Files: surfing.py Log Message: plot the symetric cost surfing graph Index: surfing.py =================================================================== RCS file: /cvsroot/jboost/jboost/scripts/surfing.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** surfing.py 23 Oct 2007 23:52:26 -0000 1.4 --- surfing.py 19 Jan 2008 04:13:49 -0000 1.5 *************** *** 39,43 **** def get_weight_line(params, start, end, max_bin): weights = [] ! s = c= c1 = c2 = theta = 0 confidence = False if(params[0] == 'BrownBoost'): --- 39,43 ---- def get_weight_line(params, start, end, max_bin): weights = [] ! s = c = c1 = c2 = theta = 0 confidence = False if(params[0] == 'BrownBoost'): *************** *** 45,52 **** s = float(params[2]) #time remaining elif(params[0] == 'NormalBoost'): 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]) --- 45,53 ---- s = float(params[2]) #time remaining elif(params[0] == 'NormalBoost'): + t = float(params[2]) # time left c = float(params[1]) ! if t < 0: ! t = 0 ! s = c-t #time played c1 = float(params[3]) c2 = float(params[4]) *************** *** 59,78 **** x = start for i in range(0,num_steps): ! mu = var = 0 ! if params[0] == 'BrownBoost': ! mu = -s ! var = c ! elif params[0] == 'NormalBoost': ! 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 ! if (confidence): ! p = min(2*p, 1) weights.append((x,y,p)) x += step - return weights --- 60,88 ---- x = start for i in range(0,num_steps): ! if params[0] == 'BrownBoost' or params[0] == 'NormalBoost': ! mu = var = 0 ! if s < 0: ! s = 0.0001 ! if params[0] == 'BrownBoost': ! mu = -s ! var = c ! elif params[0] == 'NormalBoost': ! mu = theta - c1 * (math.exp(-s) - math.exp(-c)) ! var = c2 * (math.exp(-2*s) - math.exp(-2*c)) + 0.02 ! ! 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 ! if (confidence): ! p = min(2*p, 1) ! elif params[0] == 'AdaBoost': ! y = math.exp(-x) ! p = y ! elif params[0] == 'LogLossBoost': ! y = 1.0/(1+math.exp(x)) ! p = math.log(1.0 + math.exp(-x)) ! weights.append((x,y,p)) x += step return weights *************** *** 159,166 **** epsoutlines.append('set terminal post\n') epsoutlines.append('set output \'surfing%05d.eps\'\n' % (iter)) ! epsoutlines.append('set title "'+ params[0] + ' ' + 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') ! if params[0]=='NormalBoost': epsoutlines.append('set xrange [-1:1]\n') epsoutlines.append('set yrange [0:1]\n') --- 169,179 ---- epsoutlines.append('set terminal post\n') epsoutlines.append('set output \'surfing%05d.eps\'\n' % (iter)) ! if params[0] == 'BrownBoost' or params[0] == 'NormalBoost': ! epsoutlines.append('set title "'+ params[0] + ' ' + datafile + ' Surfing: Time Remaining ' + str(params[2]) + '" font "Times,20"\n') ! if params[0] == 'AdaBoost' or params[0] == 'LogLossBoost': ! epsoutlines.append('set title "'+ params[0] + ' ' + 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] == 'NormalBoost': epsoutlines.append('set xrange [-1:1]\n') epsoutlines.append('set yrange [0:1]\n') *************** *** 246,251 **** usage() sys.exit(2) ! if(booster==None or (booster!='NormalBoost' and booster!='BrownBoost')): ! print 'Only accepts `NormalBoost` and `BrownBoost` boost.' usage() sys.exit(2) --- 259,264 ---- usage() sys.exit(2) ! if(booster==None or (booster!='NormalBoost' and booster!='BrownBoost' and booster!='AdaBoost' and booster!='LogLossBoost')): ! print 'Only accepts the same boosters (capitilization and all) from JBoost.' usage() sys.exit(2) *************** *** 263,267 **** for iter in range(0, num_iterations+1, framerate): boost_params_str = string.split(data[iter*(num_elements+1)], SEPARATOR)[2].split('boosting_params=')[1] ! if (booster=='BrownBoost'): search_str = 'r=' total_time = boost_params_str[boost_params_str.index(search_str)+2 :].split(' ')[0] --- 276,280 ---- for iter in range(0, num_iterations+1, framerate): boost_params_str = string.split(data[iter*(num_elements+1)], SEPARATOR)[2].split('boosting_params=')[1] ! if booster=='BrownBoost': search_str = 'r=' total_time = boost_params_str[boost_params_str.index(search_str)+2 :].split(' ')[0] *************** *** 269,273 **** time_left = boost_params_str[boost_params_str.index(search_str)+2 :].split(' ')[0] params = ('BrownBoost', total_time, time_left) ! if (booster=='NormalBoost'): search_str = 'c=' total_time = boost_params_str[boost_params_str.index(search_str)+2 :].split(' ')[0] --- 282,286 ---- time_left = boost_params_str[boost_params_str.index(search_str)+2 :].split(' ')[0] params = ('BrownBoost', total_time, time_left) ! elif booster=='NormalBoost': search_str = 'c=' total_time = boost_params_str[boost_params_str.index(search_str)+2 :].split(' ')[0] *************** *** 280,283 **** --- 293,317 ---- search_str = 'theta=' theta = boost_params_str[boost_params_str.index(search_str)+len(search_str) :].split(' ')[0] + search_str = 'posc=' + posc = boost_params_str[boost_params_str.index(search_str)+len(search_str) :].split(' ')[0] + search_str = 'negc=' + negc = boost_params_str[boost_params_str.index(search_str)+len(search_str) :].split(' ')[0] + search_str = 'posc1=' + posc1 = boost_params_str[boost_params_str.index(search_str)+len(search_str) :].split(' ')[0] + search_str = 'negc1=' + negc1 = boost_params_str[boost_params_str.index(search_str)+len(search_str) :].split(' ')[0] + search_str = 'posc2=' + posc2 = boost_params_str[boost_params_str.index(search_str)+len(search_str) :].split(' ')[0] + search_str = 'negc2=' + negc2 = boost_params_str[boost_params_str.index(search_str)+len(search_str) :].split(' ')[0] + search_str = 'postheta=' + postheta = boost_params_str[boost_params_str.index(search_str)+len(search_str) :].split(' ')[0] + search_str = 'negtheta=' + negtheta = boost_params_str[boost_params_str.index(search_str)+len(search_str) :].split(' ')[0] + search_str = 'asymmetric=' + asymmetric = boost_params_str[boost_params_str.index(search_str)+len(search_str) :].split(' ')[0] + use_asym = False + if asymmetric == 'true' or asymmetric == 'True' or asymmetric == '1': + use_asym = True search_str = 'confidence=' confidence = boost_params_str[boost_params_str.index(search_str)+len(search_str) :].split(' ')[0] *************** *** 286,289 **** --- 320,325 ---- use_conf = True params = ('NormalBoost', total_time, time_left, c1, c2, theta, use_conf) + else: + params = (booster,) lines = [x for x in data[iter*(num_elements+1)+1:(iter+1)*(num_elements+1)]] write_gnuplot(lines, iter, datafile, params) |
From: Aaron A. <aa...@us...> - 2007-12-17 00:36:35
|
Update of /cvsroot/jboost/jboost/src/jboost/examples In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv14785 Added Files: BooleanAttribute.java BooleanDescription.java Log Message: Adding another type, boolean --- NEW FILE: BooleanAttribute.java --- package jboost.examples; /** Represents a single real valued attribute */ public class BooleanAttribute extends Attribute { private boolean value; public BooleanAttribute(boolean value) {this.value=value; setDefined();} public BooleanAttribute() { setDefined(false);} public boolean getValue() {return value;} public String toString() { return this.isDefined() ? String.valueOf(value) : "undefined"; } } --- NEW FILE: BooleanDescription.java --- package jboost.examples; import jboost.controller.Configuration; import jboost.tokenizer.BadAttException; /** * the description for number attributes. */ class BooleanDescription extends AttributeDescription { BooleanDescription(String name, Configuration c) throws ClassNotFoundException { attributeName = name; attributeClass = Class.forName("jboost.examples.BooleanAttribute"); // 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); order=c.getBool("order",true); } /** checks format of string in datafile and converts to int * * 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 BooleanAttribute()); string=string.trim(); if(string.length()==0) return(new BooleanAttribute()); boolean att = true; // initialized because try complains otherwise. try { if(string.equals("0") || string.toLowerCase().equals("false")) att = false; } catch (NumberFormatException e) { System.err.println(string + " is not a boolean."); throw new BadAttException(string+" is not a boolean",0,0); } return new BooleanAttribute (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+=((BooleanAttribute)attr).toString(); return(retval); } } |
From: Aaron A. <aa...@us...> - 2007-12-13 07:41:46
|
Update of /cvsroot/jboost/jboost/src/jboost/booster In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv31054 Modified Files: MixedBinaryPrediction.java Log Message: New normalization technique based on dt instead of exact convolution Index: MixedBinaryPrediction.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/MixedBinaryPrediction.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** MixedBinaryPrediction.java 2 Oct 2007 02:32:07 -0000 1.3 --- MixedBinaryPrediction.java 13 Dec 2007 07:41:39 -0000 1.4 *************** *** 5,9 **** /** ! * A binary normalized predictor. See NoramlizedPrediction * * @author Aaron Arvey --- 5,9 ---- /** ! * A binary normalized predictor. See NormalizedPrediction * * @author Aaron Arvey *************** *** 11,34 **** 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(); ! 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; } --- 11,36 ---- class MixedBinaryPrediction extends BinaryPrediction implements NormalizedPrediction{ ! protected double deltaT; ! protected double normalizingConstant; + public MixedBinaryPrediction() {super();} ! public MixedBinaryPrediction(double p) ! throws NotNormalizedPredException { ! throw new NotNormalizedPredException("MixedBinaryPrediction: Need to normalize based on time!"); } ! public MixedBinaryPrediction(double p, double dt, double nc) ! throws NotNormalizedPredException { super(); ! deltaT = dt; prediction=p; + normalizingConstant = nc; } + + public Object clone(){ ! Object a = new MixedBinaryPrediction(prediction, deltaT); return a; } *************** *** 46,54 **** // 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; } --- 48,58 ---- // The prediction p is for h_t double alpha = ((MixedBinaryPrediction) p).prediction; ! prediction = Math.exp(-dt) * 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; } *************** *** 75,79 **** public boolean equals(Prediction other) { MixedBinaryPrediction bp= (MixedBinaryPrediction) other; ! return (prediction == bp.prediction); } --- 79,83 ---- public boolean equals(Prediction other) { MixedBinaryPrediction bp= (MixedBinaryPrediction) other; ! return (prediction == bp.prediction && dt == bp.dt && normalizingConstant == bp.normalizingConstant); } *************** *** 83,87 **** public String cPreamble() { ! System.out.println("Prediction::cPreamble not supported."); System.exit(2); return --- 87,91 ---- public String cPreamble() { ! System.out.println("Prediction::cPreamble not supported for 'mixed' or normalized predictions."); System.exit(2); return *************** *** 94,98 **** public String javaPreamble() { ! System.out.println("Prediction::javaPreamble not supported."); System.exit(2); return "" --- 98,102 ---- public String javaPreamble() { ! System.out.println("Prediction::javaPreamble not supported for 'mixed' or normalized predictions."); System.exit(2); return "" |
From: Aaron A. <aa...@us...> - 2007-12-13 07:21:15
|
Update of /cvsroot/jboost/jboost/src/jboost/booster In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv22919 Modified Files: BrownBoost.java Log Message: Added pos and neg values for m_s Index: BrownBoost.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/BrownBoost.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** BrownBoost.java 23 Oct 2007 22:45:40 -0000 1.8 --- BrownBoost.java 13 Dec 2007 07:21:05 -0000 1.9 *************** *** 28,33 **** --- 28,41 ---- protected double m_s; + /** In case we ever want to make BrownBoost cost sensitive. Also useful for Yaba. */ + protected double m_poss; + protected double m_negs; + /** The potential loss of each example at the begining of the game. */ protected double m_initialPotential; + + /** The potential loss of each example at the begining of the game. */ + protected double m_posInitialPotential; + protected double m_negInitialPotential; /** The last value of alpha */ *************** *** 468,471 **** --- 476,507 ---- + + /** output AdaBoost contents as a human-readable string */ + public String toString() { + String s= + "BrownBoost. No of examples = " + + m_numExamples + + ", m_epsilon = " + + m_epsilon; + s += "\nindex\tmargin\tweight\told weight\tlabel\n"; + NumberFormat f= new DecimalFormat("0.00"); + for (int i= 0; i < m_numExamples; i++) { + s += " " + + i + + " \t " + + f.format(m_margins[i]) + + " \t " + + f.format(m_weights[i]) + + " \t " + + f.format(m_oldWeights[i]) + + " \t" + + f.format(m_sampleWeights[i]) + "\t\t" + + m_labels[i] + + "\n"; + } + return s; + } + + /** * BrownBag is identical to BinaryBag, except for the method used to *************** *** 608,615 **** */ public Prediction[] getPredictions(Bag[] bags, int[][] exampleIndex) { ! boolean bagsAreWeightless = true; for (int i=0; i < bags.length; i++) { if (!bags[i].isWeightless()) { ! bagsAreWeightless = false; } } --- 644,652 ---- */ public Prediction[] getPredictions(Bag[] bags, int[][] exampleIndex) { ! ! boolean allBagsAreWeightless = true; for (int i=0; i < bags.length; i++) { if (!bags[i].isWeightless()) { ! allBagsAreWeightless = false; } } *************** *** 624,628 **** * any more iterations. */ ! if (bagsAreWeightless || m_s < 0) { for (int i=0; i < bags.length; i++) { p[i] = getZeroPred(); --- 661,665 ---- * any more iterations. */ ! if (allBagsAreWeightless || m_s < 0) { for (int i=0; i < bags.length; i++) { p[i] = getZeroPred(); |
From: Aaron A. <aa...@us...> - 2007-12-13 01:31:19
|
Update of /cvsroot/jboost/jboost/scripts In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv18895 Modified Files: resample.py Log Message: This script is pretty hacky Index: resample.py =================================================================== RCS file: /cvsroot/jboost/jboost/scripts/resample.py,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** resample.py 16 May 2007 04:06:02 -0000 1.1.1.1 --- resample.py 13 Dec 2007 01:31:14 -0000 1.2 *************** *** 11,15 **** def usage(): print 'Usage: nfold.py --k=N --label=STRING --train=TRAINFILE' ! print ' --k=N times to resample' print ' --train=TRAINFILE the training file to oversample' print ' --label=STRING the label to resample (note that this needs to be a unique identifier,' --- 11,16 ---- def usage(): print 'Usage: nfold.py --k=N --label=STRING --train=TRAINFILE' ! print ' --k=N integer, times to resample integer' ! print ' --p=R number in [0,1] prob to keep nonlabel examples' print ' --train=TRAINFILE the training file to oversample' print ' --label=STRING the label to resample (note that this needs to be a unique identifier,' *************** *** 20,47 **** # a further slight speed-up on my box # is to map a bound-method: ! def sort_dict(d): keys = d.keys() vals = d.keys() ! keys.sort(lambda x,y : y-x) return [(key,d[key]) for key in keys] ! def generateFile(trainfile, oversample, labelstr): ! # XXX: put in description ! ! # load data and shuffle it f= file(trainfile, 'r') data= f.readlines() f.close() add_lines = {} ! i = 0 for line in data: end = len(line) ! if(line[end-4:end-1].rstrip() == ' 1;'): add_lines[i] = line i = i + 1 - add_lines = sort_dict(add_lines) for (key, val) in add_lines: --- 21,56 ---- # a further slight speed-up on my box # is to map a bound-method: ! def sort_dict(d, reverse=False): keys = d.keys() vals = d.keys() ! if (reverse): ! keys.sort(lambda x,y : y-x) ! else: ! keys.sort(lambda x,y : x-y) return [(key,d[key]) for key in keys] ! def generateFile(trainfile, oversample, undersample, labelstr): f= file(trainfile, 'r') data= f.readlines() f.close() + add_lines = {} ! num_positive_examples = 0 i = 0 for line in data: end = len(line) ! if line[end-4:end-1].rstrip() == ' 1;': add_lines[i] = line + num_positive_examples += 1 + elif line[end-4:end-1].rstrip() == '-1;': + # do nothing + x = 0 + else: + print 'You clearly think this script was well written... you are mistaken...' + usage() + sys.exit(2) i = i + 1 add_lines = sort_dict(add_lines) for (key, val) in add_lines: *************** *** 49,56 **** data.insert(key,val) trainsuffix= '.train' oversample = oversample + 1 ! tfilename = trainfile + '.' + str(oversample) + trainsuffix tfile= file(tfilename, 'w') tfile.writelines(data) --- 58,100 ---- data.insert(key,val) + + del_lines = {} + num_negative_examples = 0 + i = 0 + for line in data: + end = len(line) + if line[end-4:end-1].rstrip() == ' 1;': + # do nothing + x = 0 + elif line[end-4:end-1].rstrip() == '-1;': + del_lines[i] = 'd' + num_negative_examples += 1 + else: + print 'You clearly think this script was well written... you are mistaken...' + usage() + sys.exit(2) + i = i + 1 + + del_lines = sort_dict(del_lines, True) + random.seed(107) + num_lines_deleted = 0 + for (key, val) in del_lines: + r = random.random() + if r > undersample: + num_lines_deleted += 1; + data.pop(key) + + print 'Original number of examples:' + print '\tNegative examples:', num_negative_examples + print '\tPositive examples:', num_positive_examples + print 'After sampling:' + print '\tNegative examples:', num_negative_examples - num_lines_deleted + print '\tPositive examples:', num_positive_examples * (oversample + 1) + print 'Expected num lines deleted:', num_negative_examples * (1 - undersample) + print 'Actual num lines deleted:', num_lines_deleted trainsuffix= '.train' oversample = oversample + 1 ! tfilename = trainfile + '.' + str(oversample) + '.' + str(undersample) + trainsuffix tfile= file(tfilename, 'w') tfile.writelines(data) *************** *** 60,70 **** def main(): - # Usage: - - - try: opts, args = getopt.getopt(sys.argv[1:],'' , ! ['k=','train=','label=']) except getopt.GetoptError: print 'resample.py: Illegal argument\n' --- 104,110 ---- def main(): try: opts, args = getopt.getopt(sys.argv[1:],'' , ! ['k=','train=','label=','p=']) except getopt.GetoptError: print 'resample.py: Illegal argument\n' *************** *** 73,82 **** # parse options ! trainfile = k = label = None for opt,arg in opts: if (opt == '--train'): trainfile = arg elif (opt == '--k'): ! k = float(arg) elif (opt == '--label'): label = arg --- 113,124 ---- # parse options ! trainfile = k = p = label = None for opt,arg in opts: if (opt == '--train'): trainfile = arg elif (opt == '--k'): ! k = int(arg) ! elif (opt == '--p'): ! p = float(arg) elif (opt == '--label'): label = arg *************** *** 86,98 **** ! if (trainfile==None or k==None): usage() sys.exit(2) ! p = k - int(k) k = int(k) - 1 print 'Oversample by', k print 'Prob sample', p ! generateFile(trainfile, k, label) --- 128,158 ---- ! if trainfile==None: ! print 'Must specify file for resampling' usage() sys.exit(2) ! if k==None and p==None: ! print 'Must specify over/under sample quanitity' ! usage() ! sys.exit(2) ! ! if not k==None and k < 2: ! print 'k must be larger than 2 for anything to happen' ! sys.exit(2) ! ! if not p==None and p > 1: ! print 'p must be less than 1 for anything to happen' ! sys.exit(2) ! ! if p==None: ! p = 1 ! if k==None: ! k = 1 ! k = int(k) - 1 print 'Oversample by', k print 'Prob sample', p ! generateFile(trainfile, k, p, label) |
From: Aaron A. <aa...@us...> - 2007-12-13 01:30:37
|
Update of /cvsroot/jboost/jboost/scripts In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv18494 Modified Files: atree2dot2ps.pl Log Message: MultiPredictions now handled Index: atree2dot2ps.pl =================================================================== RCS file: /cvsroot/jboost/jboost/scripts/atree2dot2ps.pl,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** atree2dot2ps.pl 16 Oct 2007 02:02:27 -0000 1.5 --- atree2dot2ps.pl 13 Dec 2007 01:30:27 -0000 1.6 *************** *** 14,19 **** print "$0 usage: \n"; print "\t -i (--info) file.info \t File containing runtime information (required) \n"; 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"; --- 14,20 ---- print "$0 usage: \n"; print "\t -i (--info) file.info \t File containing runtime information (required) \n"; + print "\t -s (--spec) file.spec \t Spec file (optional, will default to spec file in info file) \n"; print "\t -t (--tree) file.tree \t File containing the ADTree in text format (required) \n"; ! print "\t -d (--dir) directory \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"; *************** *** 29,32 **** --- 30,34 ---- $dirname = "."; $infofilename = ""; + $specfilename = ""; $filename = ""; $threshold = 0; *************** *** 37,40 **** --- 39,43 ---- if ( @ARGV > 0 ) { GetOptions ('i|info=s' => \$infofilename, + 's|spec=s' => \$specfilename, 't|tree=s' => \$filename, 'd|dir=s' => \$dirname, *************** *** 71,74 **** --- 74,97 ---- $graphtitle .= " | "; + + if ($specfilename eq "") { + while ($line = <INFO>) { + if ($line =~ /specFilename = (.*).*/) { + $specfilename = $1; + } + } + } + + print "Spec File: '$specfilename'\n"; + open(SPEC, "$dirname/$specfilename") || die "could not open spec file: $specFilename\n"; + + while ($line = <SPEC>) { + if ($line =~ /labels.*\((.*)\).*/) { + @labels = split(/,/, $1); + } + } + print "Labels: @labels\n"; + $numLabels = @labels; + $filename= $dirname . "/" . $filename; *************** *** 77,92 **** open(OUT,">$filename.$threshold.dot"); ! print "running atree2dot2ps.pl ".join(" ",@ARGV).". generating $filename.$threshold.{dot,ps,pdf}\n"; print OUT "digraph G \{\n"; print OUT "size=\"10,7.5\";\n"; ! print OUT "orientation=\"landscape\";\n"; print OUT "ratio=auto;\n"; print OUT "center=TRUE;\n"; - - $last_iter = 0; - while($line = <FILE>) { if($line =~ /^(\d*)\t\[([^\]]*)\] Splitter = (.*)$/) { --- 100,114 ---- open(OUT,">$filename.$threshold.dot"); ! print "Running atree2dot2ps.pl ".join(" ",@ARGV).".\n"; ! print "Generating $filename.$threshold.{dot,ps,pdf}\n"; print OUT "digraph G \{\n"; print OUT "size=\"10,7.5\";\n"; ! #print OUT "orientation=\"landscape\";\n"; ! print OUT "rotate=\"90\";\n"; print OUT "ratio=auto;\n"; print OUT "center=TRUE;\n"; $last_iter = 0; while($line = <FILE>) { if($line =~ /^(\d*)\t\[([^\]]*)\] Splitter = (.*)$/) { *************** *** 99,124 **** } 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\)= (.*)/) { $type = "predictor"; $iteration = $1; $index = $2; $label = $3; ! $label =~ s/(\d\.\d{3}).*/$1/; ! if($fliplabels) { ! $label = -$label; } ! print "$type, $index, $label\n"; ! } ! else { chop $line; next; --- 121,165 ---- } if ($splitType =~ /InequalitySplitter/ && $truncatesplits) { ! $label =~ /(.*)(<|>)\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 "line: $line\n"; ! #print "$type, $index, $label, $splitType\n"; } ! } elsif($line =~ /^(\d*)\t\[([^\]]*)\].*prediction.*= (.*)/) { $type = "predictor"; $iteration = $1; $index = $2; $label = $3; ! #print "label: $label\n"; ! $predType = $3; ! #print "predType: $predType\n"; ! if ($predType =~ /MultiPrediction/) { ! $label = ""; ! for ($i=0; $i<$numLabels; $i++) { ! $line = <FILE>; ! if ($line =~ /^.*prediction.*= (.*)/) { ! $pred = $1; ! } ! if ($fliplabels) { ! $pred = -$pred; ! } ! $label .= @labels[$i] . ": " . $pred . "\\n"; ! } ! #print "label: $label \n"; ! } else { ! $label =~ s/(\d\.\d{3}).*/$1/; ! #print "label: $label\n"; ! if($fliplabels) { ! $label = -$label; ! } } ! #print "$type, $predType, $index, $label\n"; ! } else { ! #print "Line ignored: $line"; chop $line; next; *************** *** 164,168 **** #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"); --- 205,209 ---- #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"); |
From: Aaron A. <aa...@us...> - 2007-12-12 23:51:18
|
Update of /cvsroot/jboost/jboost/scripts In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv11316 Modified Files: error.py Log Message: Can now show separate error for positive and negative examples Index: error.py =================================================================== RCS file: /cvsroot/jboost/jboost/scripts/error.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** error.py 23 Oct 2007 22:50:42 -0000 1.4 --- error.py 12 Dec 2007 23:50:29 -0000 1.5 *************** *** 12,36 **** print '\t--bound show the bound on training error' print '\t--separate separate the positive and negative examples' ! print '\t--scores=score_file the score file (only needed if --separate used)' ! print '\t--margins=marg_file the margin file (only needed if --separate used)' ! def do_separate(score_filename, margin_filename): ! print 'Parsing scores file' ! f = open(score_filename,'r') ! lines = f.readlines() ! f.close() ! ! read_iter = False ! data = [] ! for line in lines: ! line = line.strip() ! if (line[:8] =='End time'): ! break ! if (read_iter): ! data.append(get_score(line)) ! ! --- 12,88 ---- print '\t--bound show the bound on training error' print '\t--separate separate the positive and negative examples' ! print '\t--boost-info=file The boosting.info file for a data set' ! SEPARATOR = ':' ! def get_margin(line): ! m = line.split(SEPARATOR)[1] ! m.replace(']','') ! m.replace(';','') ! m.replace(SEPARATOR,'') ! m.replace(' ','') ! m.replace('\t','') ! return float(m) ! ! def get_score(line): ! m = line.split(SEPARATOR)[2] ! m.replace(']','') ! m.replace(';','') ! m.replace(SEPARATOR,'') ! m.replace(' ','') ! m.replace('\t','') ! return float(m) + def getErrorsSingleIter(data): + tp = 0 + fp = 0 + tn = 0 + fn = 0 + + scores = map(get_score, data) + margins = map(get_margin, data) + for score, margin in zip(scores, margins): + if score < 0 and margin < 0: + fn += 1 + if score < 0 and margin > 0: + tn += 1 + if score > 0 and margin < 0: + fp += 1 + if score > 0 and margin > 0: + tp += 1 + return (tp,fp,tn,fn) + + def getErrors(boostfilename): + f= open(boostfilename,'r') + data= f.readlines() + f.close() + score_elements = int((string.split(data[0],SEPARATOR))[1].split('=')[1]) + num_iterations = int((string.split(data[-score_elements-1],SEPARATOR))[0].split('=')[1]) + print num_iterations + + errors = [] + for iter in range(num_iterations+1): + tp,fp,tn,fn = getErrorsSingleIter([x for x in data[iter*(score_elements+1)+1:(iter+1)*(score_elements+1)]]) + print iter,tp,fp,tn,fn + ret = {} + if tp + fn > 0: + ret['recall'] = ret['sensitivity'] = float(tp) / (tp + fn) + else: + ret['recall'] = ret['sensitivity'] = 0 + if tp + fp > 0: + ret['precision'] = float(tp) / (tp + fp) + else: + ret['precision'] = 0 + if fp + tn > 0: + ret['fpr'] = float(fp) / (fp + tn) + else: + ret['fpr'] = 0 + ret['specificity'] = 1 - ret['fpr'] + ret['neg_err'] = ret['fpr'] + ret['pos_err'] = 1 - ret['sensitivity'] + ret['err'] = float(fp+fn) / (fp+tp+fn+tn) + ret['iter'] = iter + errors.append(ret) + return errors *************** *** 39,53 **** try: ! opts, args= getopt.getopt(sys.argv[1:], '', ['info=','logaxis','bound','separate','scores=','margins=']) except getopt.GetoptError: usage() sys.exit(2) ! info_filename = logaxis = showbound = show_separate = margin_filename = score_filename = None for opt,arg in opts: if (opt == '--info'): info_filename = arg ! if (opt == '--margins'): ! margin_filename = arg if (opt == '--info'): score_filename = arg --- 91,105 ---- try: ! opts, args= getopt.getopt(sys.argv[1:], '', ['info=','logaxis','bound','separate','boost-info=']) except getopt.GetoptError: usage() sys.exit(2) ! info_filename = logaxis = showbound = show_separate = boost_filename = None for opt,arg in opts: if (opt == '--info'): info_filename = arg ! if (opt == '--boost-info'): ! boost_filename = arg if (opt == '--info'): score_filename = arg *************** *** 60,69 **** ! if (show_separate and (margin_filename==None or score_filename==None)): print 'ERROR: Need to specify score and margin file if showing positive and negative elements separately' usage() sys.exit(2) ! if(info_filename == None): print 'ERROR: Need to specify info file' usage() --- 112,121 ---- ! if show_separate and boost_filename==None: print 'ERROR: Need to specify score and margin file if showing positive and negative elements separately' usage() sys.exit(2) ! if info_filename == None: print 'ERROR: Need to specify info file' usage() *************** *** 100,115 **** outlines = [] for line in data: ! out = '' ! out += line['iter'] + ' ' ! out += line['train'] + ' ' ! out += line['test'] + ' ' if (showbound): out += line['bound'] + ' ' outlines.append(out+'\n') - f = open('error.dat', 'w') f.writelines(outlines) f.close() outlines = [] --- 152,173 ---- outlines = [] for line in data: ! out = line['iter'] + ' ' + line['train'] + ' ' + line['test'] + ' ' if (showbound): out += line['bound'] + ' ' outlines.append(out+'\n') f = open('error.dat', 'w') f.writelines(outlines) f.close() + if show_separate: + lines = getErrors(boost_filename) + outlines = [] + for line in lines: + out = str(line['iter']) + ' ' + str(line['neg_err']) + ' ' + str(line['pos_err']) + ' ' + str(line['err']) + outlines.append(out+'\n') + f = open('error_sep.dat', 'w') + f.writelines(outlines) + f.close() + outlines = [] *************** *** 119,129 **** outlines.append('set ylabel "Error"\n') outlines.append('set title "' + info_filename + ' Error"\n') if (logaxis): outlines.append('set logscale x 10\n') out = '' ! out += 'plot "error.dat" using 1:2 title \'train\' with lines' ! out += ', "error.dat" using 1:3 title \'test\' with lines' ! if showbound: ! out += ', "error.dat" using 1:4 title \'bound\' with lines' out += '\n' outlines.append(out) --- 177,197 ---- outlines.append('set ylabel "Error"\n') outlines.append('set title "' + info_filename + ' Error"\n') + if show_separate: + outlines.append('set title "' + info_filename + ' Error (POSITIVE EXAMPLE ERROR MAY BE NEGATIVE EXAMPLE ERROR)"\n') if (logaxis): outlines.append('set logscale x 10\n') + outlines.append('set style line 10 lt 1 lw 1 pt 5 ps 0.65\n') + outlines.append('set style line 11 lt 3 lw 1 pt 1 ps 0.65\n') + outlines.append('set style line 12 lt 5 lw 1 pt 1 ps 0.65\n') out = '' ! if show_separate: ! out += 'plot "error_sep.dat" using 1:2 title \'Negative Example Error\' with lines linestyle 10' ! out += ', "error_sep.dat" using 1:3 title \'Positive Example Error\' with lines linestyle 11' ! out += ', "error_sep.dat" using 1:4 title \'Error\' with lines linestyle 12' ! else: ! out += 'plot "error.dat" using 1:2 title \'train\' with lines linestyle 10' ! out += ', "error.dat" using 1:3 title \'test\' with lines linestyle 11' ! if showbound: ! out += ', "error.dat" using 1:4 title \'bound\' with lines' out += '\n' outlines.append(out) *************** *** 136,148 **** os.system('gnuplot ' + pngfilename) - ##################################### - # Now do scores file for separate option - ##################################### - - if show_separate: - do_separate() - - - if __name__ == "__main__": --- 204,207 ---- |
From: Aaron A. <aa...@us...> - 2007-12-05 06:40:00
|
Update of /cvsroot/jboost/jboost/src/jboost/controller In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv26595 Modified Files: Configuration.java Controller.java Log Message: Logging changed to be correct Index: Controller.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/controller/Controller.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Controller.java 2 Oct 2007 20:36:43 -0000 1.5 --- Controller.java 5 Dec 2007 06:39:57 -0000 1.6 *************** *** 171,174 **** --- 171,175 ---- } catch (Exception e) { // XXX: what to do? + e.printStackTrace(); throw new InstantiationException(e.getMessage()); } *************** *** 206,212 **** m_learningTree= new InstrumentedAlternatingTree(m_splitterBuilderVector, m_booster, m_trainSetIndices,m_config); ! System.out.println("Finished creating root (iteration -1)"); } // main loop start= System.currentTimeMillis(); --- 207,220 ---- m_learningTree= new InstrumentedAlternatingTree(m_splitterBuilderVector, m_booster, m_trainSetIndices,m_config); ! System.out.println("Finished creating root (iteration 0)"); ! if (Monitor.logLevel > 1) { ! m_monitor.logIteration( ! 0, // iteration ! m_learningTree.getCombinedPredictor(), ! m_learningTree.getLastBasePredictor()); ! } } + // main loop start= System.currentTimeMillis(); *************** *** 346,356 **** Executor pe=ExecutorSinglet.getExecutor(); ! for (int iter= 0; iter < iterNo && !m_learningTree.boosterIsFinished(); iter++) { ! if (Monitor.logLevel > 1) { ! m_monitor.logIteration( ! iter, ! m_learningTree.getCombinedPredictor(), ! m_learningTree.getLastBasePredictor()); ! } start= System.currentTimeMillis(); Vector candidates= m_learningTree.getCandidates(); --- 354,358 ---- Executor pe=ExecutorSinglet.getExecutor(); ! for (int iter= 1; iter <= iterNo && !m_learningTree.boosterIsFinished(); iter++) { start= System.currentTimeMillis(); Vector candidates= m_learningTree.getCandidates(); *************** *** 422,429 **** + iter); } - System.out.println("Finished learning iteration " + iter); if(m_booster instanceof BrownBoost){ iterNo++; } } --- 424,437 ---- + iter); } if(m_booster instanceof BrownBoost){ iterNo++; } + System.out.println("Finished learning iteration " + iter); + if (Monitor.logLevel > 1) { + m_monitor.logIteration( + iter, + m_learningTree.getCombinedPredictor(), + m_learningTree.getLastBasePredictor()); + } } Index: Configuration.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/controller/Configuration.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Configuration.java 23 Oct 2007 22:46:32 -0000 1.7 --- Configuration.java 5 Dec 2007 06:39:57 -0000 1.8 *************** *** 95,99 **** + "\t-BoosTexter Only make a zero prediction at the root node.\n" + "\t-booster_smooth sf Smoothing factor for prediction computation (default: 0.5)\n" ! + "\t Described Shapire & Singer 1999 (smoothing the predictions), \n" + "\t $epsilon = sf / total_num_examples$ \n" + "\t-booster_paranoid Use safe version of booster (default: false)\n" --- 95,99 ---- + "\t-BoosTexter Only make a zero prediction at the root node.\n" + "\t-booster_smooth sf Smoothing factor for prediction computation (default: 0.5)\n" ! + "\t Described Schapire & Singer 1999 (smoothing the predictions), \n" + "\t $epsilon = sf / total_num_examples$ \n" + "\t-booster_paranoid Use safe version of booster (default: false)\n" |
From: Aaron A. <aa...@us...> - 2007-10-23 23:52:29
|
Update of /cvsroot/jboost/jboost In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv31948 Modified Files: CHANGES build.xml jboost Log Message: bunch of misc changes Index: jboost =================================================================== RCS file: /cvsroot/jboost/jboost/jboost,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** jboost 4 Jun 2007 22:15:12 -0000 1.4 --- jboost 23 Oct 2007 23:52:26 -0000 1.5 *************** *** 22,29 **** fi ! echo -n "JBoost jar file is:" echo "${CLASSPATH}" | sed 's/:/\n/g' | grep 'jboost\.jar' ! exec java -Xmx1000M jboost.controller.Controller $@ if [ $? -ne 0 ]; then --- 22,29 ---- fi ! echo -n "JBoost jar file is: " echo "${CLASSPATH}" | sed 's/:/\n/g' | grep 'jboost\.jar' ! exec java -Xmx500M jboost.controller.Controller $@ if [ $? -ne 0 ]; then Index: CHANGES =================================================================== RCS file: /cvsroot/jboost/jboost/CHANGES,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** CHANGES 14 Jun 2007 16:33:31 -0000 1.4 --- CHANGES 23 Oct 2007 23:52:25 -0000 1.5 *************** *** 2,5 **** --- 2,15 ---- -------------------- + + Release 1.4 + + ================= + + - NormalBoost is implemented + - BrownBoost-like update + - Asymetric cost + - Iteration order evalution of the ADTree + - More bugs fixed + - Scripts updated and made more general + + Release 1.3.1 + ================= Index: build.xml =================================================================== RCS file: /cvsroot/jboost/jboost/build.xml,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** build.xml 4 Jun 2007 22:15:10 -0000 1.7 --- build.xml 23 Oct 2007 23:52:26 -0000 1.8 *************** *** 15,19 **** <property name="dir.scripts" value="scripts"/> <property name="dir.javadoc" value="javadoc"/> ! <property name="jboost.version" value="1.3.1"/> <property name="test.class.name" value="jboost.AllTests"/> --- 15,19 ---- <property name="dir.scripts" value="scripts"/> <property name="dir.javadoc" value="javadoc"/> ! <property name="jboost.version" value="1.4"/> <property name="test.class.name" value="jboost.AllTests"/> *************** *** 76,80 **** <target name="compile" depends="prepare" description="Compile all source code."> ! <javac srcdir="${dir.src}" classpath="${dir.lib}/junit.jar:${dir.lib}/concurrent.jar" destdir="${dir.build}" debug="on" /> </target> --- 76,85 ---- <target name="compile" depends="prepare" description="Compile all source code."> ! <javac srcdir="${dir.src}" ! classpath="${dir.lib}/junit.jar:${dir.lib}/concurrent.jar" ! destdir="${dir.build}" ! debug="on" ! executable="/usr/java/jdk1.3/bin/javac" ! /> </target> *************** *** 187,195 **** </exec> ! <tar destfile="jboost-${jboost.version}.tar"> <tarfileset dir="jboost-${jboost.version}" prefix="jboost-${jboost.version}"/> </tar> <gzip zipfile="jboost-${jboost.version}.tgz" src="jboost-${jboost.version}.tar"/> --- 192,208 ---- </exec> ! <!-- <tar destfile="jboost-${jboost.version}.tar"> <tarfileset dir="jboost-${jboost.version}" prefix="jboost-${jboost.version}"/> </tar> <gzip zipfile="jboost-${jboost.version}.tgz" src="jboost-${jboost.version}.tar"/> + --> + + <exec executable="tar" > + <arg value="cpzf" /> + <arg value="jboost-${jboost.version}.tgz" /> + <arg value="jboost-${jboost.version}" /> + </exec> + |
From: Aaron A. <aa...@us...> - 2007-10-23 23:52:29
|
Update of /cvsroot/jboost/jboost/src/jboost/tokenizer In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv31948/src/jboost/tokenizer Modified Files: DataStream.java jboost_DataStream.java Log Message: bunch of misc changes Index: DataStream.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/tokenizer/DataStream.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** DataStream.java 16 May 2007 04:06:02 -0000 1.1.1.1 --- DataStream.java 23 Oct 2007 23:52:26 -0000 1.2 *************** *** 15,18 **** --- 15,19 ---- public static String WEIGHT_ATTR= "weight"; + public static String ID_ATTR = "id"; public static String LABELS_ATTR= "labels"; Index: jboost_DataStream.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/tokenizer/jboost_DataStream.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** jboost_DataStream.java 16 May 2007 04:06:02 -0000 1.1.1.1 --- jboost_DataStream.java 23 Oct 2007 23:52:26 -0000 1.2 *************** *** 359,363 **** ed.setLabel(attribute, lineCount); } else if (name.equals(DataStream.WEIGHT_ATTR)) { ! ed.setWeight(attribute, lineCount); } else { ed.addAttribute(attribute); --- 359,365 ---- ed.setLabel(attribute, lineCount); } else if (name.equals(DataStream.WEIGHT_ATTR)) { ! ed.setWeight(attribute, lineCount);/* ! } else if (name.equals(DataStream.ID_ATTR)) { ! ed.setId(attribute, lineCount);*/ } else { ed.addAttribute(attribute); |
From: Aaron A. <aa...@us...> - 2007-10-23 23:52:29
|
Update of /cvsroot/jboost/jboost/scripts In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv31948/scripts Modified Files: surfing.py Log Message: bunch of misc changes Index: surfing.py =================================================================== RCS file: /cvsroot/jboost/jboost/scripts/surfing.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** surfing.py 23 Oct 2007 22:50:42 -0000 1.3 --- surfing.py 23 Oct 2007 23:52:26 -0000 1.4 *************** *** 13,17 **** def usage(): print 'Usage: margin.py ' - print '\t--surfing=filename surfing file as output by jboost (-a -2 switch)' print '\t--boost-info=filename file as output by jboost (-a -2 switch)' print '\t--data=filename train/test filename' --- 13,16 ---- *************** *** 128,131 **** --- 127,131 ---- def write_gnuplot(lines, iter, datafile, params): + print 'Writing gnuplot file' line_compare = lambda x,y : cmp(float(string.split(x,SEPARATOR)[1]), float(string.split(y,SEPARATOR)[1])) lines.sort(line_compare); *************** *** 138,142 **** 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] --- 138,142 ---- marg_max = max(margins); marg_min = min(margins); ! lines = get_margin_hist(margins, True); max_bin = max([l[1] for l in lines]) lines = [str(l[0]) + ' ' + str(l[1]) + '\n' for l in lines] *************** *** 216,220 **** try: ! opts, args= getopt.getopt(sys.argv[1:], '', ['surfing=', 'boost-info=','data=','spec=','labels=', 'iteration=', 'framerate=', 'booster=', 'sample']) except getopt.GetoptError, inst: print 'Received an illegal argument:', inst --- 216,220 ---- try: ! opts, args= getopt.getopt(sys.argv[1:], '', ['boost-info=','data=','spec=', 'framerate=', 'booster=']) except getopt.GetoptError, inst: print 'Received an illegal argument:', inst *************** *** 257,260 **** --- 257,261 ---- num_elements= int((string.split(data[0],SEPARATOR)[1].split('=')[1])) num_iterations = int(string.split(string.split(data[-num_elements-1], SEPARATOR)[0], '=')[1]) + print 'Read ' + str(num_iterations) + ' iterations, each with ' + str(num_elements) + ' from ' + boostfile #os.system('rm surfing*.eps surfing*.png') |
From: Aaron A. <aa...@us...> - 2007-10-23 23:52:29
|
Update of /cvsroot/jboost/jboost/src/jboost/atree In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv31948/src/jboost/atree Modified Files: InstrumentedAlternatingTree.java Log Message: bunch of misc changes Index: InstrumentedAlternatingTree.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/atree/InstrumentedAlternatingTree.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** InstrumentedAlternatingTree.java 13 Oct 2007 04:32:27 -0000 1.4 --- InstrumentedAlternatingTree.java 23 Oct 2007 23:52:26 -0000 1.5 *************** *** 159,162 **** --- 159,165 ---- Prediction[] tmpPred= null; initialWeights[0]= m_booster.newBag(m_examples); + int[][] tmpEx= new int[1][]; + tmpEx[0]= m_examples; + // To make it behave like boost texter. if (m_emulateBoosTexter) { *************** *** 166,173 **** } initialWeights[0].reset(); } - int[][] tmpEx= new int[1][]; - tmpEx[0]= m_examples; tmpPred= m_booster.getPredictions(initialWeights, tmpEx); m_booster.update(tmpPred, tmpEx); --- 169,180 ---- } initialWeights[0].reset(); + tmpPred= m_booster.getPredictions(initialWeights, tmpEx); + m_booster.update(tmpPred, tmpEx); + PredictorNode predictorNode= new PredictorNode(tmpPred[0], "R", + 0, null, null, 0); + m_predictors.add(predictorNode); + return; } tmpPred= m_booster.getPredictions(initialWeights, tmpEx); m_booster.update(tmpPred, tmpEx); |
From: Aaron A. <aa...@us...> - 2007-10-23 23:52:29
|
Update of /cvsroot/jboost/jboost/demo In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv31948/demo Modified Files: stem.spec Log Message: bunch of misc changes Index: stem.spec =================================================================== RCS file: /cvsroot/jboost/jboost/demo/stem.spec,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** stem.spec 16 May 2007 04:06:02 -0000 1.1.1.1 --- stem.spec 23 Oct 2007 23:52:26 -0000 1.2 *************** *** 2,5 **** --- 2,6 ---- attributeTerminator=, maxBadExa=0 + age number income number |
From: Aaron A. <aa...@us...> - 2007-10-23 22:50:47
|
Update of /cvsroot/jboost/jboost/scripts In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv6911 Modified Files: error.py margin.py surfing.py Log Message: New output format Index: margin.py =================================================================== RCS file: /cvsroot/jboost/jboost/scripts/margin.py,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** margin.py 13 Jun 2007 16:09:14 -0000 1.7 --- margin.py 23 Oct 2007 22:50:42 -0000 1.8 *************** *** 8,20 **** import re def usage(): print 'Usage: margin.py ' ! print '\t--margins=filename margins 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--iteration=NUMBER the iteration number to inspect' ! print '\t--sample are we interested in a sample of false pos/neg' ! print '\t--labels=filename labels file (if unspecified then created from data file)' def sortByColumns(list2d, column_indices, in_place=False): --- 8,21 ---- import re + + SEPARATOR = ':' + def usage(): print 'Usage: margin.py ' ! print '\t--boost-info=filename margins file as output by jboost (-a -2 switch)' ! print '\t--data=filename train/test filename' ! print '\t--spec=filename spec filename' ! print '\t--iteration=i,j,k,... the iterations to inspect, no spaces between commas' ! print '\t--sample are we interested in a sample of false pos/neg' def sortByColumns(list2d, column_indices, in_place=False): *************** *** 45,52 **** '\n' ) ! f.write('Sensitivity: ' + str(float(len(truepos))/(len(truepos)+len(falseneg))) + '\n'); ! f.write('False Pos Rate: ' + str(float(len(falsepos))/(len(trueneg)+len(falsepos))) + '\n'); list= [[margins[w],examples[w]] for w in falseneg.keys()] sortByColumns(list, [0], True) --- 46,58 ---- '\n' ) ! f.write('Sensitivity: ' + str(1-float(len(falseneg))/(len(truepos)+len(falseneg))) + '\n') ! f.write('False Pos Rate: ' + str(float(len(falsepos))/(len(trueneg)+len(falsepos))) + '\n') + f.write('True pos: ' + str(len(truepos)) + '\n') + f.write('False pos: ' + str(len(falsepos)) + '\n') + f.write('True neg: ' + str(len(trueneg)) + '\n') + f.write('False neg: ' + str(len(falseneg)) + '\n') + list= [[margins[w],examples[w]] for w in falseneg.keys()] sortByColumns(list, [0], True) *************** *** 77,86 **** ! def write_gnuplot(scores_list, iters, datafile): margin_list = [] for i in range(len(iters)): ! scores = scores_list[i] ! margins = scores_list[i] #get_margins(labels, scores); margins.sort() margin_list.append(margins) --- 83,93 ---- ! def write_gnuplot(m_list, iters, datafile): margin_list = [] for i in range(len(iters)): ! scores = m_list[i] ! m = m_list[i] ! margins = m[:] margins.sort() margin_list.append(margins) *************** *** 131,144 **** ! f = open('margin.png.gnuplot', 'w') f.writelines(pngoutlines) f.close() ! f = open('margin.eps.gnuplot', 'w') f.writelines(epsoutlines) f.close() ! --- 138,155 ---- + pngfilename = 'margin.png.gnuplot' + epsfilename = 'margin.eps.gnuplot' ! f = open(pngfilename, 'w') f.writelines(pngoutlines) f.close() ! f = open(epsfilename, 'w') f.writelines(epsoutlines) f.close() ! os.system('gnuplot ' + pngfilename) ! os.system('gnuplot ' + epsfilename) ! os.system('epstopdf margin.eps') *************** *** 164,180 **** ! def get_margins(labels, scores): ! def computeMargin(score, label): ! return score*int(label) ! ! margins= map(computeMargin, scores, labels) ! return margins ! ! ! ! def process_data(examples, labels, margins, scores, datafile, sample): print 'Examples ' + str(len(examples)) - print 'Scores ' + str(len(scores)) print 'Margins ' + str(len(margins)) print 'Generating margins' --- 175,181 ---- ! def process_data(examples, labels, margins, datafile, sample): print 'Examples ' + str(len(examples)) print 'Margins ' + str(len(margins)) print 'Generating margins' *************** *** 182,187 **** print 'Matching margins with data' - #pos_label, neg_label = getLabels(specfile) - falsepos = dict([(w,[margins[w],examples[w],labels[w]]) for w in range(len(margins)) --- 183,186 ---- *************** *** 200,203 **** --- 199,205 ---- + # for i in range(len(margins)): + # print '%d\t %s\t %.2f\t %.2f' % (i, labels[i].strip(), margins[i]) + write_files(examples, datafile, sample, margins, falsepos, truepos, falseneg, trueneg) *************** *** 213,217 **** try: ! opts, args= getopt.getopt(sys.argv[1:], '', ['margins=', 'scores=','data=','spec=','labels=', 'iteration=', 'sample']) except getopt.GetoptError, inst: print 'Received an illegal argument:', inst --- 215,219 ---- try: ! opts, args= getopt.getopt(sys.argv[1:], '', ['boost-info=', 'data=', 'spec=', 'iteration=', 'sample']) except getopt.GetoptError, inst: print 'Received an illegal argument:', inst *************** *** 219,228 **** sys.exit(2) ! marginsfile = scoresfile = datafile = specfile = labelsfile = sample = iteration = None for opt,arg in opts: ! if (opt == '--margins'): ! marginsfile = arg ! if (opt == '--scores'): ! scoresfile = arg if (opt == '--spec'): specfile = arg --- 221,228 ---- sys.exit(2) ! boostfile = datafile = specfile = labelsfile = sample = iteration = None for opt,arg in opts: ! if (opt == '--boost-info'): ! boostfile = arg if (opt == '--spec'): specfile = arg *************** *** 237,258 **** ! if(marginsfile == None or scoresfile == None or datafile == None or specfile == None): print 'Need score, data, and spec file.' usage() sys.exit(2) - if(labelsfile == None): - labelsfile = datafile + '.labels' - #if os.path.exists(labelsfile): - # print 'Using label file:', labelsfile - # # do nothing - #else: - command = 'cat ' + datafile + ' | sed \'s/.*\(.1\);/\\1/g\' > ' + labelsfile - print command - os.system(command) - command = 'sed -i \'s/ 1/+1/g\' ' + labelsfile - print command - os.system(command) - print 'Reading data' f= open(datafile,'r') --- 237,245 ---- ! if(boostfile == None or datafile == None or specfile == None): print 'Need score, data, and spec file.' usage() sys.exit(2) print 'Reading data' f= open(datafile,'r') *************** *** 260,301 **** f.close() ! print 'Reading score values' ! f= open(scoresfile,'r') ! data= f.readlines() ! f.close() ! score_elements= int((string.split(data[0],'='))[2]) ! ! print 'Reading margin values' ! f= open(marginsfile,'r') data= f.readlines() f.close() ! margin_elements= int((string.split(data[0],'='))[2]) ! print 'Reading labels' ! f= open(labelsfile,'r') ! labels= f.readlines()[-score_elements:] ! f.close() ! scores = [] ! margin_list = [] iters = [1] iters[0] = len(data) / (margin_elements+1) if (iteration != None): ! iters = map(int, iteration.split(',')) for iter in iters: ! margins = [float(x) for x in data[iter*(margin_elements+1)+1:(iter+1)*(margin_elements+1)]] ! scores = [float(x) for x in data[iter*(score_elements+1)+1:(iter+1)*(score_elements+1)]] margin_list.append(margins) else: ! margins = [float(x) for x in data[-margin_elements:]] ! scores = [float(x) for x in data[-score_elements:]] margin_list.append(margins) ! write_gnuplot(margin_list, iters, datafile) ! ! process_data(examples, labels, margin_list[len(margin_list)-1], scores, datafile, sample) ! --- 247,294 ---- f.close() ! print 'Reading boosting info' ! f= open(boostfile,'r') data= f.readlines() f.close() ! margin_elements= int((string.split(data[0],SEPARATOR))[1].split('=')[1]) ! def get_margin(line): ! m = line.split(SEPARATOR)[1] ! m.replace(']','') ! m.replace(';','') ! m.replace(SEPARATOR,'') ! m.replace(' ','') ! m.replace('\t','') ! return float(m) ! def get_label(line): ! m = line.split(SEPARATOR)[-2] ! m.replace(']','') ! m.replace(';','') ! m.replace(SEPARATOR,'') ! m.replace(' ','') ! m.replace('\t','') ! return m + # if iterations are not specified on command line, we do the last iteration iters = [1] iters[0] = len(data) / (margin_elements+1) + + margin_list = [] if (iteration != None): ! iters = map(int, [x.strip() for x in iteration.split(',')]) for iter in iters: ! lines = [x for x in data[iter*(margin_elements+1)+1:(iter+1)*(margin_elements+1)]] ! margins = map(get_margin, lines) margin_list.append(margins) else: ! lines = [x for x in data[-margin_elements:]] ! margins = map(get_margin, lines) margin_list.append(margins) ! labels = map(get_label, [x for x in data[-margin_elements:]]) ! process_data(examples, labels, margin_list[len(margin_list)-1], datafile, sample) + write_gnuplot(margin_list, iters, datafile) Index: surfing.py =================================================================== RCS file: /cvsroot/jboost/jboost/scripts/surfing.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** surfing.py 12 Jul 2007 16:07:26 -0000 1.2 --- surfing.py 23 Oct 2007 22:50:42 -0000 1.3 *************** *** 9,20 **** 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' --- 9,22 ---- import math + SEPARATOR=':' + def usage(): print 'Usage: margin.py ' ! print '\t--surfing=filename surfing file as output by jboost (-a -2 switch)' ! print '\t--boost-info=filename 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={AdaBoost, LogLossBoost, NormalBoost, BrownBoost}' ! print '\t--framerate=num an integer specifying framerate' *************** *** 39,46 **** 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 --- 41,49 ---- weights = [] s = c= c1 = c2 = theta = 0 ! confidence = False ! if(params[0] == 'BrownBoost'): c = float(params[1]) s = float(params[2]) #time remaining ! elif(params[0] == 'NormalBoost'): c = float(params[1]) s = c-float(params[2]) #time played *************** *** 50,53 **** --- 53,57 ---- c2 = float(params[4]) theta = float(params[5]) + confidence = params[6] *************** *** 57,64 **** 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 --- 61,68 ---- for i in range(0,num_steps): mu = var = 0 ! if params[0] == 'BrownBoost': mu = -s var = c ! elif params[0] == 'NormalBoost': mu = theta - c1 * (math.exp(-s) - math.exp(-c)) var = c2 * (math.exp(-2*s) - math.exp(-2*c)) + 0.05 *************** *** 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 --- 71,76 ---- y = math.exp(-math.pow(x-mu,2)/(var)) * max_bin p = (1 - erf((x-mu)/math.sqrt(var)))/2 ! if (confidence): ! p = min(2*p, 1) weights.append((x,y,p)) x += step *************** *** 115,132 **** 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] --- 120,136 ---- def paste_gnuplot(num_iterations, framerate): print 'Starting animated gif creation' ! os.system('convert -rotate 90 -delay 5 -loop 2 surfing*.eps surfing.gif') print 'Finished gif creation' print 'See surfing.gif for animation' ! def write_gnuplot(lines, iter, datafile, params): + line_compare = lambda x,y : cmp(float(string.split(x,SEPARATOR)[1]), float(string.split(y,SEPARATOR)[1])) lines.sort(line_compare); ! margins = [ float(string.split(x,SEPARATOR)[1]) for x in lines] ! weights = [ float(string.split(x,SEPARATOR)[2]) for x in lines] ! potentials = [ float(string.split(x,SEPARATOR)[3]) for x in lines] *************** *** 155,162 **** 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') ! if params[0]=='normal': epsoutlines.append('set xrange [-1:1]\n') epsoutlines.append('set yrange [0:1]\n') --- 159,166 ---- epsoutlines.append('set terminal post\n') epsoutlines.append('set output \'surfing%05d.eps\'\n' % (iter)) ! epsoutlines.append('set title "'+ params[0] + ' ' + 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') ! if params[0]=='NormalBoost': epsoutlines.append('set xrange [-1:1]\n') epsoutlines.append('set yrange [0:1]\n') *************** *** 173,177 **** '"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') # epsoutlines.append('set trange [0:1]\n') --- 177,181 ---- '"surfing_weight.dat" using 1:2 title "Potential" with lines \n') # 'delta(t) with lines \n') ! # if params[0]=='NormalBoost': # epsoutlines.append('set parametric\n') # epsoutlines.append('set trange [0:1]\n') *************** *** 212,216 **** 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 --- 216,220 ---- try: ! opts, args= getopt.getopt(sys.argv[1:], '', ['surfing=', 'boost-info=','data=','spec=','labels=', 'iteration=', 'framerate=', 'booster=', 'sample']) except getopt.GetoptError, inst: print 'Received an illegal argument:', inst *************** *** 218,231 **** 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 --- 222,233 ---- sys.exit(2) ! boostfile = datafile = framerate = specfile = labelsfile = sample = iteration = booster = None for opt,arg in opts: if (opt == '--booster'): booster = arg if (opt == '--framerate'): framerate = int(arg) ! if (opt == '--boost-info'): ! boostfile = arg if (opt == '--spec'): specfile = arg *************** *** 236,241 **** ! if(surffile == None or scoresfile == None or datafile == None or specfile == None): ! print 'Need score, data, and spec file.' usage() sys.exit(2) --- 238,243 ---- ! if(boostfile == None or datafile == None or specfile == None): ! print 'Need boosting.info, data, and spec file.' usage() sys.exit(2) *************** *** 244,277 **** 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) --- 246,289 ---- usage() sys.exit(2) ! if(booster==None or (booster!='NormalBoost' and booster!='BrownBoost')): ! print 'Only accepts `NormalBoost` and `BrownBoost` boost.' usage() sys.exit(2) ! print 'Reading boosting.info file' ! f= open(boostfile,'r') data= f.readlines() f.close() ! num_elements= int((string.split(data[0],SEPARATOR)[1].split('=')[1])) ! num_iterations = int(string.split(string.split(data[-num_elements-1], SEPARATOR)[0], '=')[1]) ! #os.system('rm surfing*.eps surfing*.png') for iter in range(0, num_iterations+1, framerate): ! boost_params_str = string.split(data[iter*(num_elements+1)], SEPARATOR)[2].split('boosting_params=')[1] ! if (booster=='BrownBoost'): ! search_str = 'r=' ! total_time = boost_params_str[boost_params_str.index(search_str)+2 :].split(' ')[0] ! search_str = 's=' ! time_left = boost_params_str[boost_params_str.index(search_str)+2 :].split(' ')[0] ! params = ('BrownBoost', total_time, time_left) ! if (booster=='NormalBoost'): ! search_str = 'c=' ! total_time = boost_params_str[boost_params_str.index(search_str)+2 :].split(' ')[0] ! search_str = 's=' ! time_left = boost_params_str[boost_params_str.index(search_str)+2 :].split(' ')[0] ! search_str = 'c1=' ! c1 = boost_params_str[boost_params_str.index(search_str)+len(search_str) :].split(' ')[0] ! search_str = 'c2=' ! c2 = boost_params_str[boost_params_str.index(search_str)+len(search_str) :].split(' ')[0] ! search_str = 'theta=' ! theta = boost_params_str[boost_params_str.index(search_str)+len(search_str) :].split(' ')[0] ! search_str = 'confidence=' ! confidence = boost_params_str[boost_params_str.index(search_str)+len(search_str) :].split(' ')[0] ! use_conf = False ! if confidence == 'true' or confidence == 'True' or confidence == '1': ! use_conf = True ! params = ('NormalBoost', total_time, time_left, c1, c2, theta, use_conf) ! lines = [x for x in data[iter*(num_elements+1)+1:(iter+1)*(num_elements+1)]] write_gnuplot(lines, iter, datafile, params) Index: error.py =================================================================== RCS file: /cvsroot/jboost/jboost/scripts/error.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** error.py 19 May 2007 01:57:56 -0000 1.3 --- error.py 23 Oct 2007 22:50:42 -0000 1.4 *************** *** 11,14 **** --- 11,37 ---- print '\t--logaxis should the axis be log-scaled (default: false)' print '\t--bound show the bound on training error' + print '\t--separate separate the positive and negative examples' + print '\t--scores=score_file the score file (only needed if --separate used)' + print '\t--margins=marg_file the margin file (only needed if --separate used)' + + def do_separate(score_filename, margin_filename): + print 'Parsing scores file' + f = open(score_filename,'r') + lines = f.readlines() + f.close() + + read_iter = False + data = [] + for line in lines: + line = line.strip() + if (line[:8] =='End time'): + break + if (read_iter): + data.append(get_score(line)) + + + + + def main(): *************** *** 16,29 **** try: ! opts, args= getopt.getopt(sys.argv[1:], '', ['info=','logaxis','bound']) except getopt.GetoptError: usage() sys.exit(2) ! infofilename = logaxis = showbound = None for opt,arg in opts: if (opt == '--info'): ! infofilename = arg ! elif (opt == '--logaxis'): logaxis = True elif (opt == '--bound'): --- 39,58 ---- try: ! opts, args= getopt.getopt(sys.argv[1:], '', ['info=','logaxis','bound','separate','scores=','margins=']) except getopt.GetoptError: usage() sys.exit(2) ! info_filename = logaxis = showbound = show_separate = margin_filename = score_filename = None for opt,arg in opts: if (opt == '--info'): ! info_filename = arg ! if (opt == '--margins'): ! margin_filename = arg ! if (opt == '--info'): ! score_filename = arg ! if (opt == '--separate'): ! show_separate = True ! if (opt == '--logaxis'): logaxis = True elif (opt == '--bound'): *************** *** 31,44 **** ! if(infofilename == None): ! usage() ! sys.exit(2) ! print 'Reading info file' ! f = open(infofilename,'r') lines = f.readlines() f.close() ! def get_data(line): list = line.split('\t') ret = {} --- 60,80 ---- ! if (show_separate and (margin_filename==None or score_filename==None)): ! print 'ERROR: Need to specify score and margin file if showing positive and negative elements separately' ! usage() ! sys.exit(2) ! ! if(info_filename == None): ! print 'ERROR: Need to specify info file' ! usage() ! sys.exit(2) ! print 'Parsing info file' ! f = open(info_filename,'r') lines = f.readlines() f.close() ! ! def get_info_data(line): list = line.split('\t') ret = {} *************** *** 49,52 **** --- 85,89 ---- return ret + read_iter = False data = [] *************** *** 57,61 **** break if (read_iter): ! data.append(get_data(line)) if (line=='iter \tbound \ttrain \ttest'): read_iter = True --- 94,98 ---- break if (read_iter): ! data.append(get_info_data(line)) if (line=='iter \tbound \ttrain \ttest'): read_iter = True *************** *** 81,85 **** outlines.append('set xlabel "Iteration"\n') outlines.append('set ylabel "Error"\n') ! outlines.append('set title "' + infofilename + ' Error"\n') if (logaxis): outlines.append('set logscale x 10\n') --- 118,122 ---- outlines.append('set xlabel "Iteration"\n') outlines.append('set ylabel "Error"\n') ! outlines.append('set title "' + info_filename + ' Error"\n') if (logaxis): outlines.append('set logscale x 10\n') *************** *** 92,100 **** outlines.append(out) ! ! f = open('error.gnuplot', 'w') f.writelines(outlines) f.close() if __name__ == "__main__": main() --- 129,149 ---- outlines.append(out) ! pngfilename = 'error.gnuplot' ! f = open(pngfilename, 'w') f.writelines(outlines) f.close() + os.system('gnuplot ' + pngfilename) + + ##################################### + # Now do scores file for separate option + ##################################### + + if show_separate: + do_separate() + + + + if __name__ == "__main__": main() |
From: Aaron A. <aa...@us...> - 2007-10-23 22:46:36
|
Update of /cvsroot/jboost/jboost/src/jboost/controller In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv5321/controller Modified Files: Configuration.java ControllerConfiguration.java Log Message: Cost sensitive params Index: ControllerConfiguration.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/controller/ControllerConfiguration.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ControllerConfiguration.java 27 May 2007 11:20:23 -0000 1.2 --- ControllerConfiguration.java 23 Oct 2007 22:46:32 -0000 1.3 *************** *** 55,58 **** --- 55,66 ---- public static final String YABA_C2="c2"; public static final String YABA_THETA="theta"; + public static final String YABA_POS_C="pos_r"; + public static final String YABA_POS_C1="pos_c1"; + public static final String YABA_POS_C2="pos_c2"; + public static final String YABA_POS_THETA="pos_theta"; + public static final String YABA_NEG_C="neg_r"; + public static final String YABA_NEG_C1="neg_c1"; + public static final String YABA_NEG_C2="neg_c2"; + public static final String YABA_NEG_THETA="neg_theta"; public static final String BROWN_BOOST_POTENTIAL="brownBoostPotential"; *************** *** 87,90 **** --- 95,106 ---- addOption(YABA_C2, getString("c2", null)); addOption(YABA_THETA, getString("theta", null)); + addOption(YABA_POS_C,"pos_r"); + addOption(YABA_POS_C1,"pos_c1"); + addOption(YABA_POS_C2,"pos_c2"); + addOption(YABA_POS_THETA,"pos_theta"); + addOption(YABA_NEG_C,"neg_r"); + addOption(YABA_NEG_C1,"neg_c1"); + addOption(YABA_NEG_C2,"neg_c2"); + addOption(YABA_NEG_THETA,"neg_theta"); addOption(BROWN_BOOST_POTENTIAL, getString("potential", null)); } Index: Configuration.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/controller/Configuration.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Configuration.java 2 Oct 2007 20:36:43 -0000 1.6 --- Configuration.java 23 Oct 2007 22:46:32 -0000 1.7 *************** *** 47,51 **** * <p> * ! * @author Nigel Duffy (rewritten by Aaron Arvey) */ public class Configuration { --- 47,51 ---- * <p> * ! * @author Nigel Duffy (parts rewritten by Aaron Arvey) */ public class Configuration { |
From: Aaron A. <aa...@us...> - 2007-10-23 22:45:44
|
Update of /cvsroot/jboost/jboost/src/jboost/booster In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv4913/booster Modified Files: AbstractBooster.java AdaBoost.java BrownBoost.java YabaBoost.java Log Message: Cost sensitive boosting, new data output format Index: AbstractBooster.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/AbstractBooster.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** AbstractBooster.java 18 Sep 2007 03:25:58 -0000 1.5 --- AbstractBooster.java 23 Oct 2007 22:45:40 -0000 1.6 *************** *** 67,75 **** if (result instanceof jboost.booster.YabaBoost) { ! 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; } --- 67,90 ---- if (result instanceof jboost.booster.YabaBoost) { ! double c1=0, c2=0, theta=0; ! double rpos=0, c1pos=0, c2pos=0, thetapos=0; ! double rneg=0, c1neg=0, c2neg=0, thetaneg=0; ! try { ! c1 = Double.parseDouble(c.getString("c1", "Z1.0")); ! c2 = Double.parseDouble(c.getString("c2", "Z1.0")); ! theta = Double.parseDouble(c.getString("theta", "Z0.15")); ! //c1 = Double.parseDouble(c.getString("pos_r", "Z1.0")); ! //c1 = Double.parseDouble(c.getString("pos_c1", "Z1.0")); ! //c2 = Double.parseDouble(c.getString("pos_c2", "Z1.0")); ! //theta = Double.parseDouble(c.getString("pos_theta", "Z0.15")); ! } catch (NumberFormatException e) { ! String s = "Need to supply r, c1, c2, and theta!"; ! System.err.println(s); ! throw new InstantiationException(s); ! } jboost.booster.YabaBoost yaba = (jboost.booster.YabaBoost) result; yaba.setParams(c1,c2,theta); + yaba.setCostSensitiveParams(rpos, c1pos, c2pos, thetapos, + rneg, c1neg, c2neg, thetaneg); result = yaba; } Index: YabaBoost.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/YabaBoost.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** YabaBoost.java 2 Oct 2007 02:32:07 -0000 1.5 --- YabaBoost.java 23 Oct 2007 22:45:40 -0000 1.6 *************** *** 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. --- 34,37 ---- *************** *** 135,140 **** ! public void setCostSensativeParams(double pc1, double pc2, double ptheta, ! double nc1, double nc2, double ntheta) { m_posc1 = pc1; m_posc2 = pc2; --- 128,134 ---- ! public void setCostSensitiveParams(double pc, double pc1, double pc2, double ptheta, ! double nc, double nc1, double nc2, double ntheta) { ! m_posc = pc; m_posc1 = pc1; m_posc2 = pc2; *************** *** 142,145 **** --- 136,140 ---- m_posOrigTheta = ptheta; + m_negc = pc; m_negc1 = pc1; m_negc2 = pc2; *************** *** 183,187 **** * @see jboost.booster.BrownBoost#calc_constraints(int[][], double, double) */ ! protected ErfVars calc_constraints(double alpha, double t) { ErfVars vars = new ErfVars(); --- 178,182 ---- * @see jboost.booster.BrownBoost#calc_constraints(int[][], double, double) */ ! protected ErfVars calc_constraints(double alpha, double t, int[] examples) { ErfVars vars = new ErfVars(); *************** *** 202,207 **** 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; --- 197,202 ---- double margin, orig_margin, step, new_margin, new_weight, new_pot, orig_pot; int example; ! for (int i= 0; i < examples.length; i++) { ! example = examples[i]; margin = m_margins[example]; orig_margin = margin; *************** *** 229,236 **** //System.out.println("aj: " + aj + ", dj: " + dj + ", dj^2/sd^2: " + (dj*dj/(sd*sd)) + ", bj: " + bj); //System.out.println("N(mu,sigma):" + mu + "," + sd + ", B:" + vars.B + ", E:" + vars.E); ! } vars.B /= totalWeight; ! vars.E /= m_hypPredictions.length; ! vars.Potential /= m_hypPredictions.length; return vars; } --- 224,231 ---- //System.out.println("aj: " + aj + ", dj: " + dj + ", dj^2/sd^2: " + (dj*dj/(sd*sd)) + ", bj: " + bj); //System.out.println("N(mu,sigma):" + mu + "," + sd + ", B:" + vars.B + ", E:" + vars.E); ! } vars.B /= totalWeight; ! vars.E /= examples.length; ! vars.Potential /= examples.length; return vars; } *************** *** 283,288 **** * @return alpha - An appropriate value of alpha that satisfies constraints. */ ! protected double solve_constraints(double hyp_err) ! { /* * If the game has a small amount of time remaining, quit now. --- 278,282 ---- * @return alpha - An appropriate value of alpha that satisfies constraints. */ ! protected double solve_constraints(double hyp_err, int[] examples) { /* * If the game has a small amount of time remaining, quit now. *************** *** 313,317 **** double t_step = 0.1; double t=0.3; ! double alpha=0; /* --- 307,311 ---- double t_step = 0.1; double t=0.3; ! double alpha=0.1; /* *************** *** 386,390 **** // calculate constraints for values of alpha and t ! vars = calc_constraints (alpha, t); // reverse alpha search direction --- 380,384 ---- // calculate constraints for values of alpha and t ! vars = calc_constraints (alpha, t, examples); // reverse alpha search direction *************** *** 533,537 **** ! if (m_hypPredictions.length != m_margins.length) { System.err.println("WARNING: m_hypPredictions is not the same length as the margins"); } --- 527,531 ---- ! if (m_hypPredictions.length != m_margins.length || m_hypPredictions.length != m_numExamples) { System.err.println("WARNING: m_hypPredictions is not the same length as the margins"); } *************** *** 618,622 **** 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; } --- 612,616 ---- public String getParamString() { ! String ret = String.format("YabaBoost 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: AdaBoost.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/AdaBoost.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** AdaBoost.java 13 Oct 2007 04:32:28 -0000 1.3 --- AdaBoost.java 23 Oct 2007 22:45:40 -0000 1.4 *************** *** 34,37 **** --- 34,46 ---- protected double[] m_potentials; + /** */ + protected int[] m_posExamples; + /** */ + protected int[] m_negExamples; + /** */ + protected int m_numPosExamples; + /** */ + protected int m_numNegExamples; + /** sampling weights for the examples */ protected double[] m_sampleWeights; *************** *** 92,95 **** --- 101,105 ---- m_numExamples++; m_tmpList.add(new TmpData(index, (short) l, weight)); + if (l==1) m_numPosExamples++; } else { failed= "AdaBoost.addExample received index " + index + ", when it expected index " + *************** *** 139,143 **** --- 149,157 ---- m_sampleWeights= new double[m_numExamples]; m_epsilon= m_smooth / m_numExamples; + m_posExamples = new int[m_numPosExamples]; + m_numNegExamples = m_numExamples - m_numPosExamples; + m_negExamples = new int[m_numNegExamples]; + int m_posIndex=0, m_negIndex=0; for (int i= 0; i < m_tmpList.size(); i++) { TmpData a= (TmpData) m_tmpList.get(i); *************** *** 146,149 **** --- 160,167 ---- m_weights[index]= m_oldWeights[index]= defaultWeight; m_labels[index]= a.getLabel(); + if (a.getLabel()==1) + m_posExamples[m_posIndex++] = index; + else + m_negExamples[m_negIndex++] = index; m_sampleWeights[index]= a.getWeight(); } Index: BrownBoost.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/BrownBoost.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** BrownBoost.java 2 Oct 2007 02:32:07 -0000 1.7 --- BrownBoost.java 23 Oct 2007 22:45:40 -0000 1.8 *************** *** 20,23 **** --- 20,28 ---- /** The total running time of the BrownBoost game. */ protected double m_c; + + /** In case we ever want to make BrownBoost cost sensitive. Also useful for Yaba. */ + protected double m_posc; + protected double m_negc; + /** The time remaining in the BrownBoost game. */ protected double m_s; *************** *** 28,31 **** --- 33,45 ---- /** The last value of alpha */ protected double m_lastAlpha; + + + /** + * 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 in YabaBoost and m_c{pos,neg} must be set in BrownBoost. + */ + protected boolean m_isCostSensitive; + /** *************** *** 46,49 **** --- 60,68 ---- protected double m_totalPotential; + /** + * Records the potentials. Similar to m_margins and m_weights. + */ + protected int[] m_examples; + /** * Default constructor just calls AdaBoost to *************** *** 57,62 **** --- 76,83 ---- public void finalizeData() { super.finalizeData(); + m_examples = new int[m_numExamples]; for (int i=0; i<m_numExamples; i++) { m_potentials[i] = calculatePotential(0,m_c); + m_examples[i] = i; } } *************** *** 248,252 **** ! protected double solve_constraints(double hyp_err) { if( m_s < 0.001){ --- 269,273 ---- ! protected double solve_constraints(double hyp_err, int[] examples) { if( m_s < 0.001){ *************** *** 265,320 **** double new_t = 0.0; - /* - int k = 0; - while(k < 200){ - k += 1; - - vars = calc_constraints(alpha, t); - - double det = 2*(vars.V*vars.W - vars.U*vars.B); - double EPS = 0.0001; - - // If correlation and difference in potential are small, - // then we're done! - if (vars.B < EPS && vars.E < EPS){ - System.out.println("Solved constrains by minimizing B and E."); - break; - } - - if (Math.abs(det) < EPS){ - System.out.println("DETERMINANT IS TOO SMALL -- SUGGESTS JACOBIAN IS ALMOST SINGULAR!!!"); - } - - new_alpha = alpha + (c*vars.W*vars.B + Math.sqrt(Math.PI*c)*vars.U*vars.E) / det; - new_t = t + (c*vars.B*vars.B + Math.sqrt(Math.PI*c)*vars.V*vars.E) / det; - - // if newton raphson succeeded, exit loop - EPS = 0.001; - if (vars.E < EPS && vars.W < EPS){ - System.out.println("Solved constrains by minimizing E and W."); - break; - } - - EPS = 0.0001; - if (Math.abs(alpha-new_alpha) < EPS){ - System.out.println("Solved constraints by similar old and new alpha."); - break; - } - - alpha = new_alpha; - t = new_t; - } - - if (k>=100){ - System.err.println("WE DIDN'T ACTUAL FINISH ANYTHING!!! WE JUST TIMED OUT!!!"); - } - - double nr_alpha = alpha; - double nr_t = t; - System.out.println("Newton-Raphson gives alpha=" + nr_alpha + ", t=" + nr_t); - */ - - - // try binary search // find the maximal value for t for which there exists a value --- 286,289 ---- *************** *** 416,434 **** } - /* - 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; } --- 385,390 ---- } public String getParamString() { ! String ret = String.format("BrownBoost r=%.4f s=%.4f ", m_c, m_s); return ret; } *************** *** 529,537 **** /** compute the binary prediction associated with this bag */ public BinaryPrediction calcPrediction(double alpha) { ! BinaryPrediction ret = new BinaryPrediction(m_w[1] > m_w[0] ? 1.0 : -1.0 ); ret.scale(alpha); return ret; } /** Place holder to ensure that this function is not used in BrownBoost. */ --- 485,507 ---- /** compute the binary prediction associated with this bag */ public BinaryPrediction calcPrediction(double alpha) { ! BinaryPrediction ret; ! ret = new BinaryPrediction(m_w[1] > m_w[0] ? 1.0 : -1.0 ); ret.scale(alpha); return ret; } + /** compute the binary prediction associated with this bag */ + public BinaryPrediction calcPrediction(double posAlpha, double negAlpha) { + BinaryPrediction ret; + if (m_w[1] > m_w[0]) { + ret = new BinaryPrediction(1.0); + ret.scale(posAlpha); + } else { + ret = new BinaryPrediction(-1.0); + ret.scale(negAlpha); + } + return ret; + } + /** Place holder to ensure that this function is not used in BrownBoost. */ *************** *** 677,684 **** // initial guess for alpha. double gamma = getHypErr(bags, exampleIndex); ! double alpha = solve_constraints(gamma); ! ! for (int i= 0; i < bags.length; i++) { ! p[i]= ((BrownBag) bags[i]).calcPrediction(alpha); } return p; --- 647,666 ---- // initial guess for alpha. double gamma = getHypErr(bags, exampleIndex); ! ! if (m_isCostSensitive) { ! System.out.println("Solving positive example constraints"); ! double posAlpha = solve_constraints(gamma, m_posExamples); ! System.out.println("Solving negative example constraints"); ! double negAlpha = solve_constraints(gamma, m_negExamples); ! for (int i= 0; i < bags.length; i++) { ! p[i]= ((BrownBag) bags[i]).calcPrediction(posAlpha, negAlpha); ! System.out.println("p[" + i + "] = " + p[i]); ! } ! } else { ! double alpha = solve_constraints(gamma, m_examples); ! for (int i= 0; i < bags.length; i++) { ! p[i]= ((BrownBag) bags[i]).calcPrediction(alpha); ! System.out.println("p[" + i + "] = " + p[i]); ! } } return p; |
From: Aaron A. <aa...@us...> - 2007-10-23 22:45:43
|
Update of /cvsroot/jboost/jboost/src/jboost/monitor In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv4913/monitor Modified Files: Monitor.java Log Message: Cost sensitive boosting, new data output format Index: Monitor.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/monitor/Monitor.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Monitor.java 18 Sep 2007 03:25:59 -0000 1.7 --- Monitor.java 23 Oct 2007 22:45:40 -0000 1.8 *************** *** 27,30 **** --- 27,34 ---- private String outputStem; + private static final String FIELD_SEPARATOR = ": "; + private static final char SEPARATOR = ','; + + /** a high-level log of the program's progress. */ private String infoFilename; *************** *** 180,186 **** 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() ); --- 184,190 ---- private void logBoostingTrainTest(PrintWriter boostingStream, ExampleSet tSet, int iter, Predictor combined, Predictor base) { // Output the training data ! boostingStream.println("iteration=" + iter + FIELD_SEPARATOR + ! "elements=" + tSet.size() + FIELD_SEPARATOR + ! "boosting_params=" + m_booster.getParamString() + FIELD_SEPARATOR ); *************** *** 196,200 **** } ! NumberFormat f= new DecimalFormat("0.0000"); double[] tmp = null; Boolean[] labeltmp = null; --- 200,204 ---- } ! NumberFormat f= new DecimalFormat("0.00000"); double[] tmp = null; Boolean[] labeltmp = null; *************** *** 202,250 **** 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("]; "); --- 206,249 ---- for (int i=0; i < tMargin.size(); i++) { // output the example number ! boostingStream.print("" + i + FIELD_SEPARATOR); // output the margins tmp = ((double[]) tMargin.get(i)); for (j= 0; j < tmp.length; j++){ boostingStream.print(f.format(tmp[j])); if (j != tmp.length -1) ! boostingStream.print(SEPARATOR); } ! boostingStream.print(FIELD_SEPARATOR); // output the scores tmp = ((double[]) tScores.get(i)); for (j= 0; j < tmp.length; j++){ boostingStream.print(f.format(tmp[j])); if (j != tmp.length -1) ! boostingStream.print(SEPARATOR); } ! boostingStream.print(FIELD_SEPARATOR); if (boostingStream.equals(trainBoostingStream)) { // output the weights for (j= 0; j < tWeights[i].length; j++){ boostingStream.print(f.format(tWeights[i][j])); if (j != tmp.length -1) ! boostingStream.print(SEPARATOR); } ! boostingStream.print(FIELD_SEPARATOR); ! // output the potentials for (j= 0; j < tPotentials[i].length; j++){ boostingStream.print(f.format(tPotentials[i][j])); if (j != tmp.length -1) ! boostingStream.print(SEPARATOR); } ! boostingStream.print(FIELD_SEPARATOR); *************** *** 253,265 **** // 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(""); } --- 252,262 ---- // output the labels labeltmp = ((Boolean[]) tLabelIndices.get(i)); for (j= 0; j < labeltmp.length; j++){ boostingStream.print(labeltmp[j].booleanValue() ? "+1" : "-1"); if (j != tmp.length -1) ! boostingStream.print(SEPARATOR); } ! boostingStream.print(FIELD_SEPARATOR); boostingStream.println(""); } |