Index: tests/testEpdf.cpp
===================================================================
--- tests/testEpdf.cpp (revision 32)
+++ tests/testEpdf.cpp (revision 32)
@@ -0,0 +1,43 @@
+#include <itpp/itbase.h>
+#include <stat/libEF.h>
+
+using namespace itpp;
+
+//These lines are needed for use of cout and endl
+using std::cout;
+using std::endl;
+
+
+int main() {
+
+	vec x = "-10:0.1:10";
+	vec y = "-10:0.1:10";
+
+	RV rv ( "1","{x }","2","0" );
+	vec mu0 = "0.0 0.0";
+	mat V0 ( "5 -0.05; -0.05 5.20" );
+	fsqmat R = fsqmat ( V0 );
+
+	cout << "====== ENorm ====== " <<endl;
+	enorm<fsqmat> eN ( rv );
+	eN.set_parameters ( mu0,R );
+	vec pdf = zeros ( x.length() );
+
+	vec pom ( 2 );
+	double suma=0.0;
+
+	for ( int i=0;i<x.length();i++ ) {
+		for ( int j=0;j<y.length();j++ ) {
+			pom ( 0 ) = x ( i );
+			pom ( 1 ) = y ( j );
+			suma+= eN.eval ( pom );
+		}
+	}
+
+	cout << suma <<endl;
+
+	//Exit program:
+	return 0;
+
+}
+
Index: tests/test0.cpp
===================================================================
--- tests/test0.cpp (revision 28)
+++ tests/test0.cpp (revision 32)
@@ -12,10 +12,10 @@
 {
 
-	RV th = RV ( "1 2","{a b }","1 1","0 0","0 0" );
+	RV th = RV ( "1 2","{a b }","1 1","0 0");
 	RV r = RV ( "3 4" );
 
 	cout << th << r << endl;
 
-	ldmat ld = ldmat("1 0;-0.1 1","1.1 1.3");
+	ldmat ld = ldmat("1 0;0.5 1","1.1 1.3");
 	vec v = "1 -0.1";
 	
Index: tests/testSmp.cpp
===================================================================
--- tests/testSmp.cpp (revision 28)
+++ tests/testSmp.cpp (revision 32)
@@ -8,26 +8,60 @@
 using std::endl;
 
+void disp(const vec &tmu, const mat &tR,const mat &Smp){
+	int N = Smp.cols();
+	vec Emu = Smp*ones(N) /N ;
+	mat Er = (Smp*Smp.transpose())/N - outer_product(Emu,Emu);
+	cout << "True mu:" << tmu <<endl;
+	cout << "Emp  mu:" << Emu <<endl;
+	
+	cout << "True R:" << tR <<endl;
+	cout << "Emp  R:" << Er <<endl;
+}
+
 int main() {
 
-	//RNG_randomize();
+	RNG_randomize();
 
-	RV rv("1","{x }","2","0","0");
+	RV rv("1","{x }","2","0");
 	int N = 10000; //number of samples
 	vec mu0 = "1.5 1.7";
 	mat V0("1.2 0.3; 0.3 5");
 	ldmat R = ldmat(V0);
+	
+	cout << "====== ENorm ====== " <<endl;
 	enorm<ldmat> eN(rv);
 	eN.set_parameters(mu0,R);
+	mat Smp = eN.sample(N);
+
+	disp(mu0,R.to_mat(),Smp);
+
+	cout << "====== MlNorm ====== " <<endl;
+	mat I = eye(2);
+	vec lik(N);
+	mlnorm<ldmat> ML(rv,rv);
+	ML.set_parameters(I,R);
+	Smp = ML.samplecond(mu0,lik,N);
 	
-	mat Smp = eN.sample(N);
-	cout << "True:" <<endl;
-	cout << "mu:" << mu0 ;
-	cout << "R:" << R ;
-	cout << "R:" << R.to_mat() ;
+	disp(mu0,R.to_mat(),Smp);
+
+	cout << "====== EGamma ====== " <<endl;	
+	vec a = "100000,10000";
+	vec b = a/10.0;
+	egamma eG(rv);
+	eG.set_parameters(a,b);
 	
-	vec Emu = Smp*ones(N) /N ;
-	cout << "Empirical:" <<endl;
-	cout << "mu:" << Emu;
-	cout << "R:" << (Smp*Smp.transpose())/N - Emu*Emu.transpose() <<endl;
+	Smp = eG.sample(N);
+
+	vec g_mu = elem_div(a,b);
+	vec g_var = elem_div(a,pow(b,2.0));
+	disp(g_mu,diag(g_var),Smp);
+
+	cout << "====== MGamma ====== " <<endl;	
+	mgamma mG(rv,rv);
+	double k = 10.0;
+	mG.set_parameters(k);
+
+	Smp=mG.samplecond(mu0,lik,N);
+	disp(mu0,pow(mu0,2.0)/k,Smp);
 
 	//Exit program:
@@ -35,2 +69,3 @@
 
 }
+
Index: tests/testKF.cpp
===================================================================
--- tests/testKF.cpp (revision 28)
+++ tests/testKF.cpp (revision 32)
@@ -18,5 +18,5 @@
 	it_file fin( "testKF.it" );
 
-	mat Dt, Xt,Xt2,XtE;
+	mat Dt, Xt,Xt2,XtE,Xtf;
 	int Ndat;
 
@@ -42,10 +42,11 @@
 	Xt=zeros( 2,Ndat );
 	Xt2=zeros( 2,Ndat );
+	Xtf=zeros( 2,Ndat );
 	XtE=zeros( 2,Ndat );
 
 //	cout << KF;
-	RV rx("1","{x}","2","0","0");
-	RV ru("2","{u}","1","0","0");
-	RV ry("3","{y}","1","0","0");
+	RV rx("1","{x}","2","0");
+	RV ru("2","{u}","1","0");
+	RV ry("3","{y}","1","0");
 	//
 	Kalman<ldmat> KF(rx,ry,ru);
@@ -65,19 +66,26 @@
 	KFE.set_est(mu0,P0);
 
-	Xt.set_col( 0,*((enorm<ldmat>*)(KF._epdf()))->_mu() );
+	epdf& KFep = KF._epdf();
+	epdf& KFfep = KFf._epdf();
+	epdf& KFEep = KFE._epdf();
+	
+	Xt.set_col( 0,KFep.mean() );
+	Xtf.set_col( 0,KFfep.mean() );
 	Xt2.set_col( 0,KF2.mu );
-	XtE.set_col( 0,*((enorm<ldmat>*)(KFE._epdf()))->_mu() );
+	XtE.set_col( 0,KFEep.mean() );
 	for ( int t=1;t<Ndat;t++ ) {
 		KFf.bayes( Dt.get_col( t ));
 		KF.bayes( Dt.get_col( t ));
 		KF2.bayes( Dt.get_col( t ));
-//		KFE.bayes( Dt.get_col( t ));
-		Xt.set_col(t,*((enorm<ldmat>*)(KF._epdf()))->_mu());
+		KFE.bayes( Dt.get_col( t ));
+		Xt.set_col( t,KFep.mean() );
+		Xtf.set_col( t,KFfep.mean() );
 		Xt2.set_col(t,KF2.mu);
-		XtE.set_col(t,*((enorm<ldmat>*)(KFE._epdf()))->_mu());
+		XtE.set_col( t,KFEep.mean() );
 	}
 
 	it_file fou( "testKF_res.it" );
 	fou << Name("xth") << Xt;
+	fou << Name("xthf") << Xtf;
 	fou << Name("xth2") << Xt2;
 	fou << Name("xthE") << XtE;
Index: tests/testKF_QR.cpp
===================================================================
--- tests/testKF_QR.cpp (revision 32)
+++ tests/testKF_QR.cpp (revision 32)
@@ -0,0 +1,96 @@
+#include <itpp/itbase.h>
+#include <estim/libKF.h>
+#include <estim/libPF.h>
+
+using namespace itpp;
+
+//These lines are needed for use of cout and endl
+using std::cout;
+using std::endl;
+
+int main() {
+	// Klaman filter
+	mat A, B,C,D,R,Q,P0;
+	vec mu0;
+	mat Mu0;// read from matlab
+	// input from Matlab
+	it_file fin( "testKF.it" );
+
+	mat Dt, XRt,eR,eQ;
+	int Ndat;
+
+	bool xxx= fin.seek( "d" );
+	if (!xxx){ it_error("testKF.it not found");}
+	fin >>Dt;
+	fin.seek( "A" ); 
+	fin >> A;
+	fin.seek( "B" ); 
+	fin >> B;
+	fin.seek( "C" ); 
+	fin >> C;
+	fin.seek( "D" ); 
+	fin >> D;
+	fin.seek( "R" ); 
+	fin >> R;
+	fin.seek( "Q" ); fin >> Q;
+	fin.seek( "P0" ); fin >> P0;
+	fin.seek( "mu0" ); fin >> Mu0; 
+	mu0=Mu0.get_col(0);
+	
+	Ndat = Dt.cols();
+	XRt=zeros( 3,Ndat );
+
+//	cout << KF;
+	RV rx("1","{x}","2","0");
+	RV ru("2","{u}","1","0");
+	RV ry("3","{y}","1","0");
+	RV rR("4","{R}","1","0");
+	//
+	KFcondR KF(rx,ry,ru,rR);
+	Kalman<fsqmat> KFtr(rx,ry,ru);
+	Kalman<fsqmat> KFtr2(rx,ry,ru);
+	//correct KF
+	KFtr.set_parameters(A,B,C,D,fsqmat(R),fsqmat(Q));
+	KFtr.set_est(mu0,fsqmat(P0) );
+	// KF with lower R
+	mat Q2=Q/1.0;
+	mat R2=R/20.0;
+	KFtr2.set_parameters(A,B,C,D,fsqmat(R2),fsqmat(Q2));
+	KFtr2.set_est(mu0,fsqmat(P0) );
+	// KF with R unknown
+	KF.set_parameters(A,B,C,D,ldmat(R),ldmat(Q));
+	KF.set_est(mu0,ldmat(P0) );
+	//
+	mgamma evolR(rR,rR);
+	evolR.set_parameters(10.0); //sigma = 1/10 mu
+	
+	MPF<KFcondR > KF_R(rx,rR,evolR,evolR,10,KF);
+	evolR.condition("0.1");
+	epdf& pfinit=evolR._epdf();
+	KF_R.set_est(pfinit);
+	epdf& mpost=KF_R._epdf();
+
+	cout << mpost.mean()<<endl;
+
+	XRt.set_col( 0,mpost.mean());
+	double ll1=0.0;
+	double ll2=0.0;
+	for ( int t=1;t<Ndat;t++ ) {
+//		KF_R.bayes( Dt.get_col( t ));
+		KFtr.bayes( Dt.get_col( t ));
+		KFtr2.bayes( Dt.get_col( t ));
+		
+		ll1+=KFtr._ll();
+		ll2+=KFtr2._ll();
+		
+		XRt.set_col(t,mpost.mean());
+	}
+	
+	cout << ll1 << "  " << ll2 <<endl;
+
+	it_file fou( "testKF_R_res.it" );
+	fou << Name("xqrth") << XRt;
+	//Exit program:
+	return 0;
+
+}
Index: tests/testPF.cpp
===================================================================
--- tests/testPF.cpp (revision 19)
+++ tests/testPF.cpp (revision 32)
@@ -13,5 +13,5 @@
 
 	RV x("1");
-	RV xm=x; xm.t(-1);
+	RV xm=x; xm.t(-1);const
 	RV y("2");
 	
@@ -19,22 +19,22 @@
 	vec vR = "1";
 	ldmat R(vR);
+		
+	eEmp emp(x,10);
+	euni eun(x);
+	eun.set_parameters("0","1");
+	emp.set_parameters(ones(10),&eun);
+	vec &v=emp._w();
+	Array<vec> &S=emp._samples();
 	
+	for (int i=0;i<10;i++){	v(i) = exp(-0.5*sum(pow(S(i)-1,2.0))*10);}
+	v/=sum(v);
 	
-	vec ptc = randn(10);
-	vec w = exp(-0.5*(pow(ptc,2))/0.2);
+	cout << "p:" << S << endl;
+	cout << "w:" << v << endl;
 	
-	cout << "p:" << ptc << endl;
-	cout << "w:" << w << endl;
-	
-	PF pf(w);
-	ivec ind = pf.resample();
+	ivec ind = emp.resample();
 	
 	cout << ind << endl;
-	/*
-	mlnorm<ldmat> obs(x,xm,A,R);
-	mlnorm<ldmat> par(y,x,A,R);
 	
-	TrivialPF TPF(obs,par,10);
-	*/
 	//Exit program:
 	return 0;
Index: tests/testResample.cpp
===================================================================
--- tests/testResample.cpp (revision 32)
+++ tests/testResample.cpp (revision 32)
@@ -0,0 +1,42 @@
+#include <itpp/itbase.h>
+#include <estim/libPF.h>
+#include <math/libDC.h>
+#include <stat/libEF.h>
+
+using namespace itpp;
+
+//These lines are needed for use of cout and endl
+using std::cout;
+using std::endl;
+
+int main() {
+
+	RV x("1");
+	RV xm=x; xm.t(-1);const
+	RV y("2");
+	
+	mat A = "1";
+	vec vR = "1";
+	ldmat R(vR);
+		
+	eEmp emp(x,10);
+	euni eun(x);
+	eun.set_parameters("0","1");
+	emp.set_parameters(ones(10),&eun);
+	vec &v=emp._w();
+	Array<vec> &S=emp._samples();
+	
+	for (int i=0;i<10;i++){	v(i) = exp(-0.5*sum(pow(S(i)-1,2.0))*10);}
+	v/=sum(v);
+	
+	cout << "p:" << S << endl;
+	cout << "w:" << v << endl;
+	
+	ivec ind = emp.resample();
+	
+	cout << ind << endl;
+	
+	//Exit program:
+	return 0;
+
+}
Index: tests/CMakeLists.txt
===================================================================
--- tests/CMakeLists.txt (revision 22)
+++ tests/CMakeLists.txt (revision 32)
@@ -6,5 +6,6 @@
 
 ## Save all needed libraries in variable BdmLibs
-SET(BdmLibs bdm itpp)
+SET(BdmLibs bdm itpp_debug)
+#SET(BdmLibs bdm itpp)
 
 IF(WIN32)
@@ -23,4 +24,7 @@
 add_executable (testPF testPF.cpp)
 add_executable (testSmp testSmp.cpp)
+add_executable (testEpdf testEpdf.cpp)
+add_executable (testResample testResample.cpp)
+add_executable (testKF_QR testKF_QR.cpp)
 
 # Link the executable to the Hello library.
@@ -29,2 +33,5 @@
 target_link_libraries (testPF ${BdmLibs})
 target_link_libraries (testSmp ${BdmLibs})
+target_link_libraries (testEpdf ${BdmLibs})
+target_link_libraries (testResample ${BdmLibs})
+target_link_libraries (testKF_QR ${BdmLibs})
