Revision 565, 1.5 kB
(checked in by vbarta, 15 years ago)
|
using own error macros (basically copied from IT++, but never aborting)
|
-
Property svn:eol-style set to
native
|
Rev | Line | |
---|
[262] | 1 | |
---|
[386] | 2 | #include <estim/kalman.h> |
---|
| 3 | #include <estim/particles.h> |
---|
[33] | 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 |
---|
[477] | 13 | mat A, B, C, D, R, Q, P0; |
---|
[33] | 14 | vec mu0; |
---|
| 15 | mat Mu0;// read from matlab |
---|
| 16 | // input from Matlab |
---|
| 17 | it_file fin ( "testKF.it" ); |
---|
| 18 | |
---|
[477] | 19 | mat Dt, XQRt, eR, eQ; |
---|
[33] | 20 | int Ndat; |
---|
| 21 | |
---|
[477] | 22 | bool xxx = fin.seek ( "d" ); |
---|
[33] | 23 | |
---|
[477] | 24 | if ( !xxx ) { |
---|
[565] | 25 | bdm_error ( "testKF.it not found" ); |
---|
[477] | 26 | } |
---|
[33] | 27 | |
---|
[477] | 28 | fin >> Dt; |
---|
[33] | 29 | |
---|
| 30 | fin.seek ( "A" ); |
---|
| 31 | fin >> A; |
---|
| 32 | fin.seek ( "B" ); |
---|
| 33 | fin >> B; |
---|
| 34 | fin.seek ( "C" ); |
---|
| 35 | fin >> C; |
---|
| 36 | fin.seek ( "D" ); |
---|
| 37 | fin >> D; |
---|
| 38 | fin.seek ( "R" ); |
---|
| 39 | fin >> R; |
---|
[477] | 40 | fin.seek ( "Q" ); |
---|
| 41 | fin >> Q; |
---|
| 42 | fin.seek ( "P0" ); |
---|
| 43 | fin >> P0; |
---|
| 44 | fin.seek ( "mu0" ); |
---|
| 45 | fin >> Mu0; |
---|
| 46 | mu0 = Mu0.get_col ( 0 ); |
---|
[33] | 47 | |
---|
| 48 | vec vQ1 = "0.01:0.04:1"; |
---|
| 49 | vec vQ2 = "0.01:0.04:1"; |
---|
| 50 | |
---|
| 51 | mat LL = zeros ( vQ1.length(), vQ2.length() ); |
---|
| 52 | |
---|
| 53 | Ndat = Dt.cols(); |
---|
| 54 | |
---|
[477] | 55 | RV rx ( "{x}", "2" ); |
---|
| 56 | RV ru ( "{u}", "1" ); |
---|
| 57 | RV ry ( "{y}", "2" ); |
---|
[33] | 58 | // |
---|
| 59 | // |
---|
[270] | 60 | Kalman<ldmat> KFtr; |
---|
[33] | 61 | |
---|
[477] | 62 | for ( int i = 0; i < vQ1.length(); i++ ) { |
---|
[33] | 63 | |
---|
[477] | 64 | for ( int j = 0; j < vQ2.length(); j++ ) { |
---|
[33] | 65 | // KF with R unknown |
---|
| 66 | mat Qj = Q; |
---|
[477] | 67 | Qj ( 0, 0 ) = vQ1 ( i ); |
---|
| 68 | Qj ( 1, 1 ) = vQ2 ( j ); |
---|
| 69 | KFtr.set_parameters ( A, B, C, D, ldmat ( R ), ldmat ( Qj ) ); |
---|
| 70 | KFtr.set_est ( mu0, ldmat ( P0 ) ); |
---|
[33] | 71 | |
---|
[477] | 72 | for ( int t = 1; t < Ndat; t++ ) { |
---|
[33] | 73 | KFtr.bayes ( Dt.get_col ( t ) ); |
---|
[477] | 74 | LL ( i, j ) += KFtr._ll(); |
---|
[33] | 75 | } |
---|
| 76 | } |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | it_file fou ( "testKF_QR_exh.it" ); |
---|
| 80 | |
---|
| 81 | fou << Name ( "LL" ) << LL; |
---|
| 82 | fou << Name ( "Q1" ) << vQ1; |
---|
| 83 | fou << Name ( "Q2" ) << vQ2; |
---|
| 84 | //Exit program: |
---|
| 85 | return 0; |
---|
| 86 | |
---|
| 87 | } |
---|