num::moment_accumulator¶
Defined in header <stats/concepts.hpp>
template <class A, class T = real>
concept moment_accumulator = streaming_accumulator<A, T> && requires(const A &acc) {
{ acc.variance() } -> std::convertible_to<T>;
{ acc.std_dev() } -> std::convertible_to<T>;
};
Accumulator reporting the first two moments.
\[
\mu_n = \mu_{n-1} + \frac{x_n - \mu_{n-1}}{n}, \qquad s^2 = \frac{M_{2,n}}{n - 1}
\]
The recurrence is used rather than \(\sum x^2 - n\mu^2\) because the latter cancels catastrophically when the variance is small relative to the mean.