packages feed

uniqueness-periods-vector-stats 0.2.2.0 → 0.3.0.0

raw patch · 3 files changed

+77/−25 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Numeric.Stats: meanWithDispersion :: (RealFrac a, Floating a) => [a] -> a -> a -> a -> a -> a -> (a, a)
- Numeric.Stats: meanWithDispersionD :: [Double] -> Double# -> Double# -> Int# -> (Double, Double)
- Numeric.Stats: meanWithDispersionF :: [Float] -> Float# -> Float# -> Int# -> (Float, Float)
+ Numeric.Stats: meanWithDispD2P :: [Double] -> (Double, Double)
+ Numeric.Stats: meanWithDispF2P :: [Float] -> (Float, Float)
+ Numeric.Stats: meanWithDispP :: (RealFrac a, Floating a) => [a] -> (a, a)
+ Numeric.Stats: meanWithDispersionDP :: [Double] -> Double# -> Double# -> Int# -> (Double, Double)
+ Numeric.Stats: meanWithDispersionFP :: [Float] -> Float# -> Float# -> Int# -> (Float, Float)
+ Numeric.Stats: meanWithDispersionP :: (RealFrac a, Floating a) => [a] -> a -> a -> a -> a -> a -> (a, a)

Files

ChangeLog.md view
@@ -26,3 +26,6 @@  * Second version revised B. Updated the dependency boundaries to support the latest GHC and Cabal versions. +## 0.3.0.0 -- 2022-05-31++* Third version. Fixed issues with population and sample dispersion evaluation, added for this new functions.
Numeric/Stats.hs view
@@ -1,6 +1,6 @@ -- | -- Module      :  Numeric.Stats--- Copyright   :  (c) OleksandrZhabenko 2020+-- Copyright   :  (c) OleksandrZhabenko 2020-2022 -- License     :  MIT -- Stability   :  Experimental -- Maintainer  :  olexandr543@yahoo.com@@ -47,21 +47,21 @@ -- When using the needed, please, refer better to their variants. -- -- Among the 'meanWithDispersion', 'meanWithDisprsionF' and 'meanWithDispersionD' better to use the last one.-meanWithDispersion :: (RealFrac a, Floating a) => [a] -> a -> a -> a -> a -> a -> (a,a)-meanWithDispersion (!x:xs) !s1 !s2 !l1 m1 d = meanWithDispersion xs (s1 + x) (s2 + x*x) (l1 + 1) (m0 s1 l1 x) (m0 s2 l1 (x*x) - (m0 s1 l1 x)**2)+meanWithDispersionP :: (RealFrac a, Floating a) => [a] -> a -> a -> a -> a -> a -> (a,a)+meanWithDispersionP (!x:xs) !s1 !s2 !l1 m1 d = meanWithDispersionP xs (s1 + x) (s2 + x*x) (l1 + 1) (m0 s1 l1 x) (m0 s2 l1 (x*x) - (m0 s1 l1 x)**2)   where m0 !s3 !l2 !x = (s3 + x) / (l2 + 1)-meanWithDispersion _ _ _ _ !m !d = (m,d)+meanWithDispersionP _ _ _ _ !m !d = (m,d)  -- | Among the 'meanWithDispersion', 'meanWithDisprsionF' and 'meanWithDispersionD' better to use the last one.-meanWithDispersionF :: [Float] -> Float# -> Float# -> Int# -> (Float,Float)-meanWithDispersionF ((F# !x):xs) !s1 !s2 !l1 = meanWithDispersionF xs (plusFloat# s1 x) (plusFloat# s2 (timesFloat# x x)) (l1 +# 1#)-meanWithDispersionF [] !s1 !s2 !l1 = (F# m, F# (minusFloat# (divideFloat# s2 (int2Float# l1)) (timesFloat# m m)))+meanWithDispersionFP :: [Float] -> Float# -> Float# -> Int# -> (Float,Float)+meanWithDispersionFP ((F# !x):xs) !s1 !s2 !l1 = meanWithDispersionFP xs (plusFloat# s1 x) (plusFloat# s2 (timesFloat# x x)) (l1 +# 1#)+meanWithDispersionFP [] !s1 !s2 !l1 = (F# m, F# (minusFloat# (divideFloat# s2 (int2Float# l1)) (timesFloat# m m)))   where !m = divideFloat# s1 (int2Float# l1)  -- | Among the 'meanWithDispersion', 'meanWithDisprsionF' and 'meanWithDispersionD' better to use the last one.-meanWithDispersionD :: [Double] -> Double# -> Double# -> Int# -> (Double,Double)-meanWithDispersionD ((D# !x):xs) !s1 !s2 !l1 = meanWithDispersionD xs (s1 +## x) (s2 +## (x *## x)) (l1 +# 1#)-meanWithDispersionD [] !s1 !s2 !l1 = (D# m, D# ((s2 /## int2Double# l1) -## (m *## m)))+meanWithDispersionDP :: [Double] -> Double# -> Double# -> Int# -> (Double,Double)+meanWithDispersionDP ((D# !x):xs) !s1 !s2 !l1 = meanWithDispersionDP xs (s1 +## x) (s2 +## (x *## x)) (l1 +# 1#)+meanWithDispersionDP [] !s1 !s2 !l1 = (D# m, D# ((s2 /## int2Double# l1) -## (m *## m)))   where !m = s1 /## int2Double# l1  -- | Uses 'mean2F' inside.@@ -72,25 +72,74 @@ meanD :: [Double] -> Double meanD xs = mean2D xs 0.0## 0# --- | Among the 'meanWithDisp', 'meanWithDispF2' and 'meanWithDispD2' better to use the last one.+-- | Among the 'meanWithDispP', 'meanWithDispF2P' and 'meanWithDispD2P' better to use the last one.+meanWithDispP :: (RealFrac a, Floating a) => [a] -> (a,a)+meanWithDispP xs@(_:_) = meanWithDispersionP xs 0.0 0.0 0.0 0.0 0.0+meanWithDispP _ = error "Not defined for the empty list. "+{-# RULES "realfrac/float" meanWithDispP = meanWithDispF2P #-}+{-# RULES "realfrac/double" meanWithDispP = meanWithDispD2P #-}+{-# INLINE[2] meanWithDispP #-}++-- | Among the 'meanWithDispP', 'meanWithDispF2P' and 'meanWithDispD2P' better to use the last one.+meanWithDispF2P :: [Float] -> (Float,Float)+meanWithDispF2P xs@(_:_) = meanWithDispersionFP xs 0.0# 0.0# 0#+meanWithDispF2P _ = error "Not defined for the empty list. "+{-# INLINE meanWithDispF2P #-}++-- | Among the 'meanWithDispP', 'meanWithDispF2P' and 'meanWithDispD2P' better to use the last one.+meanWithDispD2P :: [Double] -> (Double,Double)+meanWithDispD2P xs@(x:_) = meanWithDispersionDP xs 0.0## 0.0## 0#+meanWithDispD2P _ = error "Not defined for the empty list. "+{-# INLINE meanWithDispD2P #-}++--------------------------------------------------++-- Inspired by: https://www.khanacademy.org/math/ap-statistics/summarizing-quantitative-data-ap/more-standard-deviation/v/simulation-showing-bias-in-sample-variance+-- and:+-- https://www.khanacademy.org/math/ap-statistics/summarizing-quantitative-data-ap/more-standard-deviation/v/simulation-providing-evidence-that-n-1-gives-us-unbiased-estimate++++-- | One-pass and tail-recursive realization for the pair of the mean and dispersion. Is vulnerable to the floating-point cancellation errors.+-- Similar code is here: Don Stewart.  https://donsbot.wordpress.com/2008/05/06/write-haskell-as-fast-as-c-exploiting-strictness-laziness-and-recursion/+-- And here: http://fixpt.de/blog/2017-12-04-strictness-analysis-part-1.html+-- And here: Michael Snoyman. https://www.fpcomplete.com/blog/2017/09/all-about-strictness/+-- When using the needed, please, refer better to their variants.+-- Among the 'meanWithDisp', 'meanWithDispF2' and 'meanWithDispD2' better to use the last one. meanWithDisp :: (RealFrac a, Floating a) => [a] -> (a,a)-meanWithDisp xs- | null xs = error "Not defined for the empty list. "- | otherwise = meanWithDispersion xs 0.0 0.0 0.0 0.0 0.0-{-# RULES "realfroc/float" meanWithDisp = meanWithDispF2 #-}-{-# RULES "realfroc/double" meanWithDisp = meanWithDispD2 #-}+meanWithDisp xs@(_:_:_) = mdl xs 0.0 0.0 0.0+  where mdl (!x:ys) !s1 !s2 !l1 = mdl ys (s1 + x) (s2 + x*x) (l1 + 1)+        mdl _ !s1 !s2 !l = (mm, (s2 - mm**2 * l) / (l - 1))+          where !mm = s1 / l+meanWithDisp _ = error "Not defined for the list with less than two elements. "+{-# RULES "realfrac/float" meanWithDisp = meanWithDispF2 #-}+{-# RULES "realfrac/double" meanWithDisp = meanWithDispD2 #-} {-# INLINE[2] meanWithDisp #-} --- | Among the 'meanWithDisp', 'meanWithDispF2' and 'meanWithDispD2' better to use the last one.+-- | One-pass and tail-recursive realization for the pair of the mean and dispersion. Is vulnerable to the floating-point cancellation errors.+-- Similar code is here: Don Stewart.  https://donsbot.wordpress.com/2008/05/06/write-haskell-as-fast-as-c-exploiting-strictness-laziness-and-recursion/+-- And here: http://fixpt.de/blog/2017-12-04-strictness-analysis-part-1.html+-- And here: Michael Snoyman. https://www.fpcomplete.com/blog/2017/09/all-about-strictness/+-- When using the needed, please, refer better to their variants.+-- Among the 'meanWithDisp', 'meanWithDispF2' and 'meanWithDispD2' better to use the last one. meanWithDispF2 :: [Float] -> (Float,Float)-meanWithDispF2 xs- | null xs = error "Not defined for the empty list. "- | otherwise = meanWithDispersionF xs 0.0# 0.0# 0#+meanWithDispF2 xs@(_:_:_) = mdlF xs 0.0# 0.0# 0#+  where mdlF (F# !x:ys) !s1 !s2 !l1 = mdlF ys (plusFloat# s1 x) (plusFloat# s2 (timesFloat# x x)) (l1 +# 1#)+        mdlF [] !s1 !s2 !l1 = (F# m, F# (divideFloat# (minusFloat# s2 (timesFloat# (timesFloat# m m) (int2Float# l1))) (int2Float# (l1 -# 1#))))+          where !m = divideFloat# s1 (int2Float# l1)+meanWithDispF2 _ = error "Not defined for the list with less than two elements. " {-# INLINE meanWithDispF2 #-} --- | Among the 'meanWithDisp', 'meanWithDispF2' and 'meanWithDispD2' better to use the last one.+-- | One-pass and tail-recursive realization for the pair of the mean and dispersion. Is vulnerable to the floating-point cancellation errors.+-- Similar code is here: Don Stewart.  https://donsbot.wordpress.com/2008/05/06/write-haskell-as-fast-as-c-exploiting-strictness-laziness-and-recursion/+-- And here: http://fixpt.de/blog/2017-12-04-strictness-analysis-part-1.html+-- And here: Michael Snoyman. https://www.fpcomplete.com/blog/2017/09/all-about-strictness/+-- When using the needed, please, refer better to their variants.+-- Among the 'meanWithDisp', 'meanWithDispF2' and 'meanWithDispD2' better to use the last one. meanWithDispD2 :: [Double] -> (Double,Double)-meanWithDispD2 xs- | null xs = error "Not defined for the empty list. "- | otherwise = meanWithDispersionD xs 0.0## 0.0## 0#+meanWithDispD2 xs@(_:_:_) = mdlD xs 0.0## 0.0## 0#+  where mdlD ((D# !x):xs) !s1 !s2 !l1 = mdlD xs (s1 +## x) (s2 +## (x *## x)) (l1 +# 1#)+        mdlD [] !s1 !s2 !l1 = (D# m, D# ((s2 -## m *## m *## int2Double# l1) /## (int2Double# (l1 -# 1#))))+          where !m = s1 /## int2Double# l1+meanWithDispD2 _ = error "Not defined for the list with less than two elements. " {-# INLINE meanWithDispD2 #-}
uniqueness-periods-vector-stats.cabal view
@@ -2,7 +2,7 @@ -- For further documentation, see http://haskell.org/cabal/users-guide/  name:                uniqueness-periods-vector-stats-version:             0.2.2.0+version:             0.3.0.0 synopsis:            A very basic descriptive statistics. description:         A very basic descriptive statistics. Functions use a tail recursion approach to compute the values and are strict by an accumulator. homepage:            https://hackage.haskell.org/package/uniqueness-periods-vector-stats