root/library/tests/egiw_test.cpp @ 456

Revision 456, 1.6 kB (checked in by vbarta, 15 years ago)

custom test location for harness tests (extended UnitTest?++), configurable tolerance - all tests pass (most of the time)

  • Property svn:eol-style set to native
Line 
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"
4#include "stat/exp_family.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
11const double epsilon = 0.00001;
12
13using namespace bdm;
14
15template<>
16const ParticularUI<egiw> &ParticularUI<egiw>::factory(
17    ParticularUI<egiw>("egiw"));
18
19template<>
20const ParticularUI<egiw_harness> &ParticularUI<egiw_harness>::factory(
21    ParticularUI<egiw_harness>("egiw_harness"));
22
23TEST(test_egiw) {
24    epdf_harness::test_config("egiw.cfg");
25}
26
27TEST(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;
32
33
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;
39
40    V(0, 1) = V(1, 0);
41    V(1, 1) = 1.0;
42    V(2, 1) = 0.0;
43
44    V(0, 2) = V(2, 0);
45    V(1, 2) = V(2, 1);
46    V(2, 2) = 1.0;
47
48    double nu = 20;
49
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);
53
54    int n = 100;
55    vec rgr(3);
56
57    mat Tmp(2 * n, n);
58
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;
66
67                Tmp(i, j) = E.evallog(rgr);
68            }
69        }
70        summ += sumsum(exp(Tmp)) / n / n / n * 3.0 * 2.0 * 4.0;
71    }
72
73    CHECK_CLOSE(1.0, summ, 0.1);
74}
Note: See TracBrowser for help on using the browser.