statistics 0.16.2.0 → 0.16.2.1
raw patch · 7 files changed
+63/−28 lines, 7 files
Files
- Statistics/Test/StudentT.hs +4/−4
- changelog.md +7/−0
- statistics.cabal +10/−9
- tests/Tests/Correlation.hs +9/−5
- tests/Tests/Distribution.hs +2/−2
- tests/Tests/Matrix.hs +14/−4
- tests/Tests/Matrix/Types.hs +17/−4
Statistics/Test/StudentT.hs view
@@ -134,16 +134,16 @@ -- Calculate T-statistics for paired sample-tStatisticsPaired :: (G.Vector v (Double, Double), G.Vector v Double)+tStatisticsPaired :: (G.Vector v (Double, Double)) => v (Double, Double) -> (Double, Double) {-# INLINE tStatisticsPaired #-} tStatisticsPaired sample = (t, ndf) where -- t-statistics- t = let d = G.map (uncurry (-)) sample- sumd = G.sum d- in sumd / sqrt ((n * G.sum (G.map square d) - square sumd) / ndf)+ t = let d = U.map (uncurry (-)) $ G.convert sample+ sumd = U.sum d+ in sumd / sqrt ((n * U.sum (U.map square d) - square sumd) / ndf) -- degree of freedom ndf = n - 1 n = fromIntegral $ G.length sample
changelog.md view
@@ -1,3 +1,10 @@+## Changes in 0.16.2.1++ * Unnecessary constraint dropped from `tStatisticsPaired`.++ * Compatibility with QuickCheck-2.14. Test suite doesn't fail every time.++ ## Changes in 0.16.2.0 * Improved precision for `complCumulative` for hypergeometric and binomial
statistics.cabal view
@@ -1,5 +1,5 @@ name: statistics-version: 0.16.2.0+version: 0.16.2.1 synopsis: A library of statistical types, data, and functions description: This library provides a number of common functions and types useful@@ -46,14 +46,15 @@ tests/utils/fftw.c tested-with:- GHC ==8.0.2- || ==8.2.2- || ==8.4.4- || ==8.6.5- || ==8.8.4- || ==8.10.7- || ==9.0.1- || ==9.2.1+ GHC ==8.4.4+ GHC ==8.6.5+ GHC ==8.8.4+ GHC ==8.10.7+ GHC ==9.0.2+ GHC ==9.2.8+ GHC ==9.4.6+ GHC ==9.6.2+ library default-language: Haskell2010
tests/Tests/Correlation.hs view
@@ -5,11 +5,11 @@ import Control.Arrow (Arrow(..)) import qualified Data.Vector as V+import Data.Maybe import Statistics.Correlation import Statistics.Correlation.Kendall-import Test.QuickCheck ((==>),Property,counterexample) import Test.Tasty-import Test.Tasty.QuickCheck+import Test.Tasty.QuickCheck hiding (sample) import Test.Tasty.HUnit import Tests.ApproxEq@@ -34,15 +34,19 @@ testPearson :: [(Double,Double)] -> Property testPearson sample- = (length sample > 1) ==> (exact ~= fast)+ = (length sample > 1 && isJust exact) ==> (case exact of+ Just e -> e ~= fast+ Nothing -> property False+ ) where (~=) = eql 1e-12 exact = exactPearson $ map (realToFrac *** realToFrac) sample fast = pearson $ V.fromList sample -exactPearson :: [(Rational,Rational)] -> Double+exactPearson :: [(Rational,Rational)] -> Maybe Double exactPearson sample- = realToFrac cov / sqrt (realToFrac (varX * varY))+ | varX == 0 || varY == 0 = Nothing+ | otherwise = Just $ realToFrac cov / sqrt (realToFrac (varX * varY)) where (xs,ys) = unzip sample n = fromIntegral $ length sample
tests/Tests/Distribution.hs view
@@ -348,7 +348,7 @@ quantileIsInvCDF_enabled _ = False -- We compute CDF and complement using same method so precision -- should be very good here.- prec_complementCDF _ = 2 * m_epsilon+ prec_complementCDF _ = 64 * m_epsilon instance Param ChiSquared where prec_quantile_CDF _ = (32,32)@@ -367,7 +367,7 @@ -- introduced by exp . logGamma. This could only be fixed in -- math-function by implementing gamma prec_quantile_CDF _ = (24,24)- prec_logDensity _ = 64+ prec_logDensity _ = 512 instance Param GeometricDistribution instance Param GeometricDistribution0 instance Param HypergeometricDistribution
tests/Tests/Matrix.hs view
@@ -5,7 +5,6 @@ import Test.Tasty (TestTree, testGroup) import Test.Tasty.QuickCheck (testProperty) import Test.QuickCheck-import Tests.ApproxEq (ApproxEq(..)) import Tests.Matrix.Types import qualified Data.Vector.Unboxed as U @@ -27,9 +26,20 @@ t_transpose m = U.concat (map (column n) [0..rows m-1]) === toVector m where n = transpose m -t_qr :: Matrix -> Property-t_qr a = hasNaN p .||. eql 1e-10 a p- where p = uncurry multiply (qr a)+t_qr :: Property+t_qr = property $ do+ a <- do (r,c) <- arbitrary+ fromMat <$> arbMatWith r c (fromIntegral <$> choose (-10, 10::Int))+ let (q,r) = qr a+ a' = multiply q r+ pure $ counterexample ("A = \n"++show a)+ $ counterexample ("A' = \n"++show a')+ $ counterexample ("Q = \n"++show q)+ $ counterexample ("R = \n"++show r)+ $ dimension a == dimension a'+ && ( hasNaN a'+ || and (zipWith (\x y -> abs (x - y) < 1e-12) (toList a) (toList a'))+ ) tests :: TestTree tests = testGroup "Matrix"
tests/Tests/Matrix/Types.hs view
@@ -6,6 +6,8 @@ Mat(..) , fromMat , toMat+ , arbMat+ , arbMatWith ) where import Control.Monad (join)@@ -32,10 +34,21 @@ arbitrary = small $ join (arbMat <$> arbitrary <*> arbitrary) shrink (Mat r c xs) = Mat r c <$> shrinkFixedList (shrinkFixedList shrink) xs -arbMat :: (Arbitrary a) => Positive (Small Int) -> Positive (Small Int)- -> Gen (Mat a)-arbMat (Positive (Small r)) (Positive (Small c)) =- Mat r c <$> vectorOf r (vector c)+arbMat+ :: (Arbitrary a)+ => Positive (Small Int)+ -> Positive (Small Int)+ -> Gen (Mat a)+arbMat r c = arbMatWith r c arbitrary++arbMatWith+ :: (Arbitrary a)+ => Positive (Small Int)+ -> Positive (Small Int)+ -> Gen a+ -> Gen (Mat a)+arbMatWith (Positive (Small r)) (Positive (Small c)) genA =+ Mat r c <$> vectorOf r (vectorOf c genA) instance Arbitrary Matrix where arbitrary = fromMat <$> arbitrary