Stability | experimental |
---|---|

Maintainer | Alexey Khudyakov <alexey.skladnoy@gmail.com> |

Safe Haskell | None |

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

- class Bin b where
- binsCenters :: (Bin b, Vector v (BinValue b)) => b -> v (BinValue b)
- class Bin b => BinEq b where
- class (Bin b, Ord (BinValue b)) => IntervalBin b where
- class IntervalBin b => Bin1D b where
- lowerLimit :: b -> BinValue b
- upperLimit :: b -> BinValue b

- class Bin b => SliceableBin b where
- unsafeSliceBin :: Int -> Int -> b -> b

- sliceBin :: SliceableBin b => Int -> Int -> b -> b
- class Bin b => MergeableBin b where
- unsafeMergeBins :: CutDirection -> Int -> b -> b

- data CutDirection
- mergeBins :: MergeableBin b => CutDirection -> Int -> b -> b
- class Bin b => VariableBin b where
- class VariableBin b => UniformBin b where
- class (Bin b, Bin b') => ConvertBin b b' where
- convertBin :: b -> b'

# Bin type class

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

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.

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)

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

# 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.

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

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.

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.

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

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

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.

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.

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) |