1// (C) Copyright Eric Niebler 2005.
2// Use, modification and distribution are subject to the
3// Boost Software License, Version 1.0. (See accompanying file
4// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6// Test case for pot_quantile.hpp
7
8#define BOOST_NUMERIC_FUNCTIONAL_STD_COMPLEX_SUPPORT
9#define BOOST_NUMERIC_FUNCTIONAL_STD_VALARRAY_SUPPORT
10#define BOOST_NUMERIC_FUNCTIONAL_STD_VECTOR_SUPPORT
11
12#include <boost/random.hpp>
13#include <boost/test/unit_test.hpp>
14#include <boost/test/floating_point_comparison.hpp>
15#include <boost/accumulators/accumulators.hpp>
16#include <boost/accumulators/statistics.hpp>
17#include <boost/accumulators/statistics/peaks_over_threshold.hpp>
18
19using namespace boost;
20using namespace unit_test;
21using namespace boost::accumulators;
22
23///////////////////////////////////////////////////////////////////////////////
24// test_stat
25//
26void test_stat()
27{
28 // tolerance in %
29 double epsilon = 1.;
30
31 // two random number generators
32 boost::lagged_fibonacci607 rng;
33 boost::normal_distribution<> mean_sigma(0,1);
34 boost::exponential_distribution<> lambda(1);
35 boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal(rng, mean_sigma);
36 boost::variate_generator<boost::lagged_fibonacci607&, boost::exponential_distribution<> > exponential(rng, lambda);
37
38 accumulator_set<double, stats<tag::pot_quantile<right>(with_threshold_value)> > acc1(
39 pot_threshold_value = 3.
40 );
41 accumulator_set<double, stats<tag::pot_quantile<right>(with_threshold_probability)> > acc2(
42 right_tail_cache_size = 2000
43 , pot_threshold_probability = 0.99
44 );
45 accumulator_set<double, stats<tag::pot_quantile<left>(with_threshold_value)> > acc3(
46 pot_threshold_value = -3.
47 );
48 accumulator_set<double, stats<tag::pot_quantile<left>(with_threshold_probability)> > acc4(
49 left_tail_cache_size = 2000
50 , pot_threshold_probability = 0.01
51 );
52
53 accumulator_set<double, stats<tag::pot_quantile<right>(with_threshold_value)> > acc5(
54 pot_threshold_value = 5.
55 );
56 accumulator_set<double, stats<tag::pot_quantile<right>(with_threshold_probability)> > acc6(
57 right_tail_cache_size = 2000
58 , pot_threshold_probability = 0.995
59 );
60
61 for (std::size_t i = 0; i < 100000; ++i)
62 {
63 double sample = normal();
64 acc1(sample);
65 acc2(sample);
66 acc3(sample);
67 acc4(sample);
68 }
69
70 for (std::size_t i = 0; i < 100000; ++i)
71 {
72 double sample = exponential();
73 acc5(sample);
74 acc6(sample);
75 }
76
77 BOOST_CHECK_CLOSE( quantile(acc1, quantile_probability = 0.999), 3.090232, 3*epsilon );
78 BOOST_CHECK_CLOSE( quantile(acc2, quantile_probability = 0.999), 3.090232, 2*epsilon );
79 BOOST_CHECK_CLOSE( quantile(acc3, quantile_probability = 0.001), -3.090232, 2*epsilon );
80 BOOST_CHECK_CLOSE( quantile(acc4, quantile_probability = 0.001), -3.090232, 2*epsilon );
81
82 BOOST_CHECK_CLOSE( quantile(acc5, quantile_probability = 0.999), 6.908, 3*epsilon );
83 BOOST_CHECK_CLOSE( quantile(acc6, quantile_probability = 0.999), 6.908, 3*epsilon );
84}
85
86///////////////////////////////////////////////////////////////////////////////
87// init_unit_test_suite
88//
89test_suite* init_unit_test_suite( int argc, char* argv[] )
90{
91 test_suite *test = BOOST_TEST_SUITE("pot_quantile test");
92
93 test->add(BOOST_TEST_CASE(&test_stat));
94
95 return test;
96}
97
98

source code of boost/libs/accumulators/test/pot_quantile.cpp