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

📄 algorithmkf.java,v

📁 包含了模式识别中常用的一些分类器设计算法
💻 JAVA,V
📖 第 1 页 / 共 3 页
字号:
		    autoCoeff_co[j] = autoCoeff_co[j] 			            + amplitude_y[k] * amplitude_y[k + j];	}   	// normalize the autocorrelation cofficient      	//     	for (int i = kforder; i >= 0; i--)       	    autoCoeff_co[i] = autoCoeff_co[i] / autoCoeff_co[0];	      }    /**     *     * Computes the Particle Filtering coefficient from the data sets        *     */    public void kfcCoefficient()    {		// Rabiner, Schafer, "Digital Processing of Speech signals", 	// Bell Laboratories, Inc. 1978, 	// section 8.3.2 Durbin's recursive solution for 	// the autocorrelation equations pp 411-412		if (set1_d.size() > 0)	{	    final_kfc_1 = new double [ kforder + 1];	    ref_coeff_1 = new double [ kforder + 1];	    estimate_err_1 = calculate_kfc( auto_co_1, 					    final_kfc_1, ref_coeff_1);	}	if (set2_d.size() > 0)	{	    final_kfc_2 = new double [ kforder + 1];	    ref_coeff_2 = new double [ kforder + 1];	    estimate_err_2 = calculate_kfc( auto_co_2, 					    final_kfc_2, ref_coeff_2);	}	if (set3_d.size() > 0)	{	    final_kfc_3 = new double [ kforder + 1];	    ref_coeff_3 = new double [ kforder + 1];	    estimate_err_3 = calculate_kfc( auto_co_3, 					    final_kfc_3, ref_coeff_3);	}	if (set4_d.size() > 0)	{	    final_kfc_4 = new double [ kforder + 1];	    ref_coeff_4 = new double [ kforder + 1];	    estimate_err_4 = calculate_kfc( auto_co_4, 					    final_kfc_4, ref_coeff_4);	}    }    /**     *     * Actually calculate the KF coefficient and the Residual Error      * Energy, and Reflection Coefficients     *     * @@param  auto_coeff array of auto correlation coefficients     * @@param  kfc        array of particle filtering coefficients     * @@param  rc_reg     array of reflection coefficients     *      * @@return residual error energy in a double     *     */    public double calculate_kfc (double[] auto_coeff, 				 double[] kfc, double[] rc_reg)    {	int j_bckwd       = 0;	long middle_index = 0;	// Reference:	// J.D. Markel and A.H. Gray, "Linear Prediction of Speech,"	// Springer-Verlag Berlin Heidelberg, New York, USA, pp. 219,	// 1980. 	// initialization	//	kfc[0] = 1;	double err_energy = auto_coeff[0];	// if the energy of the signal is zero we set all the predictor	// coefficients to zero and exit	//	if (err_energy == (double)0)	{	    for (int i = 0; i < kforder + 1 ; i++)		kfc[i] = 0;	}	else        {	    // do the first step manually	    //	    double sum = 0;	    double tmp = 0;	    	    sum         = -auto_coeff[1] / err_energy;	    rc_reg[1]   = sum;	    kfc[1]      = rc_reg[1];	    tmp         = 1 - rc_reg[1] * rc_reg[1];	    err_energy *= tmp;	    // recursion	    //	    for (int i = 2; i <= kforder; i++)	    {		sum = 0;		for (int j = 1; j < i; j++)		    sum += kfc[j] * auto_coeff[i - j]; 		rc_reg[i]    = -(auto_coeff[i] + sum) / err_energy;	    		kfc[i]       = rc_reg[i];		j_bckwd      = i - 1;		middle_index = i / 2;		for (int j = 1; j <= middle_index; j++)		{		    sum          = kfc[j_bckwd] + rc_reg[i] * kfc[j];		    kfc[j]       = kfc[j] + rc_reg[i] * kfc[i - j];		    kfc[j_bckwd] = sum;		    j_bckwd--;		}		// compute new error		//		tmp = 1.0 - rc_reg[i] * rc_reg[i];		err_energy *= tmp;	    }	}	return err_energy;    }    /**     *     * Calculates the estimated points for the data inputs     *     */    public void final_estimate()    {		if(iset_1_d.size() > 0)	    estimate (iset_1_d, y_estimate1, average1, final_kfc_1);		if(iset_2_d.size() > 0)	    	    estimate (iset_2_d, y_estimate2, average2, final_kfc_2);		if(iset_3_d.size() > 0)	    estimate (iset_3_d, y_estimate3, average3, final_kfc_3);		if(iset_4_d.size() > 0)	    estimate (iset_4_d, y_estimate4, average4, final_kfc_4);    }         /**     *     * Estimates the amplitude based on the KF coeficients.     *     * @@param    iset         interpolated data points     * @@param    y_estimate   predicted final signal data points     * @@param    avg          mean of the original datapoints given     * @@param    final_kfc    array of final particle filtering coefficients     *      */    public void estimate( Vector<MyPoint> iset, Vector<MyPoint> y_estimate, 			  double avg, double[] final_kfc)    {	   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 <= kforder) && (z > 0); j++, z-- )		   sum = sum - amplitude[z - 1] * final_kfc[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<MyPoint> y_estimate, Vector<MyPoint> 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 KF order, Error Energy and Reflection Coefficients      *     */    public void step2_display()    {	// display the KF order	//	pro_box_d.appendMessages("         KF order =  " + kforder + "\n");	if (set_1_d.size() > 0 )        {	    int num_pts =  iset_1_d.size();	    int n = 0;	    display_result(auto_co_1, ref_coeff_1, final_kfc_1, 			   actual_err_1, estimate_err_1, n, num_pts);       	}	if (set_2_d.size() > 0 )        {	    int num_pts =  iset_2_d.size();	        	    int n = 1;	    display_result(auto_co_2, ref_coeff_2, final_kfc_2, 			   actual_err_2, estimate_err_2, n, num_pts);	}	if (set_3_d.size() > 0 )        {	    int num_pts =  iset_3_d.size();	    int n = 2;	    display_result(auto_co_3, ref_coeff_3, final_kfc_3, 			   actual_err_3, estimate_err_3, n, num_pts);	}	if (set_4_d.size() > 0 )        {	    int num_pts =  iset_4_d.size();	    int n = 3;	    display_result(auto_co_4, ref_coeff_4, final_kfc_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_kfc Particle Filering 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_kfc, 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 <= kforder; i++)	    if (i == kforder)		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 <= kforder; i++)	    if (i == kforder)		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" + "         Filtering Coefficients:" 				 + "\n");	pro_box_d.appendMessages("              [ ");	for (int i = 0 ; i <= kforder; i++)	    if (i == kforder )	    pro_box_d.appendMessages(MathUtil.SetDecimal(final_kfc[i], 3) 				     + " ");	    else		pro_box_d.appendMessages(MathUtil.SetDecimal(final_kfc[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");     }a1013 2}@1.1log@Initial revision@text@d58 1a58 1public class AlgorithmPF extends Algorithmd66 1a66 1    int pforder;d82 1a82 1    String algo_id = "AlgorithmPF"; d128 1a128 1    // to store PF coefficientd130 4a133 4    double final_pfc_1[];     double final_pfc_2[];    double final_pfc_3[];    double final_pfc_4[];d158 1a158 1    New for PFd262 1a262 1	pforder    = Classify.main_menu_d.pforder;d270 1a270 1	scale      = pforder * iporder;d283 1a283 1	// Add the process description for the PF algorithmd357 2a358 2	if((checkdata_PF(set_1_d) == true) && (checkdata_PF(set_2_d) == true) 	   && (checkdata_PF(set_3_d) == true) && (checkdata_PF(set_4_d) == true))d382 3a384 3    * @@param    pf    * @@return   true if data is Vector pf is valid. It is invalid    *           if the size of pf is 1 or any element is larger than thed388 1a388 1    public boolean checkdata_PF(Vector<MyPoint> pf)d390 1a390 1	if ( pf.size() == 1) {d396 1a396 1	    for(int i = 0; i <= pf.size() - 1 ; i++ ) {d398 1a398 1		for(int j = i + 1; j <= pf.size() - 1 ; j++ ) {d402 4a405 4		   if ( (((MyPoint)pf.elementAt(i)).x == 			 ((MyPoint)pf.elementAt(j)).x) || 			(((MyPoint)pf.elementAt(i)).x > 			 ((MyPoint)pf.elementAt(j)).x) ) {d921 1a921 1       // scale = iporder * pforderd1068 1a1068 1	    auto_co_1 = new double[pforder + 1];d1074 1a1074 1	    auto_co_2 = new double[pforder + 1];d1080 1a1080 1	    auto_co_3 = new double[pforder + 1];d1086 1a1086 1	    auto_co_4 = new double[pforder + 1];d1110 1a1110 1      	for (int j = 0; j <= pforder; j++)d1121 1a1121 1     	for (int i = pforder; i >= 0; i--) d1130 1a1130 1    public void pfcCoefficient()d1140 4a1143 4	    final_pfc_1 = new double [ pforder + 1];	    ref_coeff_1 = new double [ pforder + 1];	    estimate_err_1 = calculate_pfc( auto_co_1, 					    final_pfc_1, ref_coeff_1);d1148 4a1151 4	    final_pfc_2 = new double [ pforder + 1];	    ref_coeff_2 = new double [ pforder + 1];	    estimate_err_2 = calculate_pfc( auto_co_2, 					    final_pfc_2, ref_coeff_2);d1156 4a1159 4	    final_pfc_3 = new double [ pforder + 1];	    ref_coeff_3 = new double [ pforder + 1];	    estimate_err_3 = calculate_pfc( auto_co_3, 					    final_pfc_3, ref_coeff_3);d1164 4a1167 4	    final_pfc_4 = new double [ pforder + 1];	    ref_coeff_4 = new double [ pforder + 1];	    estimate_err_4 = calculate_pfc( auto_co_4, 					    final_pfc_4, ref_coeff_4);d1173 1a1173 1     * Actually calculate the PF coefficient and the Residual Error d1177 1a1177 1     * @@param  pfc        array of particle filtering coefficientsd1183 2a1184 2    public double calculate_pfc (double[] auto_coeff, 				 double[] pfc, double[] rc_reg)d1196 1a1196 1	pfc[0] = 1;d1204 2a1205 2	    for (int i = 0; i < pforder + 1 ; i++)		pfc[i] = 0;d1216 1a1216 1	    pfc[1]      = rc_reg[1];d1221 1a1221 1	    for (int i = 2; i <= pforder; i++)d1225 1a1225 1		    sum += pfc[j] * auto_coeff[i - j];d1228 1a1228 1		pfc[i]       = rc_reg[i];d1233 3a1235 3		    sum          = pfc[j_bckwd] + rc_reg[i] * pfc[j];		    pfc[j]       = pfc[j] + rc_reg[i] * pfc[i - j];		    pfc[j_bckwd] = sum;d1255 1a1255 1	    estimate (iset_1_d, y_estimate1, average1, final_pfc_1);d1258 1a1258 1	    estimate (iset_2_d, y_estimate2, average2, final_pfc_2);d1261 1a1261 1	    estimate (iset_3_d, y_estimate3, average3, final_pfc_3);d1264 1a1264 1	    estimate (iset_4_d, y_estimate4, average4, final_pfc_4);d1269 1a1269 1     * Estimates the amplitude based on the PF coeficients.d1274 1a1274 1     * @@param    final_pfc    array of final particle filtering coefficientsd1278 1a1278 1			  double avg, double[] final_pfc)d1298 2a1299 2	       for( int j = 1; (j <= pforder) && (z > 0); j++, z-- )		   sum = sum - amplitude[z - 1] * final_pfc[j];d1376 1a1376 1     * Displays PF order, Error Energy and Reflection Coefficients d1381 1a1381 1	// display the PF orderd1383 1a1383 1	pro_box_d.appendMessages("         PF order =  " + pforder + "\n");d1389 1a1389 1	    display_result(auto_co_1, ref_coeff_1, final_pfc_1, d1397 1a1397 1	    display_result(auto_co_2, ref_coeff_2, final_pfc_2, d1405 1a1405 1	    display_result(auto_co_3, ref_coeff_3, final_pfc_3, d1413 1a1413 1	    display_result(auto_co_4, ref_coeff_4, final_pfc_4,d1423 1a1423 1     * @@param    final_pfc Particle Filering Coefficientsd1430 1a1430 1				double[] final_pfc, double est_err, d1440 2a1441 2	for (int i = 0 ; i <= pforder; i++)	    if (i == pforder)d1452 2a1453 2	for (int i = 1 ; i <= pforder; i++)	    if (i == pforder)d1464 3a1466 3	for (int i = 0 ; i <= pforder; i++)	    if (i == pforder )	    pro_box_d.appendMessages(MathUtil.SetDecimal(final_pfc[i], 3) d1469 1a1469 1		pro_box_d.appendMessages(MathUtil.SetDecimal(final_pfc[i], 3) @

⌨️ 快捷键说明

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