...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 ValueType> class mean { public: // types typedef ValueType value_type; typedef const value_type & const_reference; // construct/copy/destruct mean() = default; template<typename T> mean(const mean< T > &) noexcept; mean(const_reference, const_reference, const_reference) noexcept; // public member functions 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); };
Uses Welfords's incremental algorithm to improve the numerical stability of mean and variance computation.
mean
public
construct/copy/destructmean() = default;
template<typename T> mean(const mean< T > & o) noexcept;Allow implicit conversion from mean<T>.
mean(const_reference n, const_reference mean, const_reference variance) noexcept;Initialize to external count, mean, and variance.
mean
public member functionsvoid operator()(const_reference x) noexcept;Insert sample x.
void operator()(const weight_type< value_type > & w, const_reference x) noexcept;Insert sample x with weight w.
mean & operator+=(const mean & rhs) noexcept;Add another mean accumulator.
mean & operator *=(const_reference s) noexcept;Scale by value.
This acts as if all samples were scaled by the value.
bool operator==(const mean & rhs) const noexcept;
bool operator!=(const mean & rhs) const noexcept;
const_reference count() const noexcept;Return how many samples were accumulated.
const_reference value() const noexcept;Return mean value of accumulated samples.
The result is undefined, if count() < 1
.
value_type variance() const noexcept;Return variance of accumulated samples.
The result is undefined, if count() < 2
.
template<typename Archive> void serialize(Archive & ar, unsigned version);