foldl-incremental-0.2.0.0: incremental folds

Safe HaskellNone
LanguageHaskell2010

Control.Foldl.Incremental.Histogram

Contents

Description

incremental folds of Histograms from the histogram-fill library.

Synopsis

Incrementalize

incrementalizeHist :: BinD -> (Double -> Double) -> Double -> Fold Double (Histogram BinD Double) Source

incrementalizeHist takes a function governing the input to the histogram.

>>> incrementalizeHist (const 1)

is the usual boiler-plate meaning of histogram.

Common Histogram Folds

incHist :: BinD -> Double -> Fold Double (Histogram BinD Double) Source

incremental histogram with pre-defined bins

>>> import Control.Foldl.Incremental
>>> import qualified Control.Foldl as L
>>> let b = binDn 0 2 12
>>> L.fold (incHist b 0.9) [1..10]

incHist2D :: Bin2D BinD BinD -> Double -> Fold (Double, Double) (Histogram (Bin2D BinD BinD) Double) Source

incremental 2D histogram

incAdaptiveHist :: Double -> Double -> Int -> Double -> Fold Double (Histogram BinDU Double) Source

adaptable histogram fold

TODO: integrate Histogram.Adaptable upstream

incHist requires a pre-specified bin, which in turn requires an initial pass over the stream to determine the data ranges.

For a one pass histogram fold, we require an incremental approach to bin creation, which, in turn, requires some way of creating a histogram from scratch.

Adaptable and BinDU is a draft solution to enable a one-pass at histogram creation.

This function takes

  • a maximum frequency (thresh) for a bin, which, when triggered causes a bin to be split (at the moment using a uniform distribution assumption which is pretty bad).
  • a minimum bin size (grain). bins are further constrained to be multiples of this.
  • a maximum number of bins, which, when triggered, causes bins to be merged.
>>> L.fold (incAdaptiveHist 0.2 1.0 10 1.0) [1..1000]

provides a histogram with no bin more than 20% frequency size, with a minimum bin size of 1, with at most 10 bins, and a decay rate of 1.0