| Home | Libraries | People | FAQ | More

## Class template mean

boost::histogram::accumulators::mean — Calculates mean and variance of sample.

## Synopsis

    // In header: <boost/histogram/accumulators/mean.hpp>

    template<typename ValueType>
    class mean {
    public:
      // types
      typedef ValueType          value_type;
      typedef const value_type & const_reference;

      // public member functions
      mean() = default;
      template<typename T> mean(const mean< T > &) noexcept;
      mean(const_reference, const_reference, const_reference) noexcept;
      void operator()(const_reference) noexcept;
      void operator()(const weight_type< value_type > &, const_reference) noexcept;
      mean & operator+=(const mean &) noexcept;
      mean & operator*=(const_reference) noexcept;
      bool operator==(const mean &) const noexcept;
      bool operator!=(const mean &) const noexcept;
      const_reference count() const noexcept;
      const_reference value() const noexcept;
      value_type variance() const noexcept;
      template<typename Archive> void serialize(Archive &, unsigned);
    };

## Description

Uses Welfords's incremental algorithm to improve the numerical stability of mean and variance computation.

### `mean` public member functions

1.     mean() = default;

2.     template<typename T> mean(const mean< T > & o) noexcept;

   Allow implicit conversion from mean<T>.

3.     mean(const_reference n, const_reference mean, const_reference variance) noexcept;

   Initialize to external count, mean, and variance.

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

   Insert sample x.

5.     void operator()(const weight_type< value_type > & w, const_reference x) noexcept;

   Insert sample x with weight w.

6.     mean & operator+=(const mean & rhs) noexcept;

   Add another mean accumulator.

7.     mean & operator*=(const_reference s) noexcept;

   Scale by value.

   This acts as if all samples were scaled by the value.

8.     bool operator==(const mean & rhs) const noexcept;

9.     bool operator!=(const mean & rhs) const noexcept;

10.     const_reference count() const noexcept;

    Return how many samples were accumulated.

    count() should be used to check whethervalue() andvariance() are defined, see documentation ofvalue() andvariance().count() can be used to compute the variance of the mean by dividingvariance() bycount().

11.     const_reference value() const noexcept;

    Return mean value of accumulated samples.

    The result is undefined, if `count() < 1`.

12.     value_type variance() const noexcept;

    Return variance of accumulated samples.

    The result is undefined, if `count() < 2`.

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