-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | online statistics
--   
--   transformation of statistics to online algorithms
@package online
@version 0.3.0.0


-- | online statistics based on a moving average
module Online.Averages

-- | Most common statistics are averages.
data Averager a b

-- | online takes a function and turns it into a <a>Fold</a> where the step
--   is an incremental update of the (isomorphic) statistic.
online :: (Field b) => (a -> b) -> (b -> b) -> Fold a b

-- | 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)
--   
--   <pre>
--   &gt;&gt;&gt; L.fold (ma 1) [0..100]
--   50.0
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; L.fold (ma 1e-12) [0..100] ≈ 100
--   True
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; L.fold (ma 0.9) [0..100]
--   91.00241448887785
--   </pre>
ma :: (Field a) => a -> Fold a a

-- | absolute average
absma :: (Field a, Signed a) => a -> Fold a a

-- | average square
sqma :: (Field a) => a -> Fold a a

-- | standard deviation
--   
--   The formulae for standard deviation, expressed in online terminology,
--   highlights how this statistic is composed of averages:
--   
--   <pre>
--   (\s ss -&gt; sqrt (ss - s ** (one+one))) &lt;$&gt; ma r &lt;*&gt; sqma r
--   </pre>
--   
--   The average deviation of the numbers 1..1000 is about 1 <i> sqrt 12 *
--   1000 (see
--   &lt;&lt;https:</i><i>en.wikipedia.org</i>wiki/Uniform_distribution_(continuous)#Standard_uniform
--   wiki&gt;&gt;)
--   
--   <pre>
--   &gt;&gt;&gt; L.fold (std 1) [0..1000]
--   288.9636655359978
--   </pre>
--   
--   The average deviation with a decay of 0.99
--   
--   <pre>
--   &gt;&gt;&gt; L.fold (std 0.99) [0..1000]
--   99.28328803164005
--   </pre>
std :: (ExpField a) => a -> Fold a a

-- | the covariance of a tuple given an underlying central tendency fold
cov :: (Field a) => Fold a a -> Fold (a, a) a

-- | a generalised version of correlation of a tuple
corr :: (Field a) => Fold a a -> Fold a a -> Fold (a, a) a

-- | correlation of a tuple, specialised to Guassian
corrGauss :: (ExpField a) => a -> Fold (a, a) a

-- | the beta in a simple linear regression of a tuple given an underlying
--   central tendency fold
beta :: (Field a) => Fold a a -> Fold (a, a) a

-- | the alpha of a tuple
alpha :: (Field a) => Fold a a -> Fold (a, a) a

-- | 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<tt>t = e</tt>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,
--   
--   <pre>
--   L.fold (autocorr zero one)
--   </pre>
--   
--   would estimate the one-step autocorrelation relationship of the
--   previous value and the current value over the entire sample set.
autocorr :: (RealFloat a) => Fold a a -> Fold (a, a) a -> Fold a a

-- | a constant fold
mconst :: a -> Fold a a
instance (GHC.Base.Semigroup a, GHC.Base.Semigroup b) => GHC.Base.Semigroup (Online.Averages.Averager a b)
instance (GHC.Base.Semigroup a, GHC.Base.Semigroup b, GHC.Base.Monoid a, GHC.Base.Monoid b) => GHC.Base.Monoid (Online.Averages.Averager a b)

module Online.Medians

-- | A rough Median. The average absolute value of the stat is used to
--   callibrate estimate drift towards the median
data Medianer a b
Medianer :: a -> b -> a -> Medianer a b
[medAbsSum] :: Medianer a b -> a
[medCount] :: Medianer a b -> b
[medianEst] :: Medianer a b -> a

-- | onlineL1 takes a function and turns it into a <a>Fold</a> where the
--   step is an incremental update of an (isomorphic) median statistic.
onlineL1 :: (Ord b, Fractional b) => b -> b -> (a -> b) -> (b -> b) -> Fold a b

-- | onlineL1' takes a function and turns it into a <a>Fold</a> where the
--   step is an incremental update of an (isomorphic) median statistic.
onlineL1' :: (Ord b, Fractional b) => b -> b -> (a -> b) -> (b -> b) -> Fold a (b, b)

-- | moving median &gt;&gt;&gt; L.fold (maL1 inc d r) [1..n]
--   93.92822312742108
maL1 :: (Ord a, Fractional a) => a -> a -> a -> Fold a a

-- | moving absolute deviation
absmaL1 :: (Ord a, Fractional a) => a -> a -> a -> Fold a a

-- | covariance of a tuple
covL1 :: (Ord a, Fractional a) => a -> a -> a -> Fold (a, a) a

-- | correlation of a tuple
corrL1 :: (Ord a, Floating a) => a -> a -> a -> Fold (a, a) a

-- | the beta in a simple linear regression of a tuple
betaL1 :: (Ord a, Floating a) => a -> a -> a -> Fold (a, a) a

-- | the alpha in a simple linear regression of <a>snd</a> on <a>fst</a>
alphaL1 :: (Ord a, Floating a) => a -> a -> a -> Fold (a, a) a
autocorrL1 :: (Floating a, RealFloat a) => a -> a -> a -> a -> Fold a a

module Online.Quantiles

-- | a raw non-online tdigest fold
tDigest :: Fold Double (TDigest 25)

-- | non-online version
tDigestQuantiles :: [Double] -> Fold Double [Double]

-- | non-online version
tDigestHist :: Fold Double (Maybe (NonEmpty HistBin))
data OnlineTDigest
OnlineTDigest :: TDigest 25 -> Int -> Double -> OnlineTDigest
[td] :: OnlineTDigest -> TDigest 25
[tdN] :: OnlineTDigest -> Int
[tdRate] :: OnlineTDigest -> Double

-- | decaying quantiles based on the tdigest library
onlineQuantiles :: Double -> [Double] -> Fold Double [Double]
median :: Double -> Fold Double Double
onlineDigitize :: Double -> [Double] -> Fold Double Int

-- | decaying histogram based on the tdigest library
onlineDigestHist :: Double -> Fold Double (Maybe (NonEmpty HistBin))
instance GHC.Show.Show Online.Quantiles.OnlineTDigest


-- | online library
module Online
