1 | #include "mpdf_harness.h" |
---|
2 | #include "base/bdmbase.h" |
---|
3 | #include "base/user_info.h" |
---|
4 | #include "stat/exp_family.h" |
---|
5 | #include "mat_checks.h" |
---|
6 | #include "test_util.h" |
---|
7 | #include "UnitTest++.h" |
---|
8 | |
---|
9 | namespace bdm { |
---|
10 | |
---|
11 | template<> |
---|
12 | const ParticularUI<mpdf_harness> &ParticularUI<mpdf_harness>::factory( |
---|
13 | ParticularUI<mpdf_harness>("mpdf_harness")); |
---|
14 | |
---|
15 | void mpdf_harness::test_config(const char *config_file_name) { |
---|
16 | RV::clear_all(); |
---|
17 | |
---|
18 | UIFile in(config_file_name); |
---|
19 | Array<mpdf_harness *> input; |
---|
20 | UI::get(input, in, "data"); |
---|
21 | int sz = input.size(); |
---|
22 | CHECK(sz > 0); |
---|
23 | for (int i = 0; i < sz; ++i) { |
---|
24 | input(i)->test(config_file_name, i); |
---|
25 | } |
---|
26 | } |
---|
27 | |
---|
28 | void mpdf_harness::from_setting(const Setting &set) { |
---|
29 | hmpdf = UI::build<mpdf>(set, "mpdf"); |
---|
30 | UI::get(cond, set, "cond"); |
---|
31 | UI::get(mean, set, "mean"); |
---|
32 | |
---|
33 | if (set.exists("nsamples")) { |
---|
34 | UI::get(nsamples, set, "nsamples"); |
---|
35 | } |
---|
36 | |
---|
37 | UI::get(R, set, "R"); |
---|
38 | |
---|
39 | if (set.exists("tolerance")) { |
---|
40 | UI::get(tolerance, set, "tolerance"); |
---|
41 | } |
---|
42 | } |
---|
43 | |
---|
44 | void mpdf_harness::test(const char *config_name, int idx) |
---|
45 | { |
---|
46 | CurrentContext cc(config_name, idx); |
---|
47 | |
---|
48 | mat smp = hmpdf->samplecond_m(cond, nsamples); |
---|
49 | int n = smp.cols(); |
---|
50 | vec emu = smp * ones(n) / n; |
---|
51 | mat er = (smp * smp.T()) / n - outer_product(emu, emu); |
---|
52 | CHECK_CLOSE_EX(mean, emu, tolerance); |
---|
53 | CHECK_CLOSE_EX(R, er, tolerance); |
---|
54 | } |
---|
55 | |
---|
56 | } |
---|