...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
boost::histogram::accumulators::fraction — Accumulate boolean samples and compute the fraction of true samples.
// In header: <boost/histogram/accumulators/fraction.hpp> template<typename ValueType> class fraction { public: // types typedef ValueType value_type; typedef const value_type & const_reference; typedef typename std::conditional< std::is_floating_point< value_type >::value, value_type, double >::type real_type; typedef typename utility::wilson_interval< real_type >::interval_type interval_type; // construct/copy/destruct fraction(); fraction(const_reference, const_reference) noexcept; template<typename T> fraction(const fraction< T > &) noexcept; // public member functions void operator()(bool) noexcept; fraction & operator+=(const fraction &) noexcept; const_reference successes() const noexcept; const_reference failures() const noexcept; value_type count() const noexcept; real_type value() const noexcept; real_type variance() const noexcept; interval_type confidence_interval() const noexcept; bool operator==(const fraction &) const noexcept; bool operator!=(const fraction &) const noexcept; template<typename Archive> void serialize(Archive &, unsigned); };
This accumulator should be used to calculate the efficiency or success fraction of a random process as a function of process parameters. It returns the fraction of successes, the variance of this fraction, and a two-sided confidence interval with 68.3 % confidence level for this fraction.
There is no unique way to compute an interval for a success fraction. This class returns the Wilson score interval, because it is widely recommended in the literature for general use. More interval computers can be found in boost/histogram/utility
, which can be used to compute intervals for other confidence levels.
fraction
public
construct/copy/destructfraction();
fraction(const_reference successes, const_reference failures) noexcept;Initialize to external successes and failures.
template<typename T> fraction(const fraction< T > & e) noexcept;Allow implicit conversion from fraction with a different value type.
fraction
public member functionsvoid operator()(bool x) noexcept;Insert boolean sample x.
fraction & operator+=(const fraction & rhs) noexcept;Add another accumulator.
const_reference successes() const noexcept;Return number of boolean samples that were true.
const_reference failures() const noexcept;Return number of boolean samples that were false.
value_type count() const noexcept;Return total number of boolean samples.
real_type value() const noexcept;Return success fraction of boolean samples.
real_type variance() const noexcept;Return variance of the success fraction.
interval_type confidence_interval() const noexcept;Return standard interval with 68.3 % confidence level (Wilson score interval).
bool operator==(const fraction & rhs) const noexcept;
bool operator!=(const fraction & rhs) const noexcept;
template<typename Archive> void serialize(Archive & ar, unsigned);