root/testKF.cpp @ 11

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

resampling in PF + initial port of functions

RevLine 
[7]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
[8]13        // Klaman filter
14        mat A, B,C,D,R,Q,P0;
15        vec mu0;
16        mat Mu0;;
17        // input from Matlab
[9]18        it_file fin( "testKF.it" );
[11]19
[8]20        mat Dt, Xt,Xt2;
21        int Ndat;
[7]22
23        fin >> Name( "d" ) >> Dt;
[8]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;
[7]37       
[8]38        Ndat = Dt.cols();
39        Xt=zeros( 2,Ndat );
40        Xt2=zeros( 2,Ndat );
[7]41
[8]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
[7]46        Xt.set_col( 0,KF.mu );
[8]47        Xt2.set_col( 0,KF.mu );
[7]48        for ( int t=1;t<Ndat;t++ ) {
49                KF.bayes( Dt.get_col( t ));
[8]50                KF2.bayes( Dt.get_col( t ));
[7]51                Xt.set_col(t,KF.mu);
[8]52                Xt2.set_col(t,KF2.mu);
[7]53//              Kmu = KF.mu;
54//              cout <<  "t:" <<t<< "  " << dt<<"  "<<Kmu <<endl;
55        }
56
[9]57        it_file fou( "testKF_res.it" );
[7]58        fou << Name("xth") << Xt;
[8]59        fou << Name("xth2") << Xt2;
[7]60        //Exit program:
61        return 0;
62
63}
Note: See TracBrowser for help on using the browser.