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

Revision 878, 1.9 kB (checked in by sarka, 14 years ago)

dim ze set_parameters do validate

  • 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<const epdf*> coms ( 2 );
39        coms ( 0 ) = g0.get();
40        coms ( 1 ) = g1.get();
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       
47        CHECK_EQUAL ( vec ( "1 10 10" ), p.mean() );
48        CHECK_EQUAL ( vec ( "0 0 0" ), p.variance() );
49}
50
51TEST ( ewishart_test ) {
52        mat wM = "1.1 0.9; 0.9 1.0";
53        eWishartCh eW;
54        eW.set_parameters ( wM / 100, 100 );
55        eW.validate();
56        mat mea = zeros ( 2, 2 );
57        mat Ch;
58        for ( int i = 0; i < 100; i++ ) {
59                Ch = eW.sample_mat();
60                mea += Ch.T() * Ch;
61        }
62       
63        mat actual = mea / 100;
64        CHECK_CLOSE ( wM, actual, 0.1 );
65}
66
67TEST ( rwiwishart_test ) {
68        mat wM = "1.0 0.9; 0.9 1.0";
69        rwiWishartCh rwW;
70        rwW.set_parameters ( 2, 0.1, "1 1", 0.9 );
71        rwW.validate();
72        mat mea = zeros ( 2, 2 );
73        mat wMch = chol ( wM );
74        mat Ch ( 2, 2 );
75       
76        for ( int i = 0; i < 100; i++ ) {
77                vec tmp = rwW.samplecond ( vec ( wMch._data(), 4 ) );
78                copy_vector ( 4, tmp._data(), Ch._data() );
79                mea += Ch.T() * Ch;
80               
81        }
82       
83        mat observed ( "0.99464 0.885458; 0.885458 1.01853" );
84        mat actual = mea / 100;
85        CHECK_CLOSE ( observed, actual, 0.1 );
86}
87
88TEST ( dirich_test ) {
89        epdf_harness::test_config ( "edirich.cfg" );
90}
Note: See TracBrowser for help on using the browser.