1 | #include "stat/exp_family.h" |
---|
2 | #include "stat/merger.h" |
---|
3 | #include "mat_checks.h" |
---|
4 | #include "UnitTest++.h" |
---|
5 | |
---|
6 | const double epsilon = 0.0001; |
---|
7 | |
---|
8 | using namespace bdm; |
---|
9 | |
---|
10 | TEST ( test_merger_basic ) { |
---|
11 | RV x ( "{xmerger }", "1" ); |
---|
12 | |
---|
13 | RV z ( x ); |
---|
14 | |
---|
15 | enorm_fsqmat_ptr f1; |
---|
16 | f1->set_rv ( x ); |
---|
17 | enorm_fsqmat_ptr f2; |
---|
18 | f2->set_rv ( x ); |
---|
19 | |
---|
20 | f1->set_parameters ( "-5", mat ( "2" ) ); |
---|
21 | f2->set_parameters ( "5", mat ( "10" ) ); |
---|
22 | |
---|
23 | mpdf_array A ( 2 ); |
---|
24 | A ( 0 ) = new mepdf ( f1 ); |
---|
25 | A ( 1 ) = new mepdf ( f2 ); |
---|
26 | |
---|
27 | int Npoints = 100; |
---|
28 | mat x_grid ( 1, Npoints ); |
---|
29 | x_grid.set_row ( 0, linspace ( -10.0, 10.0 ) ); |
---|
30 | |
---|
31 | vec l_f1 = f1->evallog_m ( x_grid ); |
---|
32 | vec l_f2 = f2->evallog_m ( x_grid ); |
---|
33 | mat lW ( 2, Npoints ); |
---|
34 | lW.set_row ( 0, l_f1 ); |
---|
35 | lW.set_row ( 1, l_f2 ); |
---|
36 | |
---|
37 | merger_base M ( A ); |
---|
38 | enorm<fsqmat> g0; |
---|
39 | g0.set_rv ( x ); |
---|
40 | g0.set_parameters ( vec ( "0.0" ), mat ( "100.0" ) ); |
---|
41 | |
---|
42 | M.set_method ( LOGNORMAL, 1.2 ); |
---|
43 | M.set_support ( g0, 200 ); |
---|
44 | M.merge (); |
---|
45 | |
---|
46 | vec m2 = M.merge_points ( lW ); |
---|
47 | |
---|
48 | vec exp_f1 ( "-7.51551 -7.02066 " |
---|
49 | "-6.54622 -6.09219 " |
---|
50 | "-5.65856 -5.24534 " |
---|
51 | "-4.85252 -4.48011 -4.1281 " |
---|
52 | "-3.7965 -3.48531 -3.19452 " |
---|
53 | "-2.92414 -2.67417 -2.4446 -2.23544 -2.04668 " |
---|
54 | "-1.87833 -1.73039 -1.60285 -1.49572 -1.40899 -1.34267 -1.29676 -1.27125 -1.26615 -1.28145 -1.31717 -1.37328 -1.4498 -1.54673 -1.66407 -1.80181 -1.95996 " |
---|
55 | "-2.13851 -2.33747 -2.55683 -2.79661 " |
---|
56 | "-3.05678 -3.33737 -3.63836 -3.95975 " |
---|
57 | "-4.30155 -4.66376 " |
---|
58 | "-5.04638 -5.4494 -5.87282 " |
---|
59 | "-6.31665 -6.78089 " |
---|
60 | "-7.26554 -7.77059 " |
---|
61 | "-8.29604 -8.84191 " |
---|
62 | "-9.40818 -9.99485 " |
---|
63 | "-10.6019 " |
---|
64 | "-11.2294 -11.8773 " |
---|
65 | "-12.5456 " |
---|
66 | "-13.2343 -13.9434 " |
---|
67 | "-14.6729 " |
---|
68 | "-15.4229 " |
---|
69 | "-16.1932 -16.9839 " |
---|
70 | "-17.7951 " |
---|
71 | "-18.6266 " |
---|
72 | "-19.4786 " |
---|
73 | "-20.3509 " |
---|
74 | "-21.2437 " |
---|
75 | "-22.1569 " |
---|
76 | "-23.0905 " |
---|
77 | "-24.0444 " |
---|
78 | "-25.0188 " |
---|
79 | "-26.0136 " |
---|
80 | "-27.0288 " |
---|
81 | "-28.0644 " |
---|
82 | "-29.1205 " |
---|
83 | "-30.1969 " |
---|
84 | "-31.2937 " |
---|
85 | "-32.4109 " |
---|
86 | "-33.5486 " |
---|
87 | "-34.7066 " |
---|
88 | "-35.8851 " |
---|
89 | "-37.0839 " |
---|
90 | "-38.3032 " |
---|
91 | "-39.5429 " |
---|
92 | "-40.8029 " |
---|
93 | "-42.0834 " |
---|
94 | "-43.3843 " |
---|
95 | "-44.7056 " |
---|
96 | "-46.0473 " |
---|
97 | "-47.4094 " |
---|
98 | "-48.7919 " |
---|
99 | "-50.1948 " |
---|
100 | "-51.6182 " |
---|
101 | "-53.0619 " |
---|
102 | "-54.526 " |
---|
103 | "-56.0106 " |
---|
104 | "-57.5155" ); |
---|
105 | CHECK_CLOSE(exp_f1, l_f1, epsilon); |
---|
106 | |
---|
107 | vec exp_f2 ( "-13.3202 -13.0192 " |
---|
108 | "-12.7223 -12.4295 -12.1408 " |
---|
109 | "-11.8561 -11.5755 -11.299 -11.0266 " |
---|
110 | "-10.7582 -10.494 -10.2338 " |
---|
111 | "-9.97772 -9.7257 -9.47777 -9.23391 " |
---|
112 | "-8.99414 -8.75845 -8.52684 -8.29931 -8.07587 " |
---|
113 | "-7.8565 -7.64122 -7.43002 -7.22289 -7.01985 " |
---|
114 | "-6.82089 -6.62602 -6.43522 -6.2485 -6.06587 " |
---|
115 | "-5.88732 -5.71284 -5.54245 -5.37614 -5.21392 -5.05577 " |
---|
116 | "-4.9017 -4.75172 -4.60581 -4.46399 -4.32625 -4.19259 -4.06301 " |
---|
117 | "-3.93752 -3.8161 -3.69876 -3.58551 -3.47634 -3.37125 -3.27024 -3.17331 -3.08046 " |
---|
118 | "-2.99169 -2.90701 -2.8264 -2.74988 -2.67744 -2.60908 -2.5448 -2.4846 -2.42849 -2.37645 -2.3285 -2.28462 -2.24483 -2.20912 -2.17749 -2.14994 -2.12648 -2.10709 -2.09179 -2.08056 -2.07342 -2.07036 -2.07138 -2.07648 -2.08566 -2.09893 -2.11627 -2.1377 -2.16321 -2.1928 -2.22647 -2.26422 -2.30605 -2.35196 -2.40196 -2.45603 -2.51419 -2.57643 -2.64275 -2.71315 -2.78763 -2.8662 -2.94884 " |
---|
119 | "-3.03557 -3.12637 -3.22126 -3.32023" ); |
---|
120 | CHECK_CLOSE(exp_f2, l_f2, epsilon); |
---|
121 | |
---|
122 | vec exp_m2 ( "-7.95304 -7.47281 -7.01175 " |
---|
123 | "-6.56987 -6.14716 " |
---|
124 | "-5.74362 -5.35927 " |
---|
125 | "-4.99408 -4.64808 -4.32125 -4.01359 " |
---|
126 | "-3.72511 -3.45581 -3.20568 " |
---|
127 | "-2.97473 -2.76295 -2.57035 -2.39692 -2.24267 -2.1076 " |
---|
128 | "-1.9917 -1.89498 -1.81743 -1.75905 -1.71986 -1.69984 -1.69899 -1.71732 -1.75483 -1.81151 -1.88736 -1.9824 " |
---|
129 | "-2.0966 -2.22999 -2.38255 -2.55428 -2.74519 -2.95528 " |
---|
130 | "-3.18454 -3.43298 -3.70059 -3.98738 " |
---|
131 | "-4.2008 -4.10829 -4.0211 " |
---|
132 | "-3.93921 -3.86263 -3.79137 -3.72542 -3.66478 -3.60945 -3.55944 -3.51473 -3.47534 -3.44126 -3.41249 -3.38903 -3.37088 -3.35805 -3.35053 -3.34831 -3.35141 -3.35983 -3.37355 -3.39259 -3.41693 -3.44659 -3.48156 -3.52185 -3.56744 -3.61835 -3.67457 -3.73609 -3.80294 -3.87509 -3.95255 " |
---|
133 | "-4.03533 -4.12342 -4.21682 -4.31553 -4.41955 -4.52889 -4.64353 -4.76349 -4.88876 " |
---|
134 | "-5.01934 -5.15524 -5.29644 -5.44296 -5.59479 -5.75193 -5.91438 " |
---|
135 | "-6.08214 -6.25522 -6.4336 -6.6173 -6.80631 " |
---|
136 | "-7.00064 -7.20027 -7.40522" ); |
---|
137 | CHECK_CLOSE(exp_m2, m2, epsilon); |
---|
138 | } |
---|