-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | On-line accumulation of rank-based statistics
--   
--   A new data structure for accurate on-line accumulation of rank-based
--   statistics such as quantiles and trimmed means.
--   
--   See original paper: "Computing extremely accurate quantiles using
--   t-digest" by Ted Dunning and Otmar Ertl for more details
--   <a>https://github.com/tdunning/t-digest/blob/07b8f2ca2be8d0a9f04df2feadad5ddc1bb73c88/docs/t-digest-paper/histo.pdf</a>.
@package tdigest
@version 0.3

module Data.TDigest.Internal
type Mean = Double
type Weight = Double
type Centroid = (Mean, Weight)
type Size = Int
assert :: Bool -> String -> a -> a
eq :: Double -> Double -> Bool
negInf :: Double
posInf :: Double


-- | <tt>TDigest</tt> postprocessing functions.
--   
--   These are re-exported from <a>Data.TDigest</a> module.
module Data.TDigest.Postprocess.Internal

-- | Types from which we can extract histogram.
class Affine f => HasHistogram a f | a -> f
histogram :: HasHistogram a f => a -> f (NonEmpty HistBin)
totalWeight :: HasHistogram a f => a -> Weight

-- | Histogram bin
data HistBin
HistBin :: !Mean -> !Mean -> !Mean -> !Weight -> !Weight -> HistBin

-- | lower bound
[hbMin] :: HistBin -> !Mean

-- | upper bound
[hbMax] :: HistBin -> !Mean

-- | original value: <tt>(mi + ma) / 2</tt>
[hbValue] :: HistBin -> !Mean

-- | weight ("area" of the bar)
[hbWeight] :: HistBin -> !Weight

-- | weight from the right, excludes this bin
[hbCumWeight] :: HistBin -> !Weight

-- | Histogram from centroids
histogramFromCentroids :: NonEmpty Centroid -> NonEmpty HistBin

-- | Quantile from the histogram.
quantile :: Double -> Weight -> NonEmpty HistBin -> Double

-- | Mean from the histogram.
mean :: NonEmpty HistBin -> Double

-- | Variance from the histogram.
variance :: NonEmpty HistBin -> Double

-- | Cumulative distribution function.
cdf :: Double -> Double -> [HistBin] -> Double

-- | Validate that list of <a>HistBin</a> is a valid "histogram".
validateHistogram :: Foldable f => f HistBin -> Either String (f HistBin)

-- | Affine containers, i.e. containing at most 1 element
--   
--   This class doesn't have <a>traverse</a> analogie as it would require
--   using <tt>Pointed</tt> which is disputed type class.
--   
--   <pre>
--   traverseAff :: Pointed f =&gt; (a -&gt; f b) -&gt; t a -&gt; f (t b)
--   </pre>
class Traversable t => Affine t

-- | Like <a>foldMap</a>
affine :: Affine t => b -> (a -> b) -> t a -> b
fromAffine :: Affine t => a -> t a -> a
instance GHC.Show.Show Data.TDigest.Postprocess.Internal.HistBin
instance (Data.TDigest.Postprocess.Internal.HistBin GHC.Types.~ e) => Data.TDigest.Postprocess.Internal.HasHistogram (GHC.Base.NonEmpty Data.TDigest.Postprocess.Internal.HistBin) Data.Functor.Identity.Identity
instance (Data.TDigest.Postprocess.Internal.HistBin GHC.Types.~ e) => Data.TDigest.Postprocess.Internal.HasHistogram [Data.TDigest.Postprocess.Internal.HistBin] GHC.Maybe.Maybe
instance Data.TDigest.Postprocess.Internal.Affine Data.Functor.Identity.Identity
instance Data.TDigest.Postprocess.Internal.Affine GHC.Maybe.Maybe
instance Data.TDigest.Postprocess.Internal.Affine Data.Proxy.Proxy
instance (Data.TDigest.Postprocess.Internal.Affine f, Data.TDigest.Postprocess.Internal.Affine g) => Data.TDigest.Postprocess.Internal.Affine (Data.Functor.Compose.Compose f g)
instance GHC.Base.Semigroup Data.TDigest.Postprocess.Internal.Variance
instance GHC.Base.Semigroup Data.TDigest.Postprocess.Internal.Mean'

