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

Revision 802, 1.9 kB (checked in by smidl, 14 years ago)

new class estudent + tests

  • 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->set_rv ( a );
31
32        egamma_ptr g1;
33        g1->set_parameters ( vec ( "100000 10000" ), vec ( "10000 1000" ) );
34        g1->set_rv ( b );
35
36        Array<const epdf*> coms ( 2 );
37        coms ( 0 ) = g0.get();
38        coms ( 1 ) = g1.get();
39
40        eprod p;
41        // set_parameters doesn't say so, but it actually requires
42        // pointers in the array to outlast the eprod instance...
43        p.set_parameters ( coms );
44
45        CHECK_EQUAL ( vec ( "1 10 10" ), p.mean() );
46        CHECK_EQUAL ( vec ( "0 0 0" ), p.variance() );
47}
48
49TEST ( ewishart_test ) {
50        mat wM = "1.1 0.9; 0.9 1.0";
51        eWishartCh eW;
52        eW.set_parameters ( wM / 100, 100 );
53        mat mea = zeros ( 2, 2 );
54        mat Ch;
55        for ( int i = 0; i < 100; i++ ) {
56                Ch = eW.sample_mat();
57                mea += Ch.T() * Ch;
58        }
59
60        mat actual = mea / 100;
61        CHECK_CLOSE ( wM, actual, 0.1 );
62}
63
64TEST ( rwiwishart_test ) {
65        mat wM = "1.0 0.9; 0.9 1.0";
66        rwiWishartCh rwW;
67        rwW.set_parameters ( 2, 0.1, "1 1", 0.9 );
68        rwW.validate();
69        mat mea = zeros ( 2, 2 );
70        mat wMch = chol ( wM );
71        mat Ch ( 2, 2 );
72       
73        for ( int i = 0; i < 100; i++ ) {
74                vec tmp = rwW.samplecond ( vec ( wMch._data(), 4 ) );
75                copy_vector ( 4, tmp._data(), Ch._data() );
76                mea += Ch.T() * Ch;
77               
78        }
79
80        mat observed ( "0.99464 0.885458; 0.885458 1.01853" );
81        mat actual = mea / 100;
82        CHECK_CLOSE ( observed, actual, 0.1 );
83}
84
85TEST ( dirich_test ) {
86        epdf_harness::test_config ( "edirich.cfg" );
87}
Note: See TracBrowser for help on using the browser.