Show
Ignore:
Timestamp:
08/05/09 14:40:03 (15 years ago)
Author:
mido
Message:

panove, vite, jak jsem peclivej na upravu kodu.. snad se vam bude libit:) konfigurace je v souboru /system/astylerc

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • library/tests/test_kalman.cpp

    r386 r477  
    1010int main() { 
    1111        // Kalman filter 
    12         mat A, B,C,D,R,Q,P0; 
     12        mat A, B, C, D, R, Q, P0; 
    1313        vec mu0; 
    1414        mat Mu0;; 
    1515        // input from Matlab 
    16         it_file fin( "testKF.it" ); 
     16        it_file fin ( "testKF.it" ); 
    1717 
    1818        mat Dt; 
    1919        int Ndat; 
    2020 
    21         bool xxx= fin.seek( "d" ); 
    22         if (!xxx){ it_error("testKF.it not found");} 
    23         fin >>Dt; 
    24         fin.seek( "A" );  
     21        bool xxx = fin.seek ( "d" ); 
     22        if ( !xxx ) { 
     23                it_error ( "testKF.it not found" ); 
     24        } 
     25        fin >> Dt; 
     26        fin.seek ( "A" ); 
    2527        fin >> A; 
    26         fin.seek( "B" );  
     28        fin.seek ( "B" ); 
    2729        fin >> B; 
    28         fin.seek( "C" );  
     30        fin.seek ( "C" ); 
    2931        fin >> C; 
    30         fin.seek( "D" );  
     32        fin.seek ( "D" ); 
    3133        fin >> D; 
    32         fin.seek( "R" );  
     34        fin.seek ( "R" ); 
    3335        fin >> R; 
    34         fin.seek( "Q" ); fin >> Q; 
    35         fin.seek( "P0" ); fin >> P0; 
    36         fin.seek( "mu0" ); fin >> Mu0;  
    37         mu0=Mu0.get_col(0); 
    38          
     36        fin.seek ( "Q" ); 
     37        fin >> Q; 
     38        fin.seek ( "P0" ); 
     39        fin >> P0; 
     40        fin.seek ( "mu0" ); 
     41        fin >> Mu0; 
     42        mu0 = Mu0.get_col ( 0 ); 
     43 
    3944        Ndat = 10;//Dt.cols(); 
    4045        int dimx = A.rows(); 
    41          
     46 
    4247        // Prepare for Kalman filters in BDM: 
    43         RV rx("{x }",vec_1(A.cols())); 
    44         RV ru("{u }",vec_1(B.cols())); 
    45         RV ry("{y }",vec_1(C.rows())); 
    46          
     48        RV rx ( "{x }", vec_1 ( A.cols() ) ); 
     49        RV ru ( "{u }", vec_1 ( B.cols() ) ); 
     50        RV ry ( "{y }", vec_1 ( C.rows() ) ); 
     51 
    4752//      // LDMAT 
    4853//      Kalman<ldmat> KF(rx,ry,ru); 
     
    5055//      KF.set_est(mu0,ldmat(P0) ); 
    5156//      epdf& KFep = KF.posterior(); 
    52 //      mat Xt(2,Ndat);  
     57//      mat Xt(2,Ndat); 
    5358//      Xt.set_col( 0,KFep.mean() ); 
    5459 
    5560        //Chol 
    5661        KalmanCh KF; 
    57         KF.set_parameters(A,B,C,D,chmat(R),chmat(Q)); 
    58         KF.set_est(mu0,chmat(P0) ); //prediction! 
     62        KF.set_parameters ( A, B, C, D, chmat ( R ), chmat ( Q ) ); 
     63        KF.set_est ( mu0, chmat ( P0 ) ); //prediction! 
    5964        const epdf& KFep = KF.posterior(); 
    60         mat Xt(dimx,Ndat);       
    61         Xt.set_col( 0,KFep.mean() ); 
    62          
    63         //       
     65        mat Xt ( dimx, Ndat ); 
     66        Xt.set_col ( 0, KFep.mean() ); 
     67 
     68        // 
    6469        // FSQMAT 
    6570        Kalman<ldmat> KFf; 
    66         KFf.set_parameters(A,B,C,D,ldmat(R),ldmat(Q)); 
    67         KFf.set_est(mu0,ldmat(P0) ); 
     71        KFf.set_parameters ( A, B, C, D, ldmat ( R ), ldmat ( Q ) ); 
     72        KFf.set_est ( mu0, ldmat ( P0 ) ); 
    6873        const   epdf& KFfep = KFf.posterior(); 
    69         mat Xtf(dimx,Ndat);      
    70         Xtf.set_col( 0,KFfep.mean() ); 
    71          
     74        mat Xtf ( dimx, Ndat ); 
     75        Xtf.set_col ( 0, KFfep.mean() ); 
     76 
    7277        // FULL 
    73         KalmanFull KF2( A,B,C,D,R,Q,P0,mu0 ); 
    74         mat Xt2(dimx,Ndat);      
    75         Xt2.set_col( 0,mu0); 
     78        KalmanFull KF2 ( A, B, C, D, R, Q, P0, mu0 ); 
     79        mat Xt2 ( dimx, Ndat ); 
     80        Xt2.set_col ( 0, mu0 ); 
    7681 
    77          
     82 
    7883        // EKF 
    79         bilinfn fxu(A,B); 
    80         bilinfn hxu(C,D); 
     84        bilinfn fxu ( A, B ); 
     85        bilinfn hxu ( C, D ); 
    8186        EKFCh KFE; 
    82         KFE.set_parameters(&fxu,&hxu,Q,R); 
    83         KFE.set_est(mu0,chmat(P0)); 
     87        KFE.set_parameters ( &fxu, &hxu, Q, R ); 
     88        KFE.set_est ( mu0, chmat ( P0 ) ); 
    8489        const epdf& KFEep = KFE.posterior(); 
    85         mat XtE(dimx,Ndat);      
    86         XtE.set_col( 0,KFEep.mean() ); 
     90        mat XtE ( dimx, Ndat ); 
     91        XtE.set_col ( 0, KFEep.mean() ); 
    8792 
    8893        //test performance of each filter 
    8994        Real_Timer tt; 
    90         vec exec_times(4); // KF, KFf KF2, KFE 
    91          
    92         tt.tic(); 
    93         for ( int t=1;t<Ndat;t++ ) { 
    94                 KF.bayes( Dt.get_col( t )); 
    95                 Xt.set_col( t,KFep.mean() ); 
    96         } 
    97         exec_times(0) = tt.toc(); 
    98          
    99         tt.tic(); 
    100         for ( int t=1;t<Ndat;t++ ) { 
    101                 KFf.bayes( Dt.get_col( t )); 
    102                 Xtf.set_col( t,KFfep.mean() ); 
    103         } 
    104         exec_times(1) = tt.toc(); 
     95        vec exec_times ( 4 ); // KF, KFf KF2, KFE 
    10596 
    10697        tt.tic(); 
    107         for ( int t=1;t<Ndat;t++ ) { 
    108                 KF2.bayes( Dt.get_col( t )); 
    109                 Xt2.set_col( t,KF2.mu); 
     98        for ( int t = 1; t < Ndat; t++ ) { 
     99                KF.bayes ( Dt.get_col ( t ) ); 
     100                Xt.set_col ( t, KFep.mean() ); 
    110101        } 
    111         exec_times(2) = tt.toc(); 
     102        exec_times ( 0 ) = tt.toc(); 
    112103 
    113104        tt.tic(); 
    114         for ( int t=1;t<Ndat;t++ ) { 
    115                 KFE.bayes( Dt.get_col( t )); 
    116                 XtE.set_col( t,KFEep.mean() ); 
     105        for ( int t = 1; t < Ndat; t++ ) { 
     106                KFf.bayes ( Dt.get_col ( t ) ); 
     107                Xtf.set_col ( t, KFfep.mean() ); 
    117108        } 
    118         exec_times(3) = tt.toc(); 
     109        exec_times ( 1 ) = tt.toc(); 
     110 
     111        tt.tic(); 
     112        for ( int t = 1; t < Ndat; t++ ) { 
     113                KF2.bayes ( Dt.get_col ( t ) ); 
     114                Xt2.set_col ( t, KF2.mu ); 
     115        } 
     116        exec_times ( 2 ) = tt.toc(); 
     117 
     118        tt.tic(); 
     119        for ( int t = 1; t < Ndat; t++ ) { 
     120                KFE.bayes ( Dt.get_col ( t ) ); 
     121                XtE.set_col ( t, KFEep.mean() ); 
     122        } 
     123        exec_times ( 3 ) = tt.toc(); 
    119124 
    120125 
    121         it_file fou( "testKF_res.it" ); 
    122         fou << Name("xth") << Xt; 
    123         fou << Name("xthf") << Xtf; 
    124         fou << Name("xth2") << Xt2; 
    125         fou << Name("xthE") << XtE; 
    126         fou << Name("exec_times") << exec_times; 
     126        it_file fou ( "testKF_res.it" ); 
     127        fou << Name ( "xth" ) << Xt; 
     128        fou << Name ( "xthf" ) << Xtf; 
     129        fou << Name ( "xth2" ) << Xt2; 
     130        fou << Name ( "xthE" ) << XtE; 
     131        fou << Name ( "exec_times" ) << exec_times; 
    127132        //Exit program: 
    128133        return 0;