root/library/tests/testsuite/epdf_test.cpp @ 1158

Revision 1064, 2.2 kB (checked in by mido, 14 years ago)

astyle applied all over the library

  • Property svn:eol-style set to native
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 ( egamma_test ) {
11    epdf_harness::test_config ( "egamma.cfg" );
12}
13
14TEST ( enorm_test ) {
15    epdf_harness::test_config ( "enorm.cfg" );
16}
17
18TEST ( estudent_test ) {
19    epdf_harness::test_config ( "estudent.cfg" );
20}
21
22// not using epdf_harness because eprod isn't configurable (yet?)
23TEST ( eprod_test ) {
24
25    RV a ( "{eprod_a }", "1" );
26    RV b ( "{eprod_b }", "2" );
27
28    egamma_ptr g0;
29    g0->set_parameters ( vec ( "2" ), vec ( "2" ) );
30    g0->validate();
31    g0->set_rv ( a );
32
33    egamma_ptr g1;
34    g1->set_parameters ( vec ( "100000 10000" ), vec ( "10000 1000" ) );
35    g1->validate();
36    g1->set_rv ( b );
37
38    Array<shared_ptr<epdf> > coms ( 2 );
39    coms ( 0 ) = g0;
40    coms ( 1 ) = g1;
41
42    eprod p;
43    // set_parameters doesn't say so, but it actually requires
44    // pointers in the array to outlast the eprod instance...
45    p.set_parameters ( coms );
46    p.validate();
47
48    CHECK_EQUAL ( vec ( "1 10 10" ), p.mean() );
49    CHECK_EQUAL ( vec ( "0 0 0" ), p.variance() );
50}
51
52TEST ( ewishart_test ) {
53    mat wM = "1.1 0.9; 0.9 1.0";
54    eWishartCh eW;
55    eW.set_parameters ( wM / 100, 100 );
56    eW.validate();
57    mat mea = zeros ( 2, 2 );
58    mat Ch;
59    for ( int i = 0; i < 100; i++ ) {
60        Ch = eW.sample_mat();
61        mea += Ch.T() * Ch;
62    }
63
64    mat actual = mea / 100;
65    CHECK_CLOSE ( wM, actual, 0.1 );
66}
67
68TEST ( rwiwishart_test ) {
69    mat wM = "1.0 0.9; 0.9 1.0";
70    rwiWishartCh rwW;
71    rwW.set_parameters ( 2, 0.1, "1 1", 0.9 );
72    rwW.validate();
73    mat mea = zeros ( 2, 2 );
74    mat wMch = chol ( wM );
75    mat Ch ( 2, 2 );
76
77    for ( int i = 0; i < 100; i++ ) {
78        vec tmp = rwW.samplecond ( vec ( wMch._data(), 4 ) );
79        copy_vector ( 4, tmp._data(), Ch._data() );
80        mea += Ch.T() * Ch;
81
82    }
83
84    mat observed ( "0.99464 0.885458; 0.885458 1.01853" );
85    mat actual = mea / 100;
86    CHECK_CLOSE ( observed, actual, 0.1 );
87}
88
89TEST ( dirich_test ) {
90    epdf_harness::test_config ( "edirich.cfg" );
91}
92TEST ( ebeta_test ) {
93    epdf_harness::test_config ( "ebeta.cfg" );
94}
Note: See TracBrowser for help on using the browser.