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

📄 algorithmkf.java

📁 包含了模式识别中常用的一些分类器设计算法
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * AlgorithmKF.java v6.1  * Created by: Ryan Irwin 05/24/2005 *  * Description: Kalman Filtering * * * * *///----------------------// import java packages//----------------------import java.util.*;import java.awt.*; import java.awt.Graphics;import javax.swing.JApplet; // import class Algorithm/** * Class that handles the Kalman Filter algorithm */public class AlgorithmKF extends Algorithm {    //-----------------------------------------------------------------    //    // static data members    //    //-----------------------------------------------------------------    int kforder;    int iporder;    int scale;    //-----------------------------------------------------------------    //    // primitive data members    //    //-----------------------------------------------------------------    int output_canvas_d[][];       //-----------------------------------------------------------------    //    // instance data members    //    //-----------------------------------------------------------------    String algo_id = "AlgorithmKF";     Vector<MyPoint> support_vectors_d;    Vector<MyPoint> decision_regions_d;      // for original data    //    Vector<MyPoint> set_1_d = new Vector<MyPoint>(40, 20);    Vector<MyPoint> set_2_d = new Vector<MyPoint>(40, 20);    Vector<MyPoint> set_3_d = new Vector<MyPoint>(40, 20);    Vector<MyPoint> set_4_d = new Vector<MyPoint>(40, 20);    // for interpolation function    //    Vector<MyPoint> iset_1_d = new Vector<MyPoint>(40, 20);     Vector<MyPoint> iset_2_d = new Vector<MyPoint>(40, 20);     Vector<MyPoint> iset_3_d = new Vector<MyPoint>(40, 20);     Vector<MyPoint> iset_4_d = new Vector<MyPoint>(40, 20);     // vector for mean-subtracted [zero-mean] data    //    Vector<MyPoint> mset_1_d = new Vector<MyPoint>(40, 20);     Vector<MyPoint> mset_2_d = new Vector<MyPoint>(40, 20);     Vector<MyPoint> mset_3_d = new Vector<MyPoint>(40, 20);     Vector<MyPoint> mset_4_d = new Vector<MyPoint>(40, 20);     // for display purpose    //    Vector<MyPoint> display_set_1_d = new Vector<MyPoint>(40, 20);     Vector<MyPoint> display_set_2_d = new Vector<MyPoint>(40, 20);     Vector<MyPoint> display_set_3_d = new Vector<MyPoint>(40, 20);     Vector<MyPoint> display_set_4_d = new Vector<MyPoint>(40, 20);     // to store autoCorrelation coefficient    //    double auto_co_1[];    double auto_co_2[];    double auto_co_3[];    double auto_co_4[];    // to store the average values for each class    //    double average1;    double average2;    double average3;    double average4;    // to store KF coefficient    //    double final_kfc_1[];     double final_kfc_2[];    double final_kfc_3[];    double final_kfc_4[];    // to store residual energy     //    double estimate_err_1 = 0;	    double estimate_err_2 = 0;	    double estimate_err_3 = 0;    double estimate_err_4 = 0;     // to store actual error energy    //    double actual_err_1 = 0;    double actual_err_2 = 0;    double actual_err_3 = 0;    double actual_err_4 = 0;    // to store the reflection coefficients    //    double ref_coeff_1[];    double ref_coeff_2[];    double ref_coeff_3[];     double ref_coeff_4[];    /*********************    New for KF    *********************/    // estimate observation for each set    //    double est_obsn_1_d;    double est_obsn_2_d;    double est_obsn_3_d;    double est_obsn_4_d;    // current state for each set    //    double curr_state_1_d;    double curr_state_2_d;    double curr_state_3_d;    double curr_state_4_d;    // new state for each set    //    double new_state_1_d;    double new_state_2_d;    double new_state_3_d;    double new_state_4_d;    // newer state for each set    //    double newer_state_1_d;    double newer_state_2_d;    double newer_state_3_d;    double newer_state_4_d;    // kalman gain for each set    //    double kalman_gain_1_d;    double kalman_gain_2_d;    double kalman_gain_3_d;    double kalman_gain_4_d;    // current error for each set    //    double curr_error_1_d;    double curr_error_2_d;    double curr_error_3_d;    double curr_error_4_d;    // new error for each set    //    double new_error_1_d;    double new_error_2_d;    double new_error_3_d;    double new_error_4_d;    // newer error for each set    //    double newer_error_1_d;    double newer_error_2_d;    double newer_error_3_d;    double newer_error_4_d;    double meas_gain;    double state_gain;    double var_meas_noise;    double var_state_noise;    // to store the final results NOT NEW    //    Vector<MyPoint> y_estimate1 = new Vector<MyPoint>(40, 20);     Vector<MyPoint> y_estimate2 = new Vector<MyPoint>(40, 20);     Vector<MyPoint> y_estimate3 = new Vector<MyPoint>(40, 20);     Vector<MyPoint> y_estimate4 = new Vector<MyPoint>(40, 20);     //---------------------------------------------------------------    //    // class methods    //    //---------------------------------------------------------------    /**     *      * Implements the initialize() method in the base class. Initializes     * member data and prepares for execution of first step. This method     * "resets" the algorithm.     *     * @return   returns true if sets of data are valid     *     */    public boolean initialize() {	DisplayArea disp_area_d = new DisplayArea();	point_means_d           = new Vector<MyPoint>();	decision_regions_d      = new Vector<MyPoint>();	support_vectors_d       = new Vector<MyPoint>();	description_d           = new Vector<String>();	step_count = 6;	kforder    = Classify.main_menu_d.kforder;	iporder    = Classify.main_menu_d.iporder;	meas_gain  = Classify.main_menu_d.meas_gain;	state_gain = Classify.main_menu_d.state_gain;	var_meas_noise  = Classify.main_menu_d.var_meas_noise;	var_state_noise = Classify.main_menu_d.var_state_noise;	scale      = kforder * iporder;	curr_state_1_d = 0; 	curr_state_2_d = 0;	curr_state_3_d = 0;	curr_state_4_d = 0;   	curr_error_1_d = 0;	curr_error_2_d = 0;	curr_error_3_d = 0;	curr_error_4_d = 0;	// Add the process description for the KF algorithm	//	if (description_d.size() == 0) {	    String str = new String("   0.  Checking for the Data Validity");	    description_d.addElement(str);	    	    str = new String("   1.  Displaying the Input Data Points");	    description_d.addElement(str);	    	    str = new String("   2.  State estimate extrapolation");	    description_d.addElement(str);	    	    str = new String("   3.  Error covariance extrapolation");	    description_d.addElement(str); 	    str = new String("   4.  Innovation process \n Kalman Gain computation");	    description_d.addElement(str);	    str = new String("   5.  State estimate observational update");	    description_d.addElement(str);	    str = new String("   6.  Error covariance update \n Displaying predicted signal");	    description_d.addElement(str); 	}		// set the data points for this algorithm	//	//	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();	//	set_1_d = data_points_d.dset1;	set_2_d = data_points_d.dset2;	set_3_d = data_points_d.dset3;	set_4_d = data_points_d.dset4;	int max1 = set2_d.size();	if (set_1_d.size() > set_2_d.size())	    max1 = set1_d.size();	int max2 = set4_d.size();	if (set_3_d.size() > set_4_d.size())	    max2 = set_3_d.size();	else	    max2 = set_4_d.size();	if (max2 > max1)	    max1 = max2;	if (max1 > scale)	    scale = max1;	step_index_d = 0;	if((checkdata_KF(set_1_d) == true) && (checkdata_KF(set_2_d) == true) 	   && (checkdata_KF(set_3_d) == true) && (checkdata_KF(set_4_d) == true)) {	    pro_box_d.appendMessage((String)description_d.get(step_index_d));	    pro_box_d.appendMessage("         Data points valid");	    pro_box_d.scrollPane.getVerticalScrollBar().setValue(1000000);	    return true;		}	else  {	    pro_box_d.appendMessage("\n" + "Invalid data");	    pro_box_d.appendMessage("Clear and enter valid data" + "\n");	    pro_box_d.scrollPane.getVerticalScrollBar().setValue(1000000);	    return false;	}    }    /**    *     * Validates the class entered by user for Partical Filtering      *    * @param    kf    * @return   true if data is Vector kf is valid. It is invalid    *           if the size of kf is 1 or any element is larger than the    *           the previous element    *     */    public boolean checkdata_KF(Vector<MyPoint> kf) {	if ( kf.size() == 1) {	    return false;	}	else {	    for(int i = 0; i <= kf.size() - 1 ; i++ ) {		for(int j = i + 1; j <= kf.size() - 1 ; j++ ) {		   // amplitudes should be in time progression		   //		   if ( (((MyPoint)kf.elementAt(i)).x == 			 ((MyPoint)kf.elementAt(j)).x) || 			(((MyPoint)kf.elementAt(i)).x > 			 ((MyPoint)kf.elementAt(j)).x) ) {		       return false;		   }		}	    }	return true;	}    }    /**     *     * Implementation of the run function from the Runnable interface.     * Determines what the current step is and calls the appropriate method.     *     */    public void run() {	if (step_index_d == 1) {	    disableControl();	    step1();	    enableControl();	}	if (step_index_d == 2) {	    disableControl();	    step2();	    enableControl(); 	}	if (step_index_d == 3) {		    disableControl();	    step3(); 	    enableControl(); 	}	if (step_index_d == 4) {	    disableControl();	    step4(); 	    enableControl(); 	}	if (step_index_d == 5) {	    disableControl();	    step5(); 	    enableControl(); 	}	if (step_index_d == 6) {	    disableControl();	    step6(); 	    enableControl(); 	}	// exit gracefully	//	return;    }        /**     *     * Displays data sets from input box in output box, clears the data     * points from the Vector fro input data, zero-mean data,     * does interpolation, and then finds mean of the interpolated data     * interpolates the zero-mean data, displays the result     *     * @return   True     *     */    boolean step1() {	// set up progress bar	//	pro_box_d.setProgressMin(0);	pro_box_d.setProgressMax(1);	pro_box_d.setProgressCurr(0);	output_panel_d.disp_area_d.output_points_d.removeAllElements();	output_panel_d.disp_area_d.type_d.removeAllElements();	output_panel_d.disp_area_d.color_d.removeAllElements();	      	// Display original data	// size of the point made four times bigger	// 	if(set_1_d.size() > 0 ) {       	    display_set_1_d.removeAllElements();	    iset_1_d.removeAllElements();	    mset_1_d.removeAllElements();	    	    interpol(set_1_d, display_set_1_d);	    average1 = mean(display_set_1_d, mset_1_d);	    interpol(mset_1_d, iset_1_d);	    	    output_panel_d.addOutput(set_1_d, (Classify.PTYPE_INPUT * 4), 				     data_points_d.color_dset1);	}	if(set_2_d.size() > 0 ) {	    	    display_set_2_d.removeAllElements();	    iset_2_d.removeAllElements();  	    mset_2_d.removeAllElements();	    	    interpol(set_2_d, display_set_2_d);	    average2 = mean(display_set_2_d, mset_2_d);	    interpol(mset_2_d, iset_2_d);   	    	    output_panel_d.addOutput(set_2_d, (Classify.PTYPE_INPUT * 4), 				     data_points_d.color_dset2);	}       	if(set_3_d.size() > 0 ) {       	    display_set_3_d.removeAllElements();	    iset_3_d.removeAllElements();	    mset_3_d.removeAllElements();	    	    interpol(set_3_d, display_set_3_d);	    average3 = mean(display_set_3_d, mset_3_d);	    interpol(mset_3_d, iset_3_d);	   	    output_panel_d.addOutput(set_3_d, (Classify.PTYPE_INPUT * 4), 				     data_points_d.color_dset3);	}		if(set_4_d.size() > 0 ) {       		    display_set_4_d.removeAllElements();	    iset_4_d.removeAllElements();	    mset_4_d.removeAllElements();	    	    interpol(set_4_d, display_set_4_d);	    average4 = mean(display_set_4_d, mset_4_d);	    interpol(mset_4_d, iset_4_d);	    	    output_panel_d.addOutput(set_4_d, (Classify.PTYPE_INPUT * 4), 				     data_points_d.color_dset4);	}	pro_box_d.setProgressCurr(1);	output_panel_d.repaint();	return true;    }   /**    *    *    * @return    true    *    */    boolean step2() {

⌨️ 快捷键说明

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