[436] | 1 | #include "base/bdmbase.h" |
---|
| 2 | #include "base/user_info.h" |
---|
[386] | 3 | #include "stat/exp_family.h" |
---|
[557] | 4 | #include "stat/discrete.h" |
---|
[436] | 5 | #include "itpp_ext.h" |
---|
[717] | 6 | #include "../epdf_harness.h" |
---|
| 7 | #include "../mat_checks.h" |
---|
[436] | 8 | #include "UnitTest++.h" |
---|
[188] | 9 | |
---|
[436] | 10 | const double epsilon = 0.00001; |
---|
[188] | 11 | |
---|
[436] | 12 | using namespace bdm; |
---|
[188] | 13 | |
---|
[689] | 14 | TEST ( egiw_test ) { |
---|
[1064] | 15 | epdf_harness::test_config ( "egiw.cfg" ); |
---|
[436] | 16 | } |
---|
[188] | 17 | |
---|
[689] | 18 | TEST ( egiw_1_2_test ) { |
---|
[1064] | 19 | // Setup model |
---|
| 20 | double mu = 1.1; //unit step parametr |
---|
| 21 | double b = 3.0; // sequence of <1 -1 1 -1...> |
---|
| 22 | double s = 0.1; |
---|
[188] | 23 | |
---|
| 24 | |
---|
[1064] | 25 | // TEST 1x1 EGIW |
---|
| 26 | mat V ( 3, 3 ); |
---|
| 27 | V ( 0, 0 ) = pow ( mu, 2 ) + pow ( b, 2 ) + s; |
---|
| 28 | V ( 1, 0 ) = mu; |
---|
| 29 | V ( 2, 0 ) = b; |
---|
[188] | 30 | |
---|
[1064] | 31 | V ( 0, 1 ) = V ( 1, 0 ); |
---|
| 32 | V ( 1, 1 ) = 1.0; |
---|
| 33 | V ( 2, 1 ) = 0.0; |
---|
[188] | 34 | |
---|
[1064] | 35 | V ( 0, 2 ) = V ( 2, 0 ); |
---|
| 36 | V ( 1, 2 ) = V ( 2, 1 ); |
---|
| 37 | V ( 2, 2 ) = 1.0; |
---|
[188] | 38 | |
---|
[1064] | 39 | double nu = 20; |
---|
[188] | 40 | |
---|
[1064] | 41 | egiw E ( 1, nu * V, nu ); |
---|
| 42 | CHECK_CLOSE ( vec ( "1.1 3.0 0.142857" ), E.mean(), epsilon ); |
---|
| 43 | CHECK_CLOSE ( 7.36731, E.lognc(), epsilon ); |
---|
[188] | 44 | |
---|
[1064] | 45 | int n = 100; |
---|
| 46 | rectangular_support Sup; |
---|
| 47 | Sup.set_parameters ( "{[-2.,4.], [1.,5.], [0.,2.]} ", n*ones_i ( E.dimension() ) ); |
---|
[722] | 48 | |
---|
[1064] | 49 | double summ = exp ( E.evallog ( Sup.first_vec() ) ); |
---|
| 50 | // sum all likelihood at all points of support |
---|
| 51 | for ( int k = 1; k < Sup.points(); k++ ) { // ALL b |
---|
| 52 | summ += exp ( E.evallog ( Sup.next_vec() ) ); |
---|
| 53 | } |
---|
[436] | 54 | |
---|
[1064] | 55 | CHECK_CLOSE ( 1.0, summ*prod ( Sup._steps() ), 0.01 ); |
---|
[188] | 56 | } |
---|