histogram-fill-0.8.0.0: Library for histograms creation.

Stability experimental Alexey Khudyakov None

Data.Histogram.Bin.Classes

Description

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

Synopsis

# 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

Methods

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)

Instances

 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

Methods

binEq :: b -> b -> BoolSource

Approximate equality

Instances

 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.

Methods

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.

Instances

 IntervalBin BinI IntervalBin BinInt IntervalBin BinD IntervalBin LogBinD (Enum a, Ord a) => IntervalBin (BinEnum a) RealFrac f => IntervalBin (BinF f) IntervalBin b => IntervalBin (BinPermute b)

class IntervalBin b => Bin1D b whereSource

`IntervalBin` which domain is single finite interval

Methods

lowerLimit :: b -> BinValue bSource

Minimal accepted value of histogram

upperLimit :: b -> BinValue bSource

Maximal accepted value of histogram

Instances

 Bin1D BinI Bin1D BinInt Bin1D BinD Bin1D LogBinD (Enum a, Ord a) => Bin1D (BinEnum a) RealFrac f => Bin1D (BinF f)

class Bin b => SliceableBin b whereSource

Binning algorithm which support slicing.

Methods

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

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

Instances

 SliceableBin BinI SliceableBin BinInt SliceableBin BinD SliceableBin LogBinD (Enum a, Ord a) => SliceableBin (BinEnum a) RealFrac f => SliceableBin (BinF f)

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

Slice bin using indices

class Bin b => MergeableBin b whereSource

Bin which support rebinning.

Methods

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.

Instances

 MergeableBin BinInt MergeableBin BinD MergeableBin LogBinD RealFrac f => MergeableBin (BinF f)

How index should be dropped

Constructors

 CutLower Drop bins with smallest index CutHigher 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

Methods

binSizeN :: b -> Int -> BinValue bSource

Size of n'th bin.

Instances

 VariableBin BinI VariableBin BinInt VariableBin BinD VariableBin LogBinD RealFrac f => VariableBin (BinF f) VariableBin bin => VariableBin (MaybeBin bin) VariableBin b => VariableBin (BinPermute b)

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.

Methods

binSize :: b -> BinValue bSource

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

Instances

 UniformBin BinI UniformBin BinInt UniformBin BinD RealFrac f => UniformBin (BinF f) UniformBin b => UniformBin (BinPermute b)

# Conversion

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

Class for conversion between binning algorithms.

Methods

convertBin :: b -> b'Source

Convert bins

Instances

 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)