| Home | Libraries | People | FAQ | More

## Class template fraction

boost::histogram::accumulators::fraction — Accumulate boolean samples and compute the fraction of true samples.

## Synopsis

    // 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;

      // public member functions
      fraction();
      fraction(const_reference, const_reference) noexcept;
      template<typename T> fraction(const fraction< T > &) noexcept;
      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);
    };

## Description

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 member functions

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.

4.     void operator()(bool x) noexcept;

   Insert boolean sample x.

5.     fraction & operator+=(const fraction & rhs) noexcept;

   Add another accumulator.

6.     const_reference successes() const noexcept;

   Return number of boolean samples that were true.

7.     const_reference failures() const noexcept;

   Return number of boolean samples that were false.

8.     value_type count() const noexcept;

   Return total number of boolean samples.

9.     real_type value() const noexcept;

   Return success fraction of boolean samples.

10.     real_type variance() const noexcept;

    Return variance of the success fraction.

11.     interval_type confidence_interval() const noexcept;

    Return standard interval with 68.3 % confidence level (Wilson score interval).

12.     bool operator==(const fraction & rhs) const noexcept;

13.     bool operator!=(const fraction & rhs) const noexcept;

14.     template<typename Archive> void serialize(Archive & ar, unsigned);