Update of /cvsroot/jboost/jboost/src/jboost/booster In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv9842/booster Modified Files: MulticlassWrapMH.java AbstractBooster.java AdaBoost.java Booster.java DebugWrap.java BrownBoost.java Log Message: New log file format. Index: MulticlassWrapMH.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/MulticlassWrapMH.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** MulticlassWrapMH.java 30 May 2007 07:41:55 -0000 1.3 --- MulticlassWrapMH.java 18 Sep 2007 03:25:58 -0000 1.4 *************** *** 74,77 **** --- 74,80 ---- } + + + public void finalizeData() { m_booster.finalizeData(); *************** *** 85,88 **** --- 88,129 ---- return new MultiBag(); } + + + /** + * + */ + public double[][] getWeights() { + int numExamples = m_booster.getNumExamples() / m_numLabels; + double[][] r= new double[numExamples][m_numLabels]; + 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; + } + + /** + * + */ + public double[][] getPotentials() { + int numExamples = m_booster.getNumExamples() / m_numLabels; + double[][] r= new double[numExamples][m_numLabels]; + double[][] potentials = m_booster.getPotentials(); + for (int i= 0; i < numExamples; i++) + for (int j=0; j < m_numLabels; j++) + r[i][j]= potentials[i*m_numLabels+j][0]; + return r; + } + + + /** + * + * + */ + public String getParamString() { + return m_booster.getParamString(); + } + + /** *************** *** 91,94 **** --- 132,140 ---- * extend the abstract booster" * + * According to Aaron: It seems that multiclass booster should + * certainly extend AbstractBooster. MulticlassWrap becomes the + * booster and merely insulates the true booster via an Adaptor + * design pattern. + * * Not sure what context this function would be inappropriate. */ *************** *** 140,144 **** * train the underlying booster. */ ! public double[] getMargins() { return m_booster.getMargins(); } --- 186,190 ---- * train the underlying booster. */ ! public double[][] getMargins() { return m_booster.getMargins(); } *************** *** 314,321 **** } /** * 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 { /** --- 360,370 ---- } + + /** * 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 { /** Index: AdaBoost.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/AdaBoost.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** AdaBoost.java 16 May 2007 04:06:02 -0000 1.1.1.1 --- AdaBoost.java 18 Sep 2007 03:25:58 -0000 1.2 *************** *** 1,2 **** --- 1,3 ---- + /* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ package jboost.booster; *************** *** 30,33 **** --- 31,37 ---- /** permanent storage for example's old m_weights */ protected double[] m_oldWeights; + /** Records the potentials. Similar to m_margins and m_weights. */ + protected double[] m_potentials; + /** sampling weights for the examples */ protected double[] m_sampleWeights; *************** *** 118,121 **** --- 122,126 ---- m_labels= null; m_margins= null; + m_potentials= null; m_weights= null; m_oldWeights= null; *************** *** 126,133 **** protected void finalizeData(double defaultWeight) { ! m_margins= new double[m_numExamples]; ! m_oldMargins= new double[m_numExamples]; m_weights= new double[m_numExamples]; m_oldWeights= new double[m_numExamples]; m_labels= new short[m_numExamples]; m_sampleWeights= new double[m_numExamples]; --- 131,139 ---- protected void finalizeData(double defaultWeight) { ! m_margins= new double[m_numExamples]; ! m_oldMargins= new double[m_numExamples]; m_weights= new double[m_numExamples]; m_oldWeights= new double[m_numExamples]; + m_potentials= new double[m_numExamples]; m_labels= new short[m_numExamples]; m_sampleWeights= new double[m_numExamples]; *************** *** 150,153 **** --- 156,160 ---- } + /** * Return the theoretical bound on the training error. *************** *** 160,170 **** * Returns the margin values of the training examples. */ ! public double[] getMargins() { ! double[] r= new double[m_numExamples]; for (int i= 0; i < m_numExamples; i++) ! r[i]= m_margins[i]; return r; } /** output AdaBoost contents as a human-readable string */ public String toString() { --- 167,225 ---- * Returns the margin values of the training examples. */ ! public double[][] getMargins() { ! double[][] r= new double[m_numExamples][1]; for (int i= 0; i < m_numExamples; i++) ! r[i][0]= m_margins[i]; return r; } + /** + * + */ + public double[][] getWeights() { + double[][] r= new double[m_numExamples][1]; + for (int i= 0; i < m_numExamples; i++) + r[i][0]= m_weights[i]; + return r; + } + + /** + * + */ + public double[][] getPotentials() { + double[][] r= new double[m_numExamples][1]; + for (int i= 0; i < m_numExamples; i++) + r[i][0]= m_potentials[i]; + return r; + } + + /** + * + */ + public int getNumExamples() { + return m_numExamples; + } + + + /** + * 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() { Index: Booster.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/Booster.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** Booster.java 16 May 2007 04:06:02 -0000 1.1.1.1 --- Booster.java 18 Sep 2007 03:25:58 -0000 1.2 *************** *** 68,72 **** * for statistical purposes only (e.g., plotting all margin values). */ ! public abstract double[] getMargins(); /** --- 68,79 ---- * for statistical purposes only (e.g., plotting all margin values). */ ! public abstract double[][] getMargins(); ! ! ! public abstract double[][] getWeights(); ! public abstract double[][] getPotentials(); ! public int getNumExamples(); ! public abstract String getParamString(); ! /** Index: BrownBoost.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/BrownBoost.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** BrownBoost.java 10 Jul 2007 01:32:52 -0000 1.5 --- BrownBoost.java 18 Sep 2007 03:25:58 -0000 1.6 *************** *** 44,52 **** * 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; --- 44,47 ---- *************** *** 62,66 **** 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); --- 57,60 ---- *************** *** 421,430 **** } public String surfingData() { ! String ret = new String(""); ! ret += String.format("BrownBoost Params: %.4f %.4f\n", m_c, m_s); 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; } --- 415,431 ---- } + /* public String surfingData() { ! StringBuffer ret = new StringBuffer(""); ! ret.append(String.format("BrownBoost Params: %.4f %.4f\n", m_c, m_s)); 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(); + } + */ + + public String getParamString() { + String ret = String.format("BrownBoost Params: %.4f %.4f", m_c, m_s); return ret; } Index: DebugWrap.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/DebugWrap.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** DebugWrap.java 16 May 2007 04:06:02 -0000 1.1.1.1 --- DebugWrap.java 18 Sep 2007 03:25:58 -0000 1.2 *************** *** 140,143 **** --- 140,155 ---- return booster.calculateWeight(margin); } + + + + public double[][] getWeights() { + return new double[1][1]; + } + + public double[][] getPotentials(){ + return new double[1][1]; + } + + *************** *** 239,243 **** } ! public double[] getMargins() { return booster.getMargins(); } --- 251,255 ---- } ! public double[][] getMargins() { return booster.getMargins(); } Index: AbstractBooster.java =================================================================== RCS file: /cvsroot/jboost/jboost/src/jboost/booster/AbstractBooster.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** AbstractBooster.java 14 Jun 2007 16:33:51 -0000 1.4 --- AbstractBooster.java 18 Sep 2007 03:25:58 -0000 1.5 *************** *** 69,79 **** double c1 = Double.parseDouble(c.getString("c1", "1.0")); double c2 = Double.parseDouble(c.getString("c2", "1.0")); ! double theta = Double.parseDouble(c.getString("theta", "0.2")); jboost.booster.YabaBoost yaba = (jboost.booster.YabaBoost) result; yaba.setParams(c1,c2,theta); result = yaba; } - - } --- 69,77 ---- double c1 = Double.parseDouble(c.getString("c1", "1.0")); double c2 = Double.parseDouble(c.getString("c2", "1.0")); ! double theta = Double.parseDouble(c.getString("theta", "0.15")); jboost.booster.YabaBoost yaba = (jboost.booster.YabaBoost) result; yaba.setParams(c1,c2,theta); result = yaba; } } *************** *** 91,94 **** --- 89,101 ---- } + public int getNumExamples(){ + return 0; + } + + public String getParamString() { + return "No parameters defined"; + } + + /** * Create and return a new Bag which initially contains the |