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