A library for working with phylogenetic and population genetic data.
v0.32.0
Moments Class Reference

#include <genesis/utils/math/moments.hpp>

Detailed Description

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
 
Momentsoperator= (Moments &&)=default
 
Momentsoperator= (Moments const &)=default
 
void push (double val)
 
double standard_deviation () const
 
double stddev () const
 
double variance () const
 

Constructor & Destructor Documentation

◆ Moments() [1/5]

Moments ( size_t  ddof = 0)
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.

◆ Moments() [2/5]

Moments ( It  first,
It  last,
size_t  ddof = 0 
)
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.

◆ Moments() [3/5]

Moments ( std::initializer_list< double >  list,
size_t  ddof = 0 
)
inline

Compute Moments, over an initializer list of values.

Definition at line 94 of file moments.hpp.

◆ ~Moments()

~Moments ( )
default

◆ Moments() [4/5]

Moments ( Moments const &  )
default

◆ Moments() [5/5]

Moments ( Moments &&  )
default

Member Function Documentation

◆ count()

size_t count ( ) const
inline

Definition at line 128 of file moments.hpp.

◆ mean()

double mean ( ) const
inline

Definition at line 133 of file moments.hpp.

◆ operator=() [1/2]

Moments& operator= ( Moments &&  )
default

◆ operator=() [2/2]

Moments& operator= ( Moments const &  )
default

◆ push()

void push ( double  val)
inline

Definition at line 114 of file moments.hpp.

◆ standard_deviation()

double standard_deviation ( ) const
inline

Definition at line 148 of file moments.hpp.

◆ stddev()

double stddev ( ) const
inline

Definition at line 143 of file moments.hpp.

◆ variance()

double variance ( ) const
inline

Definition at line 138 of file moments.hpp.


The documentation for this class was generated from the following file: