module Data.TDigest.Postprocess (
I.HasHistogram (..),
I.HistBin (..),
median,
quantile,
mean,
variance,
stddev,
cdf,
icdf,
I.Affine (..)
) where
import Prelude ()
import Prelude.Compat
import qualified Data.List.NonEmpty as NE
import qualified Data.TDigest.Postprocess.Internal as I
median :: I.HasHistogram a f => a -> f Double
median = quantile 0.5
quantile :: I.HasHistogram a f => Double -> a -> f Double
quantile q x = I.quantile q (I.totalWeight x) <$> I.histogram x
mean :: I.HasHistogram a f => a -> f Double
mean x = I.mean <$> I.histogram x
variance :: I.HasHistogram a f => a -> f Double
variance x = I.variance <$> I.histogram x
stddev :: I.HasHistogram a f => a -> f Double
stddev = fmap sqrt . variance
cdf :: I.HasHistogram a f => Double -> a -> Double
cdf q x = I.affine 1 (I.cdf q (I.totalWeight x) . NE.toList) $ I.histogram x
icdf :: I.HasHistogram a f => Double -> a -> f Double
icdf = quantile