root/library/tests/epdf_harness.cpp @ 461

Revision 461, 2.1 kB (checked in by vbarta, 15 years ago)

mpdf (& its dependencies) reformat: now using shared_ptr, moved virtual method bodies to .cpp

Line 
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
9namespace bdm {
10
11template<>
12const ParticularUI<epdf_harness> &ParticularUI<epdf_harness>::factory(
13    ParticularUI<epdf_harness>("epdf_harness"));
14
15void 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
28void 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
54void 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.T()) / n - outer_product(emu, emu);
84        CHECK_CLOSE_EX(mean, emu, tolerance);
85        CHECK_CLOSE_EX(R, er, tolerance);
86    }
87}
88
89}
Note: See TracBrowser for help on using the browser.