Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.

Class template fraction

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 {
  // 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(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/destruct

  1. fraction();
  2. fraction(const_reference successes, const_reference failures) noexcept;
    Initialize to external successes and failures.
  3. template<typename T> fraction(const fraction< T > & e) noexcept;
    Allow implicit conversion from fraction with a different value type.

fraction public member functions

  1. void operator()(bool x) noexcept;
    Insert boolean sample x.
  2. fraction & operator+=(const fraction & rhs) noexcept;
    Add another accumulator.
  3. const_reference successes() const noexcept;
    Return number of boolean samples that were true.
  4. const_reference failures() const noexcept;
    Return number of boolean samples that were false.
  5. value_type count() const noexcept;
    Return total number of boolean samples.
  6. real_type value() const noexcept;
    Return success fraction of boolean samples.
  7. real_type variance() const noexcept;
    Return variance of the success fraction.
  8. interval_type confidence_interval() const noexcept;
    Return standard interval with 68.3 % confidence level (Wilson score interval).
  9. bool operator==(const fraction & rhs) const noexcept;
  10. bool operator!=(const fraction & rhs) const noexcept;
  11. template<typename Archive> void serialize(Archive & ar, unsigned);