1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- #ifndef BOOST_HISTOGRAM_UTILITY_WILSON_INTERVAL_HPP
- #define BOOST_HISTOGRAM_UTILITY_WILSON_INTERVAL_HPP
- #include <boost/histogram/fwd.hpp>
- #include <boost/histogram/utility/binomial_proportion_interval.hpp>
- #include <cmath>
- #include <utility>
- namespace boost {
- namespace histogram {
- namespace utility {
- template <class ValueType>
- class wilson_interval : public binomial_proportion_interval<ValueType> {
- public:
- using value_type = typename wilson_interval::value_type;
- using interval_type = typename wilson_interval::interval_type;
-
- explicit wilson_interval(deviation d = deviation{1.0}) noexcept
- : z_{static_cast<value_type>(d)} {}
- using binomial_proportion_interval<ValueType>::operator();
-
- interval_type operator()(value_type successes, value_type failures) const noexcept {
-
-
-
-
-
-
- const value_type half{0.5}, quarter{0.25}, zsq{z_ * z_};
- const value_type total = successes + failures;
- const value_type minv = 1 / (total + zsq);
- const value_type t1 = (successes + half * zsq) * minv;
- const value_type t2 =
- z_ * minv * std::sqrt(successes * failures / total + quarter * zsq);
- return {t1 - t2, t1 + t2};
- }
- private:
- value_type z_;
- };
- }
- }
- }
- #endif
|