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