Changeset 32 for bdm/estim/libKF.cpp

Show
Ignore:
Timestamp:
03/03/08 13:00:32 (16 years ago)
Author:
smidl
Message:

test KF : estimation of R in KF is not possible! Likelihood of y_t is growing when R -> 0

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • bdm/estim/libKF.cpp

    r28 r32  
    66using std::endl; 
    77 
    8 KalmanFull::KalmanFull( mat A0, mat B0, mat C0, mat D0, mat R0, mat Q0, mat P0, vec mu0 ) { 
     8KalmanFull::KalmanFull ( mat A0, mat B0, mat C0, mat D0, mat R0, mat Q0, mat P0, vec mu0 ) { 
    99        dimx = A0.rows(); 
    1010        dimu = B0.cols(); 
    1111        dimy = C0.rows(); 
    1212 
    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" ); 
    1919 
    2020        A = A0; 
     
    2828} 
    2929 
    30 void KalmanFull::bayes( const vec &dt) { 
    31         it_assert_debug( dt.length()==( dimy+dimu ),"KalmanFull::bayes wrong size of dt" ); 
     30void KalmanFull::bayes ( const vec &dt ) { 
     31        it_assert_debug ( dt.length() == ( dimy+dimu ),"KalmanFull::bayes wrong size of dt" ); 
    3232 
    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 ); 
    3535        //Time update 
    3636        mu = A*mu + B*u; 
     
    3939        //Data update 
    4040        _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; 
    4343        P -= _K*C*P; // P = P -KCP; 
    44         mu += _K*( y-C*mu-D*u ); 
     44        mu += _K* ( y-C*mu-D*u ); 
    4545}; 
    4646 
     
    5050} 
    5151 
     52void 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 
     59void KFcondR::condition ( const vec &R0 ) { 
     60        it_assert_debug ( R0.length() == ( rvc.count() ),"KFcondR: conditioning by incompatible vector" ); 
     61 
     62        R.setD ( R0 ); 
     63};