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] |