root/mpdm/merg_2a.cpp @ 213

Revision 213, 2.8 kB (checked in by smidl, 15 years ago)

Merging - new experiment

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        L.init();
56
57        vec Ut ( ndat );
58        vec Yt ( ndat );
59        vec Zt ( ndat );
60        vec yt ( 1 );
61
62        //Proposal
63        enorm<ldmat> g0 ( ab ); g0.set_parameters ( "1 1 ",mat ( "1 0; 0 1" ) );
64        egamma g1 ( r ); g1.set_parameters ( "2  ", "2" );
65        enorm<ldmat> g2 ( c ); g2.set_parameters ( "1 ",mat ( "1" ) );
66
67        Array<const epdf*> A ( 3 ); A ( 0 ) = &g0; A ( 1 ) =&g1; A(2) = &g2; 
68        eprod G0 ( A );
69
70        vec rgru(2);
71        vec rgry(2);
72        Yt(0) = 0.1;
73        Ut(0) = 0.0;
74        for ( t=1; t<ndat; t++ ) {
75                // True system
76                Ut ( t ) = pow ( sin ( ( t/40.0 ) *pi ),3 );
77                rgru(0) = Ut(t); rgru(1) = Ut(t-1);
78                Yt ( t ) = thy*rgru + rt * NorRNG();
79                rgry(0) = Yt(t); rgry(1) = Yt(t-1);
80                Zt ( t ) = thz*rgry + rt * NorRNG();
81
82                // Bayes for all
83                P1.bayes ( concat ( Yt ( t ),rgru ) );
84                P2.bayes ( concat ( Zt ( t ),rgry ) );
85
86                // Merge estimates
87                mepdf eG1 ( P1._e() );
88                mepdf eG2 ( P2._e() );
89                Array<mpdf*> A ( 2 ); A ( 0 ) =&eG1;A ( 1 ) =&eG2;
90                merger M ( A );
91                M.set_parameters ( 10, 100,3 ); //M._Mix().set_method(QB);
92                //M2.set_parameters ( 100.0, 1000,3 ); //M2._Mix().set_method(QB);
93                M.merge ( &G0 );
94
95                //Likelihood
96                yt ( 0 ) = Yt ( t );
97
98                //Logger
99                L.logit(Li_Data, vec_3(Ut(t), Yt(t), Zt(t)));
100                L.logit(Li_P1m, P1._e()->mean());
101                L.logit(Li_P2m, P2._e()->mean());
102                L.logit(Li_Mm, M.mean());
103                L.step ( );
104
105        }
106        L.finalize( );
107        L.itsave ( "merg_2a.it" );
108        cout << endl;
109}
Note: See TracBrowser for help on using the browser.