root/library/tests/epdf_harness.cpp @ 471

Revision 471, 3.0 kB (checked in by mido, 15 years ago)

1) ad UserInfo?: UI::get a UI::build predelany tak, ze vraci fals / NULL v pripade neexistence pozadovaneho Settingu, pridana enumericky typ UI::SettingPresence?, predelany stavajici UI implementace, dodelana UI dokumentace
2) dokoncena konfigurace ASTYLERU, brzy bude aplikovan
3) doxygen nastaven tak, ze vytvari soubor doxy_warnings.txt

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 "stat/emix.h"
6#include "mat_checks.h"
7#include "test_util.h"
8#include "UnitTest++.h"
9#include <memory>
10
11namespace bdm {
12
13template<>
14const ParticularUI<epdf_harness> &ParticularUI<epdf_harness>::factory(
15    ParticularUI<epdf_harness>("epdf_harness"));
16
17void epdf_harness::test_config(const char *config_file_name) {
18    RV::clear_all();
19
20    UIFile in(config_file_name);
21    Array<epdf_harness *> input;
22    UI::get(input, in, "data");
23    int sz = input.size();
24    CHECK(sz > 0);
25    for (int i = 0; i < sz; ++i) {
26        input(i)->test(config_file_name, i);
27    }
28}
29
30void epdf_harness::from_setting(const Setting &set) {
31    hepdf = UI::build<epdf>(set, "epdf", UI::compulsory);
32    UI::get(mean, set, "mean", UI::compulsory);
33    UI::get(variance, set, "variance", UI::compulsory);
34
35
36        UI::get(support, set, "support");
37        UI::get(nbins, set, "nbins");
38    UI::get(nsamples, set, "nsamples");
39    UI::get(R, set, "R");
40
41        RV* rv = UI::build<RV>(set, "marginal_rv");
42    if (rv) 
43        mrv = shared_ptr<RV>(rv);   
44
45        UI::get(tolerance, set, "tolerance");   
46}
47
48void epdf_harness::test(const char *config_name, int idx)
49{
50    CurrentContext cc(config_name, idx);
51
52    CHECK_CLOSE_EX(mean, hepdf->mean(), tolerance);
53    CHECK_CLOSE_EX(variance, hepdf->variance(), tolerance);
54
55    if (support.rows() == 2) {
56        vec xb = support.get_row(0);
57        vec yb = support.get_row(1);
58
59        int old_size = nbins.size();
60        if (old_size < 2) {
61            vec new_nbins("100 100");
62            for (int i = 0; i < old_size; ++i) {
63                new_nbins(i) = nbins(i);
64            }
65
66            nbins = new_nbins;
67        }
68
69        CHECK_CLOSE_EX(mean, num_mean2(hepdf.get(), xb, yb, nbins(0), nbins(1)), tolerance);
70        CHECK_CLOSE_EX(1.0, normcoef(hepdf.get(), xb, yb, nbins(0), nbins(1)), tolerance);
71    }
72
73    if (R.rows() > 0) {
74        mat smp = hepdf->sample_m(nsamples);
75        vec emu = smp * ones(nsamples) / nsamples;
76        mat er = (smp * smp.T()) / nsamples - outer_product(emu, emu);
77
78        // simplify overloading for Visual Studio
79        vec delta = sqrt(variance) / sqrt(static_cast<double>(nsamples));
80        CHECK_CLOSE_EX(mean, emu, delta);
81
82        CHECK_CLOSE_EX(R, er, tolerance);
83    }
84
85    if (mrv.get()) {
86        RV crv = hepdf->_rv().subt(*mrv);
87        shared_ptr<epdf> m = hepdf->marginal(*mrv);
88        shared_ptr<mpdf> c = hepdf->condition(crv);
89        mepdf mm(m);
90
91        Array<mpdf *> aa(2);
92        aa(0) = c.get();
93        aa(1) = &mm;
94        mprod mEp(aa);
95
96        mat smp = mEp.samplecond(vec(0), nsamples);
97        vec emu = sum(smp, 2) / nsamples;
98
99        // simplify overloading for Visual Studio
100        vec delta = sqrt(variance) / sqrt(static_cast<double>(nsamples));
101        CHECK_CLOSE_EX(mean, emu, delta);
102
103        if (R.rows() > 0) {
104            mat er = (smp * smp.T()) / nsamples - outer_product(emu, emu);
105            CHECK_CLOSE_EX(R, er, tolerance);
106        }
107
108        // test of pdflog at zero
109        vec zero(0);
110        vec zeron(hepdf->dimension());
111        for (int i = 0; i < zeron.size(); ++i) {
112            zeron(i) = 0;
113        }
114
115        CHECK_CLOSE_EX(hepdf->evallog(zeron), mEp.evallogcond(zeron, zero), tolerance);
116    }
117}
118
119}
Note: See TracBrowser for help on using the browser.