123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- #ifndef BOOST_HISTOGRAM_UTILITY_JEFFREYS_INTERVAL_HPP
- #define BOOST_HISTOGRAM_UTILITY_JEFFREYS_INTERVAL_HPP
- #include <boost/histogram/fwd.hpp>
- #include <boost/histogram/utility/binomial_proportion_interval.hpp>
- #include <boost/math/distributions/beta.hpp>
- #include <cmath>
- namespace boost {
- namespace histogram {
- namespace utility {
- template <class ValueType>
- class jeffreys_interval : public binomial_proportion_interval<ValueType> {
- public:
- using value_type = typename jeffreys_interval::value_type;
- using interval_type = typename jeffreys_interval::interval_type;
-
- explicit jeffreys_interval(confidence_level cl = deviation{1}) noexcept
- : alpha_half_{static_cast<value_type>(0.5 - 0.5 * static_cast<double>(cl))} {}
- using binomial_proportion_interval<ValueType>::operator();
-
- interval_type operator()(value_type successes, value_type failures) const noexcept {
-
-
- const value_type half{0.5};
- const value_type total = successes + failures;
-
- if (successes == 0) return {0, 1 - std::pow(alpha_half_, 1 / total)};
- if (failures == 0) return {std::pow(alpha_half_, 1 / total), 1};
- math::beta_distribution<value_type> beta(successes + half, failures + half);
- const value_type a = successes == 1 ? 0 : math::quantile(beta, alpha_half_);
- const value_type b = failures == 1 ? 1 : math::quantile(beta, 1 - alpha_half_);
- return {a, b};
- }
- private:
- value_type alpha_half_;
- };
- }
- }
- }
- #endif
|