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

📄 algorithmlp.java,v

📁 包含了模式识别中常用的一些分类器设计算法
💻 JAVA,V
📖 第 1 页 / 共 3 页
字号:
     *     */    public void final_estimate()    {		if(iset1.size() > 0)	    estimate (iset1, y_estimate1, average1, final_lpc_1);		if(iset2.size() > 0)	    	    estimate (iset2, y_estimate2, average2, final_lpc_2);		if(iset3.size() > 0)	    estimate (iset3, y_estimate3, average3, final_lpc_3);		if(iset4.size() > 0)	    estimate (iset4, y_estimate4, average4, final_lpc_4);    }         /**     *     * Estimates the amplitude based on the LP coeficients.     *     * @@param    iset         interpolated data points     * @@param    y_estimate   predicted final signal data points     * @@param    avg          mean of the original datapoints given     * @@param    final_lpc    array of final linear prediction coefficients     *      */    public void estimate( Vector<MyPoint> iset, Vector<MyPoint> y_estimate, 			  double avg, double[] final_lpc)    {	   y_estimate.removeAllElements();	   double amplitude[];		   for(int i = 0; i < iset.size(); i++)	       y_estimate.addElement(new MyPoint((MyPoint)iset.elementAt(i))); 	   amplitude = new double[y_estimate.size()];	   	   for (int i = 0; i < y_estimate.size(); i++)	       amplitude[i] = ((MyPoint)y_estimate.elementAt(i)).y;	   	   ((MyPoint)y_estimate.firstElement()).y = 0 ;	   	   for ( int i = 1; i < y_estimate.size(); i++ )	   {    	       int z = i;  	       double sum  = 0;	       	       for( int j = 1; (j <= lporder) && (z > 0); j++, z-- )		   sum = sum - amplitude[z - 1] * final_lpc[j];	       	       ((MyPoint)y_estimate.elementAt(i)).y = sum + avg;	    }    }    /**     *     * Compute the actual error from the given data points and the estimated     * values.     *     * @@param  y_estimate datapoints of the estimated datapoints     * @@param  iset       original datapoints      *     * @@return actual error energy in a double     */    public double actual_error (Vector y_estimate, Vector iset)    {	double error_value;	double act_error = (double) 0;	int j = 0;	int i = 0;	// first point and the last point have their x-coordinates same	// So the difference in y-values is the error value	//	error_value = ((MyPoint)y_estimate.firstElement()).y 	              - ((MyPoint)iset.firstElement()).y;	act_error = act_error + error_value * error_value; 	error_value = ((MyPoint)y_estimate.lastElement()).y 	              - ((MyPoint)iset.lastElement()).y;	act_error = act_error + error_value * error_value;	// for next values	// need to continue till all the user defined points are exhausted	//	j++;	for (i = 1; ( (i < y_estimate.size()) && (j < iset.size()) ); i++)	{ 	    while ( (((MyPoint)y_estimate.elementAt(i)).x < 		     ((MyPoint)iset.elementAt(j)).x) 		    && ((i < y_estimate.size() - 1) && (j < iset.size())) )	    {		    i++;	    }	    if ( j < iset.size())	    {		if ( ((MyPoint)y_estimate.elementAt(i)).x 		     == ((MyPoint)iset.elementAt(j)).x ) 		{		    error_value = ((MyPoint)y_estimate.elementAt(i)).y 			          - ((MyPoint)iset.elementAt(j)).y;		    act_error = act_error + error_value * error_value;		}		if ( ((MyPoint)y_estimate.elementAt(i)).x 		     > ((MyPoint)iset.elementAt(j)).x )		{		    double y1 = ((MyPoint)y_estimate.elementAt(i)).y;		    double y2 = ((MyPoint)y_estimate.elementAt(i - 1)).y;		    double x1 = ((MyPoint)y_estimate.elementAt(i)).x;		    double x2 = ((MyPoint)y_estimate.elementAt(i - 1)).x;		    double x_unknown = ((MyPoint)iset.elementAt(j)).x;		    error_value = y2 - ( (x2 - x_unknown) * 					 ( y2 - y1) / (x2 - x1));		    act_error = act_error + error_value * error_value ;		}	    }	    j++;	}	return act_error;    }	    /**     *     * Displays LP order, Error Energy and Reflection Coefficients      *     */    public void step2_display()    {	// display the LP order	//	pro_box_d.appendMessages("         LP order =  " + lporder + "\n");	if (set1_d.size() > 0 )        {	    int num_pts =  iset1.size();	    int n = 0;	    display_result(auto_co_1, ref_coeff_1, final_lpc_1, 			   actual_err_1, estimate_err_1, n, num_pts);       	}	if (set2_d.size() > 0 )        {	    int num_pts =  iset2.size();	        	    int n = 1;	    display_result(auto_co_2, ref_coeff_2, final_lpc_2, 			   actual_err_2, estimate_err_2, n, num_pts);	}	if (set3_d.size() > 0 )        {	    int num_pts =  iset3.size();	    int n = 2;	    display_result(auto_co_3, ref_coeff_3, final_lpc_3, 			   actual_err_3, estimate_err_3, n, num_pts);	}	if (set4_d.size() > 0 )        {	    int num_pts =  iset4.size();	    int n = 3;	    display_result(auto_co_4, ref_coeff_4, final_lpc_4,			   actual_err_4, estimate_err_4, n, num_pts);	}    }    /**     * Display the results in the process box     *     * @@param    auto_coeff Auto Correlation Coefficients     * @@param    refCoef Refelction Coefficient      * @@param    final_lpc Linear Prediction Coefficients     * @@param    est_err Estimated Error     * @@param    act_err Actual Error     * @@param    length Length of the data points     *     */     public void display_result( double[] auto_coeff, double[] refCoef, 				double[] final_lpc, double est_err, 				double act_err, int index, int length)    { 	pro_box_d.appendMessages("\n" + "         Class  " + index + " : \n");	pro_box_d.appendMessages("         Number of Points = " + length 				 + "\n");	pro_box_d.appendMessages( "         AutoCorrelation Coefficients:" 				  + "\n");	pro_box_d.appendMessages("              [ ");	for (int i = 0 ; i <= lporder; i++)	    if (i == lporder)		pro_box_d.appendMessages(MathUtil.SetDecimal(auto_coeff[i], 3)					 + " ");	    else		pro_box_d.appendMessages(MathUtil.SetDecimal(auto_coeff[i], 3)					 + ", ");	pro_box_d.appendMessages(" ]");	pro_box_d.appendMessages("\n" + "         Reflection Coefficients:" 				 + "\n");	pro_box_d.appendMessages("              [ ");	for (int i = 1 ; i <= lporder; i++)	    if (i == lporder)		pro_box_d.appendMessages(MathUtil.SetDecimal(refCoef[i], 3) 					 + " ");	    else		pro_box_d.appendMessages(MathUtil.SetDecimal(refCoef[i], 3) 					 + ", ");	pro_box_d.appendMessages(" ]");		pro_box_d.appendMessages("\n" + "         Prediction Coefficients:" 				 + "\n");	pro_box_d.appendMessages("              [ ");	for (int i = 0 ; i <= lporder; i++)	    if (i == lporder )	    pro_box_d.appendMessages(MathUtil.SetDecimal(final_lpc[i], 3) 				     + " ");	    else		pro_box_d.appendMessages(MathUtil.SetDecimal(final_lpc[i], 3) 					 + ", ");	pro_box_d.appendMessages(" ]");	pro_box_d.appendMessages("\n" + "         Estimated Error Energy  = " 				 + MathUtil.SetDecimal(act_err, 3)); 	pro_box_d.appendMessages("\n" 				 + "         Actual Error Energy         = " 				 + MathUtil.SetDecimal(est_err, 3) + "\n");     }    /**     *     * displays the predicted signal     *     * @@return   True     *      */    boolean step3()    {	// The display needs to be changed to draw a line between	// the two points on the waveform.	// The method is:	// 1. Get the first two estimated points.	// 2. Draw a straight line between these two points.	// 3. Drop the first point, now take the next point.	// 4. Continue with step 2 and 3 in the same way, 	//    till you come to the end.	//	if(set1_d.size() > 0)	    output_panel_d.addOutput( y_estimate1, Classify.PTYPE_LINE, 				      Color.black);	if(set2_d.size() > 0)	    output_panel_d.addOutput( y_estimate2, Classify.PTYPE_LINE, 				      Color.pink);	if(set3_d.size() > 0)	    output_panel_d.addOutput( y_estimate3, Classify.PTYPE_LINE, 				      Color.cyan);	if(set4_d.size() > 0)	    output_panel_d.addOutput( y_estimate4, Classify.PTYPE_LINE, 				      Color.magenta);	output_panel_d.repaint();	// displaying "Algorithm Complete" 	//	pro_box_d.appendMessages("Algorithm Complete " + "\n");       	return true;    }}@1.14log@fixed javadoc comments@text@d12 1d48 3a50 3    Vector support_vectors_d;    Vector decision_regions_d;  d53 4a56 4    Vector set1_d = new Vector(40, 20);    Vector set2_d = new Vector(40, 20);    Vector set3_d = new Vector(40, 20);    Vector set4_d = new Vector(40, 20);d60 4a63 4    Vector iset1 = new Vector(40, 20);     Vector iset2 = new Vector(40, 20);     Vector iset3 = new Vector(40, 20);     Vector iset4 = new Vector(40, 20); d67 4a70 4    Vector mset1 = new Vector(40, 20);     Vector mset2 = new Vector(40, 20);     Vector mset3 = new Vector(40, 20);     Vector mset4 = new Vector(40, 20); d74 4a77 4    Vector display_set1 = new Vector(40, 20);     Vector display_set2 = new Vector(40, 20);     Vector display_set3 = new Vector(40, 20);     Vector display_set4 = new Vector(40, 20); d124 4a127 4    Vector y_estimate1 = new Vector(40, 20);     Vector y_estimate2 = new Vector(40, 20);     Vector y_estimate3 = new Vector(40, 20);     Vector y_estimate4 = new Vector(40, 20); d148 4a151 4	point_means_d           = new Vector();	decision_regions_d      = new Vector();	support_vectors_d       = new Vector();	description_d           = new Vector();d175 12a186 5		set1_d = (Vector)data_points_d.dset1.clone();	set2_d = (Vector)data_points_d.dset2.clone();	set3_d = (Vector)data_points_d.dset3.clone();	set4_d = (Vector)data_points_d.dset4.clone();d375 1a375 1    public void interpol(Vector v , Vector iset)d516 1a516 1    public double mean(Vector v, Vector mv)d809 1a809 1    public void estimate( Vector iset, Vector y_estimate, @1.13log@Comments converted to Java Documentation Style.@text@d2 1a2 1 * AlgorithmLP.java v6.0 Last Edited by: Sanjay Patil 03/15/2005d141 1a141 1     * @@return   booleand217 4a220 2    * @@param    Vector     * @@return   booleand280 1a280 1     * @@return   booleand363 2a364 2     * @@param  Vector  input data points     * @@param  Vector  interpolated data pointsd478 1d502 4a505 2     * @@param    Vector orginal datapoints     * @@param    Vector zero mean datapoints d530 1a530 1    * @@return    booleand704 1a704 1     * @@return err_energy residual error energyd837 1a837 1     * @@return actual error energyd945 6a950 6     * @@param    Auto Correlation Coefficients     * @@param    Refelction Coefficient      * @@param    Linear Prediction Coefficients     * @@param    Estimated Error     * @@param    Actual Error     * @@param    length of the data pointsd1009 1a1009 1     * @@return   : boolean@1.12log@The Message "Algorithm Complete" added at the end of step three.As this algorithm as only three steps.@text@d1 10a10 17//----------------------------------------------------------------------// AlgorithmLP.java//// Created: 12/15/04//// Author: Nishant Aggarwal, Jun-Won Suh// // Last Edited by: Sanjay Patil//// Class: AlgorithmLP// // Description: Linear Prediction algorithm. Determines the estimate of // the data points based on the points given by the user. // The appraoch is data interpolation [ based on cubic interpolation ],// Autocorrelation coefficients and Linear Predictor Coefficients [based// on Levinson Durbin Algorithm]// --------------------------------------------------------------------d18 1a18 3// reference - Deittel, "Java, How to Program," pp 99. 5th edition.// idea is to draw a straight line between two points.// d135 9a143 11    //---------------------------------------------------------------    // method: initialize    //    // arguments: none    // return   : boolean    //    // description:      // implements the initialize() method in the base class.  initializes    // member data and prepares for execution of first step.  this method    // "resets" the algorithm.    //---------------------------------------------------------------a179 9	// contents of the email by Dr. Picone 12/28 1:51 PM	//燭he爄nterpolation爏cale爏hould燼lso燿epend爋n爐he	//

⌨️ 快捷键说明

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