Safe Haskell | Safe |
---|---|

Language | Haskell2010 |

online statistics based on a moving average

- data Averager a b
- online :: Field b => (a -> b) -> (b -> b) -> Fold a b
- ma :: Field a => a -> Fold a a
- absma :: (Field a, Signed a) => a -> Fold a a
- sqma :: Field a => a -> Fold a a
- std :: ExpField a => a -> Fold a a
- cov :: Field a => Fold a a -> Fold (a, a) a
- corr :: Field a => Fold a a -> Fold a a -> Fold (a, a) a
- corrGauss :: ExpField a => a -> Fold (a, a) a
- beta :: Field a => Fold a a -> Fold (a, a) a
- alpha :: Field a => Fold a a -> Fold (a, a) a
- autocorr :: BoundedField a => Fold a a -> Fold (a, a) a -> Fold a a
- mconst :: Field a => a -> Fold a a

# Documentation

Most common statistics are averages.

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)

`>>>`

50.0`L.fold (ma 1) [0..100]`

`>>>`

True`L.fold (ma 1e-12) [0..100] ≈ 100`

`>>>`

91.00241448887785`L.fold (ma 0.9) [0..100]`

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.org*wiki/Uniform_distribution_(continuous)#Standard_uniform wiki>>)

`>>>`

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

The average deviation with a decay of 0.99

`>>>`

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

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

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.

value`t = e`

t + 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.