root/library/tests/mepdf_test.cpp @ 456

Revision 456, 1.2 kB (checked in by vbarta, 15 years ago)

custom test location for harness tests (extended UnitTest?++), configurable tolerance - all tests pass (most of the time)

Line 
1#define BDMLIB // not an ideal way to prevent double registration of UI factories...
2#include "base/bdmbase.h"
3#include "base/user_info.h"
4#include "stat/exp_family.h"
5#include "stat/emix.h"
6#include "itpp_ext.h"
7#include "mpdf_harness.h"
8#include "mat_checks.h"
9#include "UnitTest++.h"
10
11using namespace bdm;
12
13const double epsilon = 0.00001;
14
15TEST(test_mepdf) {
16    mpdf_harness::test_config("mepdf.cfg");
17}
18
19TEST(test_mepdf_sample) {
20    // Setup model
21    vec mu("1.1 -1");
22    ldmat R(mat("1 -0.5; -0.5 2"));
23
24    RV x("{x }");
25    RV y("{y }");
26
27    enorm<ldmat> E;
28    E.set_rv(concat(x, y));
29    E.set_parameters(mu, R);
30
31    epdf *Mg = E.marginal(y);
32    CHECK_CLOSE(vec("-1"), Mg->mean(), epsilon);
33
34    // putting them back together
35    mpdf *Cn = E.condition(x);
36    mepdf mMg(Mg);
37    Array<mpdf *> A(2);
38    A(0) = Cn;
39    A(1) = &mMg;
40    mprod mEp(A);
41
42    int n = 1000;
43    mat smp = mEp.samplecond(vec(0), n);
44    vec emu = sum(smp, 2) / n;
45    CHECK_CLOSE(mu, emu, 0.3);
46
47    mat er = (smp * smp.T()) / n - outer_product(emu, emu);
48    CHECK_CLOSE(R.to_mat(), er, 0.3);
49
50    // test of pdflog at zero
51    vec zero(0);
52    vec zero2("0 0");
53    CHECK_CLOSE(E.evallog(zero2), mEp.evallogcond(zero2, zero), epsilon);
54}
Note: See TracBrowser for help on using the browser.