- Timestamp:
- 01/15/09 10:53:55 (16 years ago)
- Location:
- pmsm
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
pmsm/mpf_test.cpp
r229 r230 18 18 #include <stat/libFN.h> 19 19 20 #include <stat/loggers.h> 21 20 22 #include "pmsm.h" 21 23 #include "simulator.h" … … 29 31 double h = 1e-6; 30 32 int Nsimstep = 125; 31 int Npart = 20 ;33 int Npart = 200; 32 34 33 35 // internal model … … 56 58 MPF<EKFCh_unQ> M ( rx,rQ,evolQ,evolQ,Npart,KFEp ); 57 59 // initialize 58 evolQ.set_parameters ( 0.1, Qdiag, 1.0); //sigma = 1/10 mu 59 evolQ.condition (Qdiag ); //Zdenek default 60 double xxx; 61 cout << Qdiag <<endl << "smp:"<< evolQ.samplecond(Qdiag,xxx) <<endl; 62 eigamma* pfinit=dynamic_cast<eigamma*>(evolQ._e()); 63 cout << pfinit->mean()<<endl; 64 M.set_est ( *pfinit ); 65 evolQ.set_parameters ( 0.10, Qdiag,0.995); //sigma = 1/10 mu 66 cout << Qdiag <<endl << "smp:"<< evolQ.samplecond(Qdiag,xxx) <<endl; 67 60 evolQ.set_parameters ( 0.1, 10*Qdiag, 1.0); //sigma = 1/10 mu 61 evolQ.condition (10*Qdiag ); //Zdenek default 62 M.set_est ( *evolQ._e() ); 63 evolQ.set_parameters ( 0.10, 10*Qdiag,0.9999); //sigma = 1/10 mu 68 64 // 69 65 … … 71 67 const epdf& Mep = M._epdf(); 72 68 73 mat Xt=zeros ( Ndat ,4 ); //true state from simulator 74 mat Dt=zeros ( Ndat,2+2 ); //observation 75 mat XtE=zeros ( Ndat, 4 ); 76 mat VarE=zeros ( Ndat, 4 ); 77 mat Qtr=zeros ( Ndat, 4 ); 78 mat XtM=zeros ( Ndat,4+4 ); //Q + x 79 mat VarM=zeros ( Ndat,4+4 ); //Q + x 80 69 dirfilelog L("exp/mpf_test",100); 70 int l_X = L.add(rx, "xt"); 71 int l_D = L.add(concat(ry,ru), ""); 72 int l_XE= L.add(rx, "xtE"); 73 int l_XM= L.add(concat(rQ,rx), "xtM"); 74 int l_VE= L.add(rx, "VE"); 75 int l_VM= L.add(concat(rQ,rx), "VM"); 76 int l_Q= L.add(rQ, ""); 77 L.init(); 78 81 79 // SET SIMULATOR 82 80 pmsmsim_set_parameters ( 0.28,0.003465,0.1989,0.0,4,1.5,0.04, 200., 3e-6, h ); … … 101 99 xtm = xt; 102 100 103 104 101 //Variances 105 102 if (tK==1000) Qdiag(0)*=10; … … 116 113 M.bayes ( concat ( dt,ut ) ); 117 114 118 Xt.set_row ( tK, xt); //vec from C-array 119 Dt.set_row ( tK, concat ( dt,ut)); 120 Qtr.set_row ( tK, Qdiag); 121 XtE.set_row ( tK,KFEep.mean() ); 122 VarE.set_row ( tK,KFEep.variance() ); 123 XtM.set_row ( tK,Mep.mean() ); 124 VarM.set_row ( tK,Mep.variance() ); 115 L.logit(l_X,xt); 116 L.logit(l_D,concat(dt,ut)); 117 L.logit(l_XE,KFEep.mean()); 118 L.logit(l_XM,Mep.mean()); 119 L.logit(l_VE,KFEep.variance()); 120 L.logit(l_VM,Mep.variance()); 121 L.logit(l_Q,Qdiag); 122 L.step(); 125 123 } 126 127 it_file fou ( "mpf_test.it" ); 128 129 fou << Name ( "xth" ) << Xt; 130 fou << Name ( "Dt" ) << Dt; 131 fou << Name ( "Qtr" ) << Qtr; 132 fou << Name ( "xthE" ) << XtE; 133 fou << Name ( "xthM" ) << XtM; 134 fou << Name ( "VarE" ) << VarE; 135 fou << Name ( "VarM" ) << VarM; 124 L.finalize(); 136 125 //Exit program: 137 126 -
pmsm/mpf_u_delta.cpp
r226 r230 25 25 using namespace itpp; 26 26 27 //!Extended Kalman filter with unknown \c Q 28 class EKFCh_cond : public EKFCh , public BMcond { 27 //!Extended Kalman filter with unknown \c Q and delta u 28 class EKFCh_du_kQ : public EKFCh , public BMcond { 29 chmat Qref; 29 30 public: 30 31 //! Default constructor 31 EKFCh_cond ( RV rx, RV ry,RV ru,RV rC ) :EKFCh ( rx,ry,ru ),BMcond ( rC ) {}; 32 EKFCh_du_kQ ( RV rx, RV ry,RV ru,RV rC ) :EKFCh ( rx,ry,ru ),BMcond ( rC ),Qref(rx.count()) {}; 33 void set_ref(const chmat &Qref0){Qref=Qref0;} 32 34 void condition ( const vec &val ) { 33 pfxu->condition ( val ); 35 pfxu->condition ( val.left(2) ); 36 37 Q = Qref*std::abs(val(2)); 38 preA.set_submatrix ( dimy+dimx,dimy,Q._Ch() ); 34 39 }; 35 40 }; … … 74 79 double h = 1e-6; 75 80 int Nsimstep = 125; 76 int Npart = 20 0;81 int Npart = 20; 77 82 78 83 mat Rnoise = randn ( 2,Ndat ); … … 89 94 vec mu0= "0.0 0.0 0.0 0.0"; 90 95 vec Qdiag ( "0.4 0.4 0.001 0.000001" ); //zdenek: 0.01 0.01 0.0001 0.0001 91 vec Rdiag ( "0. 1 0.1" ); //var(diff(xth)) = "0.034 0.034"96 vec Rdiag ( "0.2 0.2" ); //var(diff(xth)) = "0.034 0.034" 92 97 chmat Q ( Qdiag ); 93 98 chmat R ( Rdiag ); … … 96 101 KFE.set_est ( mu0, chmat ( ones ( 4 ) ) ); 97 102 98 RV rUd ( "{ud }", "2" );99 EKFCh_ condKFEp ( rx,ry,ru,rUd );103 RV rUd ( "{ud k}", "2 1" ); 104 EKFCh_du_kQ KFEp ( rx,ry,ru,rUd ); 100 105 KFEp.set_parameters ( &fxu,&hxu,Q,R ); 106 KFEp.set_ref(Q); 101 107 KFEp.set_est ( mu0, chmat ( ones ( 4 ) ) ); 102 108 103 109 mlnorm<ldmat> evolUd ( rUd,rUd ); 104 MPF<EKFCh_ cond> M ( rx,rUd,evolUd,evolUd,Npart,KFEp );110 MPF<EKFCh_du_kQ> M ( rx,rUd,evolUd,evolUd,Npart,KFEp ); 105 111 // initialize 106 vec Ud0="0 0 ";107 evolUd.set_parameters ( eye ( 2 ), vec_2 ( 0.0,0.0 ), ldmat ( 10.0*eye ( 2 ) ));112 vec Ud0="0 0 1.0"; 113 evolUd.set_parameters ( eye ( 3 ), zeros(3), ldmat ( vec( "1 1 0.0001" ))); 108 114 evolUd.condition ( Ud0 ); 109 115 epdf& pfinit=evolUd._epdf(); 110 116 M.set_est ( pfinit ); 111 evolUd.set_parameters ( eye ( 2 ), vec_2 ( 0.0,0.0 ), ldmat ( 0.1*eye ( 2 ) ));117 evolUd.set_parameters ( eye ( 3 ), zeros(3), ldmat ( vec(" 4e-3 4e-3 1e-3" ))); 112 118 113 119 mat Xt=zeros ( Ndat ,4 ); //true state from simulator … … 115 121 mat XtE=zeros ( Ndat, 4 ); 116 122 mat Qtr=zeros ( Ndat, 4 ); 117 mat XtM=zeros ( Ndat, 2+4 ); //W + x123 mat XtM=zeros ( Ndat, 3+4 ); //W + x 118 124 mat XtMTh=zeros ( Ndat,1 ); 119 125