From: Aaron A. <aa...@us...> - 2007-10-02 02:32:11
|
Update of /cvsroot/jboost/jboost/src/jboost/booster In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv12745 Modified Files: BoosterTestSuite.java BrownBoost.java LogLossBoost.java MixedBinaryPrediction.java Prediction.java YabaBoost.java Added Files: NormalizedPrediction.java Log Message: MixedBinaryPrediction and tests added, confidence rated predictions switch, cost sensative params in place --- NEW FILE: NormalizedPrediction.java --- package jboost.booster; /** * A normalized predictor. When a prediction is added, we * ensure that the margin is normalized. This normalization is done * by "mixing" in the new prediction. * * @author Aaron Arvey **/ public interface NormalizedPrediction { /** * Must be used very carefully. An example: * * Prediction return_value = new MixedBinaryPrediction(Prediction root_value); * for (pi in iteration_ordered_predictions) * return_value.add(pi) * * There are two important parts to the above example. * 1) the add method is called on return_value * 2) iteration ordered predictions */ public Prediction add(Prediction p); /* public static boolean isNormPred(Prediction p); */ } Index: MixedBinaryPrediction.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/MixedBinaryPrediction.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** MixedBinaryPrediction.java 14 Jun 2007 16:35:43 -0000 1.2 --- MixedBinaryPrediction.java 2 Oct 2007 02:32:07 -0000 1.3 *************** *** 5,18 **** /** ! * A normalized predictor. When a prediction is added, we ! * ensure that the margin is normalized. This normalization is done ! * by "mixing" in the new prediction. * * @author Aaron Arvey **/ ! class MixedBinaryPrediction extends BinaryPrediction{ public MixedBinaryPrediction() {super();} public MixedBinaryPrediction(double p) throws NotNormalizedPredException{ super(); --- 5,23 ---- /** ! * A binary normalized predictor. See NoramlizedPrediction * * @author Aaron Arvey **/ ! class MixedBinaryPrediction extends BinaryPrediction implements NormalizedPrediction{ public MixedBinaryPrediction() {super();} + + /* + public static boolean isNormPred(Prediction p) { + return (p instanceof NormalizedPrediction); + } + */ + public MixedBinaryPrediction(double p) throws NotNormalizedPredException{ super(); *************** *** 30,40 **** /** ! * This may not be well defined for normalized predictions. However, ! * since we have symmetry (i.e. (1-x)y+y = (1-y)x+x ) we allow this operation. */ public Prediction add(Prediction p) throws NotNormalizedPredException{ ! double other_p = ((MixedBinaryPrediction) p).prediction; ! prediction = (1-Math.abs(prediction)) * other_p + prediction; ! if (Math.abs(other_p) > 1 || Math.abs(prediction) > 1) { throw new NotNormalizedPredException("Prediction may result in unnormalized " + "prediction! p is: " + p); --- 35,51 ---- /** ! * Be very careful with how this is used. See NormalizedPrediction ! * for details. */ public Prediction add(Prediction p) throws NotNormalizedPredException{ ! if (! (p instanceof MixedBinaryPrediction)) { ! throw new NotNormalizedPredException("Must use MixedBinaryPrediction when adding to a MixedBinaryPrediction."); ! } ! ! // H_t = (1-alpha)H_{t-1} + alpha h_t ! // The prediction p is for h_t ! double alpha = ((MixedBinaryPrediction) p).prediction; ! prediction = (1-Math.abs(alpha)) * prediction + alpha; ! if (Math.abs(alpha) > 1 || Math.abs(prediction) > 1) { throw new NotNormalizedPredException("Prediction may result in unnormalized " + "prediction! p is: " + p); Index: BrownBoost.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/BrownBoost.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** BrownBoost.java 18 Sep 2007 03:25:58 -0000 1.6 --- BrownBoost.java 2 Oct 2007 02:32:07 -0000 1.7 *************** *** 62,65 **** --- 62,66 ---- } + public void setRuntime(double runtime){ m_c = runtime; *************** *** 426,429 **** --- 427,432 ---- */ + + public String getParamString() { String ret = String.format("BrownBoost Params: %.4f %.4f", m_c, m_s); Index: BoosterTestSuite.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/BoosterTestSuite.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** BoosterTestSuite.java 27 May 2007 11:23:23 -0000 1.2 --- BoosterTestSuite.java 2 Oct 2007 02:32:07 -0000 1.3 *************** *** 25,28 **** --- 25,29 ---- //suite.addTest(new TestSuite(YabaBoostTest.class)); suite.addTest(new TestSuite(BrownBoostTest.class)); + suite.addTest(new TestSuite(MixedBinaryPredictionTest.class)); //suite.addTest(new TestSuite(MulticlassWrapMHTest.class)); //$JUnit-END$ Index: YabaBoost.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/YabaBoost.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** YabaBoost.java 10 Jul 2007 01:32:52 -0000 1.4 --- YabaBoost.java 2 Oct 2007 02:32:07 -0000 1.5 *************** *** 34,37 **** --- 34,44 ---- /** + * This is true if and only if we are cost sensitive boosting. If + * this is set, then m_{pos,neg}c{1,2} and m_{pos,neg}Theta must + * be set. + */ + protected boolean m_isCostSensitive; + + /** * Parameter for yaba that allows for decrease of potential * by translation of potential curve. *************** *** 40,43 **** --- 47,52 ---- */ protected double m_c1; + protected double m_posc1; + protected double m_negc1; *************** *** 48,51 **** --- 57,63 ---- */ protected double m_c2; + protected double m_posc2; + protected double m_negc2; + /** *************** *** 54,57 **** --- 66,71 ---- */ protected double m_theta; + protected double m_posTheta; + protected double m_negTheta; /** *************** *** 60,63 **** --- 74,79 ---- */ protected double m_origTheta; + protected double m_posOrigTheta; + protected double m_negOrigTheta; *************** *** 70,73 **** --- 86,98 ---- protected static final double FINISH_GAME_NOW = 0.05; + + /** + * A parameter indicating whether we should use confidence rated + * predictions. + */ + protected static final boolean USE_CONFIDENCE = false; + + + /** * A parameter indicating when we should stop the game. *************** *** 76,80 **** * an approximation of the 0/1 loss instead of the exact 0/1 loss. */ ! protected static final double THETA_UPDATE_STEP = 0.05; /** --- 101,105 ---- * an approximation of the 0/1 loss instead of the exact 0/1 loss. */ ! protected static final double THETA_UPDATE_STEP = 0.02; /** *************** *** 84,93 **** public YabaBoost() { super(); - /* - m_c = 1; - m_c1 = 2; - m_c2 = 1; - m_theta = 0.5; - */ } --- 109,112 ---- *************** *** 114,126 **** m_initialPotential = calculatePotential(0,m_c); } public String surfingData() { ! String ret = new String(""); ! ret += String.format("YabaBoost Params: %.4f %.4f %4f %4f %4f\n", m_c, m_s, m_c1, m_c2, m_theta); for (int i=0; i<m_margins.length; i++){ ! ret += String.format("%.4f\t%.4f\t%.4f\n", m_margins[i], m_weights[i], m_potentials[i]); } ! return ret; } --- 133,159 ---- m_initialPotential = calculatePotential(0,m_c); } + + + public void setCostSensativeParams(double pc1, double pc2, double ptheta, + double nc1, double nc2, double ntheta) { + m_posc1 = pc1; + m_posc2 = pc2; + m_posTheta = ptheta; + m_posOrigTheta = ptheta; + + m_negc1 = pc1; + m_negc2 = pc2; + m_negTheta = ptheta; + m_negOrigTheta = ptheta; + } public String surfingData() { ! StringBuffer ret = new StringBuffer(""); ! ret.append(String.format("YabaBoost Params: %.4f %.4f %4f %4f %4f\n", m_c, m_s, m_c1, m_c2, m_theta)); for (int i=0; i<m_margins.length; i++){ ! ret.append(String.format("%.4f\t%.4f\t%.4f\n", m_margins[i], m_weights[i], m_potentials[i])); } ! return ret.toString(); } *************** *** 166,180 **** double totalWeight = 0; for (int i= 0; i < m_hypPredictions.length; i++) { ! int example = i; ! double margin = m_margins[example]; ! double orig_margin = margin; ! ! // m_labels are 0 or 1, this moves it to +-1 ! double step = getStep(m_labels[example], m_hypPredictions[example]); ! double new_margin; ! double EPS = 0.0001; if (Math.abs(step) > EPS) { new_margin = (1-alpha)*margin + alpha*step; --- 199,214 ---- double totalWeight = 0; + double EPS = 0.0001; + double margin, orig_margin, step, new_margin, new_weight, new_pot, orig_pot; + int example; for (int i= 0; i < m_hypPredictions.length; i++) { ! example = i; ! margin = m_margins[example]; ! orig_margin = margin; ! // m_labels are 0 or 1, this moves it to in margin space +-1 ! step = getStep(m_labels[example], m_hypPredictions[example]); ! EPS = 0.0001; if (Math.abs(step) > EPS) { new_margin = (1-alpha)*margin + alpha*step; *************** *** 183,189 **** } ! double new_weight = calculateWeight(new_margin, new_time_remaining); ! double new_pot = calculatePotential(new_margin, new_time_remaining); ! double orig_pot = calculatePotential(orig_margin, orig_time_remaining); vars.B += new_weight*step; --- 217,223 ---- } ! new_weight = calculateWeight(new_margin, new_time_remaining); ! new_pot = calculatePotential(new_margin, new_time_remaining); ! orig_pot = calculatePotential(orig_margin, orig_time_remaining); vars.B += new_weight*step; *************** *** 394,404 **** * constant potential. */ ! double CONSTRAINT_EPS = 0.001; double EPS = 0.001; if (m_s > FINISH_GAME_NOW && Math.abs(vars.Potential-m_initialPotential)>CONSTRAINT_EPS) { - m_s = m_oldS; - dump_everything(vars); System.err.println("Average potential difference is too big!"); System.err.println("Outputting all data to outfile!"); s = m_c - m_s; --- 428,439 ---- * constant potential. */ ! double CONSTRAINT_EPS = 0.01; double EPS = 0.001; if (m_s > FINISH_GAME_NOW && Math.abs(vars.Potential-m_initialPotential)>CONSTRAINT_EPS) { System.err.println("Average potential difference is too big!"); + /* + m_s = m_oldS; System.err.println("Outputting all data to outfile!"); + dump_everything(vars); s = m_c - m_s; *************** *** 426,433 **** System.out.println("New theta is:" + m_theta); return solve_constraints(hyp_err); } if (Math.abs(vars.B) > CONSTRAINT_EPS) { - System.err.println("CORRELATION IS TOO BIG!!!"); } --- 461,469 ---- System.out.println("New theta is:" + m_theta); return solve_constraints(hyp_err); + + */ } if (Math.abs(vars.B) > CONSTRAINT_EPS) { System.err.println("CORRELATION IS TOO BIG!!!"); } *************** *** 539,543 **** double sd = Math.sqrt(m_c2*(Math.exp(-2*s) - Math.exp(-2*m_c))) + FINISH_GAME_NOW; double norm = 1 / Math.sqrt(Math.PI * sd * sd); ! return norm * Math.exp(- Math.pow((margin-mu)/sd,2)); } --- 575,588 ---- double sd = Math.sqrt(m_c2*(Math.exp(-2*s) - Math.exp(-2*m_c))) + FINISH_GAME_NOW; double norm = 1 / Math.sqrt(Math.PI * sd * sd); ! double ret = norm * Math.exp(- Math.pow((margin-mu)/sd,2)); ! ! if (USE_CONFIDENCE) { ! if (margin < mu) ! ret = 0; ! else ! ret = 2*ret; ! } ! ! return ret; } *************** *** 552,555 **** --- 597,603 ---- double sd = Math.sqrt(m_c2 * (Math.exp(-2*s) - Math.exp(-2*m_c))) + FINISH_GAME_NOW; double pot = (1 - erf((margin-mu)/sd)) / 2; + if (USE_CONFIDENCE) { + pot = Math.min(2*pot, 1.0); + } /* System.out.println("S:"+s); *************** *** 569,572 **** --- 617,626 ---- + public String getParamString() { + String ret = String.format("s=%.4f,c=%.4f,c1=%.4f,c2=%.4f,theta=%.4f,confidence=%b", m_s, m_c, m_c1, m_c2, m_theta, USE_CONFIDENCE); + return ret; + } + + /** Index: LogLossBoost.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/LogLossBoost.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** LogLossBoost.java 16 May 2007 04:06:02 -0000 1.1.1.1 --- LogLossBoost.java 2 Oct 2007 02:32:07 -0000 1.2 *************** *** 52,55 **** --- 52,62 ---- return oneOverLog2 * Z / m_margins.length; } + + + public String getParamString() { + String ret = String.format("None (LogLossBoost)"); + return ret; + } + /** Index: Prediction.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/Prediction.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** Prediction.java 16 May 2007 04:06:02 -0000 1.1.1.1 --- Prediction.java 2 Oct 2007 02:32:07 -0000 1.2 *************** *** 24,27 **** --- 24,35 ---- public abstract Prediction add(Prediction p); + + /** + * Returns true iff this prediction is normalized + */ + public static boolean isNormPred(Prediction p) { + return (p instanceof NormalizedPrediction); + } + /** |