root/mpdm/merg_2a.cpp @ 217

Revision 217, 2.9 kB (checked in by smidl, 15 years ago)

sim

Line 
1#include <estim/arx.h>
2#include <estim/merger.h>
3#include <stat/libEF.h>
4#include <stat/loggers.h>
5//#include <stat/merger.h>
6using namespace itpp;
7
8//These lines are needed for use of cout and endl
9using std::cout;
10using std::endl;
11
12/*! The purpose of this experiment is to test merging fragmental pdfs between two participants sharing the same parameter, a. However, this parameter has a different role in each model.
13
14Lets assume that:
15 u -> |a,r| -> y -> |a,r| -> z
16*/
17
18int main() {
19        // Setup model
20        RV y ( "{y }" );
21        RV u ( "{u }" );
22        RV z ( "{z }" );
23        RV a ("{a }"); 
24        RV b ("{b }"); RV ab = a; ab.add(b);
25        RV c ("{c }"); RV ac = a; ac.add(c);
26        RV r ("{r }");
27       
28        double at = 1.5;
29        double bt = 0.5;
30        double ct = -0.5;
31        double rt = 0.30;
32        // Full system
33        vec thy =vec_2 ( at,bt ); //Simulated system - zero for constant term
34        vec thz =vec_2 ( at,ct ); //Simulated system - zero for constant term
35        vec Thy = concat ( thy, vec_1(rt) ); //Full parameter
36        vec Thz = concat ( thz, vec_1(rt) ); //Full parameter
37
38        //ARX constructor
39        mat V0 = 0.001*eye ( 3 ); V0 ( 0,0 ) = 1; //
40
41        ARX P1 ( concat ( ab,r ), V0, -1 );
42        ARX P2 ( concat ( ac,r ), V0, -1 );
43
44        //Test estimation
45        int ndat = 100;
46        int t;
47
48        // Logging
49        dirfilelog L ( "exp/merg_2a",3 );
50        int Li_Data = L.add ( RV ( "{U Y Z }" ), "" );
51//      int Li_LL   = L.add ( RV ( "{P1 P2 M1 M2 }" ), "LL" );
52        int Li_P1m   = L.add ( concat ( ab,r ), "P1m" );
53        int Li_P2m   = L.add ( concat ( ac,r ), "P2m" );
54        int Li_Mm   = L.add ( concat ( ab,concat(r,c) ), "Mm" );
55        int Li_Th   = L.add ( concat ( ab,concat(c,r) ), "T" );
56        L.init();
57
58        vec Ut ( ndat );
59        vec Yt ( ndat );
60        vec Zt ( ndat );
61        vec yt ( 1 );
62
63        //Proposal
64        enorm<ldmat> g0 ( ab ); g0.set_parameters ( "1 1 ",mat ( "1 0; 0 1" ) );
65        egamma g1 ( r ); g1.set_parameters ( "2  ", "2" );
66        enorm<ldmat> g2 ( c ); g2.set_parameters ( "1 ",mat ( "1" ) );
67
68        Array<const epdf*> A ( 3 ); A ( 0 ) = &g0; A ( 1 ) =&g1; A(2) = &g2; 
69        eprod G0 ( A );
70
71        vec rgru(2);
72        vec rgry(2);
73        Yt(0) = 0.1;
74        Ut(0) = 0.0;
75        for ( t=1; t<ndat; t++ ) {
76                // True system
77                Ut ( t ) = pow ( sin ( ( t/40.0 ) *pi ),3 );
78                rgru(0) = Ut(t); rgru(1) = Ut(t-1);
79                Yt ( t ) = thy*rgru + rt * NorRNG();
80                rgry(0) = Yt(t); rgry(1) = Yt(t-1);
81                Zt ( t ) = thz*rgry + rt * NorRNG();
82
83                // Bayes for all
84                P1.bayes ( concat ( Yt ( t ),rgru ) );
85                P2.bayes ( concat ( Zt ( t ),rgry ) );
86
87                // Merge estimates
88                mepdf eG1 ( P1._e() );
89                mepdf eG2 ( P2._e() );
90                Array<mpdf*> A ( 2 ); A ( 0 ) =&eG1;A ( 1 ) =&eG2;
91                merger M ( A );
92                M.set_parameters ( 10, 100,3 ); //M._Mix().set_method(QB);
93                //M2.set_parameters ( 100.0, 1000,3 ); //M2._Mix().set_method(QB);
94                M.merge ( &G0 );
95
96                //Likelihood
97                yt ( 0 ) = Yt ( t );
98
99                //Logger
100                L.logit(Li_Data, vec_3(Ut(t), Yt(t), Zt(t)));
101                L.logit(Li_P1m, P1._e()->mean());
102                L.logit(Li_P2m, P2._e()->mean());
103                L.logit(Li_Mm, M.mean());
104                L.logit(Li_Th, concat(thy,vec_2(ct,rt)));
105                L.step ( );
106
107        }
108        L.finalize( );
109        L.itsave ( "merg_2a.it" );
110        cout << endl;
111}
Note: See TracBrowser for help on using the browser.