From: Aaron A. <aa...@us...> - 2007-06-04 07:24:45
|
Update of /cvsroot/jboost/jboost/src/jboost/booster In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv15744 Modified Files: BrownBoost.java Log Message: Some optimizations Index: BrownBoost.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/BrownBoost.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** BrownBoost.java 27 May 2007 11:23:23 -0000 1.2 --- BrownBoost.java 4 Jun 2007 07:24:38 -0000 1.3 *************** *** 179,185 **** /** ! * Implements the calculation of the constraints and partial derivatives. ! * To better understand notation, please see Freund 1999, ! * Freund 2001, and Freund & Arvey 2008. * @returns ErfVars which contains the values of the various parameters. */ --- 179,185 ---- /** ! * Implements the calculation of the constraints and partial ! * derivatives. To better understand notation, see Freund 1999, ! * Freund 2001, and Freund & Arvey 2008. * @returns ErfVars which contains the values of the various parameters. */ *************** *** 187,204 **** { ErfVars vars = new ErfVars(); - double current_time = m_c - m_s; - double c1 = 1; - double c2 = 1; - double theta = 0; - double mu = - c1*Math.exp(-current_time - t) + theta; - double sd = Math.sqrt(c2*(Math.exp(-2*current_time - 2*t) - Math.exp(-2))); ! for (int i= 0; i < m_hypPredictions.length; i++) { ! int example = i; double margin = m_margins[example]; // m_labels are 0 or 1 or arbitrary other, this moves it to +-1 double step = getStep(m_labels[example], m_hypPredictions[example]); ! // variable names are taken from Freund 1999, Freund 2001 double aj = margin + m_s; --- 187,200 ---- { ErfVars vars = new ErfVars(); ! ! double new_margin, new_time_remaining, new_weight, new_potential, orig_potential; ! for (int example= 0; example < m_hypPredictions.length; example++) { double margin = m_margins[example]; // m_labels are 0 or 1 or arbitrary other, this moves it to +-1 double step = getStep(m_labels[example], m_hypPredictions[example]); ! ! /* // variable names are taken from Freund 1999, Freund 2001 double aj = margin + m_s; *************** *** 206,235 **** double dj = margin + bj*alpha + m_s - t; double wj = Math.exp(-(dj*dj)/m_c); ! ! /* vars.W += wj; vars.U += wj*dj*bj; vars.B += wj*bj; vars.V += wj*dj*bj*bj; ! vars.I += erf(dj / Math.sqrt(m_c)) - m_initialPotential; ! vars.E += erf(dj / Math.sqrt(m_c)) - erf(aj / Math.sqrt(m_c)); vars.Potential += (1-erf( dj /Math.sqrt(m_c)))/2; */ - ! ! double new_margin = margin + bj*alpha; ! double new_time_remaining = m_s - t; ! double new_weight = calculateWeight(new_margin, new_time_remaining); ! double new_potential = calculatePotential(new_margin, new_time_remaining); ! double orig_potential = calculatePotential(margin, m_s); ! vars.E += orig_potential - new_potential; // - orig_potential; ! vars.B += new_weight * bj; ! vars.Potential += calculatePotential(new_margin, new_time_remaining) / m_hypPredictions.length; ! ! //System.out.println("Example: " + j + ", Step: " + step + ", Label: " + label + ", Margin: " + margin + ", Pred: " + pred); //System.out.println("W:" + W + ", U:" + U + ", B:" + B + ", V:" + V + ", E:" + E); } return vars; } --- 202,230 ---- double dj = margin + bj*alpha + m_s - t; double wj = Math.exp(-(dj*dj)/m_c); ! vars.W += wj; vars.U += wj*dj*bj; vars.B += wj*bj; vars.V += wj*dj*bj*bj; ! vars.I += erf(dj / Math.sqrt(m_c)) - m_initialPotential; ! vars.E += erf(dj / Math.sqrt(m_c)) - erf(aj / Math.sqrt(m_c)); vars.Potential += (1-erf( dj /Math.sqrt(m_c)))/2; */ ! new_margin = margin + step*alpha; ! new_time_remaining = m_s - t; ! new_weight = calculateWeight(new_margin, new_time_remaining); ! new_potential = calculatePotential(new_margin, new_time_remaining); ! orig_potential = calculatePotential(margin, m_s); vars.E += orig_potential - new_potential; // - orig_potential; ! vars.B += new_weight * step; ! vars.Potential += calculatePotential(new_margin, new_time_remaining); ! ! //System.out.println("Example: " + j + ", Step: " + step + ", Label: " ! //+ label + ", Margin: " + margin + ", Pred: " + pred); //System.out.println("W:" + W + ", U:" + U + ", B:" + B + ", V:" + V + ", E:" + E); } + + vars.Potential /= m_hypPredictions.length; return vars; } *************** *** 320,329 **** int NUM_ITERATIONS_FINISH_GAME = 10; int count_t_over_s = 0; - double lastE = 0; - double STEP_EPS = 0.00001; double CORR_EPS = 0.001; - boolean first_iter = true; while(Math.abs(t_step) > STEP_EPS) { --- 315,321 ---- *************** *** 407,410 **** --- 399,405 ---- t = bs_t; + m_oldS = m_s; + m_s -= t; + System.out.format("\tBrownBoost: alpha=%.4f, t=%.4f, time left=%.4f, " + "potential=%.4f\n", alpha, t, m_s, vars.Potential); *************** *** 417,422 **** } - m_oldS = m_s; - m_s -= t; //System.out.println("\ns: " + m_s); return alpha; --- 412,415 ---- *************** *** 457,474 **** int example = indexes[j]; m_margins[example] += value[m_labels[example]]; - - m_totalWeight -= m_weights[example]; - m_weights[example] = calculateWeight(m_margins[example]); - m_totalWeight += m_weights[example]; - - //System.out.println("Example: " + j + - // ", Label: " + getLabel(m_labels[example]) + - // ", Margin: " + m_margins[example] + - // ", Step: " + getStep(m_labels[example], m_hypPredictions[example]) + - // ", Weight: " + m_weights[example] - // ); } - //predictions[i].scale(alpha); } } --- 450,461 ---- 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]; + } } |