Show
Ignore:
Timestamp:
08/27/09 15:39:35 (15 years ago)
Author:
smidl
Message:

redesign of ctrl LQ control for arx

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • library/bdm/estim/kalman.h

    r583 r586  
    7878                        validate(); 
    7979                }                
     80                //! access function 
     81                int _dimx(){return dimx;} 
     82                //! access function 
     83                int _dimy(){return dimy;} 
     84                //! access function 
     85                int _dimu(){return dimu;} 
     86                //! access function 
     87                mat _A(){return A;} 
     88                //! access function 
     89                mat _B(){return B;} 
     90                //! access function 
     91                mat _C(){return C;} 
     92                //! access function 
     93                mat _D(){return D;} 
     94                //! access function 
     95                sq_T _Q(){return Q;} 
     96                //! access function 
     97                sq_T _R(){return R;} 
    8098}; 
    8199 
     
    135153                void bayes (const vec &dt); 
    136154}; 
    137  
     155UIREGISTER(KalmanFull); 
    138156 
    139157 
     
    182200                void bayes (const vec &dt); 
    183201                 
    184                 void from_settings(const Setting &set){ 
     202                void from_setting(const Setting &set){ 
    185203                        Kalman<chmat>::from_setting(set); 
    186204                        initialize(); 
    187205                } 
    188206}; 
     207UIREGISTER(KalmanCh); 
    189208 
    190209/*! 
     
    219238                } 
    220239}; 
     240UIREGISTER(EKFfull); 
     241 
    221242 
    222243/*! 
     
    330351SHAREDPTR (MultiModel); 
    331352 
     353//! conversion of outer ARX model (mlnorm) to state space model  
     354/*! 
     355The model is constructed as: 
     356\f[ x_{t+1} = Ax_t + B u_t + R^{1/2} e_t, y_t=Cx_t+Du_t + R^{1/2}w_t, \f] 
     357For example, for: 
     358\f[ y_t = a y_{t-1} + b u_{t-1}\f] 
     359the state \f$ x_t = [y_{t-1}, u_{t-1}] \f$ 
     360*/ 
     361template<class sq_T> 
     362shared_ptr<StateSpace<fsqmat> > to_state_space(const mlnorm<sq_T > &ml, ivec &theta_in_A, ivec &theta_in_C){ 
     363        //get ids of yrv 
     364                         
     365                        ivec yids= unique(ml._rv()._ids()); //yrv is now stored in _yrv 
     366                        ivec dids= unique(ml._rvc()._ids()); //yrv is now stored in _yrv 
     367                        ivec uids=unique_complement(dids, yids); 
     368         
     369                        RV yrv_uni = RV(yids,zeros_i(yids.length())); 
     370                        RV urv_uni = RV(uids,zeros_i(yids.length())); 
     371                        //We can do only 1d now... :( 
     372                        bdm_assert_debug(yrv_uni._dsize()==urv_uni._dsize()==1, "Only for SISO so far..." ); 
     373                                         
     374                        RV xrv; //empty 
     375                        RV Crv; //empty 
     376                        int td=ml._rvc().mintd(); 
     377                        for (int t=-1;t>=td;t--){ 
     378                                xrv.add(yrv_uni); 
     379                                Crv.add(urv_uni); 
     380                        } 
     381                         
     382                        int dimx = xrv._dsize(); 
     383                         
     384                        theta_in_A = ml._rv().dataind(xrv); 
     385                        theta_in_C = ml._rvc().dataind(xrv); 
     386                        // some chcek of corretness 
     387                         
     388                        vec A1row = zeros(xrv._dsize()); 
     389                        vec C1row = zeros(xrv._dsize()); 
     390                        vec theta = ml._A().get_row(0); // this  
     391                        set_subvector( A1row, theta_in_A, theta); 
     392                        set_subvector( C1row, theta_in_C, theta); 
     393 
     394                        StateSpace<fsqmat> stsp=new StateSpace<fsqmat>(); 
     395                        mat A=zeros(dimx,dimx); 
     396                        A.set_row(0,A1row); 
     397                        for (int j=1; j<dimx; j++){A(j,j-1)=1.0;} // off diagonal 
     398                        mat B=zeros(dimx,1); 
     399                        B(0) = 1.0; 
     400                        mat C=zeros(1,dimx); 
     401                        C.set_row(0,C1row); 
     402                        stsp.set_parameters(A,B,C,zeros(1,1), zeros(dimx,dimx), ml._R()); 
     403                        return stsp; 
     404} 
     405 
    332406/////////// INSTANTIATION 
    333407