Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // pot_quantile.hpp Chris@16: // Chris@16: // Copyright 2006 Daniel Egloff, Olivier Gygi. Distributed under the Boost Chris@16: // Software License, Version 1.0. (See accompanying file Chris@16: // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: #ifndef BOOST_ACCUMULATORS_STATISTICS_POT_QUANTILE_HPP_DE_01_01_2006 Chris@16: #define BOOST_ACCUMULATORS_STATISTICS_POT_QUANTILE_HPP_DE_01_01_2006 Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { namespace accumulators Chris@16: { Chris@16: Chris@16: namespace impl Chris@16: { Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // pot_quantile_impl Chris@16: // Chris@16: /** Chris@16: @brief Quantile Estimation based on Peaks over Threshold Method (for both left and right tails) Chris@16: Chris@16: Computes an estimate Chris@16: \f[ Chris@16: \hat{q}_{\alpha} = \bar{u} + \frac{\bar{\beta}}{\xi}\left[(1-\alpha)^{-\xi}-1\right] Chris@16: \f] Chris@16: 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: generalized Pareto distribution that approximates the right tail of the distribution (or the mirrored left tail, Chris@16: in case the left tail is used). In the latter case, the result is mirrored back, yielding the correct result. Chris@16: */ Chris@16: template Chris@16: struct pot_quantile_impl Chris@16: : accumulator_base Chris@16: { Chris@16: typedef typename numeric::functional::fdiv::result_type float_type; Chris@16: // for boost::result_of Chris@16: typedef float_type result_type; Chris@16: Chris@16: pot_quantile_impl(dont_care) Chris@16: : sign_((is_same::value) ? -1 : 1) Chris@16: { Chris@16: } Chris@16: Chris@16: template Chris@16: result_type result(Args const &args) const Chris@16: { Chris@16: typedef Chris@16: typename mpl::if_< Chris@16: is_same Chris@16: , tag::weighted_peaks_over_threshold Chris@16: , tag::peaks_over_threshold Chris@16: >::type Chris@16: peaks_over_threshold_tag; Chris@16: Chris@16: extractor const some_peaks_over_threshold = {}; Chris@16: Chris@16: float_type u_bar = some_peaks_over_threshold(args).template get<0>(); Chris@16: float_type beta_bar = some_peaks_over_threshold(args).template get<1>(); Chris@16: float_type xi_hat = some_peaks_over_threshold(args).template get<2>(); Chris@16: Chris@16: return this->sign_ * (u_bar + beta_bar/xi_hat * ( std::pow( Chris@16: is_same::value ? args[quantile_probability] : 1. - args[quantile_probability] Chris@16: , -xi_hat Chris@16: ) - 1.)); Chris@16: } Chris@16: Chris@16: private: Chris@16: short sign_; // if the fit parameters from the mirrored left tail extreme values are used, mirror back the result Chris@16: }; Chris@16: Chris@16: } // namespace impl Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // tag::pot_quantile<> Chris@16: // tag::pot_quantile_prob<> Chris@16: // tag::weighted_pot_quantile<> Chris@16: // tag::weighted_pot_quantile_prob<> Chris@16: // Chris@16: namespace tag Chris@16: { Chris@16: template Chris@16: struct pot_quantile Chris@16: : depends_on > Chris@16: { Chris@16: /// INTERNAL ONLY Chris@16: /// Chris@16: typedef accumulators::impl::pot_quantile_impl impl; Chris@16: }; Chris@16: template Chris@16: struct pot_quantile_prob Chris@16: : depends_on > Chris@16: { Chris@16: /// INTERNAL ONLY Chris@16: /// Chris@16: typedef accumulators::impl::pot_quantile_impl impl; Chris@16: }; Chris@16: template Chris@16: struct weighted_pot_quantile Chris@16: : depends_on > Chris@16: { Chris@16: /// INTERNAL ONLY Chris@16: /// Chris@16: typedef accumulators::impl::pot_quantile_impl impl; Chris@16: }; Chris@16: template Chris@16: struct weighted_pot_quantile_prob Chris@16: : depends_on > Chris@16: { Chris@16: /// INTERNAL ONLY Chris@16: /// Chris@16: typedef accumulators::impl::pot_quantile_impl impl; Chris@16: }; Chris@16: } Chris@16: Chris@16: // pot_quantile(with_threshold_value) -> pot_quantile Chris@16: template Chris@16: struct as_feature(with_threshold_value)> Chris@16: { Chris@16: typedef tag::pot_quantile type; Chris@16: }; Chris@16: Chris@16: // pot_quantile(with_threshold_probability) -> pot_quantile_prob Chris@16: template Chris@16: struct as_feature(with_threshold_probability)> Chris@16: { Chris@16: typedef tag::pot_quantile_prob type; Chris@16: }; Chris@16: Chris@16: // weighted_pot_quantile(with_threshold_value) -> weighted_pot_quantile Chris@16: template Chris@16: struct as_feature(with_threshold_value)> Chris@16: { Chris@16: typedef tag::weighted_pot_quantile type; Chris@16: }; Chris@16: Chris@16: // weighted_pot_quantile(with_threshold_probability) -> weighted_pot_quantile_prob Chris@16: template Chris@16: struct as_feature(with_threshold_probability)> Chris@16: { Chris@16: typedef tag::weighted_pot_quantile_prob type; Chris@16: }; Chris@16: Chris@16: // for the purposes of feature-based dependency resolution, Chris@16: // pot_quantile and pot_quantile_prob provide Chris@16: // the same feature as quantile Chris@16: template Chris@16: struct feature_of > Chris@16: : feature_of Chris@16: { Chris@16: }; Chris@16: Chris@16: template Chris@16: struct feature_of > Chris@16: : feature_of Chris@16: { Chris@16: }; Chris@16: Chris@16: // So that pot_quantile can be automatically substituted Chris@16: // with weighted_pot_quantile when the weight parameter is non-void. Chris@16: template Chris@16: struct as_weighted_feature > Chris@16: { Chris@16: typedef tag::weighted_pot_quantile type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct feature_of > Chris@16: : feature_of > Chris@16: { Chris@16: }; Chris@16: Chris@16: // So that pot_quantile_prob can be automatically substituted Chris@16: // with weighted_pot_quantile_prob when the weight parameter is non-void. Chris@16: template Chris@16: struct as_weighted_feature > Chris@16: { Chris@16: typedef tag::weighted_pot_quantile_prob type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct feature_of > Chris@16: : feature_of > Chris@16: { Chris@16: }; Chris@16: Chris@16: }} // namespace boost::accumulators Chris@16: Chris@16: #endif