📄 algorithmpf.java
字号:
} /** * Draws a gaussian distribution of points around each input point, * and draws an oval representation of the points * * @throws Exception if sleep method throws an exception * @return true * */ boolean step2() { int max_progress = set_1_d.size() + set_2_d.size() + set_3_d.size() + set_4_d.size(); int curr_progress = 0; // Vector of completed points // Vector<MyPoint> completed_points = new Vector<MyPoint>(); pro_box_d.setProgressMin(0); pro_box_d.setProgressMax(max_progress); pro_box_d.setProgressCurr(0); // Draws and removes gaussian distribution and oval from set 1 // for (int i = 0; i < set_1_d.size(); i++ ){ Vector<MyPoint> gaussian_points = new Vector<MyPoint>(); drawGaussian(set_1_d.elementAt(i).x, set_1_d.elementAt(i).y, 1); // adds 20 gaussian points // for (int j = 0; j < 20; j++) { MyPoint p = new MyPoint(gset_1_x_d[j], gset_1_y_d[j]); gaussian_points.addElement(p); } // Vector of Vector of MyPoints // needed for gausian distribution later // gset_1_d.add(gaussian_points); // an oval of points that represents the gaussian points // Vector<MyPoint> circle_points = new Vector<MyPoint>(); circle_points = transformPCA(i, 1); // adds current point to completed points vector // completed_points.addElement(new MyPoint(set_1_d.elementAt(i).x, set_1_d.elementAt(i).y)); // adds gaussian points to output panel // output_panel_d.addOutput(gaussian_points, (Classify.PTYPE_INPUT), data_points_d.color_dset1); // adds ovals to output // output_panel_d.addOutput(circle_points, (Classify.PTYPE_INPUT), data_points_d.color_dset1); // adds central point to output panel // output_panel_d.addOutput(completed_points, (Classify.PTYPE_INPUT * 4), Color.BLACK); output_panel_d.repaint(); // Sleep for 50 milliseconds // try{ Thread.sleep(50); } catch(Exception e) {} // Leaves last gaussian distribution and oval // if (i != set_1_d.size() - 1) { // Removes gaussian distribution and oval // output_panel_d.removeOutput(); output_panel_d.removeOutput(); } // Removes the progress dots // output_panel_d.removeOutput(); pro_box_d.setProgressCurr(++curr_progress); } // end of set 1 completed_points.clear(); // Draws and removes gaussian distribution and oval from set 2 // for (int i = 0; i < set_2_d.size(); i++ ) { Vector<MyPoint> gaussian_points = new Vector<MyPoint>(); drawGaussian(set_2_d.elementAt(i).x, set_2_d.elementAt(i).y, 2); // adds 20 gaussian points // for (int j = 0; j < 20; j++) { MyPoint p = new MyPoint(gset_2_x_d[j], gset_2_y_d[j]); gaussian_points.addElement(p); } // Vector of Vector of MyPoints // needed for gausian distribution later // gset_2_d.add(gaussian_points); // an oval of points that represents the gaussian points // Vector<MyPoint> circle_points = new Vector<MyPoint>(); circle_points = transformPCA(i, 2); // adds current point to completed points vector // completed_points.addElement(new MyPoint(set_2_d.elementAt(i).x, set_2_d.elementAt(i).y)); // adds gaussian points to output panel // output_panel_d.addOutput(gaussian_points, (Classify.PTYPE_INPUT), data_points_d.color_dset2); // adds ovals to output // output_panel_d.addOutput(circle_points, (Classify.PTYPE_INPUT), data_points_d.color_dset2); // adds central point to output panel // output_panel_d.addOutput(completed_points, (Classify.PTYPE_INPUT * 4), Color.BLACK); output_panel_d.repaint(); // Sleep for 50 milliseconds // try{ Thread.sleep(50); } catch(Exception e) {} // Leaves last gaussian distribution and oval // if (i != set_2_d.size() - 1) { // Removes gaussian distribution and oval // output_panel_d.removeOutput(); output_panel_d.removeOutput(); } // Removes the progress dots // output_panel_d.removeOutput(); pro_box_d.setProgressCurr(++curr_progress); } // end of set 2 iteration completed_points.clear(); // Draws and removes gaussian distribution and oval from set 3 // for (int i = 0; i < set_3_d.size(); i++ ) { Vector<MyPoint> gaussian_points = new Vector<MyPoint>(); drawGaussian(set_3_d.elementAt(i).x, set_3_d.elementAt(i).y, 3); // adds 20 gaussian points // for (int j = 0; j < 20; j++) { MyPoint p = new MyPoint(gset_3_x_d[j], gset_3_y_d[j]); gaussian_points.addElement(p); } // Vector of Vector of MyPoints // needed for gausian distribution later // gset_3_d.add(gaussian_points); // an oval of points that represents the gaussian points // Vector<MyPoint> circle_points = new Vector<MyPoint>(); circle_points = transformPCA(i, 3); // adds current point to completed points vector // completed_points.addElement(new MyPoint(set_3_d.elementAt(i).x, set_3_d.elementAt(i).y)); // adds gaussian points to output panel // output_panel_d.addOutput(gaussian_points, (Classify.PTYPE_INPUT), data_points_d.color_dset3); // adds ovals to output // output_panel_d.addOutput(circle_points, (Classify.PTYPE_INPUT), data_points_d.color_dset3); // adds central point to output panel // output_panel_d.addOutput(completed_points, (Classify.PTYPE_INPUT * 4), Color.BLACK); output_panel_d.repaint(); // Sleep for 50 milliseconds // try{ Thread.sleep(50); } catch(Exception e) {} // Leaves last gaussian distribution and oval // if (i != set_3_d.size() - 1) { // Removes gaussian distribution and oval // output_panel_d.removeOutput(); output_panel_d.removeOutput(); } // Removes the progress dots // output_panel_d.removeOutput(); pro_box_d.setProgressCurr(++curr_progress); } // end of set 3 iteration completed_points.clear(); // Draws and removes gaussian distribution and oval from set 4 // for (int i = 0; i < set_4_d.size(); i++ ) { Vector<MyPoint> gaussian_points = new Vector<MyPoint>(); drawGaussian(set_4_d.elementAt(i).x, set_4_d.elementAt(i).y, 4); // adds 20 gaussian points // for (int j = 0; j < 20; j++) { MyPoint p = new MyPoint(gset_4_x_d[j], gset_4_y_d[j]); gaussian_points.addElement(p); } // Vector of Vector of MyPoints // needed for gausian distribution later // gset_4_d.add(gaussian_points); // an oval of points that represents the gaussian points // Vector<MyPoint> circle_points = new Vector<MyPoint>(); circle_points = transformPCA(i, 4); // adds current point to completed points vector // completed_points.addElement(new MyPoint(set_4_d.elementAt(i).x, set_4_d.elementAt(i).y)); // adds gaussian points to output panel // output_panel_d.addOutput(gaussian_points, (Classify.PTYPE_INPUT), data_points_d.color_dset4); // adds ovals to output // output_panel_d.addOutput(circle_points, (Classify.PTYPE_INPUT), data_points_d.color_dset4); // adds central point to output panel // output_panel_d.addOutput(completed_points, (Classify.PTYPE_INPUT * 4), Color.BLACK); output_panel_d.repaint(); // Sleep for 50 milliseconds // try{ Thread.sleep(50); } catch(Exception e) {} // Leaves last gaussian distribution and oval // if (i != set_4_d.size() - 1) { // Removes gaussian distribution and oval // output_panel_d.removeOutput(); output_panel_d.removeOutput(); } // Removes the progress dots // output_panel_d.removeOutput(); pro_box_d.setProgressCurr(++curr_progress); } // end of set 4 iteration pro_box_d.setProgressCurr(max_progress); output_panel_d.repaint(); return true; } /** * * * @return true * */ boolean step3() { return true; } /** * * * @return true * */ boolean step4() { return true; } /** * * * @return true * */ boolean step5() { return true; } /** * * 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; * * varErrorInitial = varErrorNewer; * currentState = newerState; * * displays the predicted signal * * @return true * */ boolean step6() { double est_obsn = 0; double kalman_gain = 0; if(set_1_d.size() > 0) { y_estimate1.removeAllElements(); curr_state_1_d = set_1_d.elementAt(0).y; curr_error_1_d = 10; for (int i = 0; i < set_1_d.size(); i++) { //Equation 1 // new_state_1_d = state_gain * curr_state_1_d; //Equation 2 // new_error_1_d = curr_error_1_d * state_gain * state_gain + var_state_noise; est_obsn = meas_gain * new_state_1_d; //Equation 3 // kalman_gain = meas_gain * new_error_1_d; kalman_gain = kalman_gain / (meas_gain * meas_gain * new_error_1_d + var_meas_noise); //Equation 4 // newer_state_1_d = new_state_1_d + kalman_gain * (set_1_d.elementAt(i).y - est_obsn); //Equation 5 // double a = (1 - kalman_gain * meas_gain) * (1 - kalman_gain * meas_gain); newer_error_1_d = new_error_1_d * a + var_meas_noise * kalman_gain * kalman_gain; MyPoint pt = new MyPoint(set_1_d.elementAt(i).x, newer_state_1_d); y_estimate1.addElement(pt); curr_error_1_d = newer_error_1_d; curr_state_1_d = newer_state_1_d; } } if(set_2_d.size() > 0) { y_estimate2.removeAllElements(); curr_state_2_d = set_2_d.elementAt(0).y; curr_error_2_d = 10; for (int i = 0; i < set_2_d.size(); i++) { //Equation 1 // new_state_2_d = state_gain * curr_state_2_d; //Equation 2 // new_error_2_d = curr_error_2_d * state_gain * state_gain + var_state_noise; est_obsn = meas_gain * new_state_2_d; //Equation 3 // kalman_gain = meas_gain * new_error_2_d; kalman_gain = kalman_gain / (meas_gain * meas_gain * new_error_2_d + var_meas_noise); //Equation 4 // newer_state_2_d = new_state_2_d + kalman_gain * (set_2_d.elementAt(i).y - est_obsn); //Equation 5 // double a = (1 - kalman_gain * meas_gain) * (1 - kalman_gain * meas_gain); newer_error_2_d = new_error_2_d * a + var_meas_noise * kalman_gain * kalman_gain; MyPoint pt = new MyPoint(set_2_d.elementAt(i).x, newer_state_2_d); y_estimate2.addElement(pt); curr_error_2_d = newer_error_2_d; curr_state_2_d = newer_state_2_d; } } if(set_3_d.size() > 0) { y_estimate3.removeAllElements(); curr_state_3_d = set_3_d.elementAt(0).y; curr_error_3_d = 10; for (int i = 0; i < set_3_d.size(); i++) { //Equation 1 // new_state_3_d = state_gain * curr_state_3_d; //Equation 2 // new_error_3_d = curr_error_3_d * state_gain * state_gain + var_state_noise; est_obsn = meas_gain * new_state_3_d; //Equation 3 // kalman_gain = meas_gain * new_error_3_d; kalman_gain = kalman_gain / (meas_gain * meas_gain * new_error_3_d + var_meas_noise); //Equation 4 // newer_state_3_d = new_state_3_d + kalman_gain * (set_3_d.elementAt(i).y - est_obsn); //Equation 5 // double a = (1 - kalman_gain * meas_gain) * (1 - kalman_gain * meas_gain); newer_error_3_d = new_error_3_d * a + var_meas_noise * kalman_gain * kalman_gain;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -