|Maintainer||Alexey Khudyakov <firstname.lastname@example.org>|
Stateful and pure (still stateful under the hood) accumulators.
- class HistBuilder h where
- (<<-) :: HistBuilder h => h a b -> (a' -> a) -> h a' b
- (<<-|) :: (HistBuilder h, Foldable f) => h a b -> (a' -> f a) -> h a' b
- (<<?) :: HistBuilder h => h a b -> (a -> Bool) -> h a b
- (<<-$) :: HistBuilder h => h a b -> (h a b -> h a' b) -> h a' b
- (-<<) :: HistBuilder h => (b -> b') -> h a b -> h a b'
- data HBuilderM m a b
- feedOne :: PrimMonad m => HBuilderM m a b -> a -> m ()
- freezeHBuilderM :: PrimMonad m => HBuilderM m a b -> m b
- joinHBuilderM :: (Traversable f, PrimMonad m) => f (HBuilderM m a b) -> HBuilderM m a (f b)
- treeHBuilderM :: (PrimMonad m, Traversable f) => f (HBuilderM m a b -> HBuilderM m a' b') -> HBuilderM m a b -> HBuilderM m a' (f b')
- data HBuilder a b
- toHBuilderST :: HBuilder a b -> forall s. ST s (HBuilderM (ST s) a b)
- toHBuilderIO :: HBuilder a b -> IO (HBuilderM IO a b)
- joinHBuilder :: Traversable f => f (HBuilder a b) -> HBuilder a (f b)
- treeHBuilder :: Traversable f => f (HBuilder a b -> HBuilder a' b') -> HBuilder a b -> HBuilder a' (f b')
- module Data.Histogram.Bin
- mkSimple :: (Bin bin, Unbox val, Num val) => bin -> HBuilder (BinValue bin) (Histogram bin val)
- mkWeighted :: (Bin bin, Unbox val, Num val) => bin -> HBuilder (BinValue bin, val) (Histogram bin val)
- mkMonoidal :: (Bin bin, Unbox val, Monoid val) => bin -> HBuilder (BinValue bin, val) (Histogram bin val)
- mkFolder :: b -> (a -> b -> b) -> HBuilder a b
- fillBuilder :: Foldable f => HBuilder a b -> f a -> b
- forceInt :: Histogram bin Int -> Histogram bin Int
- forceDouble :: Histogram bin Double -> Histogram bin Double
- forceFloat :: Histogram bin Float -> Histogram bin Float
Builder type class
Type class for stateful accumulators. In this module they are called builders. Every builder is parametrized by two types. First one is type of values which are fed to accumulator and second one is type of values which could be extracted from it.
Apply function to output of histogram.
Change input of builder by applying function to it.
Put all values in container into builder
Add cut to histogram. Value would be putted into histogram only if condition is true.
Modify input of builder to use composite input
Modify output of histogram. In fact it's same as
<$> but have opposite fixity
It's useful when result should be extracted many times from the same accumulator.
Create stateful histogram from instructions. Histograms could be filled either in the ST monad or with createHistograms
Join histogram builders in container
Apply functions to builder
Stateless histogram builder
Convert builder to stateful builder in ST monad
Join hitogram builders in container.
Apply function to builder
Create builder. Bin content will be incremented by 1 for each item put into histogram
Create builder. Bin content will incremented by weight supplied for each item put into histogram
Create builder. New value wil be mappended to current content of a bin for each item put into histogram
Create histogram builder which just does ordinary pure fold. It is intended for use when some fold should be performed together with histogram filling
In some cases builder constructors do not constrain output type
enough. Output type is still parametric in value type of histogram.
Functions below are just
id function with more restrictive
In example below
forceInt used to fix type of histogram to
'Histogram BinI Int'. Without it compiler cannot infer type of
show . forceInt -<< mkSimple (BinI 1 10)
All examples will make use of operators to create builders. It's
possible to avoid their use but operators offer clear notation and
compose nicely in pipeline. Also note that data flows from right to
left as with
First example just counts ints in in [0..4] inclusive range.
fillBuilder is used to put all values into accumulator.
ghci> let h = forceInt -<< mkSimple (BinI 0 4) ghci> fillBuilder h [0,0,0,1,1,2,3,4,4,4] # Histogram # Underflows = 0 # Overflows = 0 # BinI # Low = 0 # High = 4 0 3 1 2 2 1 3 1 4 3
forceInt -<< mkSimple (BinI 0 4) <<? even
Although for example above same result could be acheved by filtering of input it doesn't work when multiple histograms with different cuts are filled simultaneously.
Next example illustrate use of applicative interface. Here two histograms are filled at the same time. First accept only even numbers and second only odd ones. Results are put into the tuple.
(,) <$> (forceInt -<< mkSimple (BinI 0 4) <<? even) (forceInt -<< mkSimple (BinI 0 4) <<? odd)
Another approach is to use
joinHBuilder to simultaneously fill
list (or any other
joinHBuilder [ forceInt -<< mkSimple (BinI 0 4) <<? even , forceInt -<< mkSimple (BinI 0 4) <<? odd ]
mconcat [ show . forceInt -<< mkSimple (BinI 0 4) <<? even , show . forceInt -<< mkSimple (BinI 0 4) <<? odd ]