Copyright | Copyright (c) 20102017 Alexey Khudyakov <alexey.skladnoy@gmail.com> |
---|---|
License | BSD3 |
Maintainer | Alexey Khudyakov <alexey.skladnoy@gmail.com> |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
- class Monoid m => StatMonoid m a where
- reduceSample :: (Foldable f, StatMonoid m a) => f a -> m
- reduceSampleVec :: (Vector v a, StatMonoid m a) => v a -> m
- data Pair a b = Pair !a !b
Type class and helpers
class Monoid m => StatMonoid m a where Source #
This type class is used to express parallelizable constant space algorithms for calculation of statistics. By definitions statistic is some measure of sample which doesn't depend on order of elements (for example: mean, sum, number of elements, variance, etc).
For many statistics it's possible to possible to construct constant space algorithm which is expressed as fold. Additionally it's usually possible to write function which combine state of fold accumulator to get statistic for union of two samples.
Thus for such algorithm we have value which corresponds to empty sample, merge function which which corresponds to merging of two samples, and single step of fold. Last one allows to evaluate statistic given data sample and first two form a monoid and allow parallelization: split data into parts, build estimate for each by folding and then merge them using mappend.
Instance must satisfy following laws. If floating point arithmetics is used then equality should be understood as approximate.
1. addValue (addValue y mempty) x == addValue mempty x <> addValue mempty y 2. x <> y == y <> x
addValue :: m -> a -> m Source #
Add one element to monoid accumulator. It's step of fold.
singletonMonoid :: a -> m Source #
State of accumulator corresponding to 1-element sample.
Real a => StatMonoid KBNSum a Source # | |
Real a => StatMonoid KahanSum a Source # | |
StatMonoid BinomAcc Bool Source # | |
(~) * a Double => StatMonoid MaxD a Source # | |
(~) * a Double => StatMonoid MinD a Source # | |
Real a => StatMonoid Variance a Source # | |
Real a => StatMonoid WelfordMean a Source # | \[ s_n = s_{n-1} + \frac{x_n - s_{n-1}}{n} \] |
Real a => StatMonoid MeanKBN a Source # | |
Real a => StatMonoid MeanKahan a Source # | |
(Num a, (~) * a a') => StatMonoid (Sum a) a' Source # | |
(Num a, (~) * a a') => StatMonoid (Product a) a' Source # | |
(Ord a, (~) * a a') => StatMonoid (Max a) a' Source # | |
(Ord a, (~) * a a') => StatMonoid (Min a) a' Source # | |
Integral a => StatMonoid (CountG a) b Source # | |
(StatMonoid a x, StatMonoid b x) => StatMonoid (Pair a b) x Source # | |
reduceSample :: (Foldable f, StatMonoid m a) => f a -> m Source #
Calculate statistic over Foldable
. It's implemented in terms of
foldl'.
reduceSampleVec :: (Vector v a, StatMonoid m a) => v a -> m Source #
Calculate statistic over vector. It's implemented in terms of foldl'.
Data types
Strict pair. It allows to calculate two statistics in parallel
Pair !a !b |
(Unbox a0, Unbox b0) => Vector Vector (Pair a0 b0) Source # | |
(Unbox a0, Unbox b0) => MVector MVector (Pair a0 b0) Source # | |
(Eq b, Eq a) => Eq (Pair a b) Source # | |
(Data b, Data a) => Data (Pair a b) Source # | |
(Ord b, Ord a) => Ord (Pair a b) Source # | |
(Show b, Show a) => Show (Pair a b) Source # | |
Generic (Pair a b) Source # | |
(Monoid a, Monoid b) => Monoid (Pair a b) Source # | |
(Unbox a0, Unbox b0) => Unbox (Pair a0 b0) Source # | |
(StatMonoid a x, StatMonoid b x) => StatMonoid (Pair a b) x Source # | |
data MVector s (Pair a0 b0) Source # | |
type Rep (Pair a b) Source # | |
data Vector (Pair a0 b0) Source # | |