From: Daniel H. <dh...@us...> - 2008-04-07 17:21:51
|
Update of /cvsroot/jboost/jboost/src/jboost/booster In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv23957/src/jboost/booster Modified Files: Tag: jboost_unstable AdaBoost.java Log Message: clean-up Index: AdaBoost.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/AdaBoost.java,v retrieving revision 1.6 retrieving revision 1.6.2.1 diff -C2 -d -r1.6 -r1.6.2.1 *** AdaBoost.java 25 Mar 2008 01:00:27 -0000 1.6 --- AdaBoost.java 7 Apr 2008 17:21:47 -0000 1.6.2.1 *************** *** 28,32 **** protected double[] m_margins; /** permanent storage for old m_margins */ ! protected double[] m_oldMargins; /** permanent storage for example m_weights */ protected double[] m_weights; --- 28,32 ---- protected double[] m_margins; /** permanent storage for old m_margins */ ! protected double[] m_oldMargins; // XXX DJH: this is never used in AdaBoost (e.g. not cleared in clear()) /** permanent storage for example m_weights */ protected double[] m_weights; *************** *** 73,77 **** /** temporary location for storing the examples as they are read in */ ! protected List m_tmpList; --- 73,77 ---- /** temporary location for storing the examples as they are read in */ ! protected List<TmpData> m_tmpList; *************** *** 90,94 **** */ AdaBoost(double smooth) { ! m_tmpList= new ArrayList(); m_numExamples= 0; m_smooth= smooth; --- 90,94 ---- */ AdaBoost(double smooth) { ! m_tmpList= new ArrayList<TmpData>(); m_numExamples= 0; m_smooth= smooth; *************** *** 104,113 **** } ! /** ! * Add an example to the data set of this booster ! * @param index ! * @param label ! * @param weight ! */ public void addExample(int index, Label label, double weight) { int l= label.getSingleValue(); --- 104,113 ---- } ! /** ! * Add an example to the data set of this booster ! * @param index ! * @param label ! * @param weight ! */ public void addExample(int index, Label label, double weight) { int l= label.getSingleValue(); *************** *** 119,128 **** if (l==POSITIVE_LABEL) m_numPosExamples++; } else { ! failed= "AdaBoost.addExample received index " + index + ", when it expected index " + ! m_numExamples; } } else { ! failed= "Adaboost.addExample expected a label which is either 0 or 1. It received " + ! l; } --- 119,128 ---- if (l==POSITIVE_LABEL) m_numPosExamples++; } else { ! // XXX DJH: determine class name at runtime ! failed= getClass().getName() + ".addExample received index " + index + ", when it expected index " + m_numExamples; } } else { ! // XXX DJH: determine class name at runtime ! failed= getClass().getName() + ".addExample expected a label which is either 0 or 1. It received " + l; } *************** *** 181,185 **** m_negExamples[m_negIndex++] = index; else { ! System.err.println("Label of example is unknown to adaboost"); System.exit(2); } --- 181,186 ---- m_negExamples[m_negIndex++] = index; else { ! // XXX DJH: determine class name at runtime ! System.err.println("Label of example is unknown to " + this.getClass().getName()); System.exit(2); } *************** *** 248,278 **** ! /** ! * Returns a string with all the weights, margins, etc ! */ ! public String getExampleData() { ! StringBuffer ret = new StringBuffer(""); ! 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])); ! } ! return ret.toString(); } ! public String getParamString() { ! String ret = String.format("None (AdaBoost)"); ! return ret; ! } /** output AdaBoost contents as a human-readable string */ public String toString() { String s= ! "Adaboost. No of examples = " ! + m_numExamples ! + ", m_epsilon = " ! + m_epsilon; s += "\nindex\tmargin\tweight\told weight\tlabel\n"; NumberFormat f= new DecimalFormat("0.00"); --- 249,282 ---- ! /** ! * Returns a string with all the weights, margins, etc ! */ ! public String getExampleData() { ! StringBuffer ret = new StringBuffer(""); ! 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])); } + return ret.toString(); + } ! public String getParamString() { ! // XXX DJH: determine class name at runtime ! String ret = String.format("None (" + getClass().getName() + ")"); ! return ret; ! } /** output AdaBoost contents as a human-readable string */ public String toString() { + // XXX DJH: determine class name at runtime String s= ! getClass().getName() + ! ". No of examples = " ! + m_numExamples ! + ", m_epsilon = " ! + m_epsilon; s += "\nindex\tmargin\tweight\told weight\tlabel\n"; NumberFormat f= new DecimalFormat("0.00"); *************** *** 289,293 **** + f.format(m_sampleWeights[i]) + "\t\t" + m_labels[i] ! + "\n"; } return s; --- 293,297 ---- + f.format(m_sampleWeights[i]) + "\t\t" + m_labels[i] ! + "\n"; } return s; *************** *** 353,357 **** * @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; --- 357,362 ---- * @return +1 if label matches hyp, -1 if label doesn't match hyp, 0 if no hyp */ ! // XXX DJH: changed from 'public' to 'protected' ! protected double getStep(short simple_label, double hyp_pred) { double step = getLabel(simple_label)*hyp_pred; double EPS = 0.000001; *************** *** 360,364 **** } ! public double getLabel(short simple_label) { return sign(-simple_label+0.5); } --- 365,370 ---- } ! // XXX DJH: changed from 'public' to 'protected' ! protected double getLabel(short simple_label) { return sign(-simple_label+0.5); } *************** *** 369,373 **** 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]; --- 375,379 ---- double total_weight = 0.0; ! // Keep track of which examples had hypotheses associated with them. boolean[] examplesWithHyp = new boolean[m_margins.length]; m_hypPredictions = new double[m_margins.length]; *************** *** 378,384 **** 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]; } } --- 384,390 ---- 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]; } } *************** *** 386,390 **** int numExamplesWithHyps = 0; - double weight; // Get all examples that have a hypothesis associated with them for (int i= 0; i < exampleIndex.length; i++) { --- 392,395 ---- *************** *** 442,446 **** } }*/ - double gamma = getHypErr(bags, exampleIndex); return getPredictions(bags); } --- 447,450 ---- *************** *** 452,456 **** */ public double calculateWeight(double margin) { ! return Math.exp(-1 * margin); } --- 456,460 ---- */ public double calculateWeight(double margin) { ! return Math.exp(-1 * margin); } *************** *** 579,583 **** double EPS = 0.0000001; if (m_w[0] < EPS && m_w[1] < EPS) { ! return true; } return false; --- 583,587 ---- double EPS = 0.0000001; if (m_w[0] < EPS && m_w[1] < EPS) { ! return true; } return false; *************** *** 665,672 **** BinaryPrediction p = new BinaryPrediction( ! m_w[1] == m_w[0] ! ? 0.0 ! : // handle case that w0=w1=0 ! 0.5 * Math.log((m_w[1] + smoothFactor) / (m_w[0] + smoothFactor))); return p; } --- 669,676 ---- BinaryPrediction p = new BinaryPrediction( ! m_w[1] == m_w[0] ! ? 0.0 ! : // handle case that w0=w1=0 ! 0.5 * Math.log((m_w[1] + smoothFactor) / (m_w[0] + smoothFactor))); return p; } |