root/testKF.cpp @ 11

Revision 11, 1.1 kB (checked in by smidl, 16 years ago)

resampling in PF + initial port of functions

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