root/library/tests/enorm_test.cpp @ 448

Revision 448, 2.0 kB (checked in by vbarta, 15 years ago)

mepdf configurable tests

  • Property svn:eol-style set to native
Line 
1#define BDMLIB // not an ideal way to prevent double registration of UI factories...
2#include "stat/exp_family.h"
3#include "epdf_harness.h"
4#include "mat_checks.h"
5#include "test_util.h"
6#include "UnitTest++.h"
7
8using namespace bdm;
9
10const double epsilon = 0.00001;
11
12namespace UnitTest
13{
14
15inline void CheckClose(TestResults &results, const itpp::vec &expected,
16                       const itpp::vec &actual, double tolerance,
17                       TestDetails const& details) {
18    if (!AreClose(expected, actual, tolerance)) { 
19        MemoryOutStream stream;
20        stream << "Expected " << expected << " +/- " << tolerance << " but was " << actual;
21
22        results.OnTestFailure(details, stream.GetText());
23    }
24}
25
26inline void CheckClose(TestResults &results, const itpp::mat &expected,
27                       const itpp::mat &actual, double tolerance,
28                       TestDetails const& details) {
29    if (!AreClose(expected, actual, tolerance)) { 
30        MemoryOutStream stream;
31        stream << "Expected " << expected << " +/- " << tolerance << " but was " << actual;
32
33        results.OnTestFailure(details, stream.GetText());
34    }
35}
36
37}
38
39template<>
40const ParticularUI<enorm<ldmat> > &ParticularUI<enorm<ldmat> >::factory(
41    ParticularUI<enorm<ldmat> >("enorm<ldmat>"));
42
43template<>
44const ParticularUI<enorm<fsqmat> > &ParticularUI<enorm<fsqmat> >::factory(
45    ParticularUI<enorm<fsqmat> >("enorm<fsqmat>"));
46
47TEST(test_enorm) {
48    RV::clear_all();
49    UIFile in("enorm.cfg");
50    Array<epdf_harness *> input;
51    UI::get(input, in, "data");
52    int sz = input.size();
53    CHECK(sz > 0);
54    for (int i = 0; i < sz; ++i) {
55        input(i)->test();
56    }
57}
58
59TEST(test_enorm_sample) {
60    RNG_randomize();
61
62    // Setup model
63    vec mu("1.1 -1");
64    ldmat R(mat("1 -0.5; -0.5 2"));
65
66    RV x("{x }");
67    RV y("{y }");
68
69    enorm<ldmat> E;
70    E.set_rv(concat(x, y));
71    E.set_parameters(mu, R);
72
73    int n = 1000;
74    vec ll(n);
75    mat smp = E.sample(1000);
76    vec emu = sum(smp, 2) / n;
77    CHECK_CLOSE(mu, emu, 0.3);
78
79    mat er = (smp * smp.T()) / n - outer_product(emu, emu);
80    CHECK_CLOSE(R.to_mat(), er, 0.3);
81}
Note: See TracBrowser for help on using the browser.