root/tests/testKF.cpp @ 19

Revision 19, 1.2 kB (checked in by smidl, 16 years ago)

Switch to CMake

Line 
1#include <itpp/itbase.h>
2#include "../bdm/estim/libKF.h"
3
4using namespace itpp;
5
6//These lines are needed for use of cout and endl
7using std::cout;
8using std::endl;
9
10int main() {
11
12
13        // Klaman filter
14        mat A, B,C,D,R,Q,P0;
15        vec mu0;
16        mat Mu0;;
17        // input from Matlab
18        it_file fin( "testKF.it" );
19
20        mat Dt, Xt,Xt2;
21        int Ndat;
22
23        bool xxx= fin.seek( "d" );
24        fin >>Dt;
25        fin.seek( "A" ); 
26        fin >> A;
27        fin.seek( "B" ); 
28        fin >> B;
29        fin.seek( "C" ); 
30        fin >> C;
31        fin.seek( "D" ); 
32        fin >> D;
33        fin.seek( "R" ); 
34        fin >> R;
35        fin.seek( "Q" ); fin >> Q;
36        fin.seek( "P0" ); fin >> P0;
37        fin.seek( "mu0" ); fin >> Mu0; 
38        mu0=Mu0.get_col(0);
39       
40        Ndat = Dt.cols();
41        Xt=zeros( 2,Ndat );
42        Xt2=zeros( 2,Ndat );
43
44        Kalman<ldmat> KF( A,B,C,D,ldmat(diag(R)),ldmat(diag(Q)),ldmat(diag(P0)),mu0 );
45//      cout << KF;
46        KalmanFull KF2( A,B,C,D,R,Q,P0,mu0 );
47
48        Xt.set_col( 0,KF.mu );
49        Xt2.set_col( 0,KF.mu );
50        for ( int t=1;t<Ndat;t++ ) {
51                KF.bayes( Dt.get_col( t ));
52                KF2.bayes( Dt.get_col( t ));
53                Xt.set_col(t,KF.mu);
54                Xt2.set_col(t,KF2.mu);
55//              Kmu = KF.mu;
56//              cout <<  "t:" <<t<< "  " << dt<<"  "<<Kmu <<endl;
57        }
58
59        it_file fou( "testKF_res.it" );
60        fou << Name("xth") << Xt;
61        fou << Name("xth2") << Xt2;
62        //Exit program:
63        return 0;
64
65}
Note: See TracBrowser for help on using the browser.