1 | #include "test_util.h" |
---|
2 | #include "stat/exp_family.h" |
---|
3 | #include <fstream> |
---|
4 | |
---|
5 | namespace bdm { |
---|
6 | |
---|
7 | using itpp::vec; |
---|
8 | using itpp::mat; |
---|
9 | |
---|
10 | std::string load_test_file ( const char *fname ) { |
---|
11 | char buffer[8192]; |
---|
12 | memset ( buffer, 0, sizeof ( buffer ) ); |
---|
13 | std::ifstream src ( fname ); |
---|
14 | src.read ( buffer, sizeof ( buffer ) - 1 ); |
---|
15 | return std::string ( buffer ); |
---|
16 | } |
---|
17 | |
---|
18 | double normcoef ( const epdf *ep, const vec &xb, const vec &yb, |
---|
19 | int xn, int yn ) { |
---|
20 | mat Pdf ( xn + 1, yn + 1 ); |
---|
21 | vec rgr ( 2 ); |
---|
22 | |
---|
23 | double xstep = ( xb ( 1 ) - xb ( 0 ) ) / xn; |
---|
24 | double ystep = ( yb ( 1 ) - yb ( 0 ) ) / yn; |
---|
25 | |
---|
26 | double x = xb ( 0 ); |
---|
27 | for ( int i = 0; i <= xn; x += xstep, i++ ) { |
---|
28 | rgr ( 0 ) = x; |
---|
29 | double y = yb ( 0 ); |
---|
30 | for ( int j = 0; j <= yn; y += ystep, j++ ) { |
---|
31 | rgr ( 1 ) = y; |
---|
32 | Pdf ( i, j ) = exp ( ep->evallog ( rgr ) ); |
---|
33 | } |
---|
34 | } |
---|
35 | |
---|
36 | return sumsum ( Pdf ) * xstep * ystep; |
---|
37 | } |
---|
38 | |
---|
39 | vec num_mean2 ( const epdf *ep, const vec &xb, const vec &yb, |
---|
40 | int xn, int yn ) { |
---|
41 | mat Pdf ( xn + 1, yn + 1 ); |
---|
42 | vec rgr ( 2 ); |
---|
43 | |
---|
44 | double xstep = ( xb ( 1 ) - xb ( 0 ) ) / xn; |
---|
45 | double ystep = ( yb ( 1 ) - yb ( 0 ) ) / yn; |
---|
46 | |
---|
47 | vec Mu ( xn + 1 ); |
---|
48 | vec Si ( yn + 1 ); |
---|
49 | |
---|
50 | double x = xb ( 0 ); |
---|
51 | for ( int i = 0; i <= xn; x += xstep, i++ ) { |
---|
52 | Mu ( i ) = x; |
---|
53 | rgr ( 0 ) = x; |
---|
54 | double y = yb ( 0 ); |
---|
55 | for ( int j = 0; j <= yn; y += ystep, j++ ) { |
---|
56 | Si ( j ) = y; |
---|
57 | rgr ( 1 ) = y; |
---|
58 | Pdf ( i, j ) = exp ( ep->evallog ( rgr ) ); |
---|
59 | } |
---|
60 | } |
---|
61 | |
---|
62 | vec fm = sum ( Pdf, 2 ); |
---|
63 | double sfm = sum ( fm ); |
---|
64 | vec fs = sum ( Pdf, 1 ); |
---|
65 | double sfs = sum ( fs ); |
---|
66 | double vi0 = Mu * fm / sfm; |
---|
67 | double vi1 = Si * fs / sfs; |
---|
68 | return vec_2 ( vi0, vi1 ); |
---|
69 | } |
---|
70 | |
---|
71 | } |
---|