[436] | 1 | #define BDMLIB // not an ideal way to prevent double registration of UI factories... |
---|
| 2 | #include "base/bdmbase.h" |
---|
| 3 | #include "base/user_info.h" |
---|
[386] | 4 | #include "stat/exp_family.h" |
---|
[436] | 5 | #include "itpp_ext.h" |
---|
| 6 | #include "epdf_harness.h" |
---|
[440] | 7 | #include "egiw_harness.h" |
---|
[436] | 8 | #include "mat_checks.h" |
---|
| 9 | #include "UnitTest++.h" |
---|
[188] | 10 | |
---|
[436] | 11 | const double epsilon = 0.00001; |
---|
[188] | 12 | |
---|
[436] | 13 | using namespace bdm; |
---|
[188] | 14 | |
---|
[436] | 15 | template<> |
---|
| 16 | const ParticularUI<egiw> &ParticularUI<egiw>::factory( |
---|
| 17 | ParticularUI<egiw>("egiw")); |
---|
[188] | 18 | |
---|
[440] | 19 | template<> |
---|
| 20 | const ParticularUI<egiw_harness> &ParticularUI<egiw_harness>::factory( |
---|
| 21 | ParticularUI<egiw_harness>("egiw_harness")); |
---|
| 22 | |
---|
[436] | 23 | TEST(test_egiw) { |
---|
[456] | 24 | epdf_harness::test_config("egiw.cfg"); |
---|
[436] | 25 | } |
---|
[188] | 26 | |
---|
[436] | 27 | TEST(test_egiw_1_2) { |
---|
| 28 | // Setup model |
---|
| 29 | double mu = 1.1; //unit step parametr |
---|
| 30 | double b = 3.0; // sequence of <1 -1 1 -1...> |
---|
| 31 | double s = 0.1; |
---|
[188] | 32 | |
---|
| 33 | |
---|
[436] | 34 | // TEST 1x1 EGIW |
---|
| 35 | mat V(3, 3); |
---|
| 36 | V(0, 0) = pow(mu, 2) + pow(b, 2) + s; |
---|
| 37 | V(1, 0) = mu; |
---|
| 38 | V(2, 0) = b; |
---|
[188] | 39 | |
---|
[436] | 40 | V(0, 1) = V(1, 0); |
---|
| 41 | V(1, 1) = 1.0; |
---|
| 42 | V(2, 1) = 0.0; |
---|
[188] | 43 | |
---|
[436] | 44 | V(0, 2) = V(2, 0); |
---|
| 45 | V(1, 2) = V(2, 1); |
---|
| 46 | V(2, 2) = 1.0; |
---|
[188] | 47 | |
---|
[436] | 48 | double nu = 20; |
---|
[188] | 49 | |
---|
[436] | 50 | egiw E(1, nu * V, nu); |
---|
| 51 | CHECK_CLOSE(vec("1.1 3.0 0.142857"), E.mean(), epsilon); |
---|
| 52 | CHECK_CLOSE(7.36731, E.lognc(), epsilon); |
---|
[188] | 53 | |
---|
[436] | 54 | int n = 100; |
---|
| 55 | vec rgr(3); |
---|
[188] | 56 | |
---|
[436] | 57 | mat Tmp(2 * n, n); |
---|
[188] | 58 | |
---|
[436] | 59 | double summ = 0.0; |
---|
| 60 | for (int k = 0; k < n; k++) { // ALL b |
---|
| 61 | rgr(1) = 1 + k * (1.0 / n) * 4.0; |
---|
| 62 | for (int i = 0; i < 2*n; i++) { //ALL mu |
---|
| 63 | rgr(0) = -2 + i * (1.0 / n) * 3.0; |
---|
| 64 | for (int j = 0; j < n; j++) { // All sigma |
---|
| 65 | rgr(2) = (j + 1) * (1.0 / n) * 2.0; |
---|
[188] | 66 | |
---|
[436] | 67 | Tmp(i, j) = E.evallog(rgr); |
---|
| 68 | } |
---|
[188] | 69 | } |
---|
[436] | 70 | summ += sumsum(exp(Tmp)) / n / n / n * 3.0 * 2.0 * 4.0; |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | CHECK_CLOSE(1.0, summ, 0.1); |
---|
[188] | 74 | } |
---|