annotate DEPENDENCIES/generic/include/boost/accumulators/statistics/pot_quantile.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1 ///////////////////////////////////////////////////////////////////////////////
Chris@16 2 // pot_quantile.hpp
Chris@16 3 //
Chris@16 4 // Copyright 2006 Daniel Egloff, Olivier Gygi. Distributed under the Boost
Chris@16 5 // Software License, Version 1.0. (See accompanying file
Chris@16 6 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 7
Chris@16 8 #ifndef BOOST_ACCUMULATORS_STATISTICS_POT_QUANTILE_HPP_DE_01_01_2006
Chris@16 9 #define BOOST_ACCUMULATORS_STATISTICS_POT_QUANTILE_HPP_DE_01_01_2006
Chris@16 10
Chris@16 11 #include <vector>
Chris@16 12 #include <limits>
Chris@16 13 #include <numeric>
Chris@16 14 #include <functional>
Chris@16 15 #include <boost/parameter/keyword.hpp>
Chris@16 16 #include <boost/tuple/tuple.hpp>
Chris@16 17 #include <boost/mpl/if.hpp>
Chris@16 18 #include <boost/type_traits/is_same.hpp>
Chris@16 19 #include <boost/mpl/placeholders.hpp>
Chris@16 20 #include <boost/accumulators/framework/accumulator_base.hpp>
Chris@16 21 #include <boost/accumulators/framework/extractor.hpp>
Chris@16 22 #include <boost/accumulators/numeric/functional.hpp>
Chris@16 23 #include <boost/accumulators/framework/parameters/sample.hpp>
Chris@16 24 #include <boost/accumulators/statistics_fwd.hpp>
Chris@16 25 #include <boost/accumulators/statistics/tail.hpp>
Chris@16 26 #include <boost/accumulators/statistics/peaks_over_threshold.hpp>
Chris@16 27 #include <boost/accumulators/statistics/weighted_peaks_over_threshold.hpp>
Chris@16 28
Chris@16 29 namespace boost { namespace accumulators
Chris@16 30 {
Chris@16 31
Chris@16 32 namespace impl
Chris@16 33 {
Chris@16 34 ///////////////////////////////////////////////////////////////////////////////
Chris@16 35 // pot_quantile_impl
Chris@16 36 //
Chris@16 37 /**
Chris@16 38 @brief Quantile Estimation based on Peaks over Threshold Method (for both left and right tails)
Chris@16 39
Chris@16 40 Computes an estimate
Chris@16 41 \f[
Chris@16 42 \hat{q}_{\alpha} = \bar{u} + \frac{\bar{\beta}}{\xi}\left[(1-\alpha)^{-\xi}-1\right]
Chris@16 43 \f]
Chris@16 44 for a right or left extreme quantile, \f$\bar[u]\f$, \f$\bar{\beta}\f$ and \f$\xi\f$ being the parameters of the
Chris@16 45 generalized Pareto distribution that approximates the right tail of the distribution (or the mirrored left tail,
Chris@16 46 in case the left tail is used). In the latter case, the result is mirrored back, yielding the correct result.
Chris@16 47 */
Chris@16 48 template<typename Sample, typename Impl, typename LeftRight>
Chris@16 49 struct pot_quantile_impl
Chris@16 50 : accumulator_base
Chris@16 51 {
Chris@16 52 typedef typename numeric::functional::fdiv<Sample, std::size_t>::result_type float_type;
Chris@16 53 // for boost::result_of
Chris@16 54 typedef float_type result_type;
Chris@16 55
Chris@16 56 pot_quantile_impl(dont_care)
Chris@16 57 : sign_((is_same<LeftRight, left>::value) ? -1 : 1)
Chris@16 58 {
Chris@16 59 }
Chris@16 60
Chris@16 61 template<typename Args>
Chris@16 62 result_type result(Args const &args) const
Chris@16 63 {
Chris@16 64 typedef
Chris@16 65 typename mpl::if_<
Chris@16 66 is_same<Impl, weighted>
Chris@16 67 , tag::weighted_peaks_over_threshold<LeftRight>
Chris@16 68 , tag::peaks_over_threshold<LeftRight>
Chris@16 69 >::type
Chris@16 70 peaks_over_threshold_tag;
Chris@16 71
Chris@16 72 extractor<peaks_over_threshold_tag> const some_peaks_over_threshold = {};
Chris@16 73
Chris@16 74 float_type u_bar = some_peaks_over_threshold(args).template get<0>();
Chris@16 75 float_type beta_bar = some_peaks_over_threshold(args).template get<1>();
Chris@16 76 float_type xi_hat = some_peaks_over_threshold(args).template get<2>();
Chris@16 77
Chris@16 78 return this->sign_ * (u_bar + beta_bar/xi_hat * ( std::pow(
Chris@16 79 is_same<LeftRight, left>::value ? args[quantile_probability] : 1. - args[quantile_probability]
Chris@16 80 , -xi_hat
Chris@16 81 ) - 1.));
Chris@16 82 }
Chris@16 83
Chris@16 84 private:
Chris@16 85 short sign_; // if the fit parameters from the mirrored left tail extreme values are used, mirror back the result
Chris@16 86 };
Chris@16 87
Chris@16 88 } // namespace impl
Chris@16 89
Chris@16 90 ///////////////////////////////////////////////////////////////////////////////
Chris@16 91 // tag::pot_quantile<>
Chris@16 92 // tag::pot_quantile_prob<>
Chris@16 93 // tag::weighted_pot_quantile<>
Chris@16 94 // tag::weighted_pot_quantile_prob<>
Chris@16 95 //
Chris@16 96 namespace tag
Chris@16 97 {
Chris@16 98 template<typename LeftRight>
Chris@16 99 struct pot_quantile
Chris@16 100 : depends_on<peaks_over_threshold<LeftRight> >
Chris@16 101 {
Chris@16 102 /// INTERNAL ONLY
Chris@16 103 ///
Chris@16 104 typedef accumulators::impl::pot_quantile_impl<mpl::_1, unweighted, LeftRight> impl;
Chris@16 105 };
Chris@16 106 template<typename LeftRight>
Chris@16 107 struct pot_quantile_prob
Chris@16 108 : depends_on<peaks_over_threshold_prob<LeftRight> >
Chris@16 109 {
Chris@16 110 /// INTERNAL ONLY
Chris@16 111 ///
Chris@16 112 typedef accumulators::impl::pot_quantile_impl<mpl::_1, unweighted, LeftRight> impl;
Chris@16 113 };
Chris@16 114 template<typename LeftRight>
Chris@16 115 struct weighted_pot_quantile
Chris@16 116 : depends_on<weighted_peaks_over_threshold<LeftRight> >
Chris@16 117 {
Chris@16 118 /// INTERNAL ONLY
Chris@16 119 ///
Chris@16 120 typedef accumulators::impl::pot_quantile_impl<mpl::_1, weighted, LeftRight> impl;
Chris@16 121 };
Chris@16 122 template<typename LeftRight>
Chris@16 123 struct weighted_pot_quantile_prob
Chris@16 124 : depends_on<weighted_peaks_over_threshold_prob<LeftRight> >
Chris@16 125 {
Chris@16 126 /// INTERNAL ONLY
Chris@16 127 ///
Chris@16 128 typedef accumulators::impl::pot_quantile_impl<mpl::_1, weighted, LeftRight> impl;
Chris@16 129 };
Chris@16 130 }
Chris@16 131
Chris@16 132 // pot_quantile<LeftRight>(with_threshold_value) -> pot_quantile<LeftRight>
Chris@16 133 template<typename LeftRight>
Chris@16 134 struct as_feature<tag::pot_quantile<LeftRight>(with_threshold_value)>
Chris@16 135 {
Chris@16 136 typedef tag::pot_quantile<LeftRight> type;
Chris@16 137 };
Chris@16 138
Chris@16 139 // pot_quantile<LeftRight>(with_threshold_probability) -> pot_quantile_prob<LeftRight>
Chris@16 140 template<typename LeftRight>
Chris@16 141 struct as_feature<tag::pot_quantile<LeftRight>(with_threshold_probability)>
Chris@16 142 {
Chris@16 143 typedef tag::pot_quantile_prob<LeftRight> type;
Chris@16 144 };
Chris@16 145
Chris@16 146 // weighted_pot_quantile<LeftRight>(with_threshold_value) -> weighted_pot_quantile<LeftRight>
Chris@16 147 template<typename LeftRight>
Chris@16 148 struct as_feature<tag::weighted_pot_quantile<LeftRight>(with_threshold_value)>
Chris@16 149 {
Chris@16 150 typedef tag::weighted_pot_quantile<LeftRight> type;
Chris@16 151 };
Chris@16 152
Chris@16 153 // weighted_pot_quantile<LeftRight>(with_threshold_probability) -> weighted_pot_quantile_prob<LeftRight>
Chris@16 154 template<typename LeftRight>
Chris@16 155 struct as_feature<tag::weighted_pot_quantile<LeftRight>(with_threshold_probability)>
Chris@16 156 {
Chris@16 157 typedef tag::weighted_pot_quantile_prob<LeftRight> type;
Chris@16 158 };
Chris@16 159
Chris@16 160 // for the purposes of feature-based dependency resolution,
Chris@16 161 // pot_quantile<LeftRight> and pot_quantile_prob<LeftRight> provide
Chris@16 162 // the same feature as quantile
Chris@16 163 template<typename LeftRight>
Chris@16 164 struct feature_of<tag::pot_quantile<LeftRight> >
Chris@16 165 : feature_of<tag::quantile>
Chris@16 166 {
Chris@16 167 };
Chris@16 168
Chris@16 169 template<typename LeftRight>
Chris@16 170 struct feature_of<tag::pot_quantile_prob<LeftRight> >
Chris@16 171 : feature_of<tag::quantile>
Chris@16 172 {
Chris@16 173 };
Chris@16 174
Chris@16 175 // So that pot_quantile can be automatically substituted
Chris@16 176 // with weighted_pot_quantile when the weight parameter is non-void.
Chris@16 177 template<typename LeftRight>
Chris@16 178 struct as_weighted_feature<tag::pot_quantile<LeftRight> >
Chris@16 179 {
Chris@16 180 typedef tag::weighted_pot_quantile<LeftRight> type;
Chris@16 181 };
Chris@16 182
Chris@16 183 template<typename LeftRight>
Chris@16 184 struct feature_of<tag::weighted_pot_quantile<LeftRight> >
Chris@16 185 : feature_of<tag::pot_quantile<LeftRight> >
Chris@16 186 {
Chris@16 187 };
Chris@16 188
Chris@16 189 // So that pot_quantile_prob can be automatically substituted
Chris@16 190 // with weighted_pot_quantile_prob when the weight parameter is non-void.
Chris@16 191 template<typename LeftRight>
Chris@16 192 struct as_weighted_feature<tag::pot_quantile_prob<LeftRight> >
Chris@16 193 {
Chris@16 194 typedef tag::weighted_pot_quantile_prob<LeftRight> type;
Chris@16 195 };
Chris@16 196
Chris@16 197 template<typename LeftRight>
Chris@16 198 struct feature_of<tag::weighted_pot_quantile_prob<LeftRight> >
Chris@16 199 : feature_of<tag::pot_quantile_prob<LeftRight> >
Chris@16 200 {
Chris@16 201 };
Chris@16 202
Chris@16 203 }} // namespace boost::accumulators
Chris@16 204
Chris@16 205 #endif