root/library/tests/epdf_test.cpp @ 547

Revision 547, 1.8 kB (checked in by vbarta, 15 years ago)

added eprod test

Line 
1#include "base/user_info.h"
2#include "stat/exp_family.h"
3#include "itpp_ext.h"
4#include "epdf_harness.h"
5#include "mat_checks.h"
6#include "UnitTest++.h"
7
8using namespace bdm;
9
10TEST ( test_egamma ) {
11        epdf_harness::test_config ( "egamma.cfg" );
12}
13
14TEST ( test_enorm ) {
15        epdf_harness::test_config ( "enorm.cfg" );
16}
17
18// not using epdf_harness because eprod isn't configurable (yet?)
19TEST ( test_eprod ) {
20        RV a ( "{eprod_a }", "1" );
21        RV b ( "{eprod_b }", "2" );
22
23        egamma_ptr g0;
24        g0->set_parameters ( vec ( "2" ), vec ( "2" ) );
25        g0->set_rv ( a );
26
27        egamma_ptr g1;
28        g1->set_parameters ( vec ( "100000 10000" ), vec ( "10000 1000" ) );
29        g1->set_rv ( b );
30
31        Array<const epdf*> coms ( 2 );
32        coms ( 0 ) = g0.get();
33        coms ( 1 ) = g1.get();
34
35        eprod p;
36        // set_parameters doesn't say so, but it actually requires
37        // pointers in the array to outlast the eprod instance...
38        p.set_parameters ( coms );
39
40        CHECK_EQUAL ( vec ( "1 10 10" ), p.mean() );
41        CHECK_EQUAL ( vec ( "0 0 0" ), p.variance() );
42}
43
44TEST ( test_ewishart ) {
45        mat wM = "1.0 0.9; 0.9 1.0";
46        eWishartCh eW;
47        eW.set_parameters ( wM / 100, 100 );
48        mat mea = zeros ( 2, 2 );
49        mat Ch;
50        for ( int i = 0; i < 100; i++ ) {
51                Ch = eW.sample_mat();
52                mea += Ch.T() * Ch;
53        }
54
55        mat observed ( "0.978486 0.88637; 0.88637 0.992141" );
56        mat actual = mea / 100;
57        CHECK_CLOSE ( observed, actual, 0.1 );
58}
59
60TEST ( test_rwiwishart ) {
61        mat wM = "1.0 0.9; 0.9 1.0";
62        rwiWishartCh rwW;
63        rwW.set_parameters ( 2, 0.1, "1 1", 0.9 );
64        mat mea = zeros ( 2, 2 );
65        mat wMch = chol ( wM );
66        mat Ch ( 2, 2 );
67        for ( int i = 0; i < 100; i++ ) {
68                vec tmp = rwW.samplecond ( vec ( wMch._data(), 4 ) );
69                copy_vector ( 4, tmp._data(), Ch._data() );
70                mea += Ch.T() * Ch;
71        }
72
73        mat observed ( "0.99464 0.885458; 0.885458 1.01853" );
74        mat actual = mea / 100;
75        CHECK_CLOSE ( observed, actual, 0.1 );
76}
Note: See TracBrowser for help on using the browser.