⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mixedbinaryprediction.java

📁 Boosting算法软件包
💻 JAVA
字号:
package jboost.booster;import jboost.examples.Label;import jboost.booster.NotNormalizedPredException;/** * A binary normalized predictor. See NoramlizedPrediction * * @author Aaron Arvey **/class MixedBinaryPrediction extends BinaryPrediction implements NormalizedPrediction{    public MixedBinaryPrediction() {super();}    /*    public static boolean isNormPred(Prediction p) {	return (p instanceof NormalizedPrediction);    }    */    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};    }}

⌨️ 快捷键说明

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