Changeset 32 for bdm/estim/libKF.cpp
- Timestamp:
- 03/03/08 13:00:32 (16 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
bdm/estim/libKF.cpp
r28 r32 6 6 using std::endl; 7 7 8 KalmanFull::KalmanFull ( mat A0, mat B0, mat C0, mat D0, mat R0, mat Q0, mat P0, vec mu0 ) {8 KalmanFull::KalmanFull ( mat A0, mat B0, mat C0, mat D0, mat R0, mat Q0, mat P0, vec mu0 ) { 9 9 dimx = A0.rows(); 10 10 dimu = B0.cols(); 11 11 dimy = C0.rows(); 12 12 13 it_assert_debug ( A0.cols()==dimx, "KalmanFull: A is not square" );14 it_assert_debug ( B0.rows()==dimx, "KalmanFull: B is not compatible" );15 it_assert_debug ( C0.cols()==dimx, "KalmanFull: C is not square" );16 it_assert_debug (( D0.rows()==dimy ) || ( D0.cols()==dimu ), "KalmanFull: D is not compatible" );17 it_assert_debug (( R0.cols()==dimy ) || ( R0.rows()==dimy ), "KalmanFull: R is not compatible" );18 it_assert_debug (( Q0.cols()==dimx ) || ( Q0.rows()==dimx ), "KalmanFull: Q is not compatible" );13 it_assert_debug ( A0.cols() ==dimx, "KalmanFull: A is not square" ); 14 it_assert_debug ( B0.rows() ==dimx, "KalmanFull: B is not compatible" ); 15 it_assert_debug ( C0.cols() ==dimx, "KalmanFull: C is not square" ); 16 it_assert_debug ( ( D0.rows() ==dimy ) || ( D0.cols() ==dimu ), "KalmanFull: D is not compatible" ); 17 it_assert_debug ( ( R0.cols() ==dimy ) || ( R0.rows() ==dimy ), "KalmanFull: R is not compatible" ); 18 it_assert_debug ( ( Q0.cols() ==dimx ) || ( Q0.rows() ==dimx ), "KalmanFull: Q is not compatible" ); 19 19 20 20 A = A0; … … 28 28 } 29 29 30 void KalmanFull::bayes ( const vec &dt) {31 it_assert_debug ( dt.length()==( dimy+dimu ),"KalmanFull::bayes wrong size of dt" );30 void KalmanFull::bayes ( const vec &dt ) { 31 it_assert_debug ( dt.length() == ( dimy+dimu ),"KalmanFull::bayes wrong size of dt" ); 32 32 33 vec u = dt.get ( dimy,dimy+dimu-1 );34 vec y = dt.get ( 0,dimy-1 );33 vec u = dt.get ( dimy,dimy+dimu-1 ); 34 vec y = dt.get ( 0,dimy-1 ); 35 35 //Time update 36 36 mu = A*mu + B*u; … … 39 39 //Data update 40 40 _Ry = C*P*C.transpose() + R; 41 _iRy = inv ( _Ry );42 _K = P*C.transpose() *_iRy;41 _iRy = inv ( _Ry ); 42 _K = P*C.transpose() *_iRy; 43 43 P -= _K*C*P; // P = P -KCP; 44 mu += _K* ( y-C*mu-D*u );44 mu += _K* ( y-C*mu-D*u ); 45 45 }; 46 46 … … 50 50 } 51 51 52 void KFcondQR::condition ( const vec &QR ) { 53 it_assert_debug ( QR.length() == ( rvc.count() ),"KFcondRQ: conditioning by incompatible vector" ); 54 55 Q.setD ( QR ( 0, dimx-1 )); 56 R.setD ( QR ( dimx, -1 )); 57 }; 58 59 void KFcondR::condition ( const vec &R0 ) { 60 it_assert_debug ( R0.length() == ( rvc.count() ),"KFcondR: conditioning by incompatible vector" ); 61 62 R.setD ( R0 ); 63 };