Changeset 213 for mpdm/merg_2a.cpp

Show
Ignore:
Timestamp:
11/25/08 12:24:42 (15 years ago)
Author:
smidl
Message:

Merging - new experiment

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • mpdm/merg_2a.cpp

    r211 r213  
    1010using std::endl; 
    1111 
     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 
    1218int main() { 
    1319        // Setup model 
    1420        RV y ( "{y }" ); 
    1521        RV u ( "{u }" ); 
    16         RV um = u; um.t(-1); 
    1722        RV z ( "{z }" ); 
    18         RV a ("{a }"); 
    19         RV b ("{b }"); 
    20         RV c ("{c }"); 
     23        RV a ("{a }");  
     24        RV b ("{b }"); RV ab = a; ab.add(b); 
     25        RV c ("{c }"); RV ac = a; ac.add(c); 
    2126        RV r ("{r }"); 
    2227         
    2328        double at = 1.5; 
    24         double bt = 0.8; 
    25         double ct = 0.50; 
    26         double sig = 0.10; 
     29        double bt = 0.5; 
     30        double ct = -0.5; 
     31        double rt = 0.30; 
    2732        // Full system 
    2833        vec thy =vec_2 ( at,bt ); //Simulated system - zero for constant term 
    29         vec thu =vec_2 ( at,ct ); //Simulated system - zero for constant term 
    30         vec Thy = concat ( thy, vec_1(sig) ); //Full parameter 
    31         vec Thu = concat ( thu, vec_1(sig) ); //Full parameter 
     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 
    3237 
    3338        //ARX constructor 
    3439        mat V0 = 0.001*eye ( 3 ); V0 ( 0,0 ) = 1; // 
    3540 
    36         ARX P1 ( concat ( a, concat(b,r) ), V0, -1 ); 
    37         ARX P2 ( concat ( a, concat(c,r) ), V0, -1 ); 
     41        ARX P1 ( concat ( ab,r ), V0, -1 ); 
     42        ARX P2 ( concat ( ac,r ), V0, -1 ); 
    3843 
    3944        //Test estimation 
     
    4247 
    4348        // Logging 
    44         dirfilelog L ( "exp/merg_2a",ndat ); 
    45         int Li_Data = L.add ( RV ( "{Y U1 U2 }" ), "" ); 
    46         int Li_LL   = L.add ( RV ( "{G M }" ), "LL" ); 
    47         int Li_P1m   = L.add ( RV ( "{a b r }" ), "P1" ); 
    48         int Li_P2m   = L.add ( RV ( "{a c r }" ), "P2" ); 
     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" ); 
    4955        L.init(); 
    5056 
     57        vec Ut ( ndat ); 
    5158        vec Yt ( ndat ); 
     59        vec Zt ( ndat ); 
    5260        vec yt ( 1 ); 
    5361 
    5462        //Proposal 
    55         enorm<ldmat> g0 ( a1 ); g0.set_parameters ( "1  ",mat ( "1" ) ); 
     63        enorm<ldmat> g0 ( ab ); g0.set_parameters ( "1 1 ",mat ( "1 0; 0 1" ) ); 
    5664        egamma g1 ( r ); g1.set_parameters ( "2  ", "2" ); 
    57         enorm<ldmat> g2 ( a2 ); g2.set_parameters ( "1 ",mat ( "1" ) ); 
     65        enorm<ldmat> g2 ( c ); g2.set_parameters ( "1 ",mat ( "1" ) ); 
    5866 
    59         Array<const epdf*> A ( 3 ); A ( 0 ) = &g0; A ( 1 ) =&g1; A ( 2 ) = &g2; 
     67        Array<const epdf*> A ( 3 ); A ( 0 ) = &g0; A ( 1 ) =&g1; A(2) = &g2;  
    6068        eprod G0 ( A ); 
    6169 
    62         for ( t=0; t<ndat; t++ ) { 
     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++ ) { 
    6375                // True system 
    64                 rgrg ( 0 ) = pow ( sin ( ( t/40.0 ) *pi ),3 ); 
    65                 rgrg ( 1 ) = pow ( cos ( ( t/40.0 +0.1 ) *pi ),3 ); 
    66  
    67                 Yt ( t ) = thg*rgrg + sqr * NorRNG(); 
     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(); 
    6881 
    6982                // Bayes for all 
    70                 P1.bayes ( concat ( Yt ( t ),vec_1 ( rgrg ( 0 ) ) ) ); 
    71                 P2.bayes ( concat ( Yt ( t ),vec_1 ( rgrg ( 1 ) ) ) ); 
    72                 PG.bayes ( concat ( Yt ( t ),rgrg ) ); 
    73  
    74  
    75                 // crippling PGk by substituting zeros. 
    76                 /*      ldmat &Vk=const_cast<egiw*>(PGk._e())->_V();  //PG ldmat does not like 0! 
    77                         mat fVk=PG._e()->_V().to_mat(); 
    78                         fVk(1,2) = 0.0; 
    79                         fVk(2,1) = 0.0; 
    80                         Vk = ldmat(fVk); 
    81                 */      //PGk is now krippled 
     83                P1.bayes ( concat ( Yt ( t ),rgru ) ); 
     84                P2.bayes ( concat ( Zt ( t ),rgry ) ); 
    8285 
    8386                // Merge estimates 
     
    8992                //M2.set_parameters ( 100.0, 1000,3 ); //M2._Mix().set_method(QB); 
    9093                M.merge ( &G0 ); 
    91                 //M2.merge ( &G0 ); 
    9294 
    9395                //Likelihood 
    9496                yt ( 0 ) = Yt ( t ); 
    9597 
    96 //              LLs ( 0 ) = P1._e()->evalpdflog ( get_vec(Th, "1 2") ); 
    97 //              LLs ( 1 ) = P2._e()->evalpdflog ( get_vec(Th, "3 2")  ); 
    98                 LLs ( 0 ) = PG._e()->evalpdflog ( Th ); 
    99                 LLs ( 1 ) = M._Mix().logpred ( concat ( Thj, vec_1 ( 1.0 ) ) ); 
    100 //              LLs ( 3 ) = M2._Mix().logpred ( concat(Thj, vec_1(1.0)) ); 
    101                 L.logit ( Li_LL, LLs ); //log-normal 
    102  
    10398                //Logger 
    104                 L.logit ( Li_Data, vec_3 ( Yt ( t ), rgrg ( 0 ), rgrg ( 1 ) ) ); 
    105                 L.logit ( Li_P1m, P1._e()->mean() ); 
    106                 L.logit ( Li_P2m, P2._e()->mean() ); 
    107                 L.logit ( Li_Gm, PG._e()->mean() ); 
    108                 L.logit ( Li_Mm, M.mean() ); 
    109  
     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()); 
    110103                L.step ( ); 
    111104 
    112                 cout << "Vg: " << PG._e()->_V().to_mat() <<endl; 
    113                 vec mea = M.mean(); 
    114                 cout << "Ve: " << M.variance() <<endl; 
    115105        } 
    116106        L.finalize( ); 
    117         L.itsave ( "merg_egiw.it" ); 
     107        L.itsave ( "merg_2a.it" ); 
    118108        cout << endl; 
    119109}