Changeset 37 for tests/testKF.cpp
- Timestamp:
- 03/14/08 18:11:21 (16 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
tests/testKF.cpp
r33 r37 9 9 10 10 int main() { 11 12 13 11 // Kalman filter 14 12 mat A, B,C,D,R,Q,P0; … … 18 16 it_file fin( "testKF.it" ); 19 17 20 mat Dt , Xt,Xt2,XtE,Xtf;18 mat Dt; 21 19 int Ndat; 22 20 … … 40 38 41 39 Ndat = Dt.cols(); 42 Xt=zeros( 2,Ndat ); 43 Xt2=zeros( 2,Ndat ); 44 Xtf=zeros( 2,Ndat ); 45 XtE=zeros( 2,Ndat ); 40 int dimx = A.rows(); 41 int dimy = C.rows(); 42 int dimu = B.cols(); 43 44 // Prepare for Kalman filters in BDM: 45 ivec tmpsize(1); 46 tmpsize(0) = A.cols(); 47 RV rx("1","{x}",tmpsize,"0"); 48 tmpsize(0) = B.cols(); 49 RV ru("2","{u}",tmpsize,"0"); 50 tmpsize(0) = C.rows(); 51 RV ry("3","{y}",tmpsize,"0"); 52 53 // // LDMAT 54 // Kalman<ldmat> KF(rx,ry,ru); 55 // KF.set_parameters(A,B,C,D,ldmat(R),ldmat(Q)); 56 // KF.set_est(mu0,ldmat(P0) ); 57 // epdf& KFep = KF._epdf(); 58 // mat Xt(2,Ndat); 59 // Xt.set_col( 0,KFep.mean() ); 46 60 47 // cout << KF; 48 RV rx("1","{x}","2","0"); 49 RV ru("2","{u}","1","0"); 50 RV ry("3","{y}","1","0"); 51 // 52 Kalman<ldmat> KF(rx,ry,ru); 53 KF.set_parameters(A,B,C,D,ldmat(R),ldmat(Q)); 54 KF.set_est(mu0,ldmat(P0) ); 55 // 56 Kalman<fsqmat> KFf(rx,ry,ru); 57 KFf.set_parameters(A,B,C,D,fsqmat(R),fsqmat(Q)); 58 KFf.set_est(mu0,fsqmat(P0) ); 59 // 61 //Chol 62 KalmanCh KF(rx,ry,ru); 63 KF.set_parameters(A,B,C,D,chmat(R),chmat(Q)); 64 KF.set_est(mu0,chmat(P0) ); //prediction! 65 epdf& KFep = KF._epdf(); 66 mat Xt(dimx,Ndat); 67 Xt.set_col( 0,KFep.mean() ); 68 69 // 70 // FSQMAT 71 Kalman<ldmat> KFf(rx,ry,ru); 72 KFf.set_parameters(A,B,C,D,ldmat(R),ldmat(Q)); 73 KFf.set_est(mu0,ldmat(P0) ); 74 epdf& KFfep = KFf._epdf(); 75 mat Xtf(dimx,Ndat); 76 Xtf.set_col( 0,KFfep.mean() ); 77 78 // FULL 60 79 KalmanFull KF2( A,B,C,D,R,Q,P0,mu0 ); 61 // 80 mat Xt2(dimx,Ndat); 81 Xt2.set_col( 0,mu0); 82 83 84 // EKF 62 85 bilinfn fxu(rx,ru,A,B); 63 86 bilinfn hxu(rx,ru,C,D); 64 EKF <ldmat>KFE(rx,ry,ru);87 EKFCh KFE(rx,ry,ru); 65 88 KFE.set_parameters(&fxu,&hxu,Q,R); 66 KFE.set_est(mu0,P0); 89 KFE.set_est(mu0,chmat(P0)); 90 epdf& KFEep = KFE._epdf(); 91 mat XtE(dimx,Ndat); 92 XtE.set_col( 0,KFEep.mean() ); 67 93 68 epdf& KFep = KF._epdf();69 epdf& KFfep = KFf._epdf();70 epdf& KFEep = KFE._epdf();94 //test performance of each filter 95 Real_Timer tt; 96 vec exec_times(4); // KF, KFf KF2, KFE 71 97 72 Xt.set_col( 0,KFep.mean() ); 73 Xtf.set_col( 0,KFfep.mean() ); 74 Xt2.set_col( 0,KF2.mu ); 75 XtE.set_col( 0,KFEep.mean() ); 98 tt.tic(); 99 for ( int t=1;t<Ndat;t++ ) { 100 KF.bayes( Dt.get_col( t )); 101 Xt.set_col( t,KFep.mean() ); 102 } 103 exec_times(0) = tt.toc(); 104 105 tt.tic(); 76 106 for ( int t=1;t<Ndat;t++ ) { 77 107 KFf.bayes( Dt.get_col( t )); 78 KF.bayes( Dt.get_col( t )); 108 Xtf.set_col( t,KFfep.mean() ); 109 } 110 exec_times(1) = tt.toc(); 111 112 tt.tic(); 113 for ( int t=1;t<Ndat;t++ ) { 79 114 KF2.bayes( Dt.get_col( t )); 115 Xt2.set_col( t,KF2.mu); 116 } 117 exec_times(2) = tt.toc(); 118 119 tt.tic(); 120 for ( int t=1;t<Ndat;t++ ) { 80 121 KFE.bayes( Dt.get_col( t )); 81 Xt.set_col( t,KFep.mean() );82 Xtf.set_col( t,KFfep.mean() );83 Xt2.set_col(t,KF2.mu);84 122 XtE.set_col( t,KFEep.mean() ); 85 123 } 124 exec_times(3) = tt.toc(); 125 86 126 87 127 it_file fou( "testKF_res.it" ); … … 90 130 fou << Name("xth2") << Xt2; 91 131 fou << Name("xthE") << XtE; 132 fou << Name("exec_times") << exec_times; 92 133 //Exit program: 93 134 return 0;