1 // Copyright John Maddock 2006, 2007.
2 // Copyright Paul A. Bristow 2007
3
4 // Use, modification and distribution are subject to the
5 // Boost Software License, Version 1.0.
6 // (See accompanying file LICENSE_1_0.txt
7 // or copy at http://www.boost.org/LICENSE_1_0.txt)
8
9 // test_cauchy.cpp Test Cauchy distribution
10
11 #ifdef _MSC_VER
12 # pragma warning(disable: 4100) // unreferenced formal parameter.
13 // Seems an entirely spurious warning - formal parameter T IS used - get error if /* T */
14 //# pragma warning(disable: 4535) // calling _set_se_translator() requires /EHa (in Boost.test)
15 // Enable C++ Exceptions Yes With SEH Exceptions (/EHa) prevents warning 4535.
16 # pragma warning(disable: 4127) // conditional expression is constant
17 #endif
18
19 // #define BOOST_MATH_ASSERT_UNDEFINED_POLICY false
20 // To compile even if Cauchy mean is used.
21 #include <boost/math/tools/test.hpp>
22 #include <boost/math/concepts/real_concept.hpp> // for real_concept
23 #include <boost/math/distributions/cauchy.hpp>
24 using boost::math::cauchy_distribution;
25
26 #include "test_out_of_range.hpp"
27
28 #define BOOST_TEST_MAIN
29 #include <boost/test/unit_test.hpp> // Boost.Test
30 #include <boost/test/tools/floating_point_comparison.hpp>
31
32 #include <iostream>
33 using std::cout;
34 using std::endl;
35
36 template <class RealType>
test_spots(RealType T)37 void test_spots(RealType T)
38 {
39 // Check some bad parameters to construct the distribution,
40 #ifndef BOOST_NO_EXCEPTIONS
41 BOOST_MATH_CHECK_THROW(boost::math::cauchy_distribution<RealType> nbad1(0, 0), std::domain_error); // zero scale.
42 BOOST_MATH_CHECK_THROW(boost::math::cauchy_distribution<RealType> nbad1(0, -1), std::domain_error); // negative scale (shape).
43 #else
44 BOOST_MATH_CHECK_THROW(boost::math::cauchy_distribution<RealType>(0, 0), std::domain_error); // zero scale.
45 BOOST_MATH_CHECK_THROW(boost::math::cauchy_distribution<RealType>(0, -1), std::domain_error); // negative scale (shape).
46 #endif
47 cauchy_distribution<RealType> C01;
48
49 BOOST_CHECK_EQUAL(C01.location(), 0); // Check standard values.
50 BOOST_CHECK_EQUAL(C01.scale(), 1);
51
52 // Basic sanity checks.
53 // 50eps as a percentage, up to a maximum of double precision
54 // (that's the limit of our test data).
55 RealType tolerance = (std::max)(
56 static_cast<RealType>(boost::math::tools::epsilon<double>()),
57 boost::math::tools::epsilon<RealType>());
58 tolerance *= 50 * 100;
59
60 cout << "Tolerance for type " << typeid(T).name() << " is " << tolerance << " %" << endl;
61
62 // These first sets of test values were calculated by punching numbers
63 // into a calculator, and using the formulas on the Mathworld website:
64 // http://mathworld.wolfram.com/CauchyDistribution.html
65 // and values from MathCAD 200 Professional,
66 // CDF:
67 //
68 BOOST_CHECK_CLOSE(
69 ::boost::math::cdf(
70 cauchy_distribution<RealType>(),
71 static_cast<RealType>(0.125)), // x
72 static_cast<RealType>(0.53958342416056554201085167134004L), // probability.
73 tolerance); // %
74 BOOST_CHECK_CLOSE(
75 ::boost::math::cdf(
76 cauchy_distribution<RealType>(),
77 static_cast<RealType>(-0.125)), // x
78 static_cast<RealType>(0.46041657583943445798914832865996L), // probability.
79 tolerance); // %
80 BOOST_CHECK_CLOSE(
81 ::boost::math::cdf(
82 cauchy_distribution<RealType>(),
83 static_cast<RealType>(0.5)), // x
84 static_cast<RealType>(0.64758361765043327417540107622474L), // probability.
85 tolerance); // %
86 BOOST_CHECK_CLOSE(
87 ::boost::math::cdf(
88 cauchy_distribution<RealType>(),
89 static_cast<RealType>(-0.5)), // x
90 static_cast<RealType>(0.35241638234956672582459892377526L), // probability.
91 tolerance); // %
92 BOOST_CHECK_CLOSE(
93 ::boost::math::cdf(
94 cauchy_distribution<RealType>(),
95 static_cast<RealType>(1.0)), // x
96 static_cast<RealType>(0.75), // probability.
97 tolerance); // %
98 BOOST_CHECK_CLOSE(
99 ::boost::math::cdf(
100 cauchy_distribution<RealType>(),
101 static_cast<RealType>(-1.0)), // x
102 static_cast<RealType>(0.25), // probability.
103 tolerance); // %
104 BOOST_CHECK_CLOSE(
105 ::boost::math::cdf(
106 cauchy_distribution<RealType>(),
107 static_cast<RealType>(2.0)), // x
108 static_cast<RealType>(0.85241638234956672582459892377526L), // probability.
109 tolerance); // %
110 BOOST_CHECK_CLOSE(
111 ::boost::math::cdf(
112 cauchy_distribution<RealType>(),
113 static_cast<RealType>(-2.0)), // x
114 static_cast<RealType>(0.14758361765043327417540107622474L), // probability.
115 tolerance); // %
116 BOOST_CHECK_CLOSE(
117 ::boost::math::cdf(
118 cauchy_distribution<RealType>(),
119 static_cast<RealType>(10.0)), // x
120 static_cast<RealType>(0.9682744825694464304850228813987L), // probability.
121 tolerance); // %
122 BOOST_CHECK_CLOSE(
123 ::boost::math::cdf(
124 cauchy_distribution<RealType>(),
125 static_cast<RealType>(-10.0)), // x
126 static_cast<RealType>(0.031725517430553569514977118601302L), // probability.
127 tolerance); // %
128
129 //
130 // Complements:
131 //
132 BOOST_CHECK_CLOSE(
133 ::boost::math::cdf(
134 complement(cauchy_distribution<RealType>(),
135 static_cast<RealType>(0.125))), // x
136 static_cast<RealType>(0.46041657583943445798914832865996L), // probability.
137 tolerance); // %
138 BOOST_CHECK_CLOSE(
139 ::boost::math::cdf(
140 complement(cauchy_distribution<RealType>(),
141 static_cast<RealType>(-0.125))), // x
142 static_cast<RealType>(0.53958342416056554201085167134004L), // probability.
143 tolerance); // %
144 BOOST_CHECK_CLOSE(
145 ::boost::math::cdf(
146 complement(cauchy_distribution<RealType>(),
147 static_cast<RealType>(0.5))), // x
148 static_cast<RealType>(0.35241638234956672582459892377526L), // probability.
149 tolerance); // %
150 BOOST_CHECK_CLOSE(
151 ::boost::math::cdf(
152 complement(cauchy_distribution<RealType>(),
153 static_cast<RealType>(-0.5))), // x
154 static_cast<RealType>(0.64758361765043327417540107622474L), // probability.
155 tolerance); // %
156 BOOST_CHECK_CLOSE(
157 ::boost::math::cdf(
158 complement(cauchy_distribution<RealType>(),
159 static_cast<RealType>(1.0))), // x
160 static_cast<RealType>(0.25), // probability.
161 tolerance); // %
162 BOOST_CHECK_CLOSE(
163 ::boost::math::cdf(
164 complement(cauchy_distribution<RealType>(),
165 static_cast<RealType>(-1.0))), // x
166 static_cast<RealType>(0.75), // probability.
167 tolerance); // %
168 BOOST_CHECK_CLOSE(
169 ::boost::math::cdf(
170 complement(cauchy_distribution<RealType>(),
171 static_cast<RealType>(2.0))), // x
172 static_cast<RealType>(0.14758361765043327417540107622474L), // probability.
173 tolerance); // %
174 BOOST_CHECK_CLOSE(
175 ::boost::math::cdf(
176 complement(cauchy_distribution<RealType>(),
177 static_cast<RealType>(-2.0))), // x
178 static_cast<RealType>(0.85241638234956672582459892377526L), // probability.
179 tolerance); // %
180 BOOST_CHECK_CLOSE(
181 ::boost::math::cdf(
182 complement(cauchy_distribution<RealType>(),
183 static_cast<RealType>(10.0))), // x
184 static_cast<RealType>(0.031725517430553569514977118601302L), // probability.
185 tolerance); // %
186 BOOST_CHECK_CLOSE(
187 ::boost::math::cdf(
188 complement(cauchy_distribution<RealType>(),
189 static_cast<RealType>(-10.0))), // x
190 static_cast<RealType>(0.9682744825694464304850228813987L), // probability.
191 tolerance); // %
192
193 //
194 // Quantiles:
195 //
196 BOOST_CHECK_CLOSE(
197 ::boost::math::quantile(
198 cauchy_distribution<RealType>(),
199 static_cast<RealType>(0.53958342416056554201085167134004L)),
200 static_cast<RealType>(0.125),
201 tolerance); // %
202 BOOST_CHECK_CLOSE(
203 ::boost::math::quantile(
204 cauchy_distribution<RealType>(),
205 static_cast<RealType>(0.46041657583943445798914832865996L)),
206 static_cast<RealType>(-0.125),
207 tolerance); // %
208 BOOST_CHECK_CLOSE(
209 ::boost::math::quantile(
210 cauchy_distribution<RealType>(),
211 static_cast<RealType>(0.64758361765043327417540107622474L)),
212 static_cast<RealType>(0.5),
213 tolerance); // %
214 BOOST_CHECK_CLOSE(
215 ::boost::math::quantile(
216 cauchy_distribution<RealType>(),
217 static_cast<RealType>(0.35241638234956672582459892377526)),
218 static_cast<RealType>(-0.5),
219 tolerance); // %
220 BOOST_CHECK_CLOSE(
221 ::boost::math::quantile(
222 cauchy_distribution<RealType>(),
223 static_cast<RealType>(0.75)),
224 static_cast<RealType>(1.0),
225 tolerance); // %
226 BOOST_CHECK_CLOSE(
227 ::boost::math::quantile(
228 cauchy_distribution<RealType>(),
229 static_cast<RealType>(0.25)),
230 static_cast<RealType>(-1.0),
231 tolerance); // %
232 BOOST_CHECK_CLOSE(
233 ::boost::math::quantile(
234 cauchy_distribution<RealType>(),
235 static_cast<RealType>(0.85241638234956672582459892377526L)),
236 static_cast<RealType>(2.0),
237 tolerance); // %
238 BOOST_CHECK_CLOSE(
239 ::boost::math::quantile(
240 cauchy_distribution<RealType>(),
241 static_cast<RealType>(0.14758361765043327417540107622474L)),
242 static_cast<RealType>(-2.0),
243 tolerance); // %
244 BOOST_CHECK_CLOSE(
245 ::boost::math::quantile(
246 cauchy_distribution<RealType>(),
247 static_cast<RealType>(0.9682744825694464304850228813987L)),
248 static_cast<RealType>(10.0),
249 tolerance); // %
250 BOOST_CHECK_CLOSE(
251 ::boost::math::quantile(
252 cauchy_distribution<RealType>(),
253 static_cast<RealType>(0.031725517430553569514977118601302L)),
254 static_cast<RealType>(-10.0),
255 tolerance); // %
256
257 //
258 // Quantile from complement:
259 //
260 BOOST_CHECK_CLOSE(
261 ::boost::math::quantile(
262 complement(cauchy_distribution<RealType>(),
263 static_cast<RealType>(0.46041657583943445798914832865996L))),
264 static_cast<RealType>(0.125),
265 tolerance); // %
266 BOOST_CHECK_CLOSE(
267 ::boost::math::quantile(
268 complement(cauchy_distribution<RealType>(),
269 static_cast<RealType>(0.53958342416056554201085167134004L))),
270 static_cast<RealType>(-0.125),
271 tolerance); // %
272 BOOST_CHECK_CLOSE(
273 ::boost::math::quantile(
274 complement(cauchy_distribution<RealType>(),
275 static_cast<RealType>(0.35241638234956672582459892377526L))),
276 static_cast<RealType>(0.5),
277 tolerance); // %
278 BOOST_CHECK_CLOSE(
279 ::boost::math::quantile(
280 complement(cauchy_distribution<RealType>(),
281 static_cast<RealType>(0.64758361765043327417540107622474L))),
282 static_cast<RealType>(-0.5),
283 tolerance); // %
284 BOOST_CHECK_CLOSE(
285 ::boost::math::quantile(
286 complement(cauchy_distribution<RealType>(),
287 static_cast<RealType>(0.25))),
288 static_cast<RealType>(1.0),
289 tolerance); // %
290 BOOST_CHECK_CLOSE(
291 ::boost::math::quantile(
292 complement(cauchy_distribution<RealType>(),
293 static_cast<RealType>(0.75))),
294 static_cast<RealType>(-1.0),
295 tolerance); // %
296 BOOST_CHECK_CLOSE(
297 ::boost::math::quantile(
298 complement(cauchy_distribution<RealType>(),
299 static_cast<RealType>(0.14758361765043327417540107622474L))),
300 static_cast<RealType>(2.0),
301 tolerance); // %
302 BOOST_CHECK_CLOSE(
303 ::boost::math::quantile(
304 complement(cauchy_distribution<RealType>(),
305 static_cast<RealType>(0.85241638234956672582459892377526L))),
306 static_cast<RealType>(-2.0),
307 tolerance); // %
308 BOOST_CHECK_CLOSE(
309 ::boost::math::quantile(
310 complement(cauchy_distribution<RealType>(),
311 static_cast<RealType>(0.031725517430553569514977118601302L))),
312 static_cast<RealType>(10.0),
313 tolerance); // %
314 BOOST_CHECK_CLOSE(
315 ::boost::math::quantile(
316 complement(cauchy_distribution<RealType>(),
317 static_cast<RealType>(0.9682744825694464304850228813987L))),
318 static_cast<RealType>(-10.0),
319 tolerance); // %
320
321 //
322 // PDF
323 //
324 BOOST_CHECK_CLOSE(
325 ::boost::math::pdf(
326 cauchy_distribution<RealType>(),
327 static_cast<RealType>(0.125)), // x
328 static_cast<RealType>(0.31341281101173235351410956479511L), // probability.
329 tolerance); // %
330 BOOST_CHECK_CLOSE(
331 ::boost::math::pdf(
332 cauchy_distribution<RealType>(),
333 static_cast<RealType>(-0.125)), // x
334 static_cast<RealType>(0.31341281101173235351410956479511L), // probability.
335 tolerance); // %
336 BOOST_CHECK_CLOSE(
337 ::boost::math::pdf(
338 cauchy_distribution<RealType>(),
339 static_cast<RealType>(0.5)), // x
340 static_cast<RealType>(0.25464790894703253723021402139602L), // probability.
341 tolerance); // %
342 BOOST_CHECK_CLOSE(
343 ::boost::math::pdf(
344 cauchy_distribution<RealType>(),
345 static_cast<RealType>(-0.5)), // x
346 static_cast<RealType>(0.25464790894703253723021402139602L), // probability.
347 tolerance); // %
348 BOOST_CHECK_CLOSE(
349 ::boost::math::pdf(
350 cauchy_distribution<RealType>(),
351 static_cast<RealType>(1.0)), // x
352 static_cast<RealType>(0.15915494309189533576888376337251L), // probability.
353 tolerance); // %
354 BOOST_CHECK_CLOSE(
355 ::boost::math::pdf(
356 cauchy_distribution<RealType>(),
357 static_cast<RealType>(-1.0)), // x
358 static_cast<RealType>(0.15915494309189533576888376337251L), // probability.
359 tolerance); // %
360 BOOST_CHECK_CLOSE(
361 ::boost::math::pdf(
362 cauchy_distribution<RealType>(),
363 static_cast<RealType>(2.0)), // x
364 static_cast<RealType>(0.063661977236758134307553505349006L), // probability.
365 tolerance); // %
366 BOOST_CHECK_CLOSE(
367 ::boost::math::pdf(
368 cauchy_distribution<RealType>(),
369 static_cast<RealType>(-2.0)), // x
370 static_cast<RealType>(0.063661977236758134307553505349006L), // probability.
371 tolerance); // %
372 BOOST_CHECK_CLOSE(
373 ::boost::math::pdf(
374 cauchy_distribution<RealType>(),
375 static_cast<RealType>(10.0)), // x
376 static_cast<RealType>(0.0031515830315226799162155200667825L), // probability.
377 tolerance); // %
378 BOOST_CHECK_CLOSE(
379 ::boost::math::pdf(
380 cauchy_distribution<RealType>(),
381 static_cast<RealType>(-10.0)), // x
382 static_cast<RealType>(0.0031515830315226799162155200667825L), // probability.
383 tolerance); // %
384 BOOST_CHECK_CLOSE(
385 ::boost::math::pdf(
386 cauchy_distribution<RealType>(2, 5),
387 static_cast<RealType>(1)), // x
388 static_cast<RealType>(0.061213439650728975295724524374044L), // probability.
389 tolerance); // %
390 BOOST_CHECK_CLOSE(
391 ::boost::math::pdf(
392 cauchy_distribution<RealType>(-2, 0.25),
393 static_cast<RealType>(1)), // x
394 static_cast<RealType>(0.0087809623774838805941453110826215L), // probability.
395 tolerance); // %
396
397 //
398 // The following test values were calculated using MathCad,
399 // precision seems to be about 10^-13.
400 //
401 tolerance = (std::max)(tolerance, static_cast<RealType>(1e-11));
402 BOOST_CHECK_CLOSE(
403 ::boost::math::cdf(
404 cauchy_distribution<RealType>(1, 1),
405 static_cast<RealType>(0.125)), // x
406 static_cast<RealType>(0.271189304634946L), // probability.
407 tolerance); // %
408 BOOST_CHECK_CLOSE(
409 ::boost::math::cdf(
410 complement(cauchy_distribution<RealType>(1, 1),
411 static_cast<RealType>(0.125))), // x
412 static_cast<RealType>(1 - 0.271189304634946L), // probability.
413 tolerance); // %
414 BOOST_CHECK_CLOSE(
415 ::boost::math::quantile(
416 cauchy_distribution<RealType>(1, 1),
417 static_cast<RealType>(0.271189304634946L)), // x
418 static_cast<RealType>(0.125), // probability.
419 tolerance); // %
420 BOOST_CHECK_CLOSE(
421 ::boost::math::quantile(
422 complement(cauchy_distribution<RealType>(1, 1),
423 static_cast<RealType>(1 - 0.271189304634946L))), // x
424 static_cast<RealType>(0.125), // probability.
425 tolerance); // %
426 BOOST_CHECK_CLOSE(
427 ::boost::math::cdf(
428 cauchy_distribution<RealType>(0, 1),
429 static_cast<RealType>(0.125)), // x
430 static_cast<RealType>(0.539583424160566L), // probability.
431 tolerance); // %
432 BOOST_CHECK_CLOSE(
433 ::boost::math::cdf(
434 cauchy_distribution<RealType>(0, 1),
435 static_cast<RealType>(0.5)), // x
436 static_cast<RealType>(0.647583617650433L), // probability.
437 tolerance); // %
438 BOOST_CHECK_CLOSE(
439 ::boost::math::cdf(
440 cauchy_distribution<RealType>(0, 1),
441 static_cast<RealType>(1)), // x
442 static_cast<RealType>(0.750000000000000), // probability.
443 tolerance); // %
444 BOOST_CHECK_CLOSE(
445 ::boost::math::cdf(
446 cauchy_distribution<RealType>(0, 1),
447 static_cast<RealType>(2)), // x
448 static_cast<RealType>(0.852416382349567), // probability.
449 tolerance); // %
450 BOOST_CHECK_CLOSE(
451 ::boost::math::cdf(
452 cauchy_distribution<RealType>(0, 1),
453 static_cast<RealType>(10)), // x
454 static_cast<RealType>(0.968274482569447), // probability.
455 tolerance); // %
456 BOOST_CHECK_CLOSE(
457 ::boost::math::cdf(
458 cauchy_distribution<RealType>(0, 1),
459 static_cast<RealType>(100)), // x
460 static_cast<RealType>(0.996817007235092), // probability.
461 tolerance); // %
462
463 BOOST_CHECK_CLOSE(
464 ::boost::math::cdf(
465 cauchy_distribution<RealType>(0, 1),
466 static_cast<RealType>(-0.125)), // x
467 static_cast<RealType>(0.460416575839434), // probability.
468 tolerance); // %
469 BOOST_CHECK_CLOSE(
470 ::boost::math::cdf(
471 cauchy_distribution<RealType>(0, 1),
472 static_cast<RealType>(-0.5)), // x
473 static_cast<RealType>(0.352416382349567), // probability.
474 tolerance); // %
475 BOOST_CHECK_CLOSE(
476 ::boost::math::cdf(
477 cauchy_distribution<RealType>(0, 1),
478 static_cast<RealType>(-1)), // x
479 static_cast<RealType>(0.2500000000000000), // probability.
480 tolerance); // %
481 BOOST_CHECK_CLOSE(
482 ::boost::math::cdf(
483 cauchy_distribution<RealType>(0, 1),
484 static_cast<RealType>(-2)), // x
485 static_cast<RealType>(0.147583617650433), // probability.
486 tolerance); // %
487 BOOST_CHECK_CLOSE(
488 ::boost::math::cdf(
489 cauchy_distribution<RealType>(0, 1),
490 static_cast<RealType>(-10)), // x
491 static_cast<RealType>(0.031725517430554), // probability.
492 tolerance); // %
493 BOOST_CHECK_CLOSE(
494 ::boost::math::cdf(
495 cauchy_distribution<RealType>(0, 1),
496 static_cast<RealType>(-100)), // x
497 static_cast<RealType>(3.18299276490824E-3), // probability.
498 tolerance); // %
499
500 BOOST_CHECK_CLOSE(
501 ::boost::math::cdf(
502 cauchy_distribution<RealType>(1, 5),
503 static_cast<RealType>(1.25)), // x
504 static_cast<RealType>(0.515902251256176), // probability.
505 tolerance); // %
506 BOOST_CHECK_CLOSE(
507 ::boost::math::cdf(
508 cauchy_distribution<RealType>(2, 2),
509 static_cast<RealType>(1.25)), // x
510 static_cast<RealType>(0.385799748780092), // probability.
511 tolerance); // %
512 BOOST_CHECK_CLOSE(
513 ::boost::math::cdf(
514 cauchy_distribution<RealType>(4, 0.125),
515 static_cast<RealType>(3)), // x
516 static_cast<RealType>(0.039583424160566), // probability.
517 tolerance); // %
518 BOOST_CHECK_CLOSE(
519 ::boost::math::cdf(
520 cauchy_distribution<RealType>(-2, static_cast<RealType>(0.0001)),
521 static_cast<RealType>(-3)), // x
522 static_cast<RealType>(3.1830988512275777e-5), // probability.
523 tolerance); // %
524 BOOST_CHECK_CLOSE(
525 ::boost::math::cdf(
526 cauchy_distribution<RealType>(4, 50),
527 static_cast<RealType>(-3)), // x
528 static_cast<RealType>(0.455724386698215), // probability.
529 tolerance); // %
530 BOOST_CHECK_CLOSE(
531 ::boost::math::cdf(
532 cauchy_distribution<RealType>(-4, 50),
533 static_cast<RealType>(-3)), // x
534 static_cast<RealType>(0.506365349100973), // probability.
535 tolerance); // %
536
537 BOOST_CHECK_CLOSE(
538 ::boost::math::cdf(
539 complement(cauchy_distribution<RealType>(1, 5),
540 static_cast<RealType>(1.25))), // x
541 static_cast<RealType>(1-0.515902251256176), // probability.
542 tolerance); // %
543 BOOST_CHECK_CLOSE(
544 ::boost::math::cdf(
545 complement(cauchy_distribution<RealType>(2, 2),
546 static_cast<RealType>(1.25))), // x
547 static_cast<RealType>(1-0.385799748780092), // probability.
548 tolerance); // %
549 BOOST_CHECK_CLOSE(
550 ::boost::math::cdf(
551 complement(cauchy_distribution<RealType>(4, 0.125),
552 static_cast<RealType>(3))), // x
553 static_cast<RealType>(1-0.039583424160566), // probability.
554 tolerance); // %
555 BOOST_CHECK_CLOSE(
556 ::boost::math::cdf(
557 cauchy_distribution<RealType>(-2, static_cast<RealType>(0.001)),
558 static_cast<RealType>(-3)), // x
559 static_cast<RealType>(0.000318309780080539), // probability.
560 tolerance); // %
561 BOOST_CHECK_CLOSE(
562 ::boost::math::cdf(
563 complement(cauchy_distribution<RealType>(4, 50),
564 static_cast<RealType>(-3))), // x
565 static_cast<RealType>(1-0.455724386698215), // probability.
566 tolerance); // %
567 BOOST_CHECK_CLOSE(
568 ::boost::math::cdf(
569 complement(cauchy_distribution<RealType>(-4, 50),
570 static_cast<RealType>(-3))), // x
571 static_cast<RealType>(1-0.506365349100973), // probability.
572 tolerance); // %
573
574 BOOST_CHECK_CLOSE(
575 ::boost::math::quantile(
576 cauchy_distribution<RealType>(1, 5),
577 static_cast<RealType>(0.515902251256176)), // x
578 static_cast<RealType>(1.25), // probability.
579 tolerance); // %
580 BOOST_CHECK_CLOSE(
581 ::boost::math::quantile(
582 cauchy_distribution<RealType>(2, 2),
583 static_cast<RealType>(0.385799748780092)), // x
584 static_cast<RealType>(1.25), // probability.
585 tolerance); // %
586 BOOST_CHECK_CLOSE(
587 ::boost::math::quantile(
588 cauchy_distribution<RealType>(4, 0.125),
589 static_cast<RealType>(0.039583424160566)), // x
590 static_cast<RealType>(3), // probability.
591 tolerance); // %
592 /*
593 BOOST_CHECK_CLOSE(
594 ::boost::math::quantile(
595 cauchy_distribution<RealType>(-2, 0.0001),
596 static_cast<RealType>(-3)), // x
597 static_cast<RealType>(0.000015915494296), // probability.
598 tolerance); // %
599 */
600 BOOST_CHECK_CLOSE(
601 ::boost::math::quantile(
602 cauchy_distribution<RealType>(4, 50),
603 static_cast<RealType>(0.455724386698215)), // x
604 static_cast<RealType>(-3), // probability.
605 tolerance); // %
606 BOOST_CHECK_CLOSE(
607 ::boost::math::quantile(
608 cauchy_distribution<RealType>(-4, 50),
609 static_cast<RealType>(0.506365349100973)), // x
610 static_cast<RealType>(-3), // probability.
611 tolerance); // %
612
613 BOOST_CHECK_CLOSE(
614 ::boost::math::quantile(
615 complement(cauchy_distribution<RealType>(1, 5),
616 static_cast<RealType>(1-0.515902251256176))), // x
617 static_cast<RealType>(1.25), // probability.
618 tolerance); // %
619 BOOST_CHECK_CLOSE(
620 ::boost::math::quantile(
621 complement(cauchy_distribution<RealType>(2, 2),
622 static_cast<RealType>(1-0.385799748780092))), // x
623 static_cast<RealType>(1.25), // probability.
624 tolerance); // %
625 BOOST_CHECK_CLOSE(
626 ::boost::math::quantile(
627 complement(cauchy_distribution<RealType>(4, 0.125),
628 static_cast<RealType>(1-0.039583424160566))), // x
629 static_cast<RealType>(3), // probability.
630 tolerance); // %
631 /*
632 BOOST_CHECK_CLOSE(
633 ::boost::math::quantile(
634 cauchy_distribution<RealType>(-2, 0.0001),
635 static_cast<RealType>(-3)), // x
636 static_cast<RealType>(0.000015915494296), // probability.
637 tolerance); // %
638 */
639 BOOST_CHECK_CLOSE(
640 ::boost::math::quantile(
641 complement(cauchy_distribution<RealType>(4, 50),
642 static_cast<RealType>(1-0.455724386698215))), // x
643 static_cast<RealType>(-3), // probability.
644 tolerance); // %
645 BOOST_CHECK_CLOSE(
646 ::boost::math::quantile(
647 complement(cauchy_distribution<RealType>(-4, 50),
648 static_cast<RealType>(1-0.506365349100973))), // x
649 static_cast<RealType>(-3), // probability.
650 tolerance); // %
651
652 cauchy_distribution<RealType> dist; // default (0, 1)
653 BOOST_CHECK_EQUAL(
654 mode(dist),
655 static_cast<RealType>(0));
656 BOOST_CHECK_EQUAL(
657 median(dist),
658 static_cast<RealType>(0));
659 RealType expected_entropy = log(2*boost::math::constants::two_pi<RealType>());
660 BOOST_CHECK_CLOSE(
661 entropy(dist),
662 expected_entropy, tolerance);
663
664 //
665 // Things that now don't compile (BOOST-STATIC_ASSERT_FAILURE) by default.
666 // #define BOOST_MATH_ASSERT_UNDEFINED_POLICY false
667 // To compile even if Cauchy mean is used.
668 // See policy reference, mathematically undefined function policies
669 //
670 //BOOST_MATH_CHECK_THROW(
671 // mean(dist),
672 // std::domain_error);
673 //BOOST_MATH_CHECK_THROW(
674 // variance(dist),
675 // std::domain_error);
676 //BOOST_MATH_CHECK_THROW(
677 // standard_deviation(dist),
678 // std::domain_error);
679 //BOOST_MATH_CHECK_THROW(
680 // kurtosis(dist),
681 // std::domain_error);
682 //BOOST_MATH_CHECK_THROW(
683 // kurtosis_excess(dist),
684 // std::domain_error);
685 //BOOST_MATH_CHECK_THROW(
686 // skewness(dist),
687 // std::domain_error);
688
689 BOOST_MATH_CHECK_THROW(
690 quantile(dist, RealType(0.0)),
691 std::overflow_error);
692 BOOST_MATH_CHECK_THROW(
693 quantile(dist, RealType(1.0)),
694 std::overflow_error);
695 BOOST_MATH_CHECK_THROW(
696 quantile(complement(dist, RealType(0.0))),
697 std::overflow_error);
698 BOOST_MATH_CHECK_THROW(
699 quantile(complement(dist, RealType(1.0))),
700 std::overflow_error);
701
702 check_out_of_range<boost::math::cauchy_distribution<RealType> >(0, 1); // (All) valid constructor parameter values.
703
704
705
706 } // template <class RealType>void test_spots(RealType)
707
BOOST_AUTO_TEST_CASE(test_main)708 BOOST_AUTO_TEST_CASE( test_main )
709 {
710 BOOST_MATH_CONTROL_FP;
711 // Check that can generate cauchy distribution using the two convenience methods:
712 boost::math::cauchy mycd1(1.); // Using typedef
713 cauchy_distribution<> mycd2(1.); // Using default RealType double.
714 cauchy_distribution<> C01; // Using default RealType double for Standard Cauchy.
715 BOOST_CHECK_EQUAL(C01.location(), 0); // Check standard values.
716 BOOST_CHECK_EQUAL(C01.scale(), 1);
717
718 // Basic sanity-check spot values.
719 // (Parameter value, arbitrarily zero, only communicates the floating point type).
720 test_spots(0.0F); // Test float. OK at decdigits = 0 tolerance = 0.0001 %
721 test_spots(0.0); // Test double. OK at decdigits 7, tolerance = 1e07 %
722 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
723 test_spots(0.0L); // Test long double.
724 #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
725 test_spots(boost::math::concepts::real_concept(0.)); // Test real concept.
726 #endif
727 #else
728 std::cout << "<note>The long double tests have been disabled on this platform "
729 "either because the long double overloads of the usual math functions are "
730 "not available at all, or because they are too inaccurate for these tests "
731 "to pass.</note>" << std::endl;
732 #endif
733
734 } // BOOST_AUTO_TEST_CASE( test_main )
735
736 /*
737 Output:
738
739 Running 1 test case...
740 Tolerance for type float is 0.000596046 %
741 Tolerance for type double is 1.11022e-012 %
742 Tolerance for type long double is 1.11022e-012 %
743 Tolerance for type class boost::math::concepts::real_concept is 1.11022e-012 %
744 *** No errors detected
745
746 */
747