1 | #include "base/bdmbase.h" |
---|
2 | #include "base/user_info.h" |
---|
3 | #include "stat/exp_family.h" |
---|
4 | #include "itpp_ext.h" |
---|
5 | #include "epdf_harness.h" |
---|
6 | #include "egiw_harness.h" |
---|
7 | #include "mat_checks.h" |
---|
8 | #include "UnitTest++.h" |
---|
9 | |
---|
10 | const double epsilon = 0.00001; |
---|
11 | |
---|
12 | using namespace bdm; |
---|
13 | |
---|
14 | TEST ( test_egiw ) { |
---|
15 | epdf_harness::test_config ( "egiw.cfg" ); |
---|
16 | } |
---|
17 | |
---|
18 | TEST ( test_egiw_1_2 ) { |
---|
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; |
---|
23 | |
---|
24 | |
---|
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; |
---|
30 | |
---|
31 | V ( 0, 1 ) = V ( 1, 0 ); |
---|
32 | V ( 1, 1 ) = 1.0; |
---|
33 | V ( 2, 1 ) = 0.0; |
---|
34 | |
---|
35 | V ( 0, 2 ) = V ( 2, 0 ); |
---|
36 | V ( 1, 2 ) = V ( 2, 1 ); |
---|
37 | V ( 2, 2 ) = 1.0; |
---|
38 | |
---|
39 | double nu = 20; |
---|
40 | |
---|
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 ); |
---|
44 | |
---|
45 | int n = 100; |
---|
46 | vec rgr ( 3 ); |
---|
47 | |
---|
48 | mat Tmp ( 2 * n, n ); |
---|
49 | |
---|
50 | double summ = 0.0; |
---|
51 | for ( int k = 0; k < n; k++ ) { // ALL b |
---|
52 | rgr ( 1 ) = 1 + k * ( 1.0 / n ) * 4.0; |
---|
53 | for ( int i = 0; i < 2*n; i++ ) { //ALL mu |
---|
54 | rgr ( 0 ) = -2 + i * ( 1.0 / n ) * 3.0; |
---|
55 | for ( int j = 0; j < n; j++ ) { // All sigma |
---|
56 | rgr ( 2 ) = ( j + 1 ) * ( 1.0 / n ) * 2.0; |
---|
57 | |
---|
58 | Tmp ( i, j ) = E.evallog ( rgr ); |
---|
59 | } |
---|
60 | } |
---|
61 | summ += sumsum ( exp ( Tmp ) ) / n / n / n * 3.0 * 2.0 * 4.0; |
---|
62 | } |
---|
63 | |
---|
64 | CHECK_CLOSE ( 1.0, summ, 0.1 ); |
---|
65 | } |
---|