BDE 4.14.0 Production release
|
Online algorithm for mean, variance, skew, and kurtosis.
This component provides a mechanism, bdlsta::Moment
, that provides online calculation of basic statistics: mean, variance, skew, and kurtosis while maintaining accuracy. Online algorithms process the data in one pass, while keeping good accuracy. The online algorithms used are Welford for variance, and the stable skew and kurtosis algorithms taken from: https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Higher-order_statistics
The implementation uses template specialization so the user can choose the statistics necessary, and not calculate or allocate memory for those statistics that are not needed.
The template parameter is a value from the provided enum and having the following interpretation:
This section illustrates intended use of this component.
This example shows how to accumulate a set of values, and calculate the skew, variance, and kurtosis.
First, we create example input and instantiate the appropriate mechanism:
Then, we invoke the add
routine to accumulate the data:
Finally, we assert that the mean, variance, and skew are what we expect: