From: Aaron A. <aa...@us...> - 2007-06-14 16:45:54
|
Update of /cvsroot/jboost/jboost/src/jboost/booster In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv24459/src/jboost/booster Modified Files: BrownBoost.java Log Message: Bug fix for weight and potential updates when hypothesis abstains Index: BrownBoost.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/BrownBoost.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** BrownBoost.java 4 Jun 2007 07:24:38 -0000 1.3 --- BrownBoost.java 14 Jun 2007 16:45:52 -0000 1.4 *************** *** 41,44 **** --- 41,54 ---- protected double[] m_hypPredictions; + /** + * Records the potentials. Similar to m_margins and m_weights. + */ + protected double[] m_potentials; + + /** + * Records the potentials. Similar to m_margins and m_weights. + */ + protected double m_totalPotential; + /** * Default constructor just calls AdaBoost to *************** *** 49,52 **** --- 59,71 ---- } + + public void finalizeData() { + super.finalizeData(); + m_potentials = new double[m_numExamples]; + for (int i=0; i<m_numExamples; i++) { + m_potentials[i] = calculatePotential(0,m_c); + } + } + public void setRuntime(double runtime){ m_c = runtime; *************** *** 316,320 **** int count_t_over_s = 0; double lastE = 0; ! double STEP_EPS = 0.00001; double CORR_EPS = 0.001; boolean first_iter = true; --- 335,339 ---- int count_t_over_s = 0; double lastE = 0; ! double STEP_EPS = 0.0001; double CORR_EPS = 0.001; boolean first_iter = true; *************** *** 365,375 **** if(sign(vars.B) != sign(alpha_step)) alpha_step /= -2; if(Math.abs(vars.B) < CORR_EPS) break; - /* - if (alpha > 5) { - alpha = 0.1; - vars = calc_constraints (alpha, t); - break; - } - */ } --- 384,387 ---- *************** *** 388,399 **** double bs_t = t; - - /* - System.out.println("\nBinary Search gives alpha=" + bs_alpha - + ", t=" + bs_t + ", s=" + m_s - + ", pot_diff=" + vars.E - + ", pot=" + vars.Potential); - */ - alpha = bs_alpha; t = bs_t; --- 400,403 ---- *************** *** 415,421 **** return alpha; } - - /** --- 419,430 ---- return alpha; } + public String surfingData() { + String ret = new String(""); + for (int i=0; i<m_margins.length; i++){ + ret += String.format("%.4f\t%.4f\t%.4f\n", m_margins[i], m_weights[i], m_potentials[i]); + } + return ret; + } /** *************** *** 432,445 **** return; } - - // save old m_weights - for (int i= 0; i < m_weights.length; i++){ - m_oldWeights[i]= m_weights[i]; - } - - // save old m_margins - for (int i= 0; i < m_margins.length; i++){ - m_oldMargins[i] = m_margins[i]; - } for (int i= 0; i < exampleIndex.length; i++) { --- 441,444 ---- *************** *** 449,460 **** for (int j= 0; j < indexes.length; j++) { int example = indexes[j]; m_margins[example] += value[m_labels[example]]; } } for (int i=0; i < m_hypPredictions.length; i++) { ! m_totalWeight -= m_weights[i]; m_weights[i] = calculateWeight(m_margins[i]); m_totalWeight += m_weights[i]; } } --- 448,467 ---- for (int j= 0; j < indexes.length; j++) { int example = indexes[j]; + m_oldMargins[example] = m_margins[example]; m_margins[example] += value[m_labels[example]]; } } + + m_totalWeight = 0; + m_totalPotential = 0; for (int i=0; i < m_hypPredictions.length; i++) { ! m_oldWeights[i]= m_weights[i]; ! m_weights[i] = calculateWeight(m_margins[i]); m_totalWeight += m_weights[i]; + + m_potentials[i] = calculatePotential(m_margins[i]); + m_totalPotential += m_potentials[i]; } } *************** *** 605,623 **** gamma /= total_weight; potential /= m_margins.length; - /* - System.out.println("---------------------------------------"); - System.out.println("---------------------------------------"); - System.out.print("gamma (weighted correlation):" + gamma); - System.out.print(", potential (unweighted):" + potential); - System.out.print(", hyp error (unweighted):" + hyp_err + "\n"); - System.out.println(""); - */ /* ! if (total_err < m_initialPotential) { ! System.err.println("WARNING: the 'weak' hypothesis was too good!"); ! System.err.println("You were aiming for an error rate of: " + m_initialPotential); ! System.err.println("With this hypothesis, you were able to achieve an error rate of: " + total_err); ! } */ --- 612,621 ---- gamma /= total_weight; potential /= m_margins.length; /* ! System.out.println("\tTotal number of examples: " + m_margins.length); ! System.out.println("\tNumber of predictions made: " + num_predictions); ! String out = "\tgamma (weighted correlation):" + gamma + ", potential (unweighted):" + potential + ", hyp error (unweighted):" + hyp_err; ! System.out.println(out); */ |