1 | #include "epdf_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<epdf_harness> &ParticularUI<epdf_harness>::factory( |
---|
13 | ParticularUI<epdf_harness>("epdf_harness")); |
---|
14 | |
---|
15 | void epdf_harness::test_config(const char *config_file_name) { |
---|
16 | RV::clear_all(); |
---|
17 | |
---|
18 | UIFile in(config_file_name); |
---|
19 | Array<epdf_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 epdf_harness::from_setting(const Setting &set) { |
---|
29 | hepdf = UI::build<epdf>(set, "epdf"); |
---|
30 | UI::get(mean, set, "mean"); |
---|
31 | UI::get(variance, set, "variance"); |
---|
32 | |
---|
33 | if (set.exists("support")) { |
---|
34 | UI::get(support, set, "support"); |
---|
35 | } |
---|
36 | |
---|
37 | if (set.exists("nbins")) { |
---|
38 | UI::get(nbins, set, "nbins"); |
---|
39 | } |
---|
40 | |
---|
41 | if (set.exists("nsamples")) { |
---|
42 | UI::get(nsamples, set, "nsamples"); |
---|
43 | } |
---|
44 | |
---|
45 | if (set.exists("R")) { |
---|
46 | UI::get(R, set, "R"); |
---|
47 | } |
---|
48 | |
---|
49 | if (set.exists("tolerance")) { |
---|
50 | UI::get(tolerance, set, "tolerance"); |
---|
51 | } |
---|
52 | } |
---|
53 | |
---|
54 | void epdf_harness::test(const char *config_name, int idx) |
---|
55 | { |
---|
56 | CurrentContext cc(config_name, idx); |
---|
57 | |
---|
58 | CHECK_CLOSE_EX(mean, hepdf->mean(), tolerance); |
---|
59 | CHECK_CLOSE_EX(variance, hepdf->variance(), tolerance); |
---|
60 | |
---|
61 | if (support.rows() == 2) { |
---|
62 | vec xb = support.get_row(0); |
---|
63 | vec yb = support.get_row(1); |
---|
64 | |
---|
65 | int old_size = nbins.size(); |
---|
66 | if (old_size < 2) { |
---|
67 | vec new_nbins("100 100"); |
---|
68 | for (int i = 0; i < old_size; ++i) { |
---|
69 | new_nbins(i) = nbins(i); |
---|
70 | } |
---|
71 | |
---|
72 | nbins = new_nbins; |
---|
73 | } |
---|
74 | |
---|
75 | CHECK_CLOSE_EX(mean, num_mean2(hepdf.get(), xb, yb, nbins(0), nbins(1)), 0.1); |
---|
76 | CHECK_CLOSE_EX(1.0, normcoef(hepdf.get(), xb, yb, nbins(0), nbins(1)), 0.1); |
---|
77 | } |
---|
78 | |
---|
79 | if (R.rows() > 0) { |
---|
80 | mat smp = hepdf->sample_m(nsamples); |
---|
81 | int n = smp.cols(); |
---|
82 | vec Emu = smp * ones(n) / n; |
---|
83 | mat Er = (smp*smp.transpose())/n - outer_product(Emu,Emu); |
---|
84 | CHECK_CLOSE_EX(mean, Emu, tolerance); |
---|
85 | CHECK_CLOSE_EX(R, Er, tolerance); |
---|
86 | } |
---|
87 | } |
---|
88 | |
---|
89 | } |
---|