[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 ) { |
---|
[477] | 11 | epdf_harness::test_config ( "egamma.cfg" ); |
---|
[441] | 12 | } |
---|
[457] | 13 | |
---|
[689] | 14 | TEST ( enorm_test ) { |
---|
[477] | 15 | epdf_harness::test_config ( "enorm.cfg" ); |
---|
[457] | 16 | } |
---|
[523] | 17 | |
---|
[547] | 18 | // not using epdf_harness because eprod isn't configurable (yet?) |
---|
[689] | 19 | TEST ( eprod_test ) { |
---|
[750] | 20 | |
---|
[547] | 21 | RV a ( "{eprod_a }", "1" ); |
---|
| 22 | RV b ( "{eprod_b }", "2" ); |
---|
| 23 | |
---|
| 24 | egamma_ptr g0; |
---|
| 25 | g0->set_parameters ( vec ( "2" ), vec ( "2" ) ); |
---|
| 26 | g0->set_rv ( a ); |
---|
| 27 | |
---|
| 28 | egamma_ptr g1; |
---|
| 29 | g1->set_parameters ( vec ( "100000 10000" ), vec ( "10000 1000" ) ); |
---|
| 30 | g1->set_rv ( b ); |
---|
| 31 | |
---|
| 32 | Array<const epdf*> coms ( 2 ); |
---|
| 33 | coms ( 0 ) = g0.get(); |
---|
| 34 | coms ( 1 ) = g1.get(); |
---|
| 35 | |
---|
| 36 | eprod p; |
---|
| 37 | // set_parameters doesn't say so, but it actually requires |
---|
| 38 | // pointers in the array to outlast the eprod instance... |
---|
| 39 | p.set_parameters ( coms ); |
---|
| 40 | |
---|
| 41 | CHECK_EQUAL ( vec ( "1 10 10" ), p.mean() ); |
---|
| 42 | CHECK_EQUAL ( vec ( "0 0 0" ), p.variance() ); |
---|
| 43 | } |
---|
| 44 | |
---|
[689] | 45 | TEST ( ewishart_test ) { |
---|
[727] | 46 | mat wM = "1.1 0.9; 0.9 1.0"; |
---|
[523] | 47 | eWishartCh eW; |
---|
| 48 | eW.set_parameters ( wM / 100, 100 ); |
---|
| 49 | mat mea = zeros ( 2, 2 ); |
---|
| 50 | mat Ch; |
---|
| 51 | for ( int i = 0; i < 100; i++ ) { |
---|
| 52 | Ch = eW.sample_mat(); |
---|
| 53 | mea += Ch.T() * Ch; |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | mat actual = mea / 100; |
---|
[725] | 57 | CHECK_CLOSE ( wM, actual, 0.1 ); |
---|
[523] | 58 | } |
---|
| 59 | |
---|
[689] | 60 | TEST ( rwiwishart_test ) { |
---|
[523] | 61 | mat wM = "1.0 0.9; 0.9 1.0"; |
---|
| 62 | rwiWishartCh rwW; |
---|
| 63 | rwW.set_parameters ( 2, 0.1, "1 1", 0.9 ); |
---|
[750] | 64 | rwW.validate(); |
---|
[523] | 65 | mat mea = zeros ( 2, 2 ); |
---|
| 66 | mat wMch = chol ( wM ); |
---|
| 67 | mat Ch ( 2, 2 ); |
---|
[750] | 68 | |
---|
[523] | 69 | for ( int i = 0; i < 100; i++ ) { |
---|
| 70 | vec tmp = rwW.samplecond ( vec ( wMch._data(), 4 ) ); |
---|
| 71 | copy_vector ( 4, tmp._data(), Ch._data() ); |
---|
| 72 | mea += Ch.T() * Ch; |
---|
[750] | 73 | |
---|
[523] | 74 | } |
---|
| 75 | |
---|
| 76 | mat observed ( "0.99464 0.885458; 0.885458 1.01853" ); |
---|
| 77 | mat actual = mea / 100; |
---|
| 78 | CHECK_CLOSE ( observed, actual, 0.1 ); |
---|
| 79 | } |
---|
[634] | 80 | |
---|
[722] | 81 | TEST ( dirich_test ) { |
---|
[634] | 82 | epdf_harness::test_config ( "edirich.cfg" ); |
---|
[723] | 83 | } |
---|