Revision 254, 1.5 kB
(checked in by smidl, 16 years ago)
|
create namespace bdm
|
Rev | Line | |
---|
[33] | 1 | #include <itpp/itbase.h> |
---|
| 2 | #include <estim/libKF.h> |
---|
| 3 | #include <estim/libPF.h> |
---|
| 4 | |
---|
[254] | 5 | using namespace bdm; |
---|
[33] | 6 | |
---|
| 7 | //These lines are needed for use of cout and endl |
---|
| 8 | using std::cout; |
---|
| 9 | using std::endl; |
---|
| 10 | |
---|
| 11 | int main() { |
---|
| 12 | // Klaman filter |
---|
| 13 | mat A, B,C,D,R,Q,P0; |
---|
| 14 | vec mu0; |
---|
| 15 | mat Mu0;// read from matlab |
---|
| 16 | // input from Matlab |
---|
| 17 | it_file fin ( "testKF.it" ); |
---|
| 18 | |
---|
| 19 | mat Dt, XQRt,eR,eQ; |
---|
| 20 | int Ndat; |
---|
| 21 | |
---|
| 22 | bool xxx= fin.seek ( "d" ); |
---|
| 23 | |
---|
| 24 | if ( !xxx ) { it_error ( "testKF.it not found" );} |
---|
| 25 | |
---|
| 26 | fin >>Dt; |
---|
| 27 | |
---|
| 28 | fin.seek ( "A" ); |
---|
| 29 | fin >> A; |
---|
| 30 | fin.seek ( "B" ); |
---|
| 31 | fin >> B; |
---|
| 32 | fin.seek ( "C" ); |
---|
| 33 | fin >> C; |
---|
| 34 | fin.seek ( "D" ); |
---|
| 35 | fin >> D; |
---|
| 36 | fin.seek ( "R" ); |
---|
| 37 | fin >> R; |
---|
| 38 | fin.seek ( "Q" ); fin >> Q; |
---|
| 39 | fin.seek ( "P0" ); fin >> P0; |
---|
| 40 | fin.seek ( "mu0" ); fin >> Mu0; |
---|
| 41 | mu0=Mu0.get_col ( 0 ); |
---|
| 42 | |
---|
| 43 | vec vQ1 = "0.01:0.04:1"; |
---|
| 44 | vec vQ2 = "0.01:0.04:1"; |
---|
| 45 | |
---|
| 46 | mat LL = zeros ( vQ1.length(), vQ2.length() ); |
---|
| 47 | |
---|
| 48 | Ndat = Dt.cols(); |
---|
| 49 | |
---|
[162] | 50 | RV rx ( "{x}","2" ); |
---|
| 51 | RV ru ( "{u}","1" ); |
---|
| 52 | RV ry ( "{y}","2" ); |
---|
[33] | 53 | // |
---|
| 54 | // |
---|
| 55 | Kalman<ldmat> KFtr ( rx,ry,ru ); |
---|
| 56 | |
---|
| 57 | for ( int i =0; i<vQ1.length();i++ ) { |
---|
| 58 | |
---|
| 59 | for ( int j = 0; j<vQ2.length();j++ ) { |
---|
| 60 | // KF with R unknown |
---|
| 61 | mat Qj = Q; |
---|
| 62 | Qj ( 0,0 ) = vQ1 ( i ); |
---|
| 63 | Qj ( 1,1 ) = vQ2 ( j ); |
---|
| 64 | KFtr.set_parameters ( A,B,C,D,ldmat ( R ),ldmat ( Qj ) ); |
---|
| 65 | KFtr.set_est ( mu0,ldmat ( P0 ) ); |
---|
| 66 | |
---|
| 67 | for ( int t=1;t<Ndat;t++ ) { |
---|
| 68 | KFtr.bayes ( Dt.get_col ( t ) ); |
---|
| 69 | LL ( i,j ) += KFtr._ll(); |
---|
| 70 | } |
---|
| 71 | } |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | it_file fou ( "testKF_QR_exh.it" ); |
---|
| 75 | |
---|
| 76 | fou << Name ( "LL" ) << LL; |
---|
| 77 | fou << Name ( "Q1" ) << vQ1; |
---|
| 78 | fou << Name ( "Q2" ) << vQ2; |
---|
| 79 | //Exit program: |
---|
| 80 | return 0; |
---|
| 81 | |
---|
| 82 | } |
---|