welford-online-mean-variance: Online computation of mean and variance using the Welford algorithm.

[ bsd3, library, statistics ] [ Propose Tags ]


Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


  • No Candidates
Versions [RSS],,,,
Change log CHANGELOG.md
Dependencies base (>=4.7 && <5), cereal, deepseq, vector [details]
License BSD-3-Clause
Copyright 2023 Manuel Schneckenreither
Author Manuel Schneckenreither
Maintainer manuel.schnecki@gmail.com
Category Statistics
Home page https://github.com/schnecki/welford-online-mean-variance#readme
Bug tracker https://github.com/schnecki/welford-online-mean-variance/issues
Source repo head: git clone https://github.com/schnecki/welford-online-mean-variance
Uploaded by schnecki at 2023-01-30T12:30:03Z
Distributions LTSHaskell:, NixOS:, Stackage:
Downloads 307 total (16 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2023-01-30 [all 1 reports]

Readme for welford-online-mean-variance-

[back to package description]

Welford: Online mean and variance computation


example :: [Double] -> IO ()
example vals = do
  let n = fromIntegral (length vals)
      mean = sum vals / n
      var = sum (map (\x -> (x - mean) ^ 2) vals) / (n - 1)
      (wMean, _, wVarSample) = finalize $ foldl' addValue WelfordExistingAggregateEmpty vals
  print (mean, var)
  print (wMean, wVarSample)

WelfordExistingAggregate is used to save the state. Use the function finalize to retrieve the current estimates for the mean, variance and sample variance.