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

Revision 750, 1.8 kB (checked in by sarka, 15 years ago)

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