uniqueness-periods-vector-stats 0.1.2.0 → 0.2.0.0
raw patch · 3 files changed
+77/−21 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Numeric.Stats: mean :: RealFrac a => [a] -> a
- Numeric.Stats: mean2 :: RealFrac a => [a] -> a -> a -> a -> a
+ Numeric.Stats: mean2D :: [Double] -> Double# -> Int# -> Double
+ Numeric.Stats: meanD :: [Double] -> Double
+ Numeric.Stats: meanWithDispD2 :: [Double] -> (Double, Double)
+ Numeric.Stats: meanWithDispF2 :: [Float] -> (Float, Float)
+ Numeric.Stats: meanWithDispersionD :: [Double] -> Double# -> Double# -> Int# -> (Double, Double)
+ Numeric.Stats: meanWithDispersionF :: [Float] -> Float# -> Float# -> Int# -> (Float, Float)
- Numeric.Stats: mean2F :: [Float] -> Float# -> Float# -> Float# -> Float
+ Numeric.Stats: mean2F :: [Float] -> Float# -> Int# -> Float
Files
- ChangeLog.md +7/−2
- Numeric/Stats.hs +69/−18
- uniqueness-periods-vector-stats.cabal +1/−1
ChangeLog.md view
@@ -7,8 +7,13 @@ ## 0.1.1.0 -- 2020-09-19 * First version revised A. Fixed issues with not importing from GHC.Prim fabsFloat# for GHC lower than 8.2* versions. Removed functions that used Neumaier summation because-they do not have the intended behaviour. +they do not have the intended behaviour. ## 0.1.2.0 -- 2020-09-19 -* First version revised B. Removed the functions that compute mean with dispersion using unlifted types, because of numeric inaccuracy. +* First version revised B. Removed the functions that compute mean with dispersion using unlifted types, because of numeric inaccuracy.++## 0.2.0.0 -- 2020-12-05++* Second version. Some documentation improvements because of the similar code snippets found in the various+previous publications by the other authors. Added new functions and rewrite the existing ones.
Numeric/Stats.hs view
@@ -9,37 +9,88 @@ {-# LANGUAGE BangPatterns, MagicHash #-} -module Numeric.Stats where +module Numeric.Stats where import GHC.Exts import GHC.Prim --- | A tail-recursive realization for the statistic mean. -mean2 :: RealFrac a => [a] -> a -> a -> a -> a-mean2 (x:xs) !s1 !l1 _ = mean2 xs (s1 + x) (l1 + 1) ((s1 + x) / (l1 + 1))-mean2 _ _ _ m = m+-- | Uses GHC unlifted types from @ghc-prim@ package.+-- 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/+--+mean2F :: [Float] -> Float# -> Int# -> Float+mean2F ((F# !x):xs) !s1 !l1 = mean2F xs (plusFloat# s1 x) (l1 +# 1#)+mean2F _ !s1 !l1 =+ case l1 ==# 0# of+ 0# -> error "Not defined for the third zero argument. "+ _ -> F# m+ where !m = divideFloat# s1 (int2Float# l1) --- | Similar to 'mean2', but uses GHC unlifted types from @ghc-prim@ package. -mean2F :: [Float] -> Float# -> Float# -> Float# -> Float-mean2F ((F# !x):xs) !s1 !l1 _ = mean2F xs (plusFloat# s1 x) (plusFloat# l1 1.0#) (divideFloat# (plusFloat# s1 x) (plusFloat# l1 1.0#))-mean2F _ _ _ m = F# m+-- | Uses GHC unlifted types from @ghc-prim@ package.+-- 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/+--+mean2D :: [Double] -> Double# -> Int# -> Double+mean2D ((D# !x):xs) !s1 !l1 = mean2D xs (s1 +## x) (l1 +# 1#)+mean2D _ !s1 !l1 =+ case l1 ==# 0# of+ 0# -> error "Not defined for the third zero argument. "+ _ -> D# m+ where !m = s1 /## int2Double# l1 --- | One-pass and tail-recursive realization for the pair of the mean and dispersion. Is vulnerable to the floating-point cancellation errors. +-- | 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 '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) where m0 !s3 !l2 !x = (s3 + x) / (l2 + 1) meanWithDispersion _ _ _ _ !m !d = (m,d) --- | A tail-recursive realization for the statistic mean. A variant of the 'mean2' function. -mean :: RealFrac a => [a] -> a-mean xs = mean2 xs 0.0 0.0 0.0-{-# INLINE mean #-}+-- | 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)))+ where !m = divideFloat# s1 (int2Float# l1) --- | Uses 'mean2F' inside. +-- | 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)))+ where !m = s1 /## int2Double# l1++-- | Uses 'mean2F' inside. meanF :: [Float] -> Float-meanF xs = mean2F xs 0.0# 0.0# 0.0#+meanF xs = mean2F xs 0.0# 0# {-# INLINE meanF #-} +meanD :: [Double] -> Double+meanD xs = mean2D xs 0.0## 0#++-- | Among the 'meanWithDisp', 'meanWithDispF2' and 'meanWithDispD2' better to use the last one. meanWithDisp :: (RealFrac a, Floating a) => [a] -> (a,a)-meanWithDisp xs = meanWithDispersion xs 0.0 0.0 0.0 0.0 0.0-{-# INLINE meanWithDisp #-}+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 #-}+{-# INLINE[2] meanWithDisp #-}++-- | 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#+{-# INLINE meanWithDispF2 #-}++-- | 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#+{-# 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.1.2.0+version: 0.2.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