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
RevLine 
[428]1#define BDMLIB // not an ideal way to prevent double registration of UI factories...
[386]2#include "stat/exp_family.h"
[443]3#include "epdf_harness.h"
[428]4#include "mat_checks.h"
[436]5#include "test_util.h"
[428]6#include "UnitTest++.h"
7
[254]8using namespace bdm;
[179]9
[428]10const double epsilon = 0.00001;
[179]11
[428]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
[443]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
[428]47TEST(test_enorm) {
[443]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) {
[428]60    RNG_randomize();
[179]61
[428]62    // Setup model
63    vec mu("1.1 -1");
64    ldmat R(mat("1 -0.5; -0.5 2"));
[179]65
[428]66    RV x("{x }");
67    RV y("{y }");
[179]68
[428]69    enorm<ldmat> E;
[443]70    E.set_rv(concat(x, y));
[428]71    E.set_parameters(mu, R);
[179]72
[448]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);
[179]78
[448]79    mat er = (smp * smp.T()) / n - outer_product(emu, emu);
80    CHECK_CLOSE(R.to_mat(), er, 0.3);
[428]81}
Note: See TracBrowser for help on using the browser.