...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::mean — Calculates mean and variance of sample.
// In header: <boost/histogram/accumulators/mean.hpp> template<typename RealType> class mean { public: // construct/copy/destruct mean() = default; mean(const std::size_t, const RealType &, const RealType &); // public member functions void operator()(const RealType &); template<typename T> mean & operator+=(const mean< T > &); mean & operator *=(const RealType &); template<typename T> bool operator==(const mean< T > &) const noexcept; template<typename T> bool operator!=(const mean< T > &) const noexcept; std::size_t count() const noexcept; const RealType & value() const noexcept; RealType variance() const; template<typename Archive> void serialize(Archive &, unsigned); };
Uses Welfords's incremental algorithm to improve the numerical stability of mean and variance computation.
mean
public member functionsvoid operator()(const RealType & x);
template<typename T> mean & operator+=(const mean< T > & rhs);
mean & operator *=(const RealType & s);
template<typename T> bool operator==(const mean< T > & rhs) const noexcept;
template<typename T> bool operator!=(const mean< T > & rhs) const noexcept;
std::size_t count() const noexcept;
const RealType & value() const noexcept;
RealType variance() const;
template<typename Archive> void serialize(Archive &, unsigned);