1 | |
---|
2 | #include "stat/exp_family.h" |
---|
3 | #include "stat/merger.h" |
---|
4 | |
---|
5 | using namespace bdm; |
---|
6 | |
---|
7 | using namespace bdm; |
---|
8 | |
---|
9 | //These lines are needed for use of cout and endl |
---|
10 | using std::cout; |
---|
11 | using std::endl; |
---|
12 | |
---|
13 | int main() { |
---|
14 | |
---|
15 | RNG_randomize(); |
---|
16 | |
---|
17 | RV x ( "{x }", "1" ); |
---|
18 | RV y ( "{y }", "1" ); |
---|
19 | |
---|
20 | RV xy = x; |
---|
21 | xy.add ( y ); |
---|
22 | |
---|
23 | enorm<fsqmat> f1; |
---|
24 | f1.set_rv ( xy ); |
---|
25 | enorm<fsqmat> f2; |
---|
26 | f2.set_rv ( xy ); |
---|
27 | enorm<fsqmat> f3; |
---|
28 | f3.set_rv ( y ); |
---|
29 | |
---|
30 | f1.set_parameters ( "4 3", mat ( "0.4 0.3; 0.3 0.4" ) ); |
---|
31 | f2.set_parameters ( "1 3", mat ( "0.3 -0.2; -0.2 0.3" ) ); |
---|
32 | f3.set_parameters ( "2", mat ( "0.4" ) ); |
---|
33 | |
---|
34 | Array<mpdf* > A ( 3 ); |
---|
35 | mepdf A1 ( &f1 ); |
---|
36 | mepdf A2 ( &f2 ); |
---|
37 | mepdf A3 ( &f3 ); |
---|
38 | A ( 0 ) = &A1; |
---|
39 | A ( 1 ) = &A2; |
---|
40 | A ( 2 ) = &A3; |
---|
41 | |
---|
42 | int Npoints = 100; |
---|
43 | mat x_grid ( 1, Npoints ); |
---|
44 | x_grid.set_row ( 0, linspace ( -2.0, 4.0, Npoints ) ); |
---|
45 | mat y_grid ( 1, Npoints ); |
---|
46 | y_grid.set_row ( 0, linspace ( -2.0, 4.0, Npoints ) ); |
---|
47 | |
---|
48 | mat Grid ( 2, Npoints*Npoints ); |
---|
49 | Grid.set_submatrix ( 0, 0, kron ( x_grid, ones ( 1, Npoints ) ) ); |
---|
50 | Grid.set_submatrix ( 1, 0, kron ( ones ( 1, Npoints ), y_grid ) ); |
---|
51 | |
---|
52 | merger_mix M ( A ); |
---|
53 | enorm<fsqmat> g0; |
---|
54 | g0.set_rv ( xy ); |
---|
55 | g0.set_parameters ( vec ( "4 4" ), mat ( "1 0; 0 1" ) ); |
---|
56 | |
---|
57 | M.set_parameters ( 5 ); |
---|
58 | M.set_method ( LOGNORMAL, 1.2 ); |
---|
59 | M.set_support ( g0, 400 ); |
---|
60 | M.merge(); |
---|
61 | |
---|
62 | MixEF &MM = M._Mix(); |
---|
63 | epdf* MP = MM.epredictor();//xy |
---|
64 | |
---|
65 | vec Res1 = M.evallog_m ( Grid ); |
---|
66 | mat Res2 = ( ( emix* ) MP )->evallog_M ( Grid ); |
---|
67 | |
---|
68 | it_file it ( "merger_iter_test.it" ); |
---|
69 | it << Name ( "Npoints" ) << Npoints; |
---|
70 | it << Name ( "Grid" ) << Grid; |
---|
71 | it << Name ( "Res1" ) << Res1; |
---|
72 | it << Name ( "Res2" ) << Res2; |
---|
73 | } |
---|