Changeset 504 for library/tests
- Timestamp:
- 08/12/09 09:27:40 (15 years ago)
- Location:
- library/tests
- Files:
-
- 4 modified
Legend:
- Unmodified
- Added
- Removed
-
library/tests/emix_test.cpp
r501 r504 15 15 RV xy = concat ( x, y ); 16 16 17 enorm<ldmat> E1; 18 E1.set_rv ( xy ); 17 shared_ptr<enorm<ldmat> > E1 = new enorm<ldmat>(); 18 E1->set_rv ( xy ); 19 E1->set_parameters ( "1.00054 1.0455" , mat ( "0.740142 -0.259015; -0.259015 1.0302" ) ); 19 20 20 E1.set_parameters ( "1.00054 1.0455" , mat ( "0.740142 -0.259015; -0.259015 1.0302" ) ); 21 enorm<ldmat> E2; 22 E2.set_rv ( xy ); 23 E2.set_parameters ( "-1.2 -0.1" , mat ( "1 0.4; 0.4 0.5" ) ); 21 shared_ptr<enorm<ldmat> > E2 = new enorm<ldmat>(); 22 E2->set_rv ( xy ); 23 E2->set_parameters ( "-1.2 -0.1" , mat ( "1 0.4; 0.4 0.5" ) ); 24 24 25 Array< epdf*> A1 ( 1 );26 A1 ( 0 ) = &E1;25 Array<shared_ptr<epdf> > A1 ( 1 ); 26 A1 ( 0 ) = E1; 27 27 28 28 emix M1; 29 29 M1.set_rv ( xy ); 30 M1.set_parameters ( vec ( "1" ), A1 , false);30 M1.set_parameters ( vec ( "1" ), A1 ); 31 31 32 32 // test if ARX and emix with one ARX are the same 33 epdf*Mm = M1.marginal ( y );34 epdf* Am = E1.marginal ( y );35 mpdf*Mc = M1.condition ( y );36 mpdf* Ac = E1.condition ( y );33 shared_ptr<epdf> Mm = M1.marginal ( y ); 34 shared_ptr<epdf> Am = E1->marginal ( y ); 35 shared_ptr<mpdf> Mc = M1.condition ( y ); 36 shared_ptr<mpdf> Ac = E1->condition ( y ); 37 37 38 mlnorm<ldmat> *wacnd = dynamic_cast<mlnorm<ldmat> *>( Ac);38 mlnorm<ldmat> *wacnd = dynamic_cast<mlnorm<ldmat> *>( Ac.get() ); 39 39 CHECK(wacnd); 40 40 if ( wacnd ) { … … 51 51 52 52 // mixture with two components 53 Array< epdf*> A2 ( 2 );54 A2 ( 0 ) = &E1;55 A2 ( 1 ) = &E2;53 Array<shared_ptr<epdf> > A2 ( 2 ); 54 A2 ( 0 ) = E1; 55 A2 ( 1 ) = E2; 56 56 57 57 emix M2; 58 58 M2.set_rv ( xy ); 59 M2.set_parameters ( vec ( "1" ), A2 , false);59 M2.set_parameters ( vec ( "1" ), A2 ); 60 60 61 61 … … 74 74 CHECK_CLOSE ( mat ( "0.740142 -0.259015; -0.259015 1.0302" ), Er, 2.0 ); 75 75 76 epdf *nm2mrg = M2.marginal ( y ); 77 CHECK ( nm2mrg ); 78 shared_ptr<epdf> Mg ( nm2mrg ); 79 mpdf *Cn = M2.condition ( x ); 80 CHECK ( Cn ); 81 82 #if false 83 it_file it ( "emix_test.it" ); 84 it << Name ( "Smp" ) << Smp; 85 #endif 76 shared_ptr<epdf> Mg = M2.marginal ( y ); 77 CHECK ( Mg.get() ); 78 shared_ptr<mpdf> Cn = M2.condition ( x ); 79 CHECK ( Cn.get() ); 86 80 87 81 // marginal mean 88 82 CHECK_CLOSE ( vec ( "1.0" ), Mg->mean(), 0.1 ); 89 90 #if false91 // putting them back together92 mepdf mMg ( Mg );93 Array<mpdf*> AA ( 2 );94 AA ( 0 ) = Cn;95 AA ( 1 ) = &mMg;96 mprod mEp ( AA );97 98 for ( int j = 0; j < N; j++ ) {99 ll2 ( j ) = mEp.evallogcond ( Smp.get_col ( j ), vec ( 0 ) );100 }101 it << Name ( "ll" ) << ll;102 it << Name ( "ll2" ) << ll2;103 #endif104 83 } -
library/tests/merger_2d_test.cpp
r477 r504 70 70 it << Name ( "S1" ) << f1.evallog_m ( Grid ); 71 71 it << Name ( "S2" ) << f2.evallog_m ( Grid ); 72 cout << ( ( enorm<ldmat>* ) ( MP->_Coms ( 0 ) ) )->_R().to_mat() << endl;72 cout << ( ( enorm<ldmat>* ) ( MP->_Coms ( 0 ).get() ) )->_R().to_mat() << endl; 73 73 } -
library/tests/mixtures_test.cpp
r477 r504 53 53 fsqmat V2 ( mat ( "2 -0.1; -0.1 2" ) ); 54 54 55 enorm<fsqmat> C1;56 C1 .set_rv ( x );57 C1 .set_parameters ( m1, V1 );58 enorm<fsqmat> C2;59 C2 .set_rv ( x );60 C2 .set_parameters ( m2, V2 );55 shared_ptr<enorm<fsqmat> > C1 = new enorm<fsqmat>(); 56 C1->set_rv ( x ); 57 C1->set_parameters ( m1, V1 ); 58 shared_ptr<enorm<fsqmat> > C2 = new enorm<fsqmat>(); 59 C2->set_rv ( x ); 60 C2->set_parameters ( m2, V2 ); 61 61 62 Array< epdf*> Sim ( 2 );63 Sim ( 0 ) = &C1;64 Sim ( 1 ) = &C2;62 Array<shared_ptr<epdf> > Sim ( 2 ); 63 Sim ( 0 ) = C1; 64 Sim ( 1 ) = C2; 65 65 emix Simul; 66 66 Simul.set_rv ( x ); 67 Simul.set_parameters ( "0.5 0.6", Sim , false);67 Simul.set_parameters ( "0.5 0.6", Sim ); 68 68 69 69 // Sample parameters -
library/tests/testSmp.cpp
r488 r504 32 32 33 33 cout << "====== ENorm ====== " << endl; 34 enorm<ldmat> eN;35 eN .set_parameters ( mu0, R );36 mat Smp = eN .sample_m ( N );34 shared_ptr<enorm<ldmat> > eN = new enorm<ldmat>(); 35 eN->set_parameters ( mu0, R ); 36 mat Smp = eN->sample_m ( N ); 37 37 38 38 disp ( mu0, R.to_mat(), Smp ); … … 49 49 vec a = "100000,10000"; 50 50 vec b = a / 10.0; 51 egamma eG;52 eG .set_parameters ( a, b );51 shared_ptr<egamma> eG = new egamma(); 52 eG->set_parameters ( a, b ); 53 53 54 cout << eG .evallog ( a ) << endl;55 Smp = eG .sample_m ( N );54 cout << eG->evallog ( a ) << endl; 55 Smp = eG->sample_m ( N ); 56 56 57 57 vec g_mu = elem_div ( a, b ); … … 60 60 61 61 cout << "====== MGamma ====== " << endl; 62 mgamma mG;62 shared_ptr<mgamma> mG = new mgamma(); 63 63 double k = 10.0; 64 mG .set_parameters ( k, mu0 );64 mG->set_parameters ( k, mu0 ); 65 65 66 Smp = mG .samplecond_m ( mu0, N );66 Smp = mG->samplecond_m ( mu0, N ); 67 67 disp ( mu0, pow ( mu0, 2.0 ) / k, Smp ); 68 68 69 69 cout << "======= EMix ======== " << endl; 70 emix eMix;71 Array< epdf*> Coms ( 2 );72 Coms ( 0 ) = &eG;73 Coms ( 1 ) = &eN;70 shared_ptr<emix> eMix = new emix(); 71 Array<shared_ptr<epdf> > Coms ( 2 ); 72 Coms ( 0 ) = eG; 73 Coms ( 1 ) = eN; 74 74 75 eMix .set_parameters ( vec_2 ( 0.5, 0.5 ), Coms );76 vec smp = eMix .sample();77 Smp = eMix .sample_m ( N );78 disp ( eMix .mean(), zeros ( 2 ), Smp );75 eMix->set_parameters ( vec_2 ( 0.5, 0.5 ), Coms ); 76 vec smp = eMix->sample(); 77 Smp = eMix->sample_m ( N ); 78 disp ( eMix->mean(), zeros ( 2 ), Smp ); 79 79 80 80 cout << "======= MEpdf ======== " << endl; 81 mepdf meMix ( &eMix );81 mepdf meMix ( eMix ); 82 82 83 83 Smp = meMix.samplecond_m ( mu0, N ); 84 disp ( eMix .mean(), zeros ( 2 ), Smp );84 disp ( eMix->mean(), zeros ( 2 ), Smp ); 85 85 86 86 cout << "======= MMix ======== " << endl; 87 87 mmix mMix; 88 88 Array<shared_ptr<mpdf> > mComs ( 2 ); 89 mComs ( 0 ) = &mG; 90 eN.set_mu ( vec_2 ( 0.0, 0.0 ) ); 91 mepdf mEnorm ( &eN ); 92 mComs ( 1 ) = &mEnorm; 89 90 // emix::set_parameters requires the first mpdf to be named 91 mG->set_rv(x); 92 mG->set_rvc(y); 93 mComs ( 0 ) = mG; 94 95 eN->set_mu ( vec_2 ( 0.0, 0.0 ) ); 96 shared_ptr<mepdf> mEnorm = new mepdf ( eN ); 97 mComs ( 1 ) = mEnorm; 93 98 mMix.set_parameters ( vec_2 ( 0.5, 0.5 ), mComs ); 94 99 95 100 Smp = mMix.samplecond_m ( mu0, N ); 96 disp ( 0.5 *eN.mean()+0.4*eG.mean(), zeros ( 2 ), Smp );101 disp ( 0.5 * eN->mean() + 0.4 * eG->mean(), zeros ( 2 ), Smp ); 97 102 98 103 cout << "======= EProd ======== " << endl; 99 // we have to change eG .rv to y100 eN .set_rv ( x );101 eG .set_rv ( y );104 // we have to change eG->rv to y 105 eN->set_rv ( x ); 106 eG->set_rv ( y ); 102 107 //create array 103 108 Array<mpdf*> A ( 2 ); 104 mepdf meN ( &eN);105 mepdf meG ( &eG);109 mepdf meN ( eN.get() ); 110 mepdf meG ( eG.get() ); 106 111 A ( 0 ) = &meN; 107 112 A ( 1 ) = &meG; … … 114 119 vec v0 = vec ( 0 ); 115 120 Smp = eP.samplecond ( v0, N ); 116 disp ( concat ( eN .mean(), eG.mean() ), epV, Smp );121 disp ( concat ( eN->mean(), eG->mean() ), epV, Smp ); 117 122 118 123 cout << "======= eWishart ======== " << endl;