]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /* test_hyperexponential_distribution.ipp |
2 | * | |
3 | * Copyright 2014 Marco Guazzone (marco.guazzone@gmail.com) | |
4 | * Distributed under the Boost Software License, Version 1.0. (See | |
5 | * accompanying file LICENSE_1_0.txt or copy at | |
6 | * http://www.boost.org/LICENSE_1_0.txt) | |
7 | * | |
8 | */ | |
9 | ||
10 | ||
11 | #include <boost/math/tools/precision.hpp> | |
12 | #include <boost/random/hyperexponential_distribution.hpp> | |
13 | #include <boost/random/linear_congruential.hpp> | |
14 | #include <boost/random/lagged_fibonacci.hpp> | |
15 | #include <boost/assign/list_of.hpp> | |
16 | #include <limits> | |
17 | #include <sstream> | |
18 | #include <vector> | |
19 | ||
20 | #include "concepts.hpp" | |
21 | ||
22 | #define BOOST_TEST_MAIN | |
23 | #include <boost/test/unit_test.hpp> | |
24 | ||
25 | ||
26 | #define BOOST_RANDOM_HYPEREXP_CHECK_CLOSE_COLLECTIONS(T, actual, expected, tol)\ | |
27 | do { \ | |
28 | std::vector<T> x = (actual); \ | |
29 | std::vector<T> y = (expected); \ | |
30 | BOOST_CHECK_EQUAL( x.size(), y.size() ); \ | |
31 | const std::size_t n = x.size(); \ | |
32 | for (std::size_t i = 0; i < n; ++i) \ | |
33 | { \ | |
34 | BOOST_CHECK_CLOSE( x[i], y[i], tol ); \ | |
35 | } \ | |
36 | } while(false) | |
37 | ||
38 | ||
39 | ||
40 | namespace /*<unnamed>*/ { namespace detail { | |
41 | ||
42 | template <typename RealT> | |
43 | RealT make_tolerance() | |
44 | { | |
45 | // Tolerance is 100eps expressed as a percentage (as required by Boost.Build): | |
46 | return boost::math::tools::epsilon<RealT>() * 100 * 100; | |
47 | } | |
48 | ||
49 | }} // Namespace <unnamed>::detail | |
50 | ||
51 | ||
52 | BOOST_CONCEPT_ASSERT((boost::random::test::RandomNumberDistribution< boost::random::hyperexponential_distribution<> >)); | |
53 | ||
54 | BOOST_AUTO_TEST_CASE( test_constructors ) | |
55 | { | |
56 | const double tol = detail::make_tolerance<double>(); | |
57 | ||
58 | // Test default ctor | |
59 | boost::random::hyperexponential_distribution<> dist; | |
60 | BOOST_CHECK_EQUAL(dist.num_phases(), 1u); | |
61 | BOOST_RANDOM_HYPEREXP_CHECK_CLOSE_COLLECTIONS(double, dist.probabilities(), boost::assign::list_of(1.0), tol); | |
62 | BOOST_RANDOM_HYPEREXP_CHECK_CLOSE_COLLECTIONS(double, dist.rates(), boost::assign::list_of(1.0), tol); | |
63 | ||
11fdf7f2 | 64 | #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) && !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) |
7c673cae FG |
65 | // Test ctor from initializer_list with probabilities and rates |
66 | boost::random::hyperexponential_distribution<> dist_il_p_r = {{1, 2, 3, 4 }, {1, 2, 3, 4}}; | |
67 | BOOST_CHECK_EQUAL(dist_il_p_r.num_phases(), 4u); | |
68 | BOOST_RANDOM_HYPEREXP_CHECK_CLOSE_COLLECTIONS(double, dist_il_p_r.probabilities(), boost::assign::list_of(.1)(.2)(.3)(.4), tol); | |
69 | BOOST_RANDOM_HYPEREXP_CHECK_CLOSE_COLLECTIONS(double, dist_il_p_r.rates(), boost::assign::list_of(1.)(2.)(3.)(4.), tol); | |
70 | ||
71 | // Test ctor from initializer_list with rates | |
72 | boost::random::hyperexponential_distribution<> dist_il_r = {{1, 2, 3, 4}}; | |
73 | BOOST_CHECK_EQUAL(dist_il_r.num_phases(), 4u); | |
74 | BOOST_RANDOM_HYPEREXP_CHECK_CLOSE_COLLECTIONS(double, dist_il_r.probabilities(), boost::assign::list_of(.25)(.25)(.25)(.25), tol); | |
75 | BOOST_RANDOM_HYPEREXP_CHECK_CLOSE_COLLECTIONS(double, dist_il_r.rates(), boost::assign::list_of(1.)(2.)(3.)(4.), tol); | |
76 | #endif | |
77 | ||
78 | const std::vector<double> probs = boost::assign::list_of(0.1)(0.2)(0.3)(0.4); | |
79 | const std::vector<double> rates = boost::assign::list_of(1.0)(2.0)(3.0)(4.0); | |
80 | ||
81 | // Test ctor from range | |
82 | boost::random::hyperexponential_distribution<> dist_r(probs, rates); | |
83 | BOOST_CHECK_EQUAL(dist_r.num_phases(), 4u); | |
84 | BOOST_RANDOM_HYPEREXP_CHECK_CLOSE_COLLECTIONS(double, dist_r.probabilities(), probs, tol); | |
85 | BOOST_RANDOM_HYPEREXP_CHECK_CLOSE_COLLECTIONS(double, dist_r.rates(), rates, tol); | |
86 | ||
87 | // Test ctor from iterators | |
88 | boost::random::hyperexponential_distribution<> dist_it(probs.begin(), probs.end(), rates.begin(), rates.end()); | |
89 | BOOST_CHECK_EQUAL(dist_it.num_phases(), 4u); | |
90 | BOOST_RANDOM_HYPEREXP_CHECK_CLOSE_COLLECTIONS(double, dist_it.probabilities(), probs, tol); | |
91 | BOOST_RANDOM_HYPEREXP_CHECK_CLOSE_COLLECTIONS(double, dist_it.rates(), rates, tol); | |
92 | ||
93 | // Test ctor from rate iterators | |
94 | boost::random::hyperexponential_distribution<> dist_r_it(rates.begin(), rates.end()); | |
95 | BOOST_CHECK_EQUAL(dist_r_it.num_phases(), 4u); | |
96 | BOOST_RANDOM_HYPEREXP_CHECK_CLOSE_COLLECTIONS(double, dist_r_it.probabilities(), boost::assign::list_of(.25)(.25)(.25)(.25), tol); | |
97 | BOOST_RANDOM_HYPEREXP_CHECK_CLOSE_COLLECTIONS(double, dist_r_it.rates(), rates, tol); | |
98 | ||
99 | // Test ctor from rate iterators #2 | |
100 | { | |
101 | const double rates2[] = {1.0,2.0,3.0,4.0}; | |
102 | boost::random::hyperexponential_distribution<> dist_r_it(rates2, rates2+4); | |
103 | BOOST_CHECK_EQUAL(dist_r_it.num_phases(), 4u); | |
104 | BOOST_RANDOM_HYPEREXP_CHECK_CLOSE_COLLECTIONS(double, dist_r_it.probabilities(), boost::assign::list_of(.25)(.25)(.25)(.25), tol); | |
105 | BOOST_RANDOM_HYPEREXP_CHECK_CLOSE_COLLECTIONS(double, dist_r_it.rates(), std::vector<double>(rates2, rates2+4), tol); | |
106 | } | |
107 | ||
108 | // Test ctor from rate range | |
109 | boost::random::hyperexponential_distribution<> dist_r_r(rates); | |
110 | BOOST_CHECK_EQUAL(dist_r_r.num_phases(), 4u); | |
111 | BOOST_RANDOM_HYPEREXP_CHECK_CLOSE_COLLECTIONS(double, dist_r_r.probabilities(), boost::assign::list_of(.25)(.25)(.25)(.25), tol); | |
112 | BOOST_RANDOM_HYPEREXP_CHECK_CLOSE_COLLECTIONS(double, dist_r_r.rates(), rates, tol); | |
113 | ||
114 | // Test copy ctor | |
115 | boost::random::hyperexponential_distribution<> cp(dist); | |
116 | BOOST_CHECK_EQUAL(cp, dist); | |
117 | boost::random::hyperexponential_distribution<> cp_r(dist_r); | |
118 | BOOST_CHECK_EQUAL(cp_r, dist_r); | |
119 | } | |
120 | ||
121 | BOOST_AUTO_TEST_CASE( test_param ) | |
122 | { | |
123 | const double tol = detail::make_tolerance<double>(); | |
124 | ||
125 | const std::vector<double> probs = boost::assign::list_of(0.1)(0.2)(0.3)(0.4); | |
126 | const std::vector<double> rates = boost::assign::list_of(1.0)(2.0)(3.0)(4.0); | |
127 | ||
128 | // Test param getter | |
129 | boost::random::hyperexponential_distribution<> dist(probs, rates); | |
130 | boost::random::hyperexponential_distribution<>::param_type param = dist.param(); | |
131 | BOOST_RANDOM_HYPEREXP_CHECK_CLOSE_COLLECTIONS(double, dist.probabilities(), param.probabilities(), tol); | |
132 | BOOST_RANDOM_HYPEREXP_CHECK_CLOSE_COLLECTIONS(double, dist.rates(), param.rates(), tol); | |
133 | ||
134 | // Test ctor from param | |
135 | boost::random::hyperexponential_distribution<> cp1(param); | |
136 | BOOST_CHECK_EQUAL(cp1, dist); | |
137 | ||
138 | // Test param setter | |
139 | boost::random::hyperexponential_distribution<> cp2; | |
140 | cp2.param(param); | |
141 | BOOST_CHECK_EQUAL(cp2, dist); | |
142 | ||
143 | // Test param constructors & operators | |
144 | boost::random::hyperexponential_distribution<>::param_type param_copy = param; | |
145 | BOOST_CHECK_EQUAL(param, param_copy); | |
146 | BOOST_CHECK(param == param_copy); | |
147 | BOOST_CHECK(!(param != param_copy)); | |
148 | boost::random::hyperexponential_distribution<>::param_type param_default; | |
149 | BOOST_RANDOM_HYPEREXP_CHECK_CLOSE_COLLECTIONS(double, param_default.probabilities(), boost::assign::list_of(1.0), tol); | |
150 | BOOST_RANDOM_HYPEREXP_CHECK_CLOSE_COLLECTIONS(double, param_default.rates(), boost::assign::list_of(1.0), tol); | |
151 | BOOST_CHECK(param != param_default); | |
152 | BOOST_CHECK(!(param == param_default)); | |
11fdf7f2 | 153 | #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) && !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) |
7c673cae FG |
154 | boost::random::hyperexponential_distribution<>::param_type param_il = {{1, 2, 3, 4 }, {1, 2, 3, 4}}; |
155 | BOOST_RANDOM_HYPEREXP_CHECK_CLOSE_COLLECTIONS(double, param_il.probabilities(), boost::assign::list_of(.1)(.2)(.3)(.4), tol); | |
156 | BOOST_RANDOM_HYPEREXP_CHECK_CLOSE_COLLECTIONS(double, param_il.rates(), boost::assign::list_of(1.)(2.)(3.)(4.), tol); | |
157 | #endif | |
158 | boost::random::hyperexponential_distribution<>::param_type param_r(probs, rates); | |
159 | BOOST_RANDOM_HYPEREXP_CHECK_CLOSE_COLLECTIONS(double, param_r.probabilities(), probs, tol); | |
160 | BOOST_RANDOM_HYPEREXP_CHECK_CLOSE_COLLECTIONS(double, param_r.rates(), rates, tol); | |
161 | ||
162 | boost::random::hyperexponential_distribution<>::param_type param_it(probs.begin(), probs.end(), rates.begin(), rates.end()); | |
163 | BOOST_RANDOM_HYPEREXP_CHECK_CLOSE_COLLECTIONS(double, param_it.probabilities(), probs, tol); | |
164 | BOOST_RANDOM_HYPEREXP_CHECK_CLOSE_COLLECTIONS(double, param_it.rates(), rates, tol); | |
165 | } | |
166 | ||
167 | BOOST_AUTO_TEST_CASE( test_min_max ) | |
168 | { | |
169 | //const double tol = detail::make_tolerance<double>(); | |
170 | ||
171 | const std::vector<double> probs = boost::assign::list_of(0.1)(0.2)(0.3)(0.4); | |
172 | const std::vector<double> rates = boost::assign::list_of(1.0)(2.0)(3.0)(4.0); | |
173 | ||
174 | boost::random::hyperexponential_distribution<> dist; | |
175 | BOOST_CHECK_EQUAL((dist.min)(), 0); | |
176 | BOOST_CHECK_EQUAL((dist.max)(), (std::numeric_limits<double>::infinity)()); | |
177 | ||
178 | boost::random::hyperexponential_distribution<> dist_r(probs, rates); | |
179 | BOOST_CHECK_EQUAL((dist_r.min)(), 0); | |
180 | BOOST_CHECK_EQUAL((dist_r.max)(), (std::numeric_limits<double>::infinity)()); | |
181 | } | |
182 | ||
183 | BOOST_AUTO_TEST_CASE(test_comparison) | |
184 | { | |
185 | //const double tol = detail::make_tolerance<double>(); | |
186 | ||
187 | const std::vector<double> probs = boost::assign::list_of(0.1)(0.2)(0.3)(0.4); | |
188 | const std::vector<double> rates = boost::assign::list_of(1.0)(2.0)(3.0)(4.0); | |
189 | ||
190 | boost::random::hyperexponential_distribution<> dist; | |
191 | boost::random::hyperexponential_distribution<> dist_copy(dist); | |
192 | ||
193 | boost::random::hyperexponential_distribution<> dist_r(probs, rates); | |
194 | boost::random::hyperexponential_distribution<> dist_r_copy(dist_r); | |
195 | ||
196 | BOOST_CHECK(dist == dist_copy); | |
197 | BOOST_CHECK(!(dist != dist_copy)); | |
198 | BOOST_CHECK(dist_r == dist_r_copy); | |
199 | BOOST_CHECK(!(dist_r != dist_r_copy)); | |
200 | BOOST_CHECK(dist != dist_r); | |
201 | BOOST_CHECK(!(dist == dist_r)); | |
202 | } | |
203 | ||
204 | BOOST_AUTO_TEST_CASE( test_streaming ) | |
205 | { | |
206 | //const double tol = detail::make_tolerance<double>(); | |
207 | ||
208 | const std::vector<double> probs = boost::assign::list_of(0.1)(0.2)(0.3)(0.4); | |
209 | const std::vector<double> rates = boost::assign::list_of(1.0)(2.0)(3.0)(4.0); | |
210 | const std::vector<double> empty_vector; | |
211 | ||
212 | // Test the reading of param_type | |
213 | ||
214 | // - Test with valid input | |
215 | { | |
216 | boost::random::hyperexponential_distribution<>::param_type parm(probs, rates); | |
217 | std::stringstream ss; | |
218 | ss << parm; | |
219 | boost::random::hyperexponential_distribution<>::param_type restored_parm; | |
220 | ss >> restored_parm; | |
221 | BOOST_CHECK_EQUAL(parm, restored_parm); | |
222 | } | |
223 | ||
224 | // - Test with an empty probability vector and ios_base exceptions disabled | |
225 | { | |
226 | std::stringstream ss; | |
227 | boost::random::detail::print_vector(ss, empty_vector); | |
228 | ss << ' '; | |
229 | boost::random::detail::print_vector(ss, rates); | |
230 | boost::random::hyperexponential_distribution<>::param_type param; | |
231 | ss >> param; | |
232 | boost::random::hyperexponential_distribution<>::param_type check_param(std::vector<double>(rates.size(), 1), rates); | |
233 | BOOST_CHECK_EQUAL(param, check_param); | |
234 | } | |
235 | ||
236 | // - Test with an empty rate vector and ios_base exceptions disabled | |
237 | { | |
238 | std::stringstream ss; | |
239 | boost::random::detail::print_vector(ss, probs); | |
240 | ss << ' '; | |
241 | boost::random::detail::print_vector(ss, empty_vector); | |
242 | boost::random::hyperexponential_distribution<>::param_type param; | |
243 | ss >> param; | |
244 | boost::random::hyperexponential_distribution<>::param_type check_param(probs, std::vector<double>(probs.size(), 1)); | |
245 | BOOST_CHECK_EQUAL(param, check_param); | |
246 | } | |
247 | ||
248 | // - Test with an empty probability and rate vectors and ios_base exceptions disabled | |
249 | { | |
250 | std::stringstream ss; | |
251 | boost::random::detail::print_vector(ss, empty_vector); | |
252 | ss << ' '; | |
253 | boost::random::detail::print_vector(ss, empty_vector); | |
254 | boost::random::hyperexponential_distribution<>::param_type param; | |
255 | ss >> param; | |
256 | boost::random::hyperexponential_distribution<>::param_type check_param; | |
257 | BOOST_CHECK_EQUAL(param, check_param); | |
258 | } | |
259 | ||
260 | // - Test with an empty probability vector and ios_base exceptions enabled | |
261 | { | |
262 | std::stringstream ss; | |
263 | boost::random::detail::print_vector(ss, empty_vector); | |
264 | ss << ' '; | |
265 | boost::random::detail::print_vector(ss, rates); | |
266 | boost::random::hyperexponential_distribution<>::param_type param; | |
267 | ss.exceptions(std::ios_base::failbit); | |
11fdf7f2 TL |
268 | ss >> param; |
269 | boost::random::hyperexponential_distribution<>::param_type check_param(std::vector<double>(rates.size(), 1), rates); | |
270 | BOOST_CHECK_EQUAL(param, check_param); | |
7c673cae FG |
271 | } |
272 | ||
273 | // - Test with an empty rate vector and ios_base exceptions enabled | |
274 | { | |
275 | std::stringstream ss; | |
276 | boost::random::detail::print_vector(ss, probs); | |
277 | ss << ' '; | |
278 | boost::random::detail::print_vector(ss, empty_vector); | |
279 | boost::random::hyperexponential_distribution<>::param_type param; | |
280 | ss.exceptions(std::ios_base::failbit); | |
11fdf7f2 TL |
281 | ss >> param; |
282 | boost::random::hyperexponential_distribution<>::param_type check_param(probs, std::vector<double>(probs.size(), 1)); | |
283 | BOOST_CHECK_EQUAL(param, check_param); | |
7c673cae FG |
284 | } |
285 | ||
286 | // - Test with an empty probability and rate vectors and ios_base exceptions enabled | |
287 | { | |
288 | std::stringstream ss; | |
289 | boost::random::detail::print_vector(ss, empty_vector); | |
290 | ss << ' '; | |
291 | boost::random::detail::print_vector(ss, empty_vector); | |
292 | boost::random::hyperexponential_distribution<>::param_type param; | |
293 | ss.exceptions(std::ios_base::failbit); | |
11fdf7f2 TL |
294 | ss >> param; |
295 | boost::random::hyperexponential_distribution<>::param_type check_param; | |
296 | BOOST_CHECK_EQUAL(param, check_param); | |
7c673cae FG |
297 | } |
298 | ||
299 | // The the reading of hyperexponential_distribution | |
300 | ||
301 | // - Test with valid input | |
302 | { | |
303 | boost::random::hyperexponential_distribution<> dist(probs, rates); | |
304 | std::stringstream ss; | |
305 | ss << dist; | |
306 | boost::random::hyperexponential_distribution<> restored_dist; | |
307 | ss >> restored_dist; | |
308 | BOOST_CHECK_EQUAL(dist, restored_dist); | |
309 | } | |
310 | ||
311 | // - Test with an empty probability vector and ios_base exceptions disabled | |
312 | { | |
313 | std::stringstream ss; | |
314 | boost::random::detail::print_vector(ss, empty_vector); | |
315 | ss << ' '; | |
316 | boost::random::detail::print_vector(ss, rates); | |
317 | boost::random::hyperexponential_distribution<> dist; | |
318 | ss >> dist; | |
11fdf7f2 | 319 | boost::random::hyperexponential_distribution<> check_dist(std::vector<double>(rates.size(), 1), rates); |
7c673cae FG |
320 | BOOST_CHECK_EQUAL(dist, check_dist); |
321 | } | |
322 | ||
323 | // - Test with an empty rate vector and ios_base exceptions disabled | |
324 | { | |
325 | std::stringstream ss; | |
326 | boost::random::detail::print_vector(ss, probs); | |
327 | ss << ' '; | |
328 | boost::random::detail::print_vector(ss, empty_vector); | |
329 | boost::random::hyperexponential_distribution<> dist; | |
330 | ss >> dist; | |
11fdf7f2 | 331 | boost::random::hyperexponential_distribution<> check_dist(probs, std::vector<double>(probs.size(), 1)); |
7c673cae FG |
332 | BOOST_CHECK_EQUAL(dist, check_dist); |
333 | } | |
334 | ||
335 | // - Test with an empty probability and rate vectors and ios_base exceptions disabled | |
336 | { | |
337 | std::stringstream ss; | |
338 | boost::random::detail::print_vector(ss, empty_vector); | |
339 | ss << ' '; | |
340 | boost::random::detail::print_vector(ss, empty_vector); | |
341 | boost::random::hyperexponential_distribution<> dist; | |
342 | ss >> dist; | |
343 | boost::random::hyperexponential_distribution<> check_dist; | |
344 | BOOST_CHECK_EQUAL(dist, check_dist); | |
345 | } | |
346 | ||
347 | // - Test with an empty probability vector and ios_base exceptions enabled | |
348 | { | |
349 | std::stringstream ss; | |
350 | boost::random::detail::print_vector(ss, empty_vector); | |
351 | ss << ' '; | |
352 | boost::random::detail::print_vector(ss, rates); | |
353 | boost::random::hyperexponential_distribution<> dist; | |
354 | ss.exceptions(std::ios_base::failbit); | |
11fdf7f2 TL |
355 | ss >> dist; |
356 | boost::random::hyperexponential_distribution<> check_dist(std::vector<double>(rates.size(), 1), rates); | |
357 | BOOST_CHECK_EQUAL(dist, check_dist); | |
7c673cae FG |
358 | } |
359 | ||
360 | // - Test with an empty rate vector and ios_base exceptions enabled | |
361 | { | |
362 | std::stringstream ss; | |
363 | boost::random::detail::print_vector(ss, probs); | |
364 | ss << ' '; | |
365 | boost::random::detail::print_vector(ss, empty_vector); | |
366 | boost::random::hyperexponential_distribution<> dist; | |
367 | ss.exceptions(std::ios_base::failbit); | |
11fdf7f2 TL |
368 | ss >> dist; |
369 | boost::random::hyperexponential_distribution<> check_dist(probs, std::vector<double>(probs.size(), 1)); | |
370 | BOOST_CHECK_EQUAL(dist, check_dist); | |
7c673cae FG |
371 | } |
372 | ||
373 | // - Test with an empty probability and rate vectors and ios_base exceptions enabled | |
374 | { | |
375 | std::stringstream ss; | |
376 | boost::random::detail::print_vector(ss, empty_vector); | |
377 | ss << ' '; | |
378 | boost::random::detail::print_vector(ss, empty_vector); | |
379 | boost::random::hyperexponential_distribution<> dist; | |
380 | ss.exceptions(std::ios_base::failbit); | |
11fdf7f2 TL |
381 | ss >> dist; |
382 | boost::random::hyperexponential_distribution<> check_dist; | |
383 | BOOST_CHECK_EQUAL(dist, check_dist); | |
7c673cae FG |
384 | } |
385 | } | |
386 | ||
387 | //NOTE: test case commented since normalization check in \c hyperexp_detail::check_probabilities has been currently commented | |
388 | //BOOST_AUTO_TEST_CASE( test_normalization ) | |
389 | //{ | |
390 | // const double tol = detail::make_tolerance<double>(); | |
391 | // | |
392 | // const std::vector<double> probs = boost::assign::list_of(1023.0)(1.0); | |
393 | // const std::vector<double> rates = boost::assign::list_of(1023.0)(1.0); | |
394 | // const std::vector<double> norm_probs = boost::assign::list_of(1023.0/1024.0)(1.0/1024.0); | |
395 | // | |
396 | // boost::random::hyperexponential_distribution<> dist(probs, rates); | |
397 | // BOOST_CHECK( boost::random::hyperexp_detail::check_params(dist.probabilities(), dist.rates()) ); | |
398 | // BOOST_RANDOM_HYPEREXP_CHECK_CLOSE_COLLECTIONS(double, dist.probabilities(), norm_probs, tol); | |
399 | // | |
400 | // const std::vector<double> probs2 = boost::assign::list_of(1001.0)(1.0); | |
401 | // const std::vector<double> rates2 = boost::assign::list_of(1001.0)(1.0); | |
402 | // const std::vector<double> norm_probs2 = boost::assign::list_of(1001.0/1002.0)(1.0/1002.0); | |
403 | // | |
404 | // boost::random::hyperexponential_distribution<> dist2(probs2, rates2); | |
405 | // BOOST_CHECK( boost::random::hyperexp_detail::check_params(dist2.probabilities(), dist2.rates()) ); | |
406 | // BOOST_RANDOM_HYPEREXP_CHECK_CLOSE_COLLECTIONS(double, dist2.probabilities(), norm_probs2, tol); | |
407 | //} | |
408 | ||
409 | void use(boost::random::hyperexponential_distribution<>::result_type) {} | |
410 | ||
411 | BOOST_AUTO_TEST_CASE(test_generation) | |
412 | { | |
413 | //const double tol = detail::make_tolerance<double>(); | |
414 | ||
415 | const std::vector<double> probs = boost::assign::list_of(0.1)(0.2)(0.3)(0.4); | |
416 | const std::vector<double> rates = boost::assign::list_of(1.0)(2.0)(3.0)(4.0); | |
417 | ||
418 | boost::minstd_rand0 gen; | |
419 | ||
420 | boost::random::hyperexponential_distribution<> dist; | |
421 | boost::random::hyperexponential_distribution<> dist_r(probs, rates); | |
422 | typedef boost::random::hyperexponential_distribution<>::result_type result_type; | |
423 | for(std::size_t i = 0; i < 10; ++i) | |
424 | { | |
425 | const result_type value = dist(gen); | |
426 | use(value); | |
427 | BOOST_CHECK_GE(value, static_cast<result_type>(0)); | |
428 | const result_type value_r = dist_r(gen); | |
429 | use(value_r); | |
430 | BOOST_CHECK_GE(value_r, static_cast<result_type>(0)); | |
431 | const result_type value_param = dist_r(gen, dist.param()); | |
432 | use(value_param); | |
433 | BOOST_CHECK_GE(value_param, static_cast<result_type>(0)); | |
434 | const result_type value_r_param = dist(gen, dist_r.param()); | |
435 | use(value_r_param); | |
436 | BOOST_CHECK_GE(value_r_param, static_cast<result_type>(0)); | |
437 | } | |
438 | } | |
439 | ||
440 | BOOST_AUTO_TEST_CASE( test_generation_float ) | |
441 | { | |
442 | //const double tol = detail::make_tolerance<double>(); | |
443 | ||
444 | const std::vector<double> probs = boost::assign::list_of(0.1)(0.2)(0.3)(0.4); | |
445 | const std::vector<double> rates = boost::assign::list_of(1.0)(2.0)(3.0)(4.0); | |
446 | ||
447 | boost::lagged_fibonacci607 gen; | |
448 | ||
449 | boost::random::hyperexponential_distribution<> dist; | |
450 | boost::random::hyperexponential_distribution<> dist_r(probs, rates); | |
451 | typedef boost::random::hyperexponential_distribution<>::result_type result_type; | |
452 | for(std::size_t i = 0; i < 10; ++i) | |
453 | { | |
454 | const result_type value = dist(gen); | |
455 | use(value); | |
456 | BOOST_CHECK_GE(value, static_cast<result_type>(0)); | |
457 | const result_type value_r = dist_r(gen); | |
458 | use(value_r); | |
459 | BOOST_CHECK_GE(value_r, static_cast<result_type>(0)); | |
460 | const result_type value_param = dist_r(gen, dist.param()); | |
461 | use(value_param); | |
462 | BOOST_CHECK_GE(value_param, static_cast<result_type>(0)); | |
463 | const result_type value_r_param = dist(gen, dist_r.param()); | |
464 | use(value_r_param); | |
465 | BOOST_CHECK_GE(value_r_param, static_cast<result_type>(0)); | |
466 | } | |
467 | } |