online-0.2.1.0: online statistics

Safe HaskellSafe
LanguageHaskell2010

Online.Averages

Contents

Description

online statistics based on a moving average

Synopsis

Documentation

data Averager a b Source #

Most common statistics are averages.

Instances

(Monoid a, Monoid b) => Monoid (Averager a b) Source # 

Methods

mempty :: Averager a b #

mappend :: Averager a b -> Averager a b -> Averager a b #

mconcat :: [Averager a b] -> Averager a b #

online :: Field b => (a -> b) -> (b -> b) -> Fold a b Source #

online takes a function and turns it into a Fold where the step is an incremental update of the (isomorphic) statistic.

online statistics

ma :: Field a => a -> Fold a a Source #

moving average with a decay rate

so 'ma 1' is the simple average (no decay in the statistic), and 'ma 0.00001' is the last value (insta-decay)

>>> L.fold (ma 1) [0..100]
50.0
>>> L.fold (ma 1e-12) [0..100] ≈ 100
True
>>> L.fold (ma 0.9) [0..100]
91.00241448887785

absma :: (Field a, Signed a) => a -> Fold a a Source #

absolute average

sqma :: Field a => a -> Fold a a Source #

average square

std :: ExpField a => a -> Fold a a Source #

standard deviation

The formulae for standard deviation, expressed in online terminology, highlights how this statistic is composed of averages:

(\s ss -> sqrt (ss - s ** (one+one))) <$> ma r <*> sqma r

The average deviation of the numbers 1..1000 is about 1 sqrt 12 * 1000 (see <<https:en.wikipedia.orgwiki/Uniform_distribution_(continuous)#Standard_uniform wiki>>)

>>> L.fold (std 1) [0..1000]
288.9636655359978

The average deviation with a decay of 0.99

>>> L.fold (std 0.99) [0..1000]
99.28328803164005

cov :: Field a => Fold a a -> Fold (a, a) a Source #

the covariance of a tuple given an underlying central tendency fold

corr :: Field a => Fold a a -> Fold a a -> Fold (a, a) a Source #

a generalised version of correlation of a tuple

corrGauss :: ExpField a => a -> Fold (a, a) a Source #

correlation of a tuple, specialised to Guassian

beta :: Field a => Fold a a -> Fold (a, a) a Source #

the beta in a simple linear regression of a tuple given an underlying central tendency fold

alpha :: Field a => Fold a a -> Fold (a, a) a Source #

the alpha of a tuple

autocorr :: BoundedField a => Fold a a -> Fold (a, a) a -> Fold a a Source #

autocorrelation is a slippery concept. This method starts with the concept that there is an underlying random error process (e), and autocorrelation is a process on top of that ie for a one-step correlation relationship.

valuet = et + k * e@t-1

where k is the autocorrelation.

There are thus two online rates needed: one for the average being considered to be the dependent variable, and one for the online of the correlation calculation between the most recent value and the moving average. For example,

L.fold (autocorr zero one)

would estimate the one-step autocorrelation relationship of the previous value and the current value over the entire sample set.

mconst :: Field a => a -> Fold a a Source #

a constant fold