annotate DEPENDENCIES/generic/include/boost/accumulators/statistics/pot_tail_mean.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_tail_mean.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_TAIL_MEAN_HPP_DE_01_01_2006
Chris@16 9 #define BOOST_ACCUMULATORS_STATISTICS_POT_TAIL_MEAN_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/range.hpp>
Chris@16 16 #include <boost/parameter/keyword.hpp>
Chris@16 17 #include <boost/tuple/tuple.hpp>
Chris@16 18 #include <boost/mpl/if.hpp>
Chris@16 19 #include <boost/mpl/placeholders.hpp>
Chris@16 20 #include <boost/type_traits/is_same.hpp>
Chris@16 21 #include <boost/accumulators/framework/accumulator_base.hpp>
Chris@16 22 #include <boost/accumulators/framework/extractor.hpp>
Chris@16 23 #include <boost/accumulators/numeric/functional.hpp>
Chris@16 24 #include <boost/accumulators/framework/parameters/sample.hpp>
Chris@16 25 #include <boost/accumulators/statistics_fwd.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 #include <boost/accumulators/statistics/pot_quantile.hpp>
Chris@16 29 #include <boost/accumulators/statistics/tail_mean.hpp>
Chris@16 30
Chris@16 31 namespace boost { namespace accumulators
Chris@16 32 {
Chris@16 33
Chris@16 34 namespace impl
Chris@16 35 {
Chris@16 36 ///////////////////////////////////////////////////////////////////////////////
Chris@16 37 // pot_tail_mean_impl
Chris@16 38 //
Chris@16 39 /**
Chris@16 40 @brief Estimation of the (coherent) tail mean based on the peaks over threshold method (for both left and right tails)
Chris@16 41
Chris@16 42 Computes an estimate for the (coherent) tail mean
Chris@16 43 \f[
Chris@16 44 \widehat{CTM}_{\alpha} = \hat{q}_{\alpha} - \frac{\bar{\beta}}{\xi-1}(1-\alpha)^{-\xi},
Chris@16 45 \f]
Chris@16 46 where \f$\bar[u]\f$, \f$\bar{\beta}\f$ and \f$\xi\f$ are the parameters of the
Chris@16 47 generalized Pareto distribution that approximates the right tail of the distribution (or the
Chris@16 48 mirrored left tail, in case the left tail is used). In the latter case, the result is mirrored
Chris@16 49 back, yielding the correct result.
Chris@16 50 */
Chris@16 51 template<typename Sample, typename Impl, typename LeftRight>
Chris@16 52 struct pot_tail_mean_impl
Chris@16 53 : accumulator_base
Chris@16 54 {
Chris@16 55 typedef typename numeric::functional::fdiv<Sample, std::size_t>::result_type float_type;
Chris@16 56 // for boost::result_of
Chris@16 57 typedef float_type result_type;
Chris@16 58
Chris@16 59 pot_tail_mean_impl(dont_care)
Chris@16 60 : sign_((is_same<LeftRight, left>::value) ? -1 : 1)
Chris@16 61 {
Chris@16 62 }
Chris@16 63
Chris@16 64 template<typename Args>
Chris@16 65 result_type result(Args const &args) const
Chris@16 66 {
Chris@16 67 typedef
Chris@16 68 typename mpl::if_<
Chris@16 69 is_same<Impl, weighted>
Chris@16 70 , tag::weighted_peaks_over_threshold<LeftRight>
Chris@16 71 , tag::peaks_over_threshold<LeftRight>
Chris@16 72 >::type
Chris@16 73 peaks_over_threshold_tag;
Chris@16 74
Chris@16 75 typedef
Chris@16 76 typename mpl::if_<
Chris@16 77 is_same<Impl, weighted>
Chris@16 78 , tag::weighted_pot_quantile<LeftRight>
Chris@16 79 , tag::pot_quantile<LeftRight>
Chris@16 80 >::type
Chris@16 81 pot_quantile_tag;
Chris@16 82
Chris@16 83 extractor<peaks_over_threshold_tag> const some_peaks_over_threshold = {};
Chris@16 84 extractor<pot_quantile_tag> const some_pot_quantile = {};
Chris@16 85
Chris@16 86 float_type beta_bar = some_peaks_over_threshold(args).template get<1>();
Chris@16 87 float_type xi_hat = some_peaks_over_threshold(args).template get<2>();
Chris@16 88
Chris@16 89 return some_pot_quantile(args) - this->sign_ * beta_bar/( xi_hat - 1. ) * std::pow(
Chris@16 90 is_same<LeftRight, left>::value ? args[quantile_probability] : 1. - args[quantile_probability]
Chris@16 91 , -xi_hat);
Chris@16 92 }
Chris@16 93 private:
Chris@16 94 short sign_; // if the fit parameters from the mirrored left tail extreme values are used, mirror back the result
Chris@16 95 };
Chris@16 96 } // namespace impl
Chris@16 97
Chris@16 98 ///////////////////////////////////////////////////////////////////////////////
Chris@16 99 // tag::pot_tail_mean
Chris@16 100 // tag::pot_tail_mean_prob
Chris@16 101 //
Chris@16 102 namespace tag
Chris@16 103 {
Chris@16 104 template<typename LeftRight>
Chris@16 105 struct pot_tail_mean
Chris@16 106 : depends_on<peaks_over_threshold<LeftRight>, pot_quantile<LeftRight> >
Chris@16 107 {
Chris@16 108 /// INTERNAL ONLY
Chris@16 109 ///
Chris@16 110 typedef accumulators::impl::pot_tail_mean_impl<mpl::_1, unweighted, LeftRight> impl;
Chris@16 111 };
Chris@16 112 template<typename LeftRight>
Chris@16 113 struct pot_tail_mean_prob
Chris@16 114 : depends_on<peaks_over_threshold_prob<LeftRight>, pot_quantile_prob<LeftRight> >
Chris@16 115 {
Chris@16 116 /// INTERNAL ONLY
Chris@16 117 ///
Chris@16 118 typedef accumulators::impl::pot_tail_mean_impl<mpl::_1, unweighted, LeftRight> impl;
Chris@16 119 };
Chris@16 120 template<typename LeftRight>
Chris@16 121 struct weighted_pot_tail_mean
Chris@16 122 : depends_on<weighted_peaks_over_threshold<LeftRight>, weighted_pot_quantile<LeftRight> >
Chris@16 123 {
Chris@16 124 /// INTERNAL ONLY
Chris@16 125 ///
Chris@16 126 typedef accumulators::impl::pot_tail_mean_impl<mpl::_1, weighted, LeftRight> impl;
Chris@16 127 };
Chris@16 128 template<typename LeftRight>
Chris@16 129 struct weighted_pot_tail_mean_prob
Chris@16 130 : depends_on<weighted_peaks_over_threshold_prob<LeftRight>, weighted_pot_quantile_prob<LeftRight> >
Chris@16 131 {
Chris@16 132 /// INTERNAL ONLY
Chris@16 133 ///
Chris@16 134 typedef accumulators::impl::pot_tail_mean_impl<mpl::_1, weighted, LeftRight> impl;
Chris@16 135 };
Chris@16 136 }
Chris@16 137
Chris@16 138 // pot_tail_mean<LeftRight>(with_threshold_value) -> pot_tail_mean<LeftRight>
Chris@16 139 template<typename LeftRight>
Chris@16 140 struct as_feature<tag::pot_tail_mean<LeftRight>(with_threshold_value)>
Chris@16 141 {
Chris@16 142 typedef tag::pot_tail_mean<LeftRight> type;
Chris@16 143 };
Chris@16 144
Chris@16 145 // pot_tail_mean<LeftRight>(with_threshold_probability) -> pot_tail_mean_prob<LeftRight>
Chris@16 146 template<typename LeftRight>
Chris@16 147 struct as_feature<tag::pot_tail_mean<LeftRight>(with_threshold_probability)>
Chris@16 148 {
Chris@16 149 typedef tag::pot_tail_mean_prob<LeftRight> type;
Chris@16 150 };
Chris@16 151
Chris@16 152 // weighted_pot_tail_mean<LeftRight>(with_threshold_value) -> weighted_pot_tail_mean<LeftRight>
Chris@16 153 template<typename LeftRight>
Chris@16 154 struct as_feature<tag::weighted_pot_tail_mean<LeftRight>(with_threshold_value)>
Chris@16 155 {
Chris@16 156 typedef tag::weighted_pot_tail_mean<LeftRight> type;
Chris@16 157 };
Chris@16 158
Chris@16 159 // weighted_pot_tail_mean<LeftRight>(with_threshold_probability) -> weighted_pot_tail_mean_prob<LeftRight>
Chris@16 160 template<typename LeftRight>
Chris@16 161 struct as_feature<tag::weighted_pot_tail_mean<LeftRight>(with_threshold_probability)>
Chris@16 162 {
Chris@16 163 typedef tag::weighted_pot_tail_mean_prob<LeftRight> type;
Chris@16 164 };
Chris@16 165
Chris@16 166 // for the purposes of feature-based dependency resolution,
Chris@16 167 // pot_tail_mean<LeftRight> and pot_tail_mean_prob<LeftRight> provide
Chris@16 168 // the same feature as tail_mean
Chris@16 169 template<typename LeftRight>
Chris@16 170 struct feature_of<tag::pot_tail_mean<LeftRight> >
Chris@16 171 : feature_of<tag::tail_mean>
Chris@16 172 {
Chris@16 173 };
Chris@16 174
Chris@16 175 template<typename LeftRight>
Chris@16 176 struct feature_of<tag::pot_tail_mean_prob<LeftRight> >
Chris@16 177 : feature_of<tag::tail_mean>
Chris@16 178 {
Chris@16 179 };
Chris@16 180
Chris@16 181 // So that pot_tail_mean can be automatically substituted
Chris@16 182 // with weighted_pot_tail_mean when the weight parameter is non-void.
Chris@16 183 template<typename LeftRight>
Chris@16 184 struct as_weighted_feature<tag::pot_tail_mean<LeftRight> >
Chris@16 185 {
Chris@16 186 typedef tag::weighted_pot_tail_mean<LeftRight> type;
Chris@16 187 };
Chris@16 188
Chris@16 189 template<typename LeftRight>
Chris@16 190 struct feature_of<tag::weighted_pot_tail_mean<LeftRight> >
Chris@16 191 : feature_of<tag::pot_tail_mean<LeftRight> >
Chris@16 192 {
Chris@16 193 };
Chris@16 194
Chris@16 195 // So that pot_tail_mean_prob can be automatically substituted
Chris@16 196 // with weighted_pot_tail_mean_prob when the weight parameter is non-void.
Chris@16 197 template<typename LeftRight>
Chris@16 198 struct as_weighted_feature<tag::pot_tail_mean_prob<LeftRight> >
Chris@16 199 {
Chris@16 200 typedef tag::weighted_pot_tail_mean_prob<LeftRight> type;
Chris@16 201 };
Chris@16 202
Chris@16 203 template<typename LeftRight>
Chris@16 204 struct feature_of<tag::weighted_pot_tail_mean_prob<LeftRight> >
Chris@16 205 : feature_of<tag::pot_tail_mean_prob<LeftRight> >
Chris@16 206 {
Chris@16 207 };
Chris@16 208
Chris@16 209 }} // namespace boost::accumulators
Chris@16 210
Chris@16 211 #endif