Copyright | Copyright (c) 2009 Alexey Khudyakov <alexey.skladnoy@gmail.com> |
---|---|
License | BSD3 |
Maintainer | Alexey Khudyakov <alexey.skladnoy@gmail.com> |
Stability | experimental |
Safe Haskell | None |
Language | Haskell98 |
Generic immutable histograms.
Synopsis
- data Histogram v bin a
- module Data.Histogram.Bin
- histogram :: (Vector v a, Bin bin) => bin -> v a -> Histogram v bin a
- histogramUO :: (Vector v a, Bin bin) => bin -> Maybe (a, a) -> v a -> Histogram v bin a
- asList :: (Vector v a, Bin bin) => Histogram v bin a -> [(BinValue bin, a)]
- asVector :: (Bin bin, Vector v a, Vector v (BinValue bin, a)) => Histogram v bin a -> v (BinValue bin, a)
- readHistogram :: (Read bin, Read a, Bin bin, Vector v a) => String -> Histogram v bin a
- readFileHistogram :: (Read bin, Read a, Bin bin, Vector v a) => FilePath -> IO (Histogram v bin a)
- bins :: Histogram v bin a -> bin
- histData :: Histogram v bin a -> v a
- underflows :: Histogram v bin a -> Maybe a
- overflows :: Histogram v bin a -> Maybe a
- outOfRange :: Histogram v bin a -> Maybe (a, a)
- data HistIndex b
- histIndex :: Bin b => b -> HistIndex b -> Int
- at :: (Bin bin, Vector v a) => Histogram v bin a -> HistIndex bin -> a
- atV :: (Bin bin, Vector v a) => Histogram v bin a -> BinValue bin -> a
- atI :: (Bin bin, Vector v a) => Histogram v bin a -> Int -> a
- map :: (Vector v a, Vector v b) => (a -> b) -> Histogram v bin a -> Histogram v bin b
- bmap :: (Vector v a, Vector v b, Bin bin) => (BinValue bin -> a -> b) -> Histogram v bin a -> Histogram v bin b
- mapData :: (Vector v a, Vector u b, Bin bin) => (v a -> u b) -> Histogram v bin a -> Histogram u bin b
- zip :: (BinEq bin, Vector v a, Vector v b, Vector v c) => (a -> b -> c) -> Histogram v bin a -> Histogram v bin b -> Histogram v bin c
- zipSafe :: (BinEq bin, Vector v a, Vector v b, Vector v c) => (a -> b -> c) -> Histogram v bin a -> Histogram v bin b -> Maybe (Histogram v bin c)
- convert :: (Vector v a, Vector w a) => Histogram v bin a -> Histogram w bin a
- convertBinning :: (ConvertBin bin bin', Vector v a) => Histogram v bin a -> Histogram v bin' a
- foldl :: Vector v a => (b -> a -> b) -> b -> Histogram v bin a -> b
- bfoldl :: (Bin bin, Vector v a) => (b -> BinValue bin -> a -> b) -> b -> Histogram v bin a -> b
- sum :: (Vector v a, Num a) => Histogram v bin a -> a
- minimum :: (Vector v a, Ord a) => Histogram v bin a -> a
- minimumBy :: Vector v a => (a -> a -> Ordering) -> Histogram v bin a -> a
- maximum :: (Vector v a, Ord a) => Histogram v bin a -> a
- maximumBy :: Vector v a => (a -> a -> Ordering) -> Histogram v bin a -> a
- minIndex :: (Ord a, Vector v a) => Histogram v bin a -> Int
- minIndexBy :: Vector v a => (a -> a -> Ordering) -> Histogram v bin a -> Int
- maxIndex :: (Ord a, Vector v a) => Histogram v bin a -> Int
- maxIndexBy :: Vector v a => (a -> a -> Ordering) -> Histogram v bin a -> Int
- minBin :: (Bin bin, Ord a, Vector v a) => Histogram v bin a -> BinValue bin
- minBinBy :: (Bin bin, Vector v a) => (a -> a -> Ordering) -> Histogram v bin a -> BinValue bin
- maxBin :: (Bin bin, Ord a, Vector v a) => Histogram v bin a -> BinValue bin
- maxBinBy :: (Bin bin, Vector v a) => (a -> a -> Ordering) -> Histogram v bin a -> BinValue bin
- slice :: (SliceableBin bin, Vector v a) => HistIndex bin -> HistIndex bin -> Histogram v bin a -> Histogram v bin a
- rebin :: (MergeableBin bin, Vector v a) => CutDirection -> Int -> (a -> a -> a) -> Histogram v bin a -> Histogram v bin a
- rebinFold :: (MergeableBin bin, Vector v a, Vector v b) => CutDirection -> Int -> (b -> a -> b) -> b -> Histogram v bin a -> Histogram v bin b
- sliceAlongX :: (Vector v a, Bin bX, Bin bY) => Histogram v (Bin2D bX bY) a -> HistIndex bY -> Histogram v bX a
- sliceAlongY :: (Vector v a, Bin bX, Bin bY) => Histogram v (Bin2D bX bY) a -> HistIndex bX -> Histogram v bY a
- listSlicesAlongX :: (Vector v a, Bin bX, Bin bY) => Histogram v (Bin2D bX bY) a -> [(BinValue bY, Histogram v bX a)]
- listSlicesAlongY :: (Vector v a, Bin bX, Bin bY) => Histogram v (Bin2D bX bY) a -> [(BinValue bX, Histogram v bY a)]
- reduceX :: (Vector v a, Vector v b, Bin bX, Bin bY) => (Histogram v bX a -> b) -> Histogram v (Bin2D bX bY) a -> Histogram v bY b
- breduceX :: (Vector v a, Vector v b, Bin bX, Bin bY) => (BinValue bY -> Histogram v bX a -> b) -> Histogram v (Bin2D bX bY) a -> Histogram v bY b
- reduceY :: (Vector v a, Vector v b, Bin bX, Bin bY) => (Histogram v bY a -> b) -> Histogram v (Bin2D bX bY) a -> Histogram v bX b
- breduceY :: (Vector v a, Vector v b, Bin bX, Bin bY) => (BinValue bX -> Histogram v bY a -> b) -> Histogram v (Bin2D bX bY) a -> Histogram v bX b
- liftX :: (Bin bX, Bin bY, Bin bX', BinEq bX', Vector v a, Vector v b) => (Histogram v bX a -> Histogram v bX' b) -> Histogram v (Bin2D bX bY) a -> Histogram v (Bin2D bX' bY) b
- liftY :: (Bin bX, Bin bY, Bin bY', BinEq bY', Vector v a, Vector v b, Vector v Int) => (Histogram v bY a -> Histogram v bY' b) -> Histogram v (Bin2D bX bY) a -> Histogram v (Bin2D bX bY') b
Immutable histograms
data Histogram v bin a Source #
Immutable histogram. A histogram consists of a binning algorithm, an optional number of under- and overflows, and data. Type parameters have following meaning:
v
- type of vector used to store bin content.
bin
- binning. It should be instance of
Bin
. Check that type class description for details. a
- type of bin content.
Instances
Functor v => Functor (Histogram v bin) Source # | If vector is a functor then histogram is functor as well |
(Eq bin, Eq a, Eq (v a)) => Eq (Histogram v bin a) Source # | |
(Show a, Show (BinValue bin), Show bin, Bin bin, Vector v a) => Show (Histogram v bin a) Source # | |
(NFData a, NFData bin, NFData (v a)) => NFData (Histogram v bin a) Source # | Vector do not supply |
Defined in Data.Histogram.Generic |
module Data.Histogram.Bin
Constructors
histogram :: (Vector v a, Bin bin) => bin -> v a -> Histogram v bin a Source #
Create histogram from binning algorithm and a vector with data. Overflows are set to Nothing.
Number of bins and vector size must match.
histogramUO :: (Vector v a, Bin bin) => bin -> Maybe (a, a) -> v a -> Histogram v bin a Source #
Create histogram from binning algorithm and vector with data.
Number of bins and vector size must match.
Conversion to other data types
asList :: (Vector v a, Bin bin) => Histogram v bin a -> [(BinValue bin, a)] Source #
Convert histogram data to list.
asVector :: (Bin bin, Vector v a, Vector v (BinValue bin, a)) => Histogram v bin a -> v (BinValue bin, a) Source #
Convert histogram data to vector
Serialization to strings
Show
instance is abused for serialization and produces human
readable data like that:
# Histogram # Underflows = 0 # Overflows = 88 # BinI # Low = 0 # High = 9 0 99 1 91 2 95 3 81 4 92 5 105 6 90 7 79 8 91 9 89
It could be deserialize using readHistogram
function. Read
instance could be provided as well but it turned out to be
impractically slow.
Serialization with cereal package is provided by histogram-fill-cereal
readFileHistogram :: (Read bin, Read a, Bin bin, Vector v a) => FilePath -> IO (Histogram v bin a) Source #
Read histogram from file.
Accessors
underflows :: Histogram v bin a -> Maybe a Source #
Number of underflows
outOfRange :: Histogram v bin a -> Maybe (a, a) Source #
Underflows and overflows
Indexing
atV :: (Bin bin, Vector v a) => Histogram v bin a -> BinValue bin -> a Source #
Index histogram using bin value
atI :: (Bin bin, Vector v a) => Histogram v bin a -> Int -> a Source #
Index histogram using vector index
Transformations
map :: (Vector v a, Vector v b) => (a -> b) -> Histogram v bin a -> Histogram v bin b Source #
fmap lookalike. It's not possible to create Functor instance because of type class context.
bmap :: (Vector v a, Vector v b, Bin bin) => (BinValue bin -> a -> b) -> Histogram v bin a -> Histogram v bin b Source #
Map histogram using bin value and content. Overflows and underflows are set to Nothing.
mapData :: (Vector v a, Vector u b, Bin bin) => (v a -> u b) -> Histogram v bin a -> Histogram u bin b Source #
zip :: (BinEq bin, Vector v a, Vector v b, Vector v c) => (a -> b -> c) -> Histogram v bin a -> Histogram v bin b -> Histogram v bin c Source #
Zip two histograms elementwise. Bins of histograms must be equal otherwise error will be called.
zipSafe :: (BinEq bin, Vector v a, Vector v b, Vector v c) => (a -> b -> c) -> Histogram v bin a -> Histogram v bin b -> Maybe (Histogram v bin c) Source #
Zip two histograms elementwise. If bins are not equal return Nothing
Type conversion
convert :: (Vector v a, Vector w a) => Histogram v bin a -> Histogram w bin a Source #
Convert between different vector types
convertBinning :: (ConvertBin bin bin', Vector v a) => Histogram v bin a -> Histogram v bin' a Source #
Convert between binning types using ConvertBin
type class.
Folding
foldl :: Vector v a => (b -> a -> b) -> b -> Histogram v bin a -> b Source #
Strict fold over bin content in index order. Underflows and overflows are ignored.
bfoldl :: (Bin bin, Vector v a) => (b -> BinValue bin -> a -> b) -> b -> Histogram v bin a -> b Source #
Strict fold over bin content in index order. Function is applied to bin content and bin value. Underflows and overflows are ignored.
Specialized folds
minimumBy :: Vector v a => (a -> a -> Ordering) -> Histogram v bin a -> a Source #
Minimal bin content using custom comparison.
maximumBy :: Vector v a => (a -> a -> Ordering) -> Histogram v bin a -> a Source #
Maximal bin content using custom comparison.
minIndex :: (Ord a, Vector v a) => Histogram v bin a -> Int Source #
Index of a bin with minimal content.
minIndexBy :: Vector v a => (a -> a -> Ordering) -> Histogram v bin a -> Int Source #
Index of a bin with minimal content using custom comparison.
maxIndex :: (Ord a, Vector v a) => Histogram v bin a -> Int Source #
Index of a bin with maximal content.
maxIndexBy :: Vector v a => (a -> a -> Ordering) -> Histogram v bin a -> Int Source #
Index of a bin with maximal content using custom comparison.
minBin :: (Bin bin, Ord a, Vector v a) => Histogram v bin a -> BinValue bin Source #
Value of a bin with minimal content
minBinBy :: (Bin bin, Vector v a) => (a -> a -> Ordering) -> Histogram v bin a -> BinValue bin Source #
Value bin with minimal content using custom comparison.
maxBin :: (Bin bin, Ord a, Vector v a) => Histogram v bin a -> BinValue bin Source #
Value of a bin with maximal content.
maxBinBy :: (Bin bin, Vector v a) => (a -> a -> Ordering) -> Histogram v bin a -> BinValue bin Source #
Value of a bin with maximal content using custom comparison.
Slicing & rebinning
:: (MergeableBin bin, Vector v a) | |
=> CutDirection | On which side bins should be discarded |
-> Int | Number of bins to join |
-> (a -> a -> a) | Accumulation function |
-> Histogram v bin a | |
-> Histogram v bin a |
Rebin histogram by joining n
adjacent bins.
:: (MergeableBin bin, Vector v a, Vector v b) | |
=> CutDirection | On which side bins should be discarded |
-> Int | Number of bins to join |
-> (b -> a -> b) | Accumulation function |
-> b | Initial value |
-> Histogram v bin a | |
-> Histogram v bin b |
Rebin histogram by joining n
adjacent bins.
2D histograms
Data in 2D histograms is stored in row major order. This in fact
is dictated by the implementation of Bin2D
. So indices of the bin are
arranged in the following pattern:
0 1 2 3 4 5 6 7 8 9 10 11
Functions from AlongX
family work with histogram slices along the X
axis (as the name suggests) which are contigous, and therefore are
generally faster than those from the AlongY
family.
:: (Vector v a, Bin bX, Bin bY) | |
=> Histogram v (Bin2D bX bY) a | 2D histogram |
-> HistIndex bY | Position along Y axis |
-> Histogram v bX a |
Get slice of 2D histogram along the X axis. This function is faster
than sliceAlongY
since no array reallocations are required.
:: (Vector v a, Bin bX, Bin bY) | |
=> Histogram v (Bin2D bX bY) a | 2D histogram |
-> HistIndex bX | Position along X axis |
-> Histogram v bY a |
Get slice of 2D histogram along X axis
listSlicesAlongX :: (Vector v a, Bin bX, Bin bY) => Histogram v (Bin2D bX bY) a -> [(BinValue bY, Histogram v bX a)] Source #
Slice 2D histogram along Y axis. This function is fast because it does not require reallocations.
listSlicesAlongY :: (Vector v a, Bin bX, Bin bY) => Histogram v (Bin2D bX bY) a -> [(BinValue bX, Histogram v bY a)] Source #
Slice 2D histogram along X axis.
Reducing along axis
:: (Vector v a, Vector v b, Bin bX, Bin bY) | |
=> (Histogram v bX a -> b) | Function to reduce single slice along X axis |
-> Histogram v (Bin2D bX bY) a | 2D histogram |
-> Histogram v bY b |
Reduce along X axis. Information about under/overlows is lost.
:: (Vector v a, Vector v b, Bin bX, Bin bY) | |
=> (BinValue bY -> Histogram v bX a -> b) | Function to reduce single slice along X axis |
-> Histogram v (Bin2D bX bY) a | 2D histogram |
-> Histogram v bY b |
Reduce along X axis. Information about under/overlows is lost.
:: (Vector v a, Vector v b, Bin bX, Bin bY) | |
=> (Histogram v bY a -> b) | Function to reduce histogram along Y axis |
-> Histogram v (Bin2D bX bY) a | 2D histogram |
-> Histogram v bX b |
Reduce along Y axis. Information about under/overflows is lost.
:: (Vector v a, Vector v b, Bin bX, Bin bY) | |
=> (BinValue bX -> Histogram v bY a -> b) | Function to reduce histogram along Y axis |
-> Histogram v (Bin2D bX bY) a | 2D histogram |
-> Histogram v bX b |
Reduce along Y axis. Information about under/overflows is lost.