1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
|
// Copyright John Maddock 2006.
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
// test_extreme_value.cpp
#include <boost/math/tools/test.hpp>
#include <boost/math/concepts/real_concept.hpp> // for real_concept
#include <boost/math/distributions/extreme_value.hpp>
using boost::math::extreme_value_distribution;
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp> // Boost.Test
#include <boost/test/tools/floating_point_comparison.hpp>
#include "test_out_of_range.hpp"
#include <iostream>
using std::cout;
using std::endl;
using std::setprecision;
template <class RealType>
void test_spot(RealType a, RealType b, RealType x, RealType p, RealType q, RealType tolerance)
{
BOOST_CHECK_CLOSE(
::boost::math::cdf(
extreme_value_distribution<RealType>(a, b),
x),
p,
tolerance); // %
BOOST_CHECK_CLOSE(
::boost::math::cdf(
complement(extreme_value_distribution<RealType>(a, b),
x)),
q,
tolerance); // %
if((p < 0.999) && (p > 0))
{
BOOST_CHECK_CLOSE(
::boost::math::quantile(
extreme_value_distribution<RealType>(a, b),
p),
x,
tolerance); // %
}
if((q < 0.999) && (q > 0))
{
BOOST_CHECK_CLOSE(
::boost::math::quantile(
complement(extreme_value_distribution<RealType>(a, b),
q)),
x,
tolerance); // %
}
}
template <class RealType>
void test_spots(RealType)
{
// Basic sanity checks.
// 50eps as a percentage, up to a maximum of double precision
// (that's the limit of our test data).
RealType tolerance = (std::max)(
static_cast<RealType>(boost::math::tools::epsilon<double>()),
boost::math::tools::epsilon<RealType>());
tolerance *= 50 * 100;
cout << "Tolerance for type " << typeid(RealType).name() << " is " << tolerance << " %" << endl;
// Results calculated by punching numbers into a calculator,
// and using the formula at http://mathworld.wolfram.com/ExtremeValueDistribution.html
test_spot(
static_cast<RealType>(0.5), // a
static_cast<RealType>(1.5), // b
static_cast<RealType>(0.125), // x
static_cast<RealType>(0.27692033409990891617007608217222L), // p
static_cast<RealType>(0.72307966590009108382992391782778L), //q
tolerance);
test_spot(
static_cast<RealType>(0.5), // a
static_cast<RealType>(2), // b
static_cast<RealType>(-5), // x
static_cast<RealType>(1.6087601139887776413169427645933e-7L), // p
static_cast<RealType>(0.99999983912398860112223586830572L), //q
tolerance);
test_spot(
static_cast<RealType>(0.5), // a
static_cast<RealType>(0.25), // b
static_cast<RealType>(0.75), // x
static_cast<RealType>(0.69220062755534635386542199718279L), // p
static_cast<RealType>(0.30779937244465364613457800281721), //q
tolerance);
test_spot(
static_cast<RealType>(0.5), // a
static_cast<RealType>(0.25), // b
static_cast<RealType>(5), // x
static_cast<RealType>(0.99999998477002037126351248727041L), // p
static_cast<RealType>(1.5229979628736487512729586276294e-8L), //q
tolerance);
BOOST_CHECK_CLOSE(
::boost::math::pdf(
extreme_value_distribution<RealType>(0.5, 2),
static_cast<RealType>(0.125)), // x
static_cast<RealType>(0.18052654830890205978204427757846L), // probability.
tolerance); // %
BOOST_CHECK_CLOSE(
::boost::math::pdf(
extreme_value_distribution<RealType>(1, 3),
static_cast<RealType>(5)), // x
static_cast<RealType>(0.0675057324099851209129017326286L), // probability.
tolerance); // %
BOOST_CHECK_CLOSE(
::boost::math::pdf(
extreme_value_distribution<RealType>(1, 3),
static_cast<RealType>(0)), // x
static_cast<RealType>(0.11522236828583456431277265757312L), // probability.
tolerance); // %
BOOST_CHECK_CLOSE(
::boost::math::mean(
extreme_value_distribution<RealType>(2, 3)),
static_cast<RealType>(3.731646994704598581819536270246L),
tolerance); // %
BOOST_CHECK_CLOSE(
::boost::math::standard_deviation(
extreme_value_distribution<RealType>(1, 0.5)),
static_cast<RealType>(0.6412749150809320477720181798355L),
tolerance); // %
BOOST_CHECK_CLOSE(
::boost::math::mode(
extreme_value_distribution<RealType>(2, 3)),
static_cast<RealType>(2),
tolerance); // %
BOOST_CHECK_CLOSE(
::boost::math::median(
extreme_value_distribution<RealType>(0, 1)),
static_cast<RealType>(+0.36651292058166432701243915823266946945426344783710526305367771367056),
tolerance); // %
BOOST_CHECK_CLOSE(
::boost::math::skewness(
extreme_value_distribution<RealType>(2, 3)),
static_cast<RealType>(1.1395470994046486574927930193898461120875997958366L),
tolerance); // %
BOOST_CHECK_CLOSE(
::boost::math::kurtosis(
extreme_value_distribution<RealType>(2, 3)),
static_cast<RealType>(5.4),
tolerance); // %
BOOST_CHECK_CLOSE(
::boost::math::kurtosis_excess(
extreme_value_distribution<RealType>(2, 3)),
static_cast<RealType>(2.4),
tolerance); // %
//
// Things that are errors:
//
extreme_value_distribution<RealType> dist(0.5, 2);
BOOST_MATH_CHECK_THROW(
quantile(dist, RealType(1.0)),
std::overflow_error);
BOOST_MATH_CHECK_THROW(
quantile(complement(dist, RealType(0.0))),
std::overflow_error);
BOOST_MATH_CHECK_THROW(
quantile(dist, RealType(0.0)),
std::overflow_error);
BOOST_MATH_CHECK_THROW(
quantile(complement(dist, RealType(1.0))),
std::overflow_error);
BOOST_MATH_CHECK_THROW(
cdf(extreme_value_distribution<RealType>(0, -1), RealType(1)),
std::domain_error);
BOOST_MATH_CHECK_THROW(
quantile(dist, RealType(-1)),
std::domain_error);
BOOST_MATH_CHECK_THROW(
quantile(dist, RealType(2)),
std::domain_error);
check_out_of_range<extreme_value_distribution<RealType> >(1, 2);
if(std::numeric_limits<RealType>::has_infinity)
{
RealType inf = std::numeric_limits<RealType>::infinity();
BOOST_CHECK_EQUAL(pdf(extreme_value_distribution<RealType>(), -inf), 0);
BOOST_CHECK_EQUAL(pdf(extreme_value_distribution<RealType>(), inf), 0);
BOOST_CHECK_EQUAL(cdf(extreme_value_distribution<RealType>(), -inf), 0);
BOOST_CHECK_EQUAL(cdf(extreme_value_distribution<RealType>(), inf), 1);
BOOST_CHECK_EQUAL(cdf(complement(extreme_value_distribution<RealType>(), -inf)), 1);
BOOST_CHECK_EQUAL(cdf(complement(extreme_value_distribution<RealType>(), inf)), 0);
}
//
// Bug reports:
//
// https://svn.boost.org/trac/boost/ticket/10938:
BOOST_CHECK_CLOSE(
::boost::math::pdf(
extreme_value_distribution<RealType>(0, 1),
static_cast<RealType>(-1000)), // x
static_cast<RealType>(0), // probability.
tolerance); // %
} // template <class RealType>void test_spots(RealType)
BOOST_AUTO_TEST_CASE( test_main )
{
// Check that can generate extreme_value distribution using the two convenience methods:
boost::math::extreme_value mycev1(1.); // Using typedef
extreme_value_distribution<> myev2(1.); // Using default RealType double.
// Basic sanity-check spot values.
// (Parameter value, arbitrarily zero, only communicates the floating point type).
test_spots(0.0F); // Test float. OK at decdigits = 0 tolerance = 0.0001 %
test_spots(0.0); // Test double. OK at decdigits 7, tolerance = 1e07 %
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
test_spots(0.0L); // Test long double.
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
test_spots(boost::math::concepts::real_concept(0.)); // Test real concept.
#endif
#else
std::cout << "<note>The long double tests have been disabled on this platform "
"either because the long double overloads of the usual math functions are "
"not available at all, or because they are too inaccurate for these tests "
"to pass.</note>" << std::endl;
#endif
} // BOOST_AUTO_TEST_CASE( test_main )
/*
Output is:
-Running 1 test case...
Tolerance for type float is 0.000596046 %
Tolerance for type double is 1.11022e-012 %
Tolerance for type long double is 1.11022e-012 %
Tolerance for type class boost::math::concepts::real_concept is 1.11022e-012 %
*** No errors detected
*/
|