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