numhask-space-0.11.1.0: Numerical spaces.
Safe HaskellSafe-Inferred
LanguageGHC2021

NumHask.Space.Histogram

Description

A histogram, if you squint, is a series of contiguous Ranges, annotated with values.

Synopsis

Documentation

data Histogram Source #

This Histogram is a list of contiguous boundaries (a boundary being the lower edge of one bucket and the upper edge of another), and a value (usually a count) for each bucket, represented here as a map

Overs and Unders are contained in key = 0 and key = length cuts Intervals are defined as (l,u]

Constructors

Histogram 

Instances

Instances details
Show Histogram Source # 
Instance details

Defined in NumHask.Space.Histogram

Eq Histogram Source # 
Instance details

Defined in NumHask.Space.Histogram

emptyHistogram :: Histogram Source #

A histogram with no cuts nor data.

data DealOvers Source #

Whether or not to ignore unders and overs. If overs and unders are dealt with, IncludeOvers supplies an assumed width for the outer buckets.

fill :: Foldable f => [Double] -> f Double -> Histogram Source #

Fill a Histogram using pre-specified cuts

>>> fill [0,50,100] [0..99]
Histogram {cuts = [0.0,50.0,100.0], values = fromList [(1,50.0),(2,50.0)]}

cutI :: Ord a => Vector a -> a -> Int Source #

find the index of the bucket the value is contained in.

regular :: Int -> [Double] -> Histogram Source #

Make a histogram using n equally spaced cuts over the entire range of the data

>>> regular 4 [0..100]
Histogram {cuts = [0.0,25.0,50.0,75.0,100.0], values = fromList [(1,25.0),(2,25.0),(3,25.0),(4,25.0),(5,1.0)]}

makeRects :: DealOvers -> Histogram -> [Rect Double] Source #

Transform a Histogram to Rects

>>> makeRects IgnoreOvers (regular 4 [0..100])
[Rect 0.0 25.0 0.0 0.25,Rect 25.0 50.0 0.0 0.25,Rect 50.0 75.0 0.0 0.25,Rect 75.0 100.0 0.0 0.25]

regularQuantiles :: Double -> [Double] -> [Double] Source #

approx regular n-quantiles

>>> regularQuantiles 4 [0..100]
[0.0,24.75,50.0,75.25,100.0]

quantileFold :: [Double] -> [Double] -> [Double] Source #

one-pass approximate quantiles fold

freq :: Histogram -> Histogram Source #

normalize a histogram

\h -> sum (values $ freq h) == one
>>> freq $ fill [0,50,100] [0..99]
Histogram {cuts = [0.0,50.0,100.0], values = fromList [(1,0.5),(2,0.5)]}

average :: Foldable f => f Double -> Double Source #

average

>>> average [0..1000]
500.0

quantiles :: Foldable f => Int -> f Double -> [Double] Source #

Regularly spaced (approx) quantiles

>>> quantiles 5 [1..1000]
[1.0,200.5,400.5,600.5000000000001,800.5,1000.0]

quantile :: Foldable f => Double -> f Double -> Double Source #

single (approx) quantile

>>> quantile 0.1 [1..1000]
100.5