histogram-fill- Library for histograms creation.

MaintainerAlexey Khudyakov <alexey.skladnoy@gmail.com>
Safe HaskellNone




Type classes for binning algorithms. This is mapping from set of interest to integer indices and approximate reverse.


Bin type class

class Bin b whereSource

This type represent some abstract data binning algorithms. It maps sets/intervals of values of type 'BinValue b' to integer indices.

Following invariant is expected to hold:

 toIndex . fromIndex == id

Associated Types

type BinValue b Source

Type of value to bin


toIndex :: b -> BinValue b -> IntSource

Convert from value to index. Function must not fail for any input and should produce out of range indices for invalid input.

fromIndex :: b -> Int -> BinValue bSource

Convert from index to value. Returned value should correspond to center of bin. Definition of center is left for definition of instance. Funtion may fail for invalid indices but encouraged not to do so.

nBins :: b -> IntSource

Total number of bins.

inRange :: b -> BinValue b -> BoolSource

Check whether value in range. Have default implementation. Should satisfy: inRange b x ⇔ toIndex b x ∈ [0,nBins b)


Bin BinI 
Bin BinInt 
Bin BinD 
Bin LogBinD 
Enum a => Bin (BinEnum a) 
RealFrac f => Bin (BinF f) 
Bin bin => Bin (MaybeBin bin) 
Bin b => Bin (BinPermute b) 
Enum2D i => Bin (BinEnum2D i) 
(Bin binX, Bin binY) => Bin (Bin2D binX binY) 

binsCenters :: (Bin b, Vector v (BinValue b)) => b -> v (BinValue b)Source

Return vector of bin centers

Approximate equality

class Bin b => BinEq b whereSource

Approximate equality for bins. It's nessesary to define approximate equality since exact equality is ill defined for bins which work with floating point data. It's not safe to compare floating point numbers for exact equality


binEq :: b -> b -> BoolSource

Approximate equality


BinEq BinI 
BinEq BinInt 
BinEq BinD

Equality is up to 3e-11 (2/3th of digits)

BinEq LogBinD 
Enum a => BinEq (BinEnum a) 
RealFloat f => BinEq (BinF f)

Equality is up to 2/3th of digits

BinEq bin => BinEq (MaybeBin bin) 
(BinEq bx, BinEq by) => BinEq (Bin2D bx by) 

1D bins

class (Bin b, Ord (BinValue b)) => IntervalBin b whereSource

For binning algorithms which work with bin values which have some natural ordering and every bin is continous interval.


binInterval :: b -> Int -> (BinValue b, BinValue b)Source

Interval for n'th bin

binsList :: Vector v (BinValue b, BinValue b) => b -> v (BinValue b, BinValue b)Source

List of all bins. Could be overridden for efficiency.

class IntervalBin b => Bin1D b whereSource

IntervalBin which domain is single finite interval


lowerLimit :: b -> BinValue bSource

Minimal accepted value of histogram

upperLimit :: b -> BinValue bSource

Maximal accepted value of histogram


class Bin b => SliceableBin b whereSource

Binning algorithm which support slicing.


unsafeSliceBin :: Int -> Int -> b -> bSource

Slice bin by indices. This function doesn't perform any checks and may produce invalid bin. Use sliceBin instead.

sliceBin :: SliceableBin b => Int -> Int -> b -> bSource

Slice bin using indices

class Bin b => MergeableBin b whereSource

Bin which support rebinning.


unsafeMergeBins :: CutDirection -> Int -> b -> bSource

N consecutive bins are joined into single bin. If number of bins isn't multiple of N remaining bins with highest or lowest index are dropped. This function doesn't do any checks. Use mergeBins instead.

data CutDirection Source

How index should be dropped



Drop bins with smallest index


Drop bins with bigger index

mergeBins :: MergeableBin b => CutDirection -> Int -> b -> bSource

N consecutive bins are joined into single bin. If number of bins isn't multiple of N remaining bins with highest or lowest index are dropped. If N is larger than number of bins all bins are merged into single one.

Sizes of bin

class Bin b => VariableBin b whereSource

1D binning algorithms with variable bin size


binSizeN :: b -> Int -> BinValue bSource

Size of n'th bin.

class VariableBin b => UniformBin b whereSource

1D binning algorithms with constant size bins. Constant sized bins could be thought as specialization of variable-sized bins therefore a superclass constraint.


binSize :: b -> BinValue bSource

Size of bin. Default implementation just uses 0th bin.


class (Bin b, Bin b') => ConvertBin b b' whereSource

Class for conversion between binning algorithms.


convertBin :: b -> b'Source

Convert bins


ConvertBin BinI BinInt 
ConvertBin BinI BinD 
ConvertBin BinInt BinD 
RealFrac f => ConvertBin BinI (BinF f) 
RealFrac f => ConvertBin BinInt (BinF f) 
(ConvertBin bx bx', ConvertBin by by') => ConvertBin (Bin2D bx by) (Bin2D bx' by') 
(ConvertBin by by', Bin bx) => ConvertBin (Bin2D bx by) (Bin2D bx by') 
(ConvertBin bx bx', Bin by) => ConvertBin (Bin2D bx by) (Bin2D bx' by)