module Data.TDigest.Postprocess

-- | Types from which we can extract histogram.
class Affine f => HasHistogram a f | a -> f
histogram :: HasHistogram a f => a -> f (NonEmpty HistBin)
totalWeight :: HasHistogram a f => a -> Weight

-- | Histogram bin
data HistBin
HistBin :: !Mean -> !Mean -> !Mean -> !Weight -> !Weight -> HistBin

-- | lower bound
[hbMin] :: HistBin -> !Mean

-- | upper bound
[hbMax] :: HistBin -> !Mean

-- | original value: <tt>(mi + ma) / 2</tt>
[hbValue] :: HistBin -> !Mean

-- | weight ("area" of the bar)
[hbWeight] :: HistBin -> !Weight

-- | weight from the right, excludes this bin
[hbCumWeight] :: HistBin -> !Weight

-- | Median, i.e. <tt><a>quantile</a> 0.5</tt>.
median :: HasHistogram a f => a -> f Double

-- | Calculate quantile of a specific value.
quantile :: HasHistogram a f => Double -> a -> f Double

-- | Mean.
--   
--   <pre>
--   &gt;&gt;&gt; mean (Tree.tdigest [1..100] :: Tree.TDigest 10)
--   Just 50.5
--   </pre>
--   
--   <i>Note:</i> if you only need the mean, calculate it directly.
mean :: HasHistogram a f => a -> f Double

-- | Variance.
variance :: HasHistogram a f => a -> f Double

-- | Standard deviation, square root of variance.
stddev :: HasHistogram a f => a -> f Double

-- | Cumulative distribution function.
--   
--   <i>Note:</i> if this is the only thing you need, it's more efficient
--   to count this directly.
cdf :: HasHistogram a f => Double -> a -> Double

-- | An alias for <a>quantile</a>.
icdf :: HasHistogram a f => Double -> a -> f Double

-- | Affine containers, i.e. containing at most 1 element
--   
--   This class doesn't have <a>traverse</a> analogie as it would require
--   using <tt>Pointed</tt> which is disputed type class.
--   
--   <pre>
--   traverseAff :: Pointed f =&gt; (a -&gt; f b) -&gt; t a -&gt; f (t b)
--   </pre>
class Traversable t => Affine t

-- | Like <a>foldMap</a>
affine :: Affine t => b -> (a -> b) -> t a -> b
fromAffine :: Affine t => a -> t a -> a


-- | Internals of <a>TDigest</a>.
--   
--   Tree implementation is based on <i>Adams’ Trees Revisited</i> by Milan
--   Straka <a>http://fox.ucw.cz/papers/bbtree/bbtree.pdf</a>
module Data.TDigest.Tree.Internal

-- | <a>TDigest</a> is a tree of centroids.
--   
--   <tt>compression</tt> is a <tt>1/δ</tt>. The greater the value of
--   <tt>compression</tt> the less likely value merging will happen.
data TDigest (compression :: Nat)

