brownboosttest.java

来自「Boosting算法软件包」· Java 代码 · 共 192 行

JAVA
192
字号
package jboost.booster;import jboost.examples.Label;/** * @author Aaron Arvey * * To change the template for this generated type comment go to * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments */public class BrownBoostTest extends AbstractBoosterTest {    BrownBoost m_brownBoost;    /**     * Constructor for BrownBoostTest.     * @param arg0     */    public BrownBoostTest(String arg0) {        super(arg0);    }    /**     * Tests the BrownBoost constructor and sets up boosters for     * other tests.     * @see TestCase#setUp()     */    protected void setUp() throws Exception {        m_odd= new BrownBoost();	((BrownBoost)m_odd).setRuntime(1.0);        m_even= new BrownBoost();	((BrownBoost)m_even).setRuntime(1.0);        m_allTrue= new BrownBoost();	((BrownBoost)m_allTrue).setRuntime(1.0);        m_allFalse= new BrownBoost();	((BrownBoost)m_allFalse).setRuntime(1.0);        m_brownBoost= new BrownBoost();	((BrownBoost)m_brownBoost).setRuntime(1.0);        m_solitaires= new BrownBoost[COUNT];        for (int i=0; i < COUNT; i++) {            m_solitaires[i]= new BrownBoost();	    ((BrownBoost)m_solitaires[i]).setRuntime(1.0);        }        super.setUp();    }    final public void testAddExample() {        //TODO Implement addExample().    }    final public void testFinalizeData() {        //TODO Implement finalizeData().    }    final public void testClear() {        //TODO Implement clear().    }    /*     * Test for Bag newBag(int[])     */    final public void testNewBagintArray() {        //TODO Implement newBag().    }    /*     * Test for Bag newBag()     */    final public void testNewBag() {        //TODO Implement newBag().    }    /*     * Test for Bag newBag(Bag)     */    final public void testNewBagBag() {        //TODO Implement newBag().    }            /**     * This test indicates whether or not the update algorithm in      * BrownBoost is producing the correct weights.  This is the core     * of the BrownBoost algorithm and is thus the most important to test.     */    public final void testUpdate() {      //TODO Implement update().      // fill in booster      Bag bags[];      int[] indices= new int[COUNT];      int[] ones= new int[COUNT/2];      int[] zeroes= new int[COUNT/2];      for (int i=0; i < COUNT/2; i++) {        m_brownBoost.addExample(i, new Label(0));        indices[i]= i;        zeroes[i]= i;      }      for (int i=COUNT/2, j=0; i < COUNT; i++, j++) {        m_brownBoost.addExample(i, new Label(1));        indices[i]= i;        ones[j]= i;      }      /*      m_brownBoost.finalizeData();      int[][] partition = new int[][] {zeroes};      bags = new Bag[1];      bags[0] = m_brownBoost.newBag(zeroes);      Prediction[] p1= ((BrownBoost)m_brownBoost).getPredictions(bags, partition);      m_brownBoost.update(p1, partition);      for (int i=0; i < zeroes.length; i++) {        zeroes[i]= indices[COUNT/2 + i];        for (int j=0; j < zeroes.length; j++) {          int index= zeroes[j];          double weight= m_brownBoost.m_weights[index];          double margin= m_brownBoost.m_margins[index];          double s = m_brownBoost.m_s;          double c = m_brownBoost.m_c;	  System.out.println("weight, margin, s, c : " + weight			     + ", " + margin			     + ", " + s + ", " + c);       	  assertEquals(weight, Math.exp(-Math.pow(margin+s,2)/c), 0.0001);        }      }            for (int i=0; i < ones.length; i++) {        ones[i]= indices[COUNT/2 + i];	bags = new Bag[1];	bags[0] = m_brownBoost.newBag(ones);	int[][] parition = new int[][] {ones};	p1 = ((BrownBoost)m_brownBoost).getPredictions(bags, partition);        m_brownBoost.update(p1, parition);        for (int j=0; j < ones.length; j++) {          int index= ones[j];          double weight= m_brownBoost.m_weights[index];          double margin= m_brownBoost.m_oldMargins[index];          double s = m_brownBoost.m_oldS;          double c = m_brownBoost.m_c;          if(Double.isNaN(weight)){        	  System.err.println("Warning: weight is NaN!");        	  continue;          }          assertEquals(weight, Math.exp(-Math.pow(margin+s,2)/c), 0.001);        }      }      */    }        final public void testGetPredictions() {        //TODO Implement getPredictions().    }    final public void testGetTheoryBound() {        //TODO Implement getTheoryBound().    }    final public void testGetMargins() {        //TODO Implement getMargins().    }    /*     * Test for void BrownBoost()     * Not yet implemented.     */    final public void testBrownBoost() {        //TODO Implement BrownBoost().    }    /*     * Test for void BrownBoost(double)     * Not yet implemented.     */    final public void testBrownBoostdouble() {        //TODO Implement BrownBoost().    }    final public void testGetPrediction() {        //TODO Implement getPrediction().    }    final public void testErf() {	assertEquals(BrownBoost.erf(0.5), .5204998, 0.0001);	assertEquals(BrownBoost.erf(1.0), .8427007, 0.0001);	assertEquals(BrownBoost.erf(2.0), .9953222, 0.0001);	assertEquals(BrownBoost.erf(-0.5), -.5204998, 0.0001);	assertEquals(BrownBoost.erf(-1.0), -.8427007, 0.0001);	assertEquals(BrownBoost.erf(-2.0), -.9953222, 0.0001);    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?