Safe Haskell | None |
---|---|
Language | Haskell2010 |
Monoids for calculating various statistics in constant space. This module contains algorithms that should be generally avoided unless there's specific reason to use them.
Synopsis
- data WelfordMean = WelfordMean !Int !Double
- asWelfordMean :: WelfordMean -> WelfordMean
- data MeanKahan = MeanKahan !Int !KahanSum
- asMeanKahan :: MeanKahan -> MeanKahan
- data MeanKB2 = MeanKB2 !Int !KB2Sum
- asMeanKB2 :: MeanKB2 -> MeanKB2
Mean
data WelfordMean Source #
Incremental calculation of mean. Note that this algorithm doesn't offer better numeric precision than plain summation. Its only advantage is protection against double overflow:
>>>
calcMean $ reduceSample @MeanKBN (replicate 100 1e308) :: Maybe Double
Just NaN>>>
calcMean $ reduceSample @WelfordMean (replicate 100 1e308) :: Maybe Double
Just 1.0e308
Unless this feature is needed KBNSum
should be used. Algorithm is due to Welford [Welford1962]
\[ s_n = s_{n-1} + \frac{x_n - s_{n-1}}{n} \]
Instances
asWelfordMean :: WelfordMean -> WelfordMean Source #
Type restricted id
Incremental calculation of mean. Sum of elements is calculated
using compensated Kahan summation. It's provided only for sake of
completeness. KBNSum
should be used
instead.
Instances
asMeanKahan :: MeanKahan -> MeanKahan Source #
Incremental calculation of mean which uses second-order
compensated Kahan-Babuška summation. In most cases
KBNSum
should provide enough
precision.
- [Welford1962] Welford, B.P. (1962) Note on a method for calculating corrected sums of squares and products. Technometrics 4(3):419-420. http://www.jstor.org/stable/1266577