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 (ENormMerger_test){ |
---|
11 | ENormMerger<ldmat> m1; |
---|
12 | m1.sources.set_length(2); |
---|
13 | m1.sources(0) = new enorm<ldmat>(vec_2(1.0, 1.0), mat_2x2(1.0, 0.0, 0.0, 2.0)); |
---|
14 | m1.sources(1) = new enorm<ldmat>(vec_2(2.0, 2.0), mat_2x2(2.0, 1.0, 1.0, 2.0)); |
---|
15 | m1.validate(); |
---|
16 | m1.merge(); |
---|
17 | |
---|
18 | cout << "mean: " << m1.merger().mean() << endl; |
---|
19 | cout << "var: " << m1.merger().covariance() << endl; |
---|
20 | } |
---|
21 | |
---|
22 | TEST ( merger_base_test ) { |
---|
23 | RV x ( "{xmerger }", "1" ); |
---|
24 | |
---|
25 | RV z ( x ); |
---|
26 | |
---|
27 | enorm_fsqmat_ptr f1; |
---|
28 | f1->set_rv ( x ); |
---|
29 | enorm_fsqmat_ptr f2; |
---|
30 | f2->set_rv ( x ); |
---|
31 | |
---|
32 | f1->set_parameters ( "-5", mat ( "2" ) ); |
---|
33 | f2->set_parameters ( "5", mat ( "10" ) ); |
---|
34 | |
---|
35 | pdf_array A ( 2 ); |
---|
36 | A ( 0 ) = f1; |
---|
37 | A ( 1 ) = f2; |
---|
38 | |
---|
39 | int Npoints = 100; |
---|
40 | mat x_grid ( 1, Npoints ); |
---|
41 | x_grid.set_row ( 0, linspace ( -10.0, 10.0 ) ); |
---|
42 | |
---|
43 | vec l_f1 = f1->evallog_mat ( x_grid ); |
---|
44 | vec l_f2 = f2->evallog_mat ( x_grid ); |
---|
45 | mat lW ( 2, Npoints ); |
---|
46 | lW.set_row ( 0, l_f1 ); |
---|
47 | lW.set_row ( 1, l_f2 ); |
---|
48 | |
---|
49 | MergerDiscrete M ( A ); |
---|
50 | enorm<fsqmat> g0; |
---|
51 | g0.set_rv ( x ); |
---|
52 | g0.set_parameters ( vec ( "0.0" ), mat ( "100.0" ) ); |
---|
53 | |
---|
54 | M.set_method ( LOGNORMAL, 1.2 ); |
---|
55 | M.set_support ( g0, 200 ); |
---|
56 | M.merge (); |
---|
57 | |
---|
58 | vec m2 = M.merge_points ( lW ); |
---|
59 | |
---|
60 | vec exp_f1 ( "-7.51551 -7.02066 " |
---|
61 | "-6.54622 -6.09219 " |
---|
62 | "-5.65856 -5.24534 " |
---|
63 | "-4.85252 -4.48011 -4.1281 " |
---|
64 | "-3.7965 -3.48531 -3.19452 " |
---|
65 | "-2.92414 -2.67417 -2.4446 -2.23544 -2.04668 " |
---|
66 | "-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 " |
---|
67 | "-2.13851 -2.33747 -2.55683 -2.79661 " |
---|
68 | "-3.05678 -3.33737 -3.63836 -3.95975 " |
---|
69 | "-4.30155 -4.66376 " |
---|
70 | "-5.04638 -5.4494 -5.87282 " |
---|
71 | "-6.31665 -6.78089 " |
---|
72 | "-7.26554 -7.77059 " |
---|
73 | "-8.29604 -8.84191 " |
---|
74 | "-9.40818 -9.99485 " |
---|
75 | "-10.6019 " |
---|
76 | "-11.2294 -11.8773 " |
---|
77 | "-12.5456 " |
---|
78 | "-13.2343 -13.9434 " |
---|
79 | "-14.6729 " |
---|
80 | "-15.4229 " |
---|
81 | "-16.1932 -16.9839 " |
---|
82 | "-17.7951 " |
---|
83 | "-18.6266 " |
---|
84 | "-19.4786 " |
---|
85 | "-20.3509 " |
---|
86 | "-21.2437 " |
---|
87 | "-22.1569 " |
---|
88 | "-23.0905 " |
---|
89 | "-24.0444 " |
---|
90 | "-25.0188 " |
---|
91 | "-26.0136 " |
---|
92 | "-27.0288 " |
---|
93 | "-28.0644 " |
---|
94 | "-29.1205 " |
---|
95 | "-30.1969 " |
---|
96 | "-31.2937 " |
---|
97 | "-32.4109 " |
---|
98 | "-33.5486 " |
---|
99 | "-34.7066 " |
---|
100 | "-35.8851 " |
---|
101 | "-37.0839 " |
---|
102 | "-38.3032 " |
---|
103 | "-39.5429 " |
---|
104 | "-40.8029 " |
---|
105 | "-42.0834 " |
---|
106 | "-43.3843 " |
---|
107 | "-44.7056 " |
---|
108 | "-46.0473 " |
---|
109 | "-47.4094 " |
---|
110 | "-48.7919 " |
---|
111 | "-50.1948 " |
---|
112 | "-51.6182 " |
---|
113 | "-53.0619 " |
---|
114 | "-54.526 " |
---|
115 | "-56.0106 " |
---|
116 | "-57.5155" ); |
---|
117 | CHECK_CLOSE ( exp_f1, l_f1, epsilon ); |
---|
118 | |
---|
119 | vec exp_f2 ( "-13.3202 -13.0192 " |
---|
120 | "-12.7223 -12.4295 -12.1408 " |
---|
121 | "-11.8561 -11.5755 -11.299 -11.0266 " |
---|
122 | "-10.7582 -10.494 -10.2338 " |
---|
123 | "-9.97772 -9.7257 -9.47777 -9.23391 " |
---|
124 | "-8.99414 -8.75845 -8.52684 -8.29931 -8.07587 " |
---|
125 | "-7.8565 -7.64122 -7.43002 -7.22289 -7.01985 " |
---|
126 | "-6.82089 -6.62602 -6.43522 -6.2485 -6.06587 " |
---|
127 | "-5.88732 -5.71284 -5.54245 -5.37614 -5.21392 -5.05577 " |
---|
128 | "-4.9017 -4.75172 -4.60581 -4.46399 -4.32625 -4.19259 -4.06301 " |
---|
129 | "-3.93752 -3.8161 -3.69876 -3.58551 -3.47634 -3.37125 -3.27024 -3.17331 -3.08046 " |
---|
130 | "-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 " |
---|
131 | "-3.03557 -3.12637 -3.22126 -3.32023" ); |
---|
132 | CHECK_CLOSE ( exp_f2, l_f2, epsilon ); |
---|
133 | |
---|
134 | vec exp_m2 ( "-7.95304 -7.47281 -7.01175 " |
---|
135 | "-6.56987 -6.14716 " |
---|
136 | "-5.74362 -5.35927 " |
---|
137 | "-4.99408 -4.64808 -4.32125 -4.01359 " |
---|
138 | "-3.72511 -3.45581 -3.20568 " |
---|
139 | "-2.97473 -2.76295 -2.57035 -2.39692 -2.24267 -2.1076 " |
---|
140 | "-1.9917 -1.89498 -1.81743 -1.75905 -1.71986 -1.69984 -1.69899 -1.71732 -1.75483 -1.81151 -1.88736 -1.9824 " |
---|
141 | "-2.0966 -2.22999 -2.38255 -2.55428 -2.74519 -2.95528 " |
---|
142 | "-3.18454 -3.43298 -3.70059 -3.98738 " |
---|
143 | "-4.2008 -4.10829 -4.0211 " |
---|
144 | "-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 " |
---|
145 | "-4.03533 -4.12342 -4.21682 -4.31553 -4.41955 -4.52889 -4.64353 -4.76349 -4.88876 " |
---|
146 | "-5.01934 -5.15524 -5.29644 -5.44296 -5.59479 -5.75193 -5.91438 " |
---|
147 | "-6.08214 -6.25522 -6.4336 -6.6173 -6.80631 " |
---|
148 | "-7.00064 -7.20027 -7.40522" ); |
---|
149 | CHECK_CLOSE ( exp_m2, m2, epsilon ); |
---|
150 | } |
---|
151 | |
---|
152 | TEST ( merger_base_sources_test ) { |
---|
153 | UIFile in ( "merger.cfg" ); |
---|
154 | |
---|
155 | shared_ptr<MergerDiscrete> mb = |
---|
156 | UI::build<MergerDiscrete> ( in, "Merger", UI::compulsory ); |
---|
157 | |
---|
158 | pdf_array sources; |
---|
159 | UI::get ( sources, in, "Sources", UI::compulsory ); |
---|
160 | mb->set_sources ( sources ); |
---|
161 | |
---|
162 | shared_ptr<rectangular_support> support = |
---|
163 | UI::build<rectangular_support> ( in, "Support", UI::compulsory ); |
---|
164 | mb->set_support ( *support ); |
---|
165 | |
---|
166 | mb->merge(); |
---|
167 | vec m = mb->merger().mean(); |
---|
168 | CHECK_EQUAL ( 2, m.size() ); |
---|
169 | } |
---|
170 | |
---|
171 | TEST ( merger_base_sources_error_test ) { |
---|
172 | UIFile in ( "merger_error.cfg" ); |
---|
173 | |
---|
174 | pdf_array sources; |
---|
175 | try { |
---|
176 | UI::get ( sources, in, "Sources", UI::compulsory ); |
---|
177 | CHECK ( false ); |
---|
178 | } catch ( UISettingException &exc ) { |
---|
179 | CHECK ( exc.what() ); |
---|
180 | } |
---|
181 | } |
---|