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

[ bsd3, library, statistics ] [ Propose Tags ] [ Report a vulnerability ]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.1.0.1, 0.1.0.2, 0.1.0.4, 0.2.0.0
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:0.2.0.0, NixOS:0.2.0.0, Stackage:0.2.0.0
Downloads 411 total (10 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-0.2.0.0

[back to package description]

Welford: Online mean and variance computation

Example

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.