root/library/tests/egiw_test.cpp @ 477

Revision 477, 1.7 kB (checked in by mido, 15 years ago)

panove, vite, jak jsem peclivej na upravu kodu.. snad se vam bude libit:) konfigurace je v souboru /system/astylerc

  • Property svn:eol-style set to native
RevLine 
[436]1#define BDMLIB // not an ideal way to prevent double registration of UI factories...
2#include "base/bdmbase.h"
3#include "base/user_info.h"
[386]4#include "stat/exp_family.h"
[436]5#include "itpp_ext.h"
6#include "epdf_harness.h"
[440]7#include "egiw_harness.h"
[436]8#include "mat_checks.h"
9#include "UnitTest++.h"
[188]10
[436]11const double epsilon = 0.00001;
[188]12
[436]13using namespace bdm;
[188]14
[436]15template<>
[477]16const ParticularUI<egiw> &ParticularUI<egiw>::factory (
17    ParticularUI<egiw> ( "egiw" ) );
[188]18
[440]19template<>
[477]20const ParticularUI<egiw_harness> &ParticularUI<egiw_harness>::factory (
21    ParticularUI<egiw_harness> ( "egiw_harness" ) );
[440]22
[477]23TEST ( test_egiw ) {
24        epdf_harness::test_config ( "egiw.cfg" );
[436]25}
[188]26
[477]27TEST ( test_egiw_1_2 ) {
28        // Setup model
29        double mu = 1.1; //unit step parametr
30        double b = 3.0; // sequence of <1 -1 1 -1...>
31        double s = 0.1;
[188]32
33
[477]34        // TEST 1x1 EGIW
35        mat V ( 3, 3 );
36        V ( 0, 0 ) = pow ( mu, 2 ) + pow ( b, 2 ) + s;
37        V ( 1, 0 ) = mu;
38        V ( 2, 0 ) = b;
[188]39
[477]40        V ( 0, 1 ) = V ( 1, 0 );
41        V ( 1, 1 ) = 1.0;
42        V ( 2, 1 ) = 0.0;
[188]43
[477]44        V ( 0, 2 ) = V ( 2, 0 );
45        V ( 1, 2 ) = V ( 2, 1 );
46        V ( 2, 2 ) = 1.0;
[188]47
[477]48        double nu = 20;
[188]49
[477]50        egiw E ( 1, nu * V, nu );
51        CHECK_CLOSE ( vec ( "1.1 3.0 0.142857" ), E.mean(), epsilon );
52        CHECK_CLOSE ( 7.36731, E.lognc(), epsilon );
[188]53
[477]54        int n = 100;
55        vec rgr ( 3 );
[188]56
[477]57        mat Tmp ( 2 * n, n );
[188]58
[477]59        double summ = 0.0;
60        for ( int k = 0; k < n; k++ ) { // ALL b
61                rgr ( 1 ) = 1 + k * ( 1.0 / n ) * 4.0;
62                for ( int i = 0; i < 2*n; i++ ) { //ALL mu
63                        rgr ( 0 ) = -2 + i * ( 1.0 / n ) * 3.0;
64                        for ( int j = 0; j < n; j++ ) { // All sigma
65                                rgr ( 2 ) = ( j + 1 ) * ( 1.0 / n ) * 2.0;
[188]66
[477]67                                Tmp ( i, j ) = E.evallog ( rgr );
68                        }
69                }
70                summ += sumsum ( exp ( Tmp ) ) / n / n / n * 3.0 * 2.0 * 4.0;
[188]71        }
[436]72
[477]73        CHECK_CLOSE ( 1.0, summ, 0.1 );
[188]74}
Note: See TracBrowser for help on using the browser.