root/tests/testSmp.cpp @ 104

Revision 104, 1.8 kB (checked in by smidl, 16 years ago)

new mixture model test

Line 
1#include <itpp/itbase.h>
2#include <stat/libEF.h>
3#include <stat/emix.h>
4
5using namespace itpp;
6
7//These lines are needed for use of cout and endl
8using std::cout;
9using std::endl;
10
11void disp(const vec &tmu, const mat &tR,const mat &Smp){
12        int N = Smp.cols();
13        vec Emu = Smp*ones(N) /N ;
14        mat Er = (Smp*Smp.transpose())/N - outer_product(Emu,Emu);
15        cout << "True mu:" << tmu <<endl;
16        cout << "Emp  mu:" << Emu <<endl;
17       
18        cout << "True R:" << tR <<endl;
19        cout << "Emp  R:" << Er <<endl;
20}
21
22int main() {
23
24        RNG_randomize();
25
26        RV rv("1","{x }","2","0");
27        int N = 10000; //number of samples
28        vec mu0 = "1.5 1.7";
29        mat V0("1.2 0.3; 0.3 5");
30        ldmat R = ldmat(V0);
31       
32        cout << "====== ENorm ====== " <<endl;
33        enorm<ldmat> eN(rv);
34        eN.set_parameters(mu0,R);
35        mat Smp = eN.sample(N);
36
37        disp(mu0,R.to_mat(),Smp);
38
39        cout << "====== MlNorm ====== " <<endl;
40        mat I = eye(2);
41        vec lik(N);
42        mlnorm<ldmat> ML(rv,rv);
43        ML.set_parameters(I,R);
44        Smp = ML.samplecond(mu0,lik,N);
45       
46        disp(mu0,R.to_mat(),Smp);
47
48        cout << "====== EGamma ====== " <<endl; 
49        vec a = "100000,10000";
50        vec b = a/10.0;
51        egamma eG(rv);
52        eG.set_parameters(a,b);
53       
54        cout << eG.eval(a)<<endl;
55        Smp = eG.sampleN(N);
56
57        vec g_mu = elem_div(a,b);
58        vec g_var = elem_div(a,pow(b,2.0));
59        disp(g_mu,diag(g_var),Smp);
60
61        cout << "====== MGamma ====== " <<endl; 
62        mgamma mG(rv,rv);
63        double k = 10.0;
64        mG.set_parameters(k);
65
66        Smp=mG.samplecond(mu0,lik,N);
67        disp(mu0,pow(mu0,2.0)/k,Smp);
68       
69        cout << "======= EMix ======== " << endl;
70        emix eMix(rv);
71        Array<epdf*> Coms(2);
72        Coms(0) = &eG;
73        Coms(1) = &eN;
74       
75        eMix.set_parameters(vec_2(0.5,0.5), Coms);
76        vec smp = eMix.sample();
77        Smp = eMix.sampleN(N);
78        disp(eMix.mean(),zeros(2),Smp);
79
80        cout << "======= MMix_triv ======== " << endl;
81        mmix_triv mMix(rv,rv,&eMix);
82       
83        Smp = mMix.samplecond(mu0,lik,N);
84        disp(eMix.mean(),zeros(2),Smp);
85
86        //Exit program:
87        return 0;
88
89}
Note: See TracBrowser for help on using the browser.