foldl-incremental 0.1.0.2 → 0.1.1.0
raw patch · 5 files changed
+54/−21 lines, 5 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Control.Foldl.Incremental: Increment :: {-# UNPACK #-} !Double -> {-# UNPACK #-} !Double -> {-# UNPACK #-} !Double -> Increment
- Control.Foldl.Incremental: _adder :: Increment -> {-# UNPACK #-} !Double
- Control.Foldl.Incremental: _counter :: Increment -> {-# UNPACK #-} !Double
- Control.Foldl.Incremental: _rate :: Increment -> {-# UNPACK #-} !Double
- Control.Foldl.Incremental: data Increment
Files
- .gitignore +6/−0
- .travis.yml +6/−0
- CHANGELOG.markdown +3/−0
- foldl-incremental.cabal +12/−6
- src/Control/Foldl/Incremental.hs +27/−15
+ .gitignore view
@@ -0,0 +1,6 @@+.cabal-sandbox+dist+/cabal.sandbox.config+*.hi+*.o+/TAGS
+ .travis.yml view
@@ -0,0 +1,6 @@+language: haskell+install: cabal install --only-dependencies --enable-tests --enable-benchmarks+script: cabal configure --enable-benchmarks --enable-tests && cabal build && cabal test && cabal bench+notifications:+ email:+ - tonyday567@gmail.com
+ CHANGELOG.markdown view
@@ -0,0 +1,3 @@+0.1.1+---+* Removed Increment from API
foldl-incremental.cabal view
@@ -1,5 +1,5 @@ Name: foldl-incremental-Version: 0.1.0.2+Version: 0.1.1.0 Author: Tony Day Maintainer: tonyday567@gmail.com License: MIT@@ -9,13 +9,19 @@ Build-Type: Simple Stability: Experimental Cabal-Version: >= 1.10-Extra-Source-Files: README.markdown+Extra-Source-Files:+ .travis.yml+ .gitignore+ README.markdown+ CHANGELOG.markdown Synopsis: incremental folds-Description:- `foldl-incremental` allows you to create incremental folds and scans such as moving averages or moving deviations.- .- It supplies `Incremental` which represents a state of an exponential moving average calculation, and `incrementalize`, which turns functions into suitable step functions.+Description: This library provides incremental statistical folds based upon the + foldl libray. An incremental statistical fold can be thought of as + exponentially-weighting statistics designed to be efficient computations over + a Foldable. + It supplies "incrementalize" which turns any unary function into a + "Fold". As a reference, \"incrementalize id\" is an exponentially-weighted moving average. Homepage: https://github.com/tonyday567/foldl-incremental Bug-Reports: https://github.com/tonyday567/foldl-incremental/issues Tested-With: GHC==7.6.3
src/Control/Foldl/Incremental.hs view
@@ -1,27 +1,42 @@-{-| This module provides incremental statistics folds based upon the foldl library+{-| This module provides incremental statistical folds based upon the foldl library - To avoid clashes, Control.Foldl should be qualified.+An incremental statsitical fold can be thought of as exponentially-weighting statistics designed to be efficient computations over a Foldable. +Some throat clearing is required, however.++The common usage term \"exponential moving ...\" refers to the cumulative effect+of the fold referencing the original data. From the point of view of a+single step, the algorithm could be better described as \"constant proportion\" or+\"geometric\" decay. Many other methods are also possible and future versions of the library may introduce some more.++A main point of the library is that the traditional simple moving average+uses a sliding window of past data and thus requires keeping track of+the last n elements in State (in a LIFO queue most likey). It may be simple for the human brain but its a more complex and costly computational than this single-pass version.++For clarity, moving average (and moving whatever) below refers to geometric decay+rather than the common usage. So with the throat clearing out of the way:++To avoid clashes, Control.Foldl should be qualified.+ >>> import Control.Foldl.Incremental >>> import qualified Control.Foldl as L - The folds represent incremental statistics such as `moving averages`.+The folds represent incremental statistics such as moving averages`. - Statistics are based on exponential-weighting schemes which enable statistics to be calculated in a streaming one-pass manner. The stream of moving averages with a `rate` of 0.9 is:+The stream of moving averages with a `rate` of 0.1 is: ->>> L.scan (incMa 0.9) [1..10]+>>> L.scan (incMa 0.1) [1.. 10] or if you just want the moving average at the end. ->>> L.fold (incMa 0.9) [1..10]+>>> L.fold (incMa 0.1) [1..10] -} module Control.Foldl.Incremental (- -- * Increment- Increment(..)- , incrementalize- -- * common incremental folds+ -- * incrementalize+ incrementalize+ -- * common incremental folds , incMa , incAbs , incSq@@ -38,7 +53,7 @@ , _rate :: {-# UNPACK #-} !Double } deriving (Show) -{-| Incrementalize takes a function and turns it into a `Control.Foldl.Fold` where the step incremental is an Increment with a step function iso to a step in an exponential moving average calculation.+{-| Incrementalize takes a function and turns it into a `Control.Foldl.Fold` where the step is an Increment iso to the typical step in an exponential moving average calculation. >>> incrementalize id @@ -52,8 +67,6 @@ >>> std r = (\s ss -> sqrt (ss - s**2)) <$> incrementalize id r <*> incrementalize (*2) r -An exponential moving average approach (where `average` id abstracted to `function`) represents an efficient single-pass computation that attempts to keep track of a running average of some Foldable.- The rate is the parameter regulating the discount of current state and the introduction of the current value. >>> incrementalize id 1@@ -62,12 +75,11 @@ >>> incrementalize id 0 -produces the latest value (ie current state is discounted to zero)+produces the latest value (ie current state is discounted (or decays) to zero) A exponential moving average with a duration of 10 (the average lag of the values effecting the calculation) is >>> incrementalize id (1/10)- -} incrementalize :: (a -> Double) -> Double -> Fold a Double