root/library/tests/egiw_test.cpp @ 386

Revision 386, 2.1 kB (checked in by mido, 15 years ago)

possibly broken? 4th part

  • Property svn:eol-style set to native
Line 
1#include "stat/exp_family.h"
2using namespace bdm;
3
4//These lines are needed for use of cout and endl
5using std::cout;
6using std::endl;
7
8void Test ( const egiw &E ) {
9}
10
11int main() {
12        cout << "Testing eGiw(1,1)"<<endl;
13        {
14                // Setup model
15                double mu=1.1;
16                double s=0.1;
17
18                // TEST 1x1 EGIW
19                mat V ( 2,2 );
20                V ( 0,0 ) = pow ( mu,2 ) +s;
21                V ( 1,0 ) = mu;
22                V ( 0,1 ) = V ( 1,0 );
23                V ( 1,1 ) = 1.0;
24
25                double nu=10;
26
27                egiw E ( 1,nu*V,nu );
28                cout << "egiw mean value:" << E.mean() <<endl;
29                cout << "egiw normalizing constant:" << E.lognc() <<endl;
30
31                int n=100;
32                vec t_val ( 2 );
33
34                mat pdf ( 2*n,n );
35                vec Mu ( 2*n );
36                vec Si ( n );
37
38                for ( int i=0;i<2*n;i++ ) {
39                        Mu ( i ) = -2+i* ( 1.0/ ( n ) ) *3.0;
40                        t_val ( 0 ) = Mu ( i );
41                        for ( int j=0;j<n;j++ ) {
42                                Si ( j ) = ( j+1 ) * ( 1.0/n ) *2;
43                                t_val ( 1 ) = Si ( j );
44
45                                pdf ( i,j ) =E.evallog ( t_val );
46                        }
47                }
48
49                mat Pdf=exp ( pdf );
50                vec fm=sum ( Pdf,2 );
51                vec fs=sum ( Pdf,1 );
52                cout << "Numerical mean: " << vec_2 ( Mu*fm/sum ( fm ), Si*fs/sum ( fs ) ) <<endl;
53                cout << "Numerical integral of pdf: "<<sumsum ( Pdf/n/n*3*2 ) <<endl;
54        }
55        cout << "Testing Egiw(1,2)"<<endl;
56        {
57                // Setup model
58                double mu=1.1; //unit step parametr
59                double b=3.0; // sequence of <1 -1 1 -1...>
60                double s=0.1;
61
62
63                // TEST 1x1 EGIW
64                mat V ( 3,3 );
65                V ( 0,0 ) = pow ( mu,2 ) +pow ( b ,2 )  +s;
66                V ( 1,0 ) = mu;
67                V ( 2,0 ) = b;
68
69                V ( 0,1 ) = V ( 1,0 );
70                V ( 1,1 ) = 1.0;
71                V ( 2,1 ) = 0.0;
72
73                V ( 0,2 ) = V ( 2,0 );
74                V ( 1,2 ) = V ( 2,1 );
75                V ( 2,2 ) = 1.0;
76
77
78                double nu=20;
79
80                egiw E ( 1,nu*V,nu );
81                cout << "egiw mean value:" << E.mean() <<endl;
82                cout << "egiw normalizing constant:" << E.lognc() <<endl;
83
84                int n=100;
85                vec t_val ( 3 );
86
87                mat Tmp= zeros ( 2*n,n );
88
89                double summ=0.0;
90                for ( int k=0;k<n;k++ ) { // ALL b
91                        t_val ( 1 ) = 1 + k* ( 1.0/n ) * 4.0;
92                        for ( int i=0;i<2*n;i++ ) { //ALL mu
93                                t_val ( 0 ) = -2+i* ( 1.0/  n ) *3.0;
94                                for ( int j=0;j<n;j++ ) { // All sigma
95                                        t_val ( 2 ) = ( j+1 ) * ( 1.0/n ) *2.0;
96
97                                        Tmp ( i,j ) = E.evallog ( t_val );
98                                }
99                        }
100                        summ += sumsum ( exp ( Tmp ) ) /n/n/n*3.0*2.0*4.0;
101                }
102
103
104                cout << "Numerical integral of pdf: "<<summ <<endl;
105        }
106       
107       
108}
Note: See TracBrowser for help on using the browser.