From: Aaron A. <aa...@us...> - 2007-10-02 02:32:51
|
Update of /cvsroot/jboost/jboost/src/jboost/booster In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv12857 Added Files: MixedBinaryPredictionTest.java Log Message: MixedBinaryPredictionTest added... ooops --- NEW FILE: MixedBinaryPredictionTest.java --- package jboost.booster; import jboost.booster.NotNormalizedPredException; import junit.framework.TestCase; /** * @author Aaron Arvey * * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments */ public class MixedBinaryPredictionTest extends TestCase { //protected MixedBinaryPrediction p; /** * Constructor for * @param arg0 */ public MixedBinaryPredictionTest(String arg0) { super(arg0); System.out.println("Making MixedPred class"); } final public void testAdd() { System.out.println("test add"); Prediction p = new MixedBinaryPrediction(); assertEquals(true, Prediction.isNormPred(p)); MixedBinaryPrediction np = new MixedBinaryPrediction(); assertEquals(true, Prediction.isNormPred(np)); } protected void setUp() { System.out.println("set up "); } protected void tearDown() { System.out.println("tear down"); } final public void testCodeOutput() { System.out.println("test code output"); } final public void testIsNormPred() { System.out.println("is norm pred"); BinaryPrediction bp = new BinaryPrediction(); assertEquals(false, Prediction.isNormPred(bp)); Prediction p = new MixedBinaryPrediction(); assertEquals(true, Prediction.isNormPred(p)); MixedBinaryPrediction np = new MixedBinaryPrediction(); assertEquals(true, Prediction.isNormPred(np)); } final public void testConstructor() { System.out.println("test constructor"); MixedBinaryPrediction p; boolean exceptionThrown = false; try { p = new MixedBinaryPrediction(5); } catch (NotNormalizedPredException e) { exceptionThrown = true; } if (!exceptionThrown) { assertEquals(1,0); } try { p = new MixedBinaryPrediction(-5); } catch (NotNormalizedPredException e) { exceptionThrown = true; } if (!exceptionThrown) { assertEquals(1,0); } try { p = new MixedBinaryPrediction(0.0); p = new MixedBinaryPrediction(0.3); p = new MixedBinaryPrediction(0.99); p = new MixedBinaryPrediction(1.0); } catch (NotNormalizedPredException e) { assertEquals(1,0); } } } // public MixedBinaryPrediction(double p) throws NotNormalizedPredException{ // super(); // if (Math.abs(p) > 1) { // throw new NotNormalizedPredException("Prediction is unnormalized " // + "prediction! p is: " + p); // } // prediction=p; // } // public Object clone(){ // Object a = new MixedBinaryPrediction(prediction); // return a; // } // /** // * Be very careful with how this is used. See NormalizedPrediction // * for details. // */ // public Prediction add(Prediction p) throws NotNormalizedPredException{ // if (! (p instanceof MixedBinaryPrediction)) { // throw new NotNormalizedPredException("Must use MixedBinaryPrediction when adding to a MixedBinaryPrediction."); // } // // H_t = (1-alpha)H_{t-1} + alpha h_t // // The prediction p is for h_t // double alpha = ((MixedBinaryPrediction) p).prediction; // prediction = (1-Math.abs(alpha)) * prediction + alpha; // if (Math.abs(alpha) > 1 || Math.abs(prediction) > 1) { // throw new NotNormalizedPredException("Prediction may result in unnormalized " // + "prediction! p is: " + p); // } // return this; // } // /** // * This is not well defined for normalized predictions. However, we // * do allow it. // */ // public Prediction scale(double w) throws NotNormalizedPredException{ // if (Math.abs(w) > 1) { // throw new NotNormalizedPredException("Scalar may result in unnormalized " // + "prediction! w is: " + w); // } // prediction *= w; // return this; // } // public Prediction add(double w, Prediction p) { // ((MixedBinaryPrediction) p).scale(w); // this.add( (MixedBinaryPrediction) p ); // return this; // } // public boolean equals(Prediction other) { // MixedBinaryPrediction bp= (MixedBinaryPrediction) other; // return (prediction == bp.prediction); // } // public String toString() { // return "MixedBinaryPrediction. p(1)= " + prediction; // } // public String cPreamble() { // System.out.println("Prediction::cPreamble not supported."); // System.exit(2); // return // "typedef double Prediction_t;\n" + // "#define reset_pred() {p = 0.0;}\n" + // "#define add_pred(X) {p = (1-(X))*p + (X);}\n" + // "#define finalize_pred()" + // " ((r) ? (r[1] = p , r[0] = -p) : -p)\n"; // } // public String javaPreamble() { // System.out.println("Prediction::javaPreamble not supported."); // System.exit(2); // return "" // + " static private double p;\n" // + " static private void reset_pred() { p = 0.0; }\n" // + " static private void add_pred(double x) { p = (1-x)*p + x; }\n" // + " static private double[] finalize_pred() {\n" // + " return new double[] {-p, p};\n" // + " }\n"; // } // public double[] toCodeArray() { // return new double[] {prediction}; // } // } |