-- | 'TDigest' postprocessing functions.
--
-- These are re-exported from "Data.TDigest" module.
--
module Data.TDigest.Tree.Postprocess (
    -- * Quantiles
    median,
    quantile,
    -- * Mean & variance
    --
    -- | As we have "full" histogram, we can calculate other statistical
    -- variables.
    mean,
    variance,
    stddev,
    -- * CDF
    cdf,
    icdf,
    ) where

import Prelude ()
import Prelude.Compat

import Data.TDigest.Tree.Internal

import qualified Data.TDigest.Postprocess as PP

-- $setup
-- >>> import Data.TDigest.Tree

-------------------------------------------------------------------------------
-- Quantile
-------------------------------------------------------------------------------

-- | Median, i.e. @'quantile' 0.5@.
median :: TDigest comp -> Maybe Double
median :: TDigest comp -> Maybe Double
median = TDigest comp -> Maybe Double
forall a (f :: * -> *). HasHistogram a f => a -> f Double
PP.median

-- | Calculate quantile of a specific value.
quantile :: Double -> TDigest comp -> Maybe Double
quantile :: Double -> TDigest comp -> Maybe Double
quantile = Double -> TDigest comp -> Maybe Double
forall a (f :: * -> *). HasHistogram a f => Double -> a -> f Double
PP.quantile

-------------------------------------------------------------------------------
-- Mean
-------------------------------------------------------------------------------

-- | Mean.
--
-- >>> mean (tdigest [1..100] :: TDigest 10)
-- Just 50.5
--
-- /Note:/ if you only need the mean, calculate it directly.
--
mean :: TDigest comp -> Maybe Double
mean :: TDigest comp -> Maybe Double
mean = TDigest comp -> Maybe Double
forall a (f :: * -> *). HasHistogram a f => a -> f Double
PP.mean

-- | Variance.
--
variance :: TDigest comp -> Maybe Double
variance :: TDigest comp -> Maybe Double
variance = TDigest comp -> Maybe Double
forall a (f :: * -> *). HasHistogram a f => a -> f Double
PP.variance

-- | Standard deviation, square root of variance.
stddev :: TDigest comp -> Maybe Double
stddev :: TDigest comp -> Maybe Double
stddev = TDigest comp -> Maybe Double
forall a (f :: * -> *). HasHistogram a f => a -> f Double
PP.stddev

-------------------------------------------------------------------------------
-- CDF - cumulative distribution function
-------------------------------------------------------------------------------

-- | Cumulative distribution function.
--
-- /Note:/ if this is the only thing you need, it's more efficient to count
-- this directly.
cdf :: Double -> TDigest comp -> Double
cdf :: Double -> TDigest comp -> Double
cdf = Double -> TDigest comp -> Double
forall a (f :: * -> *). HasHistogram a f => Double -> a -> Double
PP.cdf

-- | An alias for 'quantile'
icdf :: Double -> TDigest comp -> Maybe Double
icdf :: Double -> TDigest comp -> Maybe Double
icdf = Double -> TDigest comp -> Maybe Double
forall (comp :: Nat). Double -> TDigest comp -> Maybe Double
quantile