- Timestamp:
- 03/03/08 13:00:32 (17 years ago)
- Location:
- tests
- Files:
-
- 3 added
- 5 modified
Legend:
- Unmodified
- Added
- Removed
-
tests/CMakeLists.txt
r22 r32 6 6 7 7 ## Save all needed libraries in variable BdmLibs 8 SET(BdmLibs bdm itpp) 8 SET(BdmLibs bdm itpp_debug) 9 #SET(BdmLibs bdm itpp) 9 10 10 11 IF(WIN32) … … 23 24 add_executable (testPF testPF.cpp) 24 25 add_executable (testSmp testSmp.cpp) 26 add_executable (testEpdf testEpdf.cpp) 27 add_executable (testResample testResample.cpp) 28 add_executable (testKF_QR testKF_QR.cpp) 25 29 26 30 # Link the executable to the Hello library. … … 29 33 target_link_libraries (testPF ${BdmLibs}) 30 34 target_link_libraries (testSmp ${BdmLibs}) 35 target_link_libraries (testEpdf ${BdmLibs}) 36 target_link_libraries (testResample ${BdmLibs}) 37 target_link_libraries (testKF_QR ${BdmLibs}) -
tests/test0.cpp
r28 r32 12 12 { 13 13 14 RV th = RV ( "1 2","{a b }","1 1","0 0" ,"0 0");14 RV th = RV ( "1 2","{a b }","1 1","0 0"); 15 15 RV r = RV ( "3 4" ); 16 16 17 17 cout << th << r << endl; 18 18 19 ldmat ld = ldmat("1 0; -0.11","1.1 1.3");19 ldmat ld = ldmat("1 0;0.5 1","1.1 1.3"); 20 20 vec v = "1 -0.1"; 21 21 -
tests/testKF.cpp
r28 r32 18 18 it_file fin( "testKF.it" ); 19 19 20 mat Dt, Xt,Xt2,XtE ;20 mat Dt, Xt,Xt2,XtE,Xtf; 21 21 int Ndat; 22 22 … … 42 42 Xt=zeros( 2,Ndat ); 43 43 Xt2=zeros( 2,Ndat ); 44 Xtf=zeros( 2,Ndat ); 44 45 XtE=zeros( 2,Ndat ); 45 46 46 47 // cout << KF; 47 RV rx("1","{x}","2","0" ,"0");48 RV ru("2","{u}","1","0" ,"0");49 RV ry("3","{y}","1","0" ,"0");48 RV rx("1","{x}","2","0"); 49 RV ru("2","{u}","1","0"); 50 RV ry("3","{y}","1","0"); 50 51 // 51 52 Kalman<ldmat> KF(rx,ry,ru); … … 65 66 KFE.set_est(mu0,P0); 66 67 67 Xt.set_col( 0,*((enorm<ldmat>*)(KF._epdf()))->_mu() ); 68 epdf& KFep = KF._epdf(); 69 epdf& KFfep = KFf._epdf(); 70 epdf& KFEep = KFE._epdf(); 71 72 Xt.set_col( 0,KFep.mean() ); 73 Xtf.set_col( 0,KFfep.mean() ); 68 74 Xt2.set_col( 0,KF2.mu ); 69 XtE.set_col( 0, *((enorm<ldmat>*)(KFE._epdf()))->_mu() );75 XtE.set_col( 0,KFEep.mean() ); 70 76 for ( int t=1;t<Ndat;t++ ) { 71 77 KFf.bayes( Dt.get_col( t )); 72 78 KF.bayes( Dt.get_col( t )); 73 79 KF2.bayes( Dt.get_col( t )); 74 // KFE.bayes( Dt.get_col( t )); 75 Xt.set_col(t,*((enorm<ldmat>*)(KF._epdf()))->_mu()); 80 KFE.bayes( Dt.get_col( t )); 81 Xt.set_col( t,KFep.mean() ); 82 Xtf.set_col( t,KFfep.mean() ); 76 83 Xt2.set_col(t,KF2.mu); 77 XtE.set_col( t,*((enorm<ldmat>*)(KFE._epdf()))->_mu());84 XtE.set_col( t,KFEep.mean() ); 78 85 } 79 86 80 87 it_file fou( "testKF_res.it" ); 81 88 fou << Name("xth") << Xt; 89 fou << Name("xthf") << Xtf; 82 90 fou << Name("xth2") << Xt2; 83 91 fou << Name("xthE") << XtE; -
tests/testPF.cpp
r19 r32 13 13 14 14 RV x("1"); 15 RV xm=x; xm.t(-1); 15 RV xm=x; xm.t(-1);const 16 16 RV y("2"); 17 17 … … 19 19 vec vR = "1"; 20 20 ldmat R(vR); 21 22 eEmp emp(x,10); 23 euni eun(x); 24 eun.set_parameters("0","1"); 25 emp.set_parameters(ones(10),&eun); 26 vec &v=emp._w(); 27 Array<vec> &S=emp._samples(); 21 28 29 for (int i=0;i<10;i++){ v(i) = exp(-0.5*sum(pow(S(i)-1,2.0))*10);} 30 v/=sum(v); 22 31 23 vec ptc = randn(10);24 vec w = exp(-0.5*(pow(ptc,2))/0.2);32 cout << "p:" << S << endl; 33 cout << "w:" << v << endl; 25 34 26 cout << "p:" << ptc << endl; 27 cout << "w:" << w << endl; 28 29 PF pf(w); 30 ivec ind = pf.resample(); 35 ivec ind = emp.resample(); 31 36 32 37 cout << ind << endl; 33 /*34 mlnorm<ldmat> obs(x,xm,A,R);35 mlnorm<ldmat> par(y,x,A,R);36 38 37 TrivialPF TPF(obs,par,10);38 */39 39 //Exit program: 40 40 return 0; -
tests/testSmp.cpp
r28 r32 8 8 using std::endl; 9 9 10 void disp(const vec &tmu, const mat &tR,const mat &Smp){ 11 int N = Smp.cols(); 12 vec Emu = Smp*ones(N) /N ; 13 mat Er = (Smp*Smp.transpose())/N - outer_product(Emu,Emu); 14 cout << "True mu:" << tmu <<endl; 15 cout << "Emp mu:" << Emu <<endl; 16 17 cout << "True R:" << tR <<endl; 18 cout << "Emp R:" << Er <<endl; 19 } 20 10 21 int main() { 11 22 12 //RNG_randomize();23 RNG_randomize(); 13 24 14 RV rv("1","{x }","2","0" ,"0");25 RV rv("1","{x }","2","0"); 15 26 int N = 10000; //number of samples 16 27 vec mu0 = "1.5 1.7"; 17 28 mat V0("1.2 0.3; 0.3 5"); 18 29 ldmat R = ldmat(V0); 30 31 cout << "====== ENorm ====== " <<endl; 19 32 enorm<ldmat> eN(rv); 20 33 eN.set_parameters(mu0,R); 34 mat Smp = eN.sample(N); 35 36 disp(mu0,R.to_mat(),Smp); 37 38 cout << "====== MlNorm ====== " <<endl; 39 mat I = eye(2); 40 vec lik(N); 41 mlnorm<ldmat> ML(rv,rv); 42 ML.set_parameters(I,R); 43 Smp = ML.samplecond(mu0,lik,N); 21 44 22 mat Smp = eN.sample(N); 23 cout << "True:" <<endl; 24 cout << "mu:" << mu0 ; 25 cout << "R:" << R ; 26 cout << "R:" << R.to_mat() ; 45 disp(mu0,R.to_mat(),Smp); 46 47 cout << "====== EGamma ====== " <<endl; 48 vec a = "100000,10000"; 49 vec b = a/10.0; 50 egamma eG(rv); 51 eG.set_parameters(a,b); 27 52 28 vec Emu = Smp*ones(N) /N ; 29 cout << "Empirical:" <<endl; 30 cout << "mu:" << Emu; 31 cout << "R:" << (Smp*Smp.transpose())/N - Emu*Emu.transpose() <<endl; 53 Smp = eG.sample(N); 54 55 vec g_mu = elem_div(a,b); 56 vec g_var = elem_div(a,pow(b,2.0)); 57 disp(g_mu,diag(g_var),Smp); 58 59 cout << "====== MGamma ====== " <<endl; 60 mgamma mG(rv,rv); 61 double k = 10.0; 62 mG.set_parameters(k); 63 64 Smp=mG.samplecond(mu0,lik,N); 65 disp(mu0,pow(mu0,2.0)/k,Smp); 32 66 33 67 //Exit program: … … 35 69 36 70 } 71