[441] | 1 | #include "base/user_info.h" |
---|
| 2 | #include "stat/exp_family.h" |
---|
[523] | 3 | #include "itpp_ext.h" |
---|
[717] | 4 | #include "../epdf_harness.h" |
---|
| 5 | #include "../mat_checks.h" |
---|
[441] | 6 | #include "UnitTest++.h" |
---|
| 7 | |
---|
| 8 | using namespace bdm; |
---|
| 9 | |
---|
[689] | 10 | TEST ( egamma_test ) { |
---|
[1064] | 11 | epdf_harness::test_config ( "egamma.cfg" ); |
---|
[441] | 12 | } |
---|
[457] | 13 | |
---|
[689] | 14 | TEST ( enorm_test ) { |
---|
[1064] | 15 | epdf_harness::test_config ( "enorm.cfg" ); |
---|
[457] | 16 | } |
---|
[523] | 17 | |
---|
[802] | 18 | TEST ( estudent_test ) { |
---|
[1064] | 19 | epdf_harness::test_config ( "estudent.cfg" ); |
---|
[802] | 20 | } |
---|
| 21 | |
---|
[547] | 22 | // not using epdf_harness because eprod isn't configurable (yet?) |
---|
[689] | 23 | TEST ( eprod_test ) { |
---|
[1064] | 24 | |
---|
| 25 | RV a ( "{eprod_a }", "1" ); |
---|
| 26 | RV b ( "{eprod_b }", "2" ); |
---|
| 27 | |
---|
| 28 | egamma_ptr g0; |
---|
| 29 | g0->set_parameters ( vec ( "2" ), vec ( "2" ) ); |
---|
| 30 | g0->validate(); |
---|
| 31 | g0->set_rv ( a ); |
---|
| 32 | |
---|
| 33 | egamma_ptr g1; |
---|
| 34 | g1->set_parameters ( vec ( "100000 10000" ), vec ( "10000 1000" ) ); |
---|
| 35 | g1->validate(); |
---|
| 36 | g1->set_rv ( b ); |
---|
| 37 | |
---|
| 38 | Array<shared_ptr<epdf> > coms ( 2 ); |
---|
| 39 | coms ( 0 ) = g0; |
---|
| 40 | coms ( 1 ) = g1; |
---|
| 41 | |
---|
| 42 | eprod p; |
---|
| 43 | // set_parameters doesn't say so, but it actually requires |
---|
| 44 | // pointers in the array to outlast the eprod instance... |
---|
| 45 | p.set_parameters ( coms ); |
---|
| 46 | p.validate(); |
---|
| 47 | |
---|
| 48 | CHECK_EQUAL ( vec ( "1 10 10" ), p.mean() ); |
---|
| 49 | CHECK_EQUAL ( vec ( "0 0 0" ), p.variance() ); |
---|
[547] | 50 | } |
---|
| 51 | |
---|
[689] | 52 | TEST ( ewishart_test ) { |
---|
[1064] | 53 | mat wM = "1.1 0.9; 0.9 1.0"; |
---|
| 54 | eWishartCh eW; |
---|
[1189] | 55 | eW.set_parameters ( wM , 10 ); |
---|
[1064] | 56 | eW.validate(); |
---|
| 57 | mat mea = zeros ( 2, 2 ); |
---|
[1189] | 58 | chmat Ch; |
---|
[1064] | 59 | for ( int i = 0; i < 100; i++ ) { |
---|
| 60 | Ch = eW.sample_mat(); |
---|
[1189] | 61 | mea += Ch.to_mat(); |
---|
[1064] | 62 | } |
---|
| 63 | |
---|
| 64 | mat actual = mea / 100; |
---|
[1189] | 65 | CHECK_CLOSE ( 10*wM, actual, 0.3 ); |
---|
[523] | 66 | } |
---|
| 67 | |
---|
[689] | 68 | TEST ( rwiwishart_test ) { |
---|
[1064] | 69 | mat wM = "1.0 0.9; 0.9 1.0"; |
---|
| 70 | rwiWishartCh rwW; |
---|
| 71 | rwW.set_parameters ( 2, 0.1, "1 1", 0.9 ); |
---|
| 72 | rwW.validate(); |
---|
| 73 | mat mea = zeros ( 2, 2 ); |
---|
| 74 | mat wMch = chol ( wM ); |
---|
| 75 | mat Ch ( 2, 2 ); |
---|
| 76 | |
---|
| 77 | for ( int i = 0; i < 100; i++ ) { |
---|
| 78 | vec tmp = rwW.samplecond ( vec ( wMch._data(), 4 ) ); |
---|
| 79 | copy_vector ( 4, tmp._data(), Ch._data() ); |
---|
| 80 | mea += Ch.T() * Ch; |
---|
| 81 | |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | mat observed ( "0.99464 0.885458; 0.885458 1.01853" ); |
---|
| 85 | mat actual = mea / 100; |
---|
| 86 | CHECK_CLOSE ( observed, actual, 0.1 ); |
---|
[523] | 87 | } |
---|
[634] | 88 | |
---|
[722] | 89 | TEST ( dirich_test ) { |
---|
[1064] | 90 | epdf_harness::test_config ( "edirich.cfg" ); |
---|
[723] | 91 | } |
---|
[1033] | 92 | TEST ( ebeta_test ) { |
---|
[1064] | 93 | epdf_harness::test_config ( "ebeta.cfg" ); |
---|
[1033] | 94 | } |
---|