📄 algorithmpf.java,v
字号:
head 1.4;access;symbols;locks rirwin:1.4; strict;comment @# @;1.4date 2005.06.10.15.48.39; author rirwin; state Exp;branches;next 1.3;1.3date 2005.06.10.14.55.05; author rirwin; state Exp;branches;next 1.2;1.2date 2005.06.08.21.43.24; author rirwin; state Exp;branches;next 1.1;1.1date 2005.06.06.18.52.58; author rirwin; state Exp;branches;next ;desc@initial version of AlgorithmPF.java.@1.4log@Made scrollbar scroll down upon initializing.@text@/** * AlgorithmPF.java v6.0 * Created by: Ryan Irwin 05/24/2005 * * Description: Particle Filtering * * * * * **************** UNDER CONSTRUCTION***************** * *//**************************************************** // first observation // initialObsn = 1200; estimateObsn = 0; 1 newState = stateGain * currentState;2 varErrorNew = varErrorInitial * stateGain * stateGain + varStateNoise; estimateObsn = measureGain * newState;3 kalmanGain = measureGain * varErrorNew ; kalmanGain = kalmanGain / ( measureGain * measureGain * varErrorNew + varMeasureNoise);4 newerState = newState + kalmanGain * (obsnSequence[index] - estimateObsn);5 double a = 0; a = ( 1 - kalmanGain * measureGain) * ( 1 - kalmanGain * measureGain); varErrorNewer = varErrorNew * a + varMeasureNoise * kalmanGain * kalmanGain; varErrorNewer = varErrorInitial; currentState = newerState; *******************************************************///----------------------// import java packages//----------------------import java.util.*;import java.awt.*; import java.awt.Graphics;import javax.swing.JApplet; // import class Algorithmpublic class AlgorithmPF extends Algorithm{ //----------------------------------------------------------------- // // static data members // //----------------------------------------------------------------- int pforder; int iporder; int scale; //----------------------------------------------------------------- // // primitive data members // //----------------------------------------------------------------- int output_canvas_d[][]; //----------------------------------------------------------------- // // instance data members // //----------------------------------------------------------------- String algo_id = "AlgorithmPF"; 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 PF coefficient // double final_pfc_1[]; double final_pfc_2[]; double final_pfc_3[]; double final_pfc_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 PF *********************/ // 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; pforder = Classify.main_menu_d.pforder; 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 = pforder * 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 PF algorithm // if (description_d.size() == 0) { /*************** UNDER CONSTRUCTION *****************/ //String str = new String(" 0. Checking for the Data Validity."); String str = new String("\n**** Under Construction **** \n" + "\nKalman Filter implementation \n" + "\nInitial Settings:" + "\nMeasurement Gain: " + meas_gain + "\nState Gain: " + state_gain + "\nVariance of Measurement Noise" + var_meas_noise + "\nVariance of State Noise" + var_state_noise + "\n" + "\n0. Checking for the Data Validity\n"); 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_PF(set_1_d) == true) && (checkdata_PF(set_2_d) == true) && (checkdata_PF(set_3_d) == true) && (checkdata_PF(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 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 the * the previous element * */ public boolean checkdata_PF(Vector<MyPoint> pf) { if ( pf.size() == 1) { return false; } else { for(int i = 0; i <= pf.size() - 1 ; i++ ) { for(int j = i + 1; j <= pf.size() - 1 ; j++ ) { // amplitudes should be in time progression // if ( (((MyPoint)pf.elementAt(i)).x == ((MyPoint)pf.elementAt(j)).x) || (((MyPoint)pf.elementAt(i)).x > ((MyPoint)pf.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() { return true; } /** * * * @@return true * */ boolean step3() { return true; } /** * *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -