1 // Copyright John Maddock 2006.
3 // Use, modification and distribution are subject to the
4 // Boost Software License, Version 1.0.
5 // (See accompanying file LICENSE_1_0.txt
6 // or copy at http://www.boost.org/LICENSE_1_0.txt)
8 // test_extreme_value.cpp
10 #include <boost/math/tools/test.hpp>
11 #include <boost/math/concepts/real_concept.hpp> // for real_concept
12 #include <boost/math/distributions/extreme_value.hpp>
13 using boost::math::extreme_value_distribution
;
15 #define BOOST_TEST_MAIN
16 #include <boost/test/unit_test.hpp> // Boost.Test
17 #include <boost/test/tools/floating_point_comparison.hpp>
18 #include "test_out_of_range.hpp"
23 using std::setprecision
;
25 template <class RealType
>
26 void test_spot(RealType a
, RealType b
, RealType x
, RealType p
, RealType q
, RealType tolerance
)
30 extreme_value_distribution
<RealType
>(a
, b
),
36 complement(extreme_value_distribution
<RealType
>(a
, b
),
40 if((p
< 0.999) && (p
> 0))
43 ::boost::math::quantile(
44 extreme_value_distribution
<RealType
>(a
, b
),
49 if((q
< 0.999) && (q
> 0))
52 ::boost::math::quantile(
53 complement(extreme_value_distribution
<RealType
>(a
, b
),
60 template <class RealType
>
61 void test_spots(RealType
)
63 // Basic sanity checks.
64 // 50eps as a percentage, up to a maximum of double precision
65 // (that's the limit of our test data).
66 RealType tolerance
= (std::max
)(
67 static_cast<RealType
>(boost::math::tools::epsilon
<double>()),
68 boost::math::tools::epsilon
<RealType
>());
69 tolerance
*= 50 * 100;
71 cout
<< "Tolerance for type " << typeid(RealType
).name() << " is " << tolerance
<< " %" << endl
;
73 // Results calculated by punching numbers into a calculator,
74 // and using the formula at http://mathworld.wolfram.com/ExtremeValueDistribution.html
76 static_cast<RealType
>(0.5), // a
77 static_cast<RealType
>(1.5), // b
78 static_cast<RealType
>(0.125), // x
79 static_cast<RealType
>(0.27692033409990891617007608217222L), // p
80 static_cast<RealType
>(0.72307966590009108382992391782778L), //q
83 static_cast<RealType
>(0.5), // a
84 static_cast<RealType
>(2), // b
85 static_cast<RealType
>(-5), // x
86 static_cast<RealType
>(1.6087601139887776413169427645933e-7L), // p
87 static_cast<RealType
>(0.99999983912398860112223586830572L), //q
90 static_cast<RealType
>(0.5), // a
91 static_cast<RealType
>(0.25), // b
92 static_cast<RealType
>(0.75), // x
93 static_cast<RealType
>(0.69220062755534635386542199718279L), // p
94 static_cast<RealType
>(0.30779937244465364613457800281721), //q
97 static_cast<RealType
>(0.5), // a
98 static_cast<RealType
>(0.25), // b
99 static_cast<RealType
>(5), // x
100 static_cast<RealType
>(0.99999998477002037126351248727041L), // p
101 static_cast<RealType
>(1.5229979628736487512729586276294e-8L), //q
106 extreme_value_distribution
<RealType
>(0.5, 2),
107 static_cast<RealType
>(0.125)), // x
108 static_cast<RealType
>(0.18052654830890205978204427757846L), // probability.
112 extreme_value_distribution
<RealType
>(1, 3),
113 static_cast<RealType
>(5)), // x
114 static_cast<RealType
>(0.0675057324099851209129017326286L), // probability.
118 extreme_value_distribution
<RealType
>(1, 3),
119 static_cast<RealType
>(0)), // x
120 static_cast<RealType
>(0.11522236828583456431277265757312L), // probability.
125 extreme_value_distribution
<RealType
>(2, 3)),
126 static_cast<RealType
>(3.731646994704598581819536270246L),
129 ::boost::math::standard_deviation(
130 extreme_value_distribution
<RealType
>(1, 0.5)),
131 static_cast<RealType
>(0.6412749150809320477720181798355L),
135 extreme_value_distribution
<RealType
>(2, 3)),
136 static_cast<RealType
>(2),
139 ::boost::math::median(
140 extreme_value_distribution
<RealType
>(0, 1)),
141 static_cast<RealType
>(+0.36651292058166432701243915823266946945426344783710526305367771367056),
145 ::boost::math::skewness(
146 extreme_value_distribution
<RealType
>(2, 3)),
147 static_cast<RealType
>(1.1395470994046486574927930193898461120875997958366L),
150 ::boost::math::kurtosis(
151 extreme_value_distribution
<RealType
>(2, 3)),
152 static_cast<RealType
>(5.4),
155 ::boost::math::kurtosis_excess(
156 extreme_value_distribution
<RealType
>(2, 3)),
157 static_cast<RealType
>(2.4),
161 // Things that are errors:
163 extreme_value_distribution
<RealType
> dist(0.5, 2);
164 BOOST_MATH_CHECK_THROW(
165 quantile(dist
, RealType(1.0)),
166 std::overflow_error
);
167 BOOST_MATH_CHECK_THROW(
168 quantile(complement(dist
, RealType(0.0))),
169 std::overflow_error
);
170 BOOST_MATH_CHECK_THROW(
171 quantile(dist
, RealType(0.0)),
172 std::overflow_error
);
173 BOOST_MATH_CHECK_THROW(
174 quantile(complement(dist
, RealType(1.0))),
175 std::overflow_error
);
176 BOOST_MATH_CHECK_THROW(
177 cdf(extreme_value_distribution
<RealType
>(0, -1), RealType(1)),
179 BOOST_MATH_CHECK_THROW(
180 quantile(dist
, RealType(-1)),
182 BOOST_MATH_CHECK_THROW(
183 quantile(dist
, RealType(2)),
185 check_out_of_range
<extreme_value_distribution
<RealType
> >(1, 2);
186 if(std::numeric_limits
<RealType
>::has_infinity
)
188 RealType inf
= std::numeric_limits
<RealType
>::infinity();
189 BOOST_CHECK_EQUAL(pdf(extreme_value_distribution
<RealType
>(), -inf
), 0);
190 BOOST_CHECK_EQUAL(pdf(extreme_value_distribution
<RealType
>(), inf
), 0);
191 BOOST_CHECK_EQUAL(cdf(extreme_value_distribution
<RealType
>(), -inf
), 0);
192 BOOST_CHECK_EQUAL(cdf(extreme_value_distribution
<RealType
>(), inf
), 1);
193 BOOST_CHECK_EQUAL(cdf(complement(extreme_value_distribution
<RealType
>(), -inf
)), 1);
194 BOOST_CHECK_EQUAL(cdf(complement(extreme_value_distribution
<RealType
>(), inf
)), 0);
199 // https://svn.boost.org/trac/boost/ticket/10938:
202 extreme_value_distribution
<RealType
>(0, 1),
203 static_cast<RealType
>(-1000)), // x
204 static_cast<RealType
>(0), // probability.
207 } // template <class RealType>void test_spots(RealType)
209 BOOST_AUTO_TEST_CASE( test_main
)
212 // Check that can generate extreme_value distribution using the two convenience methods:
213 boost::math::extreme_value
mycev1(1.); // Using typedef
214 extreme_value_distribution
<> myev2(1.); // Using default RealType double.
216 // Basic sanity-check spot values.
217 // (Parameter value, arbitrarily zero, only communicates the floating point type).
218 test_spots(0.0F
); // Test float. OK at decdigits = 0 tolerance = 0.0001 %
219 test_spots(0.0); // Test double. OK at decdigits 7, tolerance = 1e07 %
220 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
221 test_spots(0.0L); // Test long double.
222 #if !BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x582))
223 test_spots(boost::math::concepts::real_concept(0.)); // Test real concept.
226 std::cout
<< "<note>The long double tests have been disabled on this platform "
227 "either because the long double overloads of the usual math functions are "
228 "not available at all, or because they are too inaccurate for these tests "
229 "to pass.</note>" << std::endl
;
233 } // BOOST_AUTO_TEST_CASE( test_main )
239 -Running 1 test case...
240 Tolerance for type float is 0.000596046 %
241 Tolerance for type double is 1.11022e-012 %
242 Tolerance for type long double is 1.11022e-012 %
243 Tolerance for type class boost::math::concepts::real_concept is 1.11022e-012 %
244 *** No errors detected