[262] | 1 | |
---|
[205] | 2 | #include <stat/libEF.h> |
---|
| 3 | #include <estim/merger.h> |
---|
| 4 | |
---|
[254] | 5 | using namespace bdm; |
---|
[205] | 6 | |
---|
| 7 | //These lines are needed for use of cout and endl |
---|
| 8 | using std::cout; |
---|
| 9 | using std::endl; |
---|
| 10 | |
---|
| 11 | int main() { |
---|
| 12 | |
---|
| 13 | RNG_randomize(); |
---|
| 14 | |
---|
| 15 | RV y ( "{y }","1" ); |
---|
| 16 | RV u1 ( "{u1 }","1" ); |
---|
| 17 | RV u2 ( "{u2 }","1" ); |
---|
| 18 | |
---|
| 19 | RV all = y; |
---|
| 20 | all.add ( u1 ); |
---|
| 21 | all.add ( u2 ); |
---|
| 22 | |
---|
[270] | 23 | mlnorm<fsqmat> f1; f1.set_rv( y ); f1.set_rvc( u1 ); |
---|
| 24 | mlnorm<fsqmat> f2; f2.set_rv( y ); f2.set_rvc( u2 ); |
---|
[205] | 25 | |
---|
| 26 | //Differneces in constant term are essential |
---|
| 27 | f1.set_parameters ( "0.4","1",mat ( "0.04" ) ); |
---|
| 28 | f2.set_parameters ( "0.2","-1",mat ( "0.08" ) ); |
---|
| 29 | |
---|
| 30 | Array<mpdf* > A ( 2 ); |
---|
| 31 | A ( 0 ) =&f1; |
---|
| 32 | A ( 1 ) =&f2; |
---|
| 33 | |
---|
| 34 | merger M ( A ); |
---|
[299] | 35 | M.debug_file("iter_cond_debug.it"); |
---|
| 36 | enorm<ldmat> g0; g0.set_rv ( all ); |
---|
| 37 | mat Cov=0.3*eye ( 3 ); |
---|
| 38 | Cov(1,2)=0.29; |
---|
| 39 | Cov(2,1)=0.29; |
---|
| 40 | g0.set_parameters ( vec ( "1 1 1" ),Cov);// +1*ones ( 3,3 ) ); |
---|
[205] | 41 | |
---|
[299] | 42 | enorm<ldmat>* teste=g0.marginal(concat(u1,u2)); |
---|
| 43 | mlnorm<ldmat>* testm=(mlnorm<ldmat>*)teste->condition(u2); |
---|
| 44 | |
---|
[205] | 45 | M.set_parameters ( 1.2,1000,1 ); |
---|
[299] | 46 | |
---|
| 47 | Array<vec> YUU(3); |
---|
| 48 | YUU(0)=linspace(-2.9,3.1,20); |
---|
| 49 | YUU(1)=linspace(-5,5,20); |
---|
| 50 | YUU(2)=linspace(-3,3,20); |
---|
[205] | 51 | |
---|
[299] | 52 | M.set_grid(YUU); |
---|
| 53 | |
---|
| 54 | int Ntrials=1; |
---|
[205] | 55 | vec A1s ( Ntrials ); |
---|
| 56 | vec A2s ( Ntrials ); |
---|
| 57 | vec R1s ( Ntrials ); |
---|
| 58 | vec R2s ( Ntrials ); |
---|
| 59 | vec C1s ( Ntrials ); |
---|
| 60 | vec C2s ( Ntrials ); |
---|
| 61 | |
---|
| 62 | for ( int it=0;it<Ntrials;it++ ) { |
---|
| 63 | M.merge ( &g0 ); |
---|
| 64 | |
---|
| 65 | MixEF &MM = M._Mix(); |
---|
[270] | 66 | epdf* MP = MM._Coms ( 0 )->epredictor ( ); |
---|
[299] | 67 | MP->set_rv(all); |
---|
[205] | 68 | |
---|
| 69 | RV yu1 = y; yu1.add ( u1 ); |
---|
| 70 | RV yu2 = y; yu2.add ( u2 ); |
---|
| 71 | enorm<ldmat>* P1m= ( enorm<ldmat>* ) MP->marginal ( yu1 ); |
---|
| 72 | enorm<ldmat>* P2m= ( enorm<ldmat>* ) MP->marginal ( yu2 ); |
---|
| 73 | mlnorm<ldmat>* P1c= ( mlnorm<ldmat>* ) ( P1m->condition ( y ) ); |
---|
| 74 | mlnorm<ldmat>* P2c= ( mlnorm<ldmat>* ) ( P2m->condition ( y ) ); |
---|
| 75 | |
---|
| 76 | A1s(it) = P1c->_A()(0,0); |
---|
| 77 | A2s(it) = P2c->_A()(0,0); |
---|
| 78 | R1s(it) = P1c->_R()(0,0); |
---|
| 79 | R2s(it) = P2c->_R()(0,0); |
---|
| 80 | C1s(it) = P1c->_mu_const()(0); |
---|
| 81 | C2s(it) = P2c->_mu_const()(0); |
---|
| 82 | |
---|
[299] | 83 | cout << "mean: " << MM._Coms(0)->_e()->mean() <<endl; |
---|
[205] | 84 | } |
---|
[299] | 85 | |
---|
| 86 | |
---|
| 87 | |
---|
| 88 | cout << "A1s:" <<A1s<<endl; |
---|
| 89 | cout << "C2s:" <<C2s<<endl; |
---|
[205] | 90 | double A1mean = sum(A1s)/Ntrials; |
---|
| 91 | double A2mean = sum(A2s)/Ntrials; |
---|
| 92 | double C1mean = sum(C1s)/Ntrials; |
---|
| 93 | double C2mean = sum(C2s)/Ntrials; |
---|
| 94 | double R1mean = sum(R1s)/Ntrials; |
---|
| 95 | double R2mean = sum(R2s)/Ntrials; |
---|
[299] | 96 | cout << "A1: " << A1mean << " +- " << 2*sqrt(sum_sqr(A1s)/Ntrials-A1mean*A1mean) <<endl; |
---|
| 97 | cout << "A2: " << A2mean << " +- " << 2*sqrt(sum_sqr(A2s)/Ntrials-A2mean*A2mean) <<endl; |
---|
| 98 | cout << "C1: " << C1mean << " +- " << 2*sqrt(sum_sqr(C1s)/Ntrials-C1mean*C1mean) <<endl; |
---|
| 99 | cout << "C2: " << C2mean << " +- " << 2*sqrt(sum_sqr(C2s)/Ntrials-C2mean*C2mean) <<endl; |
---|
| 100 | cout << "R1: " << R1mean << " +- " << 2*sqrt(sum_sqr(R1s)/Ntrials-R1mean*R1mean) <<endl; |
---|
| 101 | cout << "R2: " << R2mean << " +- " << 2*sqrt(sum_sqr(R2s)/Ntrials-R2mean*R2mean) <<endl; |
---|
[205] | 102 | } |
---|