#include <genesis/utils/math/moments.hpp>
Compute running mean and variance for an input.
The class allows to keep a running mean and variance for some input, without having to know the number of elements beforehand, and in a single pass.
This class is modelled after Knuth's algorithm in TAOCP vol 2, 3rd edition, page 232. See also https://www.johndcook.com/blog/standard_deviation/ and https://stackoverflow.com/q/2341340
Definition at line 54 of file moments.hpp.
Public Member Functions | |
template<class It > | |
Moments (It first, It last, size_t ddof=0) | |
Compute Momemnts by iteration over a range of double . More... | |
Moments (Moments &&)=default | |
Moments (Moments const &)=default | |
Moments (size_t ddof=0) | |
Construct empty Moments. More... | |
Moments (std::initializer_list< double > list, size_t ddof=0) | |
Compute Moments, over an initializer list of values. More... | |
~Moments ()=default | |
size_t | count () const |
double | mean () const |
Moments & | operator= (Moments &&)=default |
Moments & | operator= (Moments const &)=default |
void | push (double val) |
double | standard_deviation () const |
double | stddev () const |
double | variance () const |
|
inlineexplicit |
Construct empty Moments.
Takes the ddof
"Delta Degrees of Freedom": the divisor used in the calculation of the variance is N - ddof, where N represents the number of elements. By default ddof
is zero, meaning that we are computing the population variance (and standard deviation), instead of the sample variance. See for instance https://numpy.org/doc/stable/reference/generated/numpy.var.html for details.
Definition at line 71 of file moments.hpp.
|
inline |
Compute Momemnts by iteration over a range of double
.
The given iterator pair first
to last
needs to dereference to values that are convertible to double
.
Definition at line 82 of file moments.hpp.
|
inline |
Compute Moments, over an initializer list of values.
Definition at line 94 of file moments.hpp.
|
default |
|
inline |
Definition at line 128 of file moments.hpp.
|
inline |
Definition at line 133 of file moments.hpp.
|
inline |
Definition at line 114 of file moments.hpp.
|
inline |
Definition at line 148 of file moments.hpp.
|
inline |
Definition at line 143 of file moments.hpp.
|
inline |
Definition at line 138 of file moments.hpp.