-- | Tree node
Node :: {-# UNPACK #-} !Size -> {-# UNPACK #-} !Mean -> {-# UNPACK #-} !Weight -> {-# UNPACK #-} !Weight -> !TDigest compression -> !TDigest compression -> TDigest (compression :: Nat)

-- | Empty tree
Nil :: TDigest (compression :: Nat)
getCentroids :: TDigest comp -> [Centroid]

-- | Total count of samples.
--   
--   <pre>
--   &gt;&gt;&gt; totalWeight (tdigest [1..100] :: TDigest 5)
--   100.0
--   </pre>
totalWeight :: TDigest comp -> Weight
size :: TDigest comp -> Int

-- | Center of left-most centroid. Note: may be different than min element
--   inserted.
--   
--   <pre>
--   &gt;&gt;&gt; minimumValue (tdigest [1..100] :: TDigest 3)
--   1.0
--   </pre>
minimumValue :: TDigest comp -> Mean

-- | Center of right-most centroid. Note: may be different than max element
--   inserted.
--   
--   <pre>
--   &gt;&gt;&gt; maximumValue (tdigest [1..100] :: TDigest 3)
--   99.0
--   </pre>
maximumValue :: TDigest comp -> Mean
emptyTDigest :: TDigest comp
combineDigest :: KnownNat comp => TDigest comp -> TDigest comp -> TDigest comp
insertCentroid :: forall comp. KnownNat comp => Centroid -> TDigest comp -> TDigest comp

-- | Constructor which calculates size and total weight.
node :: Mean -> Weight -> TDigest comp -> TDigest comp -> TDigest comp

-- | Balance after right insertion.
balanceR :: Mean -> Weight -> TDigest comp -> TDigest comp -> TDigest comp

-- | Balance after left insertion.
balanceL :: Mean -> Weight -> TDigest comp -> TDigest comp -> TDigest comp

-- | Alias to <a>Node</a>
node' :: Int -> Mean -> Weight -> Weight -> TDigest comp -> TDigest comp -> TDigest comp

-- | Create singular node.
singNode :: Mean -> Weight -> TDigest comp

-- | Add two weighted means together.
combinedCentroid :: Mean -> Weight -> Mean -> Weight -> Centroid

-- | Calculate the threshold, i.e. maximum weight of centroid.
threshold :: Double -> Double -> Double -> Double

-- | Compress <a>TDigest</a>.
--   
--   Reinsert the centroids in "better" order (in original paper: in
--   random) so they have opportunity to merge.
--   
--   Compression will happen only if size is both: bigger than
--   <tt><a>relMaxSize</a> * comp</tt> and bigger than <a>absMaxSize</a>.
compress :: forall comp. KnownNat comp => TDigest comp -> TDigest comp

-- | Perform compression, even if current size says it's not necessary.
forceCompress :: forall comp. KnownNat comp => TDigest comp -> TDigest comp
toMVector :: forall comp s. KnownNat comp => TDigest comp -> ST s (MVector s (Centroid, Double))

-- | Relative size parameter. Hard-coded value: 25.
relMaxSize :: Int

-- | Absolute size parameter. Hard-coded value: 1000.
absMaxSize :: Int
balOmega :: Int
balAlpha :: Int

-- | Output the <a>TDigest</a> tree.
debugPrint :: TDigest comp -> IO ()

-- | <pre>
--   <a>isRight</a> . <a>validate</a>
--   </pre>
valid :: TDigest comp -> Bool

-- | Check various invariants in the <a>TDigest</a> tree.
validate :: TDigest comp -> Either String (TDigest comp)

-- | Insert single value into <a>TDigest</a>.
insert :: KnownNat comp => Double -> TDigest comp -> TDigest comp

-- | Insert single value, don't compress <a>TDigest</a> even if needed.
--   
--   For sensibly bounded input, it makes sense to let <a>TDigest</a> grow
--   (it might grow linearly in size), and after that compress it once.
insert' :: KnownNat comp => Double -> TDigest comp -> TDigest comp

-- | Make a <a>TDigest</a> of a single data point.
singleton :: KnownNat comp => Double -> TDigest comp

-- | Strict <a>foldl'</a> over <a>Foldable</a> structure.
tdigest :: (Foldable f, KnownNat comp) => f Double -> TDigest comp
instance GHC.Show.Show (Data.TDigest.Tree.Internal.TDigest compression)
instance GHC.TypeNats.KnownNat comp => GHC.Base.Semigroup (Data.TDigest.Tree.Internal.TDigest comp)
instance GHC.TypeNats.KnownNat comp => Data.Semigroup.Reducer.Reducer GHC.Types.Double (Data.TDigest.Tree.Internal.TDigest comp)
instance GHC.TypeNats.KnownNat comp => GHC.Base.Monoid (Data.TDigest.Tree.Internal.TDigest comp)
instance Control.DeepSeq.NFData (Data.TDigest.Tree.Internal.TDigest comp)
instance GHC.TypeNats.KnownNat comp => Data.Binary.Class.Binary (Data.TDigest.Tree.Internal.TDigest comp)
instance Data.TDigest.Postprocess.Internal.HasHistogram (Data.TDigest.Tree.Internal.TDigest comp) GHC.Maybe.Maybe


-- | This is non empty version of <a>TDigest</a>, i.e. this is not a
--   <a>Monoid</a>, but on the other hand, <a>quantile</a> returns
--   <a>Double</a> not <tt><a>Maybe</a> <a>Double</a></tt>.
--   
--   See <a>Data.TDigest</a> for documentation. The exports should be
--   similar, sans non-<a>Maybe</a> results.
--   
--   <h3>Examples</h3>
--   
--   <pre>
--   &gt;&gt;&gt; quantile 0.99 (tdigest (1 :| [2..1000]) :: TDigest 25)
--   990.5
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; quantile 0.99 (tdigest (1 :| [2..1000]) :: TDigest 3)
--   989.0...
--   </pre>
--   
--   t-Digest is more precise in tails, especially median is imprecise:
--   
--   <pre>
--   &gt;&gt;&gt; median (forceCompress $ tdigest (1 :| [2..1000]) :: TDigest 25)
--   497.6...
--   </pre>
module Data.TDigest.Tree.NonEmpty
data TDigest comp
tdigest :: (Foldable1 f, KnownNat comp) => f Double -> TDigest comp
singleton :: KnownNat comp => Double -> TDigest comp
insert :: KnownNat comp => Double -> TDigest comp -> TDigest comp
insert' :: KnownNat comp => Double -> TDigest comp -> TDigest comp
compress :: forall comp. KnownNat comp => TDigest comp -> TDigest comp
forceCompress :: forall comp. KnownNat comp => TDigest comp -> TDigest comp
totalWeight :: TDigest comp -> Weight
minimumValue :: TDigest comp -> Mean
maximumValue :: TDigest comp -> Mean
median :: TDigest comp -> Double
quantile :: Double -> TDigest comp -> Double
mean :: TDigest comp -> Double
variance :: TDigest comp -> Double
stddev :: TDigest comp -> Double
cdf :: Double -> TDigest comp -> Double

-- | Alias of <a>quantile</a>.
icdf :: Double -> TDigest comp -> Double
size :: TDigest comp -> Int
valid :: TDigest comp -> Bool
validate :: TDigest comp -> Either String (TDigest comp)
debugPrint :: TDigest comp -> IO ()
instance Control.DeepSeq.NFData (Data.TDigest.Tree.NonEmpty.TDigest comp)
instance GHC.Show.Show (Data.TDigest.Tree.NonEmpty.TDigest comp)
instance GHC.TypeNats.KnownNat comp => GHC.Base.Semigroup (Data.TDigest.Tree.NonEmpty.TDigest comp)
instance GHC.TypeNats.KnownNat comp => Data.Semigroup.Reducer.Reducer GHC.Types.Double (Data.TDigest.Tree.NonEmpty.TDigest comp)
instance GHC.TypeNats.KnownNat comp => Data.Binary.Class.Binary (Data.TDigest.Tree.NonEmpty.TDigest comp)
instance Data.TDigest.Postprocess.Internal.HasHistogram (Data.TDigest.Tree.NonEmpty.TDigest comp) Data.Functor.Identity.Identity

module Data.TDigest.NonEmpty


-- | <a>TDigest</a> postprocessing functions.
--   
--   These are re-exported from <a>Data.TDigest</a> module.
module Data.TDigest.Tree.Postprocess

-- | Median, i.e. <tt><a>quantile</a> 0.5</tt>.
median :: TDigest comp -> Maybe Double

-- | Calculate quantile of a specific value.
quantile :: Double -> TDigest comp -> Maybe Double

-- | Mean.
--   
--   <pre>
--   &gt;&gt;&gt; mean (tdigest [1..100] :: TDigest 10)
--   Just 50.5
--   </pre>
--   
--   <i>Note:</i> if you only need the mean, calculate it directly.
mean :: TDigest comp -> Maybe Double

-- | Variance.
variance :: TDigest comp -> Maybe Double

-- | Standard deviation, square root of variance.
stddev :: TDigest comp -> Maybe Double

-- | Cumulative distribution function.
--   
--   <i>Note:</i> if this is the only thing you need, it's more efficient
--   to count this directly.
cdf :: Double -> TDigest comp -> Double

-- | An alias for <a>quantile</a>
icdf :: Double -> TDigest comp -> Maybe Double


-- | A new data structure for accurate on-line accumulation of rank-based
--   statistics such as quantiles and trimmed means. . See original paper:
--   "Computing extremely accurate quantiles using t-digest" by Ted Dunning
--   and Otmar Ertl for more details
--   <a>https://github.com/tdunning/t-digest/blob/master/docs/t-digest-paper/histo.pdf</a>.
--   
--   <h3>Examples</h3>
--   
--   <pre>
--   &gt;&gt;&gt; quantile 0.99 (tdigest [1..1000] :: TDigest 25)
--   Just 990.5
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; quantile 0.99 (tdigest [1..1000] :: TDigest 3)
--   Just 989.0...
--   </pre>
--   
--   t-Digest is more precise in tails, especially median is imprecise:
--   
--   <pre>
--   &gt;&gt;&gt; median (forceCompress $ tdigest [1..1000] :: TDigest 25)
--   Just 497.6...
--   </pre>
--   
--   <h3>Semigroup</h3>
--   
--   This operation isn't strictly associative, but statistical variables
--   shouldn't be affected.
--   
--   <pre>
--   &gt;&gt;&gt; let td xs = tdigest xs :: TDigest 10
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; median (td [1..500] &lt;&gt; (td [501..1000] &lt;&gt; td [1001..1500]))
--   Just 802...
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; median ((td [1..500] &lt;&gt; td [501..1000]) &lt;&gt; td [1001..1500])
--   Just 726...
--   </pre>
--   
--   The linear is worst-case scenario:
--   
--   <pre>
--   &gt;&gt;&gt; let td' xs = tdigest (fairshuffle xs) :: TDigest 10
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; median (td' [1..500] &lt;&gt; (td' [501..1000] &lt;&gt; td' [1001..1500]))
--   Just 750.3789...
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; median ((td' [1..500] &lt;&gt; td' [501..1000]) &lt;&gt; td' [1001..1500])
--   Just 750.3789...
--   </pre>
module Data.TDigest.Tree

-- | <a>TDigest</a> is a tree of centroids.
--   
--   <tt>compression</tt> is a <tt>1/δ</tt>. The greater the value of
--   <tt>compression</tt> the less likely value merging will happen.
data TDigest (compression :: Nat)

-- | Strict <a>foldl'</a> over <a>Foldable</a> structure.
tdigest :: (Foldable f, KnownNat comp) => f Double -> TDigest comp

-- | Make a <a>TDigest</a> of a single data point.
singleton :: KnownNat comp => Double -> TDigest comp

-- | Insert single value into <a>TDigest</a>.
insert :: KnownNat comp => Double -> TDigest comp -> TDigest comp

-- | Insert single value, don't compress <a>TDigest</a> even if needed.
--   
--   For sensibly bounded input, it makes sense to let <a>TDigest</a> grow
--   (it might grow linearly in size), and after that compress it once.
insert' :: KnownNat comp => Double -> TDigest comp -> TDigest comp

-- | Compress <a>TDigest</a>.
--   
--   Reinsert the centroids in "better" order (in original paper: in
--   random) so they have opportunity to merge.
--   
--   Compression will happen only if size is both: bigger than
--   <tt><a>relMaxSize</a> * comp</tt> and bigger than <a>absMaxSize</a>.
compress :: forall comp. KnownNat comp => TDigest comp -> TDigest comp

-- | Perform compression, even if current size says it's not necessary.
forceCompress :: forall comp. KnownNat comp => TDigest comp -> TDigest comp

-- | Center of left-most centroid. Note: may be different than min element
--   inserted.
--   
--   <pre>
--   &gt;&gt;&gt; minimumValue (tdigest [1..100] :: TDigest 3)
--   1.0
--   </pre>
minimumValue :: TDigest comp -> Mean

-- | Center of right-most centroid. Note: may be different than max element
--   inserted.
--   
--   <pre>
--   &gt;&gt;&gt; maximumValue (tdigest [1..100] :: TDigest 3)
--   99.0
--   </pre>
maximumValue :: TDigest comp -> Mean

-- | Median, i.e. <tt><a>quantile</a> 0.5</tt>.
median :: TDigest comp -> Maybe Double

-- | Calculate quantile of a specific value.
quantile :: Double -> TDigest comp -> Maybe Double

-- | Mean.
--   
--   <pre>
--   &gt;&gt;&gt; mean (tdigest [1..100] :: TDigest 10)
--   Just 50.5
--   </pre>
--   
--   <i>Note:</i> if you only need the mean, calculate it directly.
mean :: TDigest comp -> Maybe Double

-- | Variance.
variance :: TDigest comp -> Maybe Double

-- | Standard deviation, square root of variance.
stddev :: TDigest comp -> Maybe Double

-- | Cumulative distribution function.
--   
--   <i>Note:</i> if this is the only thing you need, it's more efficient
--   to count this directly.
cdf :: Double -> TDigest comp -> Double

-- | An alias for <a>quantile</a>
icdf :: Double -> TDigest comp -> Maybe Double
size :: TDigest comp -> Int

-- | <pre>
--   <a>isRight</a> . <a>validate</a>
--   </pre>
valid :: TDigest comp -> Bool

-- | Check various invariants in the <a>TDigest</a> tree.
validate :: TDigest comp -> Either String (TDigest comp)

-- | Output the <a>TDigest</a> tree.
debugPrint :: TDigest comp -> IO ()

module Data.TDigest

module Data.TDigest.Vector.Internal

-- | <a>TDigest</a> is a vector of centroids plus not yet merged elements.
--   
--   The size of structure is dictated by <tt>compression</tt>, *𝛿*. And is
--   *O(𝛿)*.
data TDigest (compression :: Nat)
TDigest :: !Size -> !Vector Centroid -> !Size -> [Double] -> !Bool -> TDigest (compression :: Nat)

-- | sum of vector and buffer size
[tdigestTotalWeight] :: TDigest (compression :: Nat) -> !Size

-- | actual data. *Invariants:* sorted by mean; length &lt;= 2 𝛿 (soft)
[tdigestData] :: TDigest (compression :: Nat) -> !Vector Centroid
[tdigestBufferSize] :: TDigest (compression :: Nat) -> !Size

-- | addition buffer, elements with weight 1. *Invariants:* length 2 &lt;=
--   𝛿
[tdigestBuffer] :: TDigest (compression :: Nat) -> [Double]

-- | direction is a hack, so we merge from left and right. *TODO* remove?
[tdigestDirection] :: TDigest (compression :: Nat) -> !Bool

-- | Size of structure
size :: TDigest comp -> Int
totalWeight :: TDigest comp -> Weight

-- | Center of left-most centroid. Note: may be different than min element
--   inserted.
--   
--   <pre>
--   &gt;&gt;&gt; minimumValue (tdigest [1..100] :: TDigest 3)
--   1.0
--   </pre>
minimumValue :: KnownNat comp => TDigest comp -> Mean

-- | Center of right-most centroid. Note: may be different than max element
--   inserted.
--   
--   <pre>
--   &gt;&gt;&gt; maximumValue (tdigest [1..100] :: TDigest 3)
--   100.0
--   </pre>
maximumValue :: KnownNat comp => TDigest comp -> Mean

-- | Mapping from quantile *q* to notional index *k* with compression
--   parameter *𝛿*.
--   
--   <pre>
--   &gt;&gt;&gt; ksize 42 0
--   0.0
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; ksize 42 1
--   42.0
--   </pre>
--   
--   <ul>
--   <li>q@ is clamped.:</li>
--   </ul>
--   
--   <pre>
--   &gt;&gt;&gt; ksize 42 2
--   42.0
--   </pre>
ksize :: Double -> Double -> Double
clamp :: Double -> Double

-- | Inverse of <a>ksize</a>.
--   
--   <pre>
--   &gt;&gt;&gt; ksizeInv 42 0
--   0.0
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; ksizeInv 42 42
--   1.0
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; ksizeInv 42 (ksize 42 0.3)
--   0.3
--   </pre>
ksizeInv :: Double -> Double -> Double
merge :: Int -> Double -> [(Mean, Weight)] -> [(Mean, Weight)]
emptyTDigest :: TDigest comp
combineTDigest :: forall comp. KnownNat comp => TDigest comp -> TDigest comp -> TDigest comp

-- | Flush insertion buffer
finalize :: forall comp. KnownNat comp => TDigest comp -> TDigest comp
forceCompress :: forall comp. KnownNat comp => TDigest comp -> TDigest comp
compress :: forall comp. KnownNat comp => TDigest comp -> TDigest comp
sizeCoefficient :: Num a => a

-- | <pre>
--   <a>isRight</a> . <a>validate</a>
--   </pre>
valid :: TDigest comp -> Bool

-- | Check various invariants in the <a>TDigest</a> structure.
validate :: TDigest comp -> Either String (TDigest comp)

-- | Insert single value into <a>TDigest</a>.
insert :: KnownNat comp => Double -> TDigest comp -> TDigest comp

-- | Insert single value, don't compress <a>TDigest</a> even if needed.
--   
--   This may violate the insertion buffer size invariant.
--   
--   For sensibly bounded input, it makes sense to let <a>TDigest</a> grow
--   (it might grow linearly in size), and after that compress it once.
insert' :: KnownNat comp => Double -> TDigest comp -> TDigest comp

-- | Make a <a>TDigest</a> of a single data point.
singleton :: Double -> TDigest comp

-- | Strict <a>foldl'</a> over <a>Foldable</a> structure.
tdigest :: (Foldable f, KnownNat comp) => f Double -> TDigest comp
instance GHC.Show.Show (Data.TDigest.Vector.Internal.TDigest compression)
instance GHC.TypeNats.KnownNat comp => GHC.Base.Semigroup (Data.TDigest.Vector.Internal.TDigest comp)
instance GHC.TypeNats.KnownNat comp => GHC.Base.Monoid (Data.TDigest.Vector.Internal.TDigest comp)
instance GHC.TypeNats.KnownNat comp => Data.Semigroup.Reducer.Reducer GHC.Types.Double (Data.TDigest.Vector.Internal.TDigest comp)
instance Control.DeepSeq.NFData (Data.TDigest.Vector.Internal.TDigest comp)
instance GHC.TypeNats.KnownNat comp => Data.TDigest.Postprocess.Internal.HasHistogram (Data.TDigest.Vector.Internal.TDigest comp) GHC.Maybe.Maybe

module Data.TDigest.Vector.NonEmpty


-- | <a>TDigest</a> postprocessing functions.
--   
--   These are re-exported from <a>Data.TDigest</a> module.
module Data.TDigest.Vector.Postprocess

-- | Median, i.e. <tt><a>quantile</a> 0.5</tt>.
median :: KnownNat comp => TDigest comp -> Maybe Double

-- | Calculate quantile of a specific value.
quantile :: KnownNat comp => Double -> TDigest comp -> Maybe Double

-- | Mean.
--   
--   <pre>
--   &gt;&gt;&gt; mean (tdigest [1..100] :: TDigest 10)
--   Just 50.5
--   </pre>
--   
--   <i>Note:</i> if you only need the mean, calculate it directly.
mean :: KnownNat comp => TDigest comp -> Maybe Double

-- | Variance.
variance :: KnownNat comp => TDigest comp -> Maybe Double

-- | Standard deviation, square root of variance.
stddev :: KnownNat comp => TDigest comp -> Maybe Double

-- | Cumulative distribution function.
--   
--   <i>Note:</i> if this is the only thing you need, it's more efficient
--   to count this directly.
cdf :: KnownNat comp => Double -> TDigest comp -> Double

-- | An alias for <a>quantile</a>
icdf :: KnownNat comp => Double -> TDigest comp -> Maybe Double


-- | A new data structure for accurate on-line accumulation of rank-based
--   statistics such as quantiles and trimmed means. . See original paper:
--   "Computing extremely accurate quantiles using t-digest" by Ted Dunning
--   and Otmar Ertl for more details
--   <a>https://github.com/tdunning/t-digest/blob/master/docs/t-digest-paper/histo.pdf</a>.
--   
--   <h3>Examples</h3>
--   
--   <pre>
--   &gt;&gt;&gt; quantile 0.99 (tdigest [1..1000] :: TDigest 25)
--   Just 990.5
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; quantile 0.99 (tdigest [1..1000] :: TDigest 3)
--   Just 990.3...
--   </pre>
--   
--   t-Digest is more precise in tails, especially median is imprecise:
--   
--   <pre>
--   &gt;&gt;&gt; median (forceCompress $ tdigest [1..1000] :: TDigest 10)
--   Just 500.5
--   </pre>
--   
--   <h3>Semigroup</h3>
--   
--   This operation isn't strictly associative, but statistical variables
--   shouldn't be affected.
--   
--   <pre>
--   &gt;&gt;&gt; let td xs = tdigest xs :: TDigest 10
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; median (td [1..500] &lt;&gt; (td [501..1000] &lt;&gt; td [1001..1500]))
--   Just 750.5
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; median ((td [1..500] &lt;&gt; td [501..1000]) &lt;&gt; td [1001..1500])
--   Just 750.5
--   </pre>
--   
--   The linear is worst-case scenario:
--   
--   <pre>
--   &gt;&gt;&gt; let td' xs = tdigest (fairshuffle xs) :: TDigest 10
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; median (td' [1..500] &lt;&gt; (td' [501..1000] &lt;&gt; td' [1001..1500]))
--   Just 750.5
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; median ((td' [1..500] &lt;&gt; td' [501..1000]) &lt;&gt; td' [1001..1500])
--   Just 750.5
--   </pre>
module Data.TDigest.Vector

-- | <a>TDigest</a> is a vector of centroids plus not yet merged elements.
--   
--   The size of structure is dictated by <tt>compression</tt>, *𝛿*. And is
--   *O(𝛿)*.
data TDigest (compression :: Nat)

-- | Strict <a>foldl'</a> over <a>Foldable</a> structure.
tdigest :: (Foldable f, KnownNat comp) => f Double -> TDigest comp

-- | Make a <a>TDigest</a> of a single data point.
singleton :: Double -> TDigest comp

-- | Insert single value into <a>TDigest</a>.
insert :: KnownNat comp => Double -> TDigest comp -> TDigest comp

-- | Insert single value, don't compress <a>TDigest</a> even if needed.
--   
--   This may violate the insertion buffer size invariant.
--   
--   For sensibly bounded input, it makes sense to let <a>TDigest</a> grow
--   (it might grow linearly in size), and after that compress it once.
insert' :: KnownNat comp => Double -> TDigest comp -> TDigest comp
compress :: forall comp. KnownNat comp => TDigest comp -> TDigest comp
forceCompress :: forall comp. KnownNat comp => TDigest comp -> TDigest comp

-- | Center of left-most centroid. Note: may be different than min element
--   inserted.
--   
--   <pre>
--   &gt;&gt;&gt; minimumValue (tdigest [1..100] :: TDigest 3)
--   1.0
--   </pre>
minimumValue :: KnownNat comp => TDigest comp -> Mean

-- | Center of right-most centroid. Note: may be different than max element
--   inserted.
--   
--   <pre>
--   &gt;&gt;&gt; maximumValue (tdigest [1..100] :: TDigest 3)
--   100.0
--   </pre>
maximumValue :: KnownNat comp => TDigest comp -> Mean

-- | Median, i.e. <tt><a>quantile</a> 0.5</tt>.
median :: KnownNat comp => TDigest comp -> Maybe Double

-- | Calculate quantile of a specific value.
quantile :: KnownNat comp => Double -> TDigest comp -> Maybe Double

-- | Mean.
--   
--   <pre>
--   &gt;&gt;&gt; mean (tdigest [1..100] :: TDigest 10)
--   Just 50.5
--   </pre>
--   
--   <i>Note:</i> if you only need the mean, calculate it directly.
mean :: KnownNat comp => TDigest comp -> Maybe Double

-- | Variance.
variance :: KnownNat comp => TDigest comp -> Maybe Double

-- | Standard deviation, square root of variance.
stddev :: KnownNat comp => TDigest comp -> Maybe Double

-- | Cumulative distribution function.
--   
--   <i>Note:</i> if this is the only thing you need, it's more efficient
--   to count this directly.
cdf :: KnownNat comp => Double -> TDigest comp -> Double

-- | An alias for <a>quantile</a>
icdf :: KnownNat comp => Double -> TDigest comp -> Maybe Double

-- | Size of structure
size :: TDigest comp -> Int

-- | <pre>
--   <a>isRight</a> . <a>validate</a>
--   </pre>
valid :: TDigest comp -> Bool

-- | Check various invariants in the <a>TDigest</a> structure.
validate :: TDigest comp -> Either String (TDigest comp)
