statistics 0.15.1.1 → 0.15.2.0
raw patch · 18 files changed
+205/−140 lines, 18 filesdep +tastydep +tasty-expected-failuredep +tasty-hunitdep −HUnitdep −test-frameworkdep −test-framework-hunitPVP ok
version bump matches the API change (PVP)
Dependencies added: tasty, tasty-expected-failure, tasty-hunit, tasty-quickcheck
Dependencies removed: HUnit, test-framework, test-framework-hunit, test-framework-quickcheck2
API changes (from Hackage documentation)
Files
- Statistics/ConfidenceInt.hs +1/−1
- Statistics/Distribution/Exponential.hs +2/−2
- Statistics/Distribution/Geometric.hs +13/−3
- Statistics/Sample/Histogram.hs +1/−1
- changelog.md +13/−0
- statistics.cabal +6/−5
- tests/Tests/Correlation.hs +4/−5
- tests/Tests/Distribution.hs +100/−56
- tests/Tests/Function.hs +3/−3
- tests/Tests/Helpers.hs +6/−6
- tests/Tests/KDE.hs +7/−7
- tests/Tests/Matrix.hs +5/−5
- tests/Tests/NonParametric.hs +12/−13
- tests/Tests/Parametric.hs +5/−5
- tests/Tests/Quantile.hs +4/−6
- tests/Tests/Serialization.hs +5/−5
- tests/Tests/Transform.hs +5/−5
- tests/tests.hs +13/−12
Statistics/ConfidenceInt.hs view
@@ -30,7 +30,7 @@ poissonCI :: CL Double -> Int -> Estimate ConfInt Double poissonCI cl@(significanceLevel -> p) n | n < 0 = error "Statistics.ConfidenceInt.poissonCI: negative number of trials"- | n == 0 = estimateFromInterval m (m1,m2) cl+ | n == 0 = estimateFromInterval m (0 ,m2) cl | otherwise = estimateFromInterval m (m1,m2) cl where m = fromIntegral n
Statistics/Distribution/Exponential.hs view
@@ -30,7 +30,7 @@ import Data.Binary (Binary, put, get) import Data.Data (Data, Typeable) import GHC.Generics (Generic)-import Numeric.SpecFunctions (log1p)+import Numeric.SpecFunctions (log1p,expm1) import Numeric.MathFunctions.Constants (m_neg_inf) import qualified System.Random.MWC.Distributions as MWC import qualified Data.Vector.Generic as G@@ -101,7 +101,7 @@ cumulative :: ExponentialDistribution -> Double -> Double cumulative (ED l) x | x <= 0 = 0- | otherwise = 1 - exp (-l * x)+ | otherwise = - expm1 (-l * x) complCumulative :: ExponentialDistribution -> Double -> Double complCumulative (ED l) x | x <= 0 = 1
Statistics/Distribution/Geometric.hs view
@@ -40,6 +40,7 @@ import Data.Data (Data, Typeable) import GHC.Generics (Generic) import Numeric.MathFunctions.Constants (m_pos_inf, m_neg_inf)+import Numeric.SpecFunctions (log1p,expm1) import qualified System.Random.MWC.Distributions as MWC import qualified Statistics.Distribution as D@@ -74,7 +75,8 @@ instance D.Distribution GeometricDistribution where- cumulative = cumulative+ cumulative = cumulative+ complCumulative = complCumulative instance D.DiscreteDistr GeometricDistribution where probability (GD s) n@@ -118,9 +120,16 @@ | x < 1 = 0 | isInfinite x = 1 | isNaN x = error "Statistics.Distribution.Geometric.cumulative: NaN input"- | otherwise = 1 - (1-s) ^ (floor x :: Int)+ | otherwise = negate $ expm1 $ fromIntegral (floor x :: Int) * log1p (-s) +complCumulative :: GeometricDistribution -> Double -> Double+complCumulative (GD s) x+ | x < 1 = 1+ | isInfinite x = 0+ | isNaN x = error "Statistics.Distribution.Geometric.cumulative: NaN input"+ | otherwise = exp $ fromIntegral (floor x :: Int) * log1p (-s) + -- | Create geometric distribution. geometric :: Double -- ^ Success rate -> GeometricDistribution@@ -164,7 +173,8 @@ instance D.Distribution GeometricDistribution0 where- cumulative (GD0 s) x = cumulative (GD s) (x + 1)+ cumulative (GD0 s) x = cumulative (GD s) (x + 1)+ complCumulative (GD0 s) x = complCumulative (GD s) (x + 1) instance D.DiscreteDistr GeometricDistribution0 where probability (GD0 s) n = D.probability (GD s) (n + 1)
Statistics/Sample/Histogram.hs view
@@ -73,7 +73,7 @@ b = truncate $ (x - lo) / d write' bins b . (+1) =<< GM.read bins b go (i+1)- write' bins b !e = GM.write bins b e+ write' bins' b !e = GM.write bins' b e len = G.length xs d = ((hi - lo) * (1 + realToFrac m_epsilon)) / fromIntegral numBins {-# INLINE histogram_ #-}
changelog.md view
@@ -1,3 +1,16 @@+## Changes in 0.15.2.0++ * Test suite is finally fixed (#42, #123). It took very-very-very long+ time but finally happened.++ * Avoid loss of precision when computing CDF for exponential districution.++ * Avoid loss of precision when computing CDF for geometric districution. Add+ complement of CDF.++ * Correctly handle case of n=0 in poissonCI++ ## Changes in 0.15.1.1 * Fix build for GHC8.0 & 7.10
statistics.cabal view
@@ -1,5 +1,5 @@ name: statistics-version: 0.15.1.1+version: 0.15.2.0 synopsis: A library of statistical types, data, and functions description: This library provides a number of common functions and types useful@@ -54,6 +54,7 @@ || ==8.2.2 || ==8.4.4 || ==8.6.5+ || ==8.8.1 , GHCJS ==8.4 @@ -158,7 +159,6 @@ build-depends: base , statistics , dense-linear-algebra- , HUnit , QuickCheck >= 2.7.5 , binary , erf@@ -167,9 +167,10 @@ , math-functions , mwc-random , primitive- , test-framework- , test-framework-hunit- , test-framework-quickcheck2+ , tasty+ , tasty-hunit+ , tasty-quickcheck+ , tasty-expected-failure , vector , vector-algorithms
tests/Tests/Correlation.hs view
@@ -8,10 +8,9 @@ import Statistics.Correlation import Statistics.Correlation.Kendall import Test.QuickCheck ((==>),Property,counterexample)-import Test.Framework-import Test.Framework.Providers.QuickCheck2-import Test.Framework.Providers.HUnit-import Test.HUnit (Assertion, (@=?))+import Test.Tasty+import Test.Tasty.QuickCheck+import Test.Tasty.HUnit import Tests.ApproxEq @@ -19,7 +18,7 @@ -- Tests list ---------------------------------------------------------------- -tests :: Test+tests :: TestTree tests = testGroup "Correlation" [ testProperty "Pearson correlation" testPearson , testProperty "Spearman correlation is scale invariant" testSpearmanScale
tests/Tests/Distribution.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE FlexibleInstances, OverlappingInstances, ScopedTypeVariables,+{-# LANGUAGE FlexibleInstances, ScopedTypeVariables, ViewPatterns #-} module Tests.Distribution (tests) where @@ -6,8 +6,7 @@ import qualified Control.Exception as E import Data.List (find) import Data.Typeable (Typeable)-import qualified Numeric.IEEE as IEEE-import Numeric.MathFunctions.Constants (m_tiny,m_epsilon)+import Numeric.MathFunctions.Constants (m_tiny,m_huge,m_epsilon) import Numeric.MathFunctions.Comparison import Statistics.Distribution import Statistics.Distribution.Beta (BetaDistribution)@@ -23,11 +22,12 @@ import Statistics.Distribution.Normal (NormalDistribution) import Statistics.Distribution.Poisson (PoissonDistribution) import Statistics.Distribution.StudentT-import Statistics.Distribution.Transform (LinearTransform, linTransDistr)+import Statistics.Distribution.Transform (LinearTransform) import Statistics.Distribution.Uniform (UniformDistribution)-import Statistics.Distribution.DiscreteUniform (DiscreteUniform, discreteUniformAB)-import Test.Framework (Test, testGroup)-import Test.Framework.Providers.QuickCheck2 (testProperty)+import Statistics.Distribution.DiscreteUniform (DiscreteUniform)+import Test.Tasty (TestTree, testGroup)+import Test.Tasty.QuickCheck (testProperty)+import Test.Tasty.ExpectedFailure (ignoreTest) import Test.QuickCheck as QC import Test.QuickCheck.Monadic as QC import Text.Printf (printf)@@ -38,7 +38,7 @@ import Tests.Orphanage () -- | Tests for all distributions-tests :: Test+tests :: TestTree tests = testGroup "Tests for all distributions" [ contDistrTests (T :: T BetaDistribution ) , contDistrTests (T :: T CauchyDistribution )@@ -67,18 +67,20 @@ ---------------------------------------------------------------- -- Tests for continuous distribution-contDistrTests :: (Param d, ContDistr d, QC.Arbitrary d, Typeable d, Show d) => T d -> Test+contDistrTests :: (Param d, ContDistr d, QC.Arbitrary d, Typeable d, Show d) => T d -> TestTree contDistrTests t = testGroup ("Tests for: " ++ typeName t) $ cdfTests t ++ [ testProperty "PDF sanity" $ pdfSanityCheck t- , testProperty "Quantile is CDF inverse" $ quantileIsInvCDF t+ ] +++ [ (if quantileIsInvCDF_enabled t then id else ignoreTest)+ $ testProperty "Quantile is CDF inverse" $ quantileIsInvCDF t , testProperty "quantile fails p<0||p>1" $ quantileShouldFail t , testProperty "log density check" $ logDensityCheck t , testProperty "complQuantile" $ complQuantileCheck t ] -- Tests for discrete distribution-discreteDistrTests :: (Param d, DiscreteDistr d, QC.Arbitrary d, Typeable d, Show d) => T d -> Test+discreteDistrTests :: (Param d, DiscreteDistr d, QC.Arbitrary d, Typeable d, Show d) => T d -> TestTree discreteDistrTests t = testGroup ("Tests for: " ++ typeName t) $ cdfTests t ++ [ testProperty "Prob. sanity" $ probSanityCheck t@@ -88,7 +90,7 @@ ] -- Tests for distributions which have CDF-cdfTests :: (Param d, Distribution d, QC.Arbitrary d, Show d) => T d -> [Test]+cdfTests :: (Param d, Distribution d, QC.Arbitrary d, Show d) => T d -> [TestTree] cdfTests t = [ testProperty "C.D.F. sanity" $ cdfSanityCheck t , testProperty "CDF limit at +inf" $ cdfLimitAtPosInfinity t@@ -122,29 +124,33 @@ = cumulative d (-1/0) == 0 -- CDF limit at +∞ is 1-cdfLimitAtPosInfinity :: (Param d, Distribution d) => T d -> d -> Property-cdfLimitAtPosInfinity _ d =- okForInfLimit d ==> counterexample ("Last elements: " ++ show (drop 990 probs))- $ Just 1.0 == (find (>=1) probs)+cdfLimitAtPosInfinity :: (Param d, Distribution d) => T d -> d -> Bool+cdfLimitAtPosInfinity _ d+ = Just 1.0 == find (>=1) probs where- probs = take 1000 $ map (cumulative d) $ iterate (*1.4) 1000+ probs = map (cumulative d)+ $ takeWhile (< (m_huge/2))+ $ iterate (*1.4) 1 -- CDF limit at -∞ is 0-cdfLimitAtNegInfinity :: (Param d, Distribution d) => T d -> d -> Property-cdfLimitAtNegInfinity _ d =- okForInfLimit d ==> counterexample ("Last elements: " ++ show (drop 990 probs))- $ case find (< IEEE.epsilon) probs of- Nothing -> False- Just p -> p >= 0+cdfLimitAtNegInfinity :: (Param d, Distribution d) => T d -> d -> Bool+cdfLimitAtNegInfinity _ d+ = Just 0 == find (<=0) probs where- probs = take 1000 $ map (cumulative d) $ iterate (*1.4) (-1)+ probs = map (cumulative d)+ $ takeWhile (> (-m_huge/2))+ $ iterate (*1.4) (-1) + -- CDF's complement is implemented correctly-cdfComplementIsCorrect :: (Distribution d) => T d -> d -> Double -> Bool-cdfComplementIsCorrect _ d x = (eq 1e-14) 1 (cumulative d x + complCumulative d x)+cdfComplementIsCorrect :: (Distribution d, Param d) => T d -> d -> Double -> Bool+cdfComplementIsCorrect _ d x+ = 1 - (cumulative d x + complCumulative d x) <= tol+ where+ tol = prec_complementCDF d -- CDF for discrete distribution uses <= for comparison-cdfDiscreteIsCorrect :: (DiscreteDistr d) => T d -> d -> Property+cdfDiscreteIsCorrect :: (Param d, DiscreteDistr d) => T d -> d -> Property cdfDiscreteIsCorrect _ d = counterexample (unlines badN) $ null badN@@ -163,8 +169,9 @@ dp = probability d i relerr = ((p1 - p) - dp) / max p1 dp , not (p == 0 && p1 == 0 && dp == 0)- && relerr > 1e-14+ && relerr > tol ]+ tol = prec_discreteCDF d logDensityCheck :: (ContDistr d) => T d -> d -> Double -> Property logDensityCheck _ d x@@ -175,7 +182,11 @@ $ counterexample (printf "eps = %g" (abs (logP - log p) / max (abs (log p)) (abs logP))) $ or [ p == 0 && logP == (-1/0) , p <= m_tiny && logP < log m_tiny- , eq 1e-14 (log p) logP+ -- To avoid problems with roundtripping error in case+ -- when density is computed as exponent of logDensity we+ -- accept either inequality+ , (ulpDistance (log p) logP <= 32)+ || (ulpDistance p (exp logP) <= 32) ]) where p = density d x@@ -187,19 +198,25 @@ where p = density d x complQuantileCheck :: (ContDistr d) => T d -> d -> Double01 -> Property-complQuantileCheck _ d (Double01 p) =+complQuantileCheck _ d (Double01 p)+ = counterexample (printf "x0 = %g" x0)+ $ counterexample (printf "x1 = %g" x1) -- We avoid extreme tails of distributions -- -- FIXME: all parameters are arbitrary at the moment- p > 0.01 && p < 0.99 ==> (abs (x1 - x0) < 1e-6)+ $ and [ p > 0.01+ , p < 0.99+ , not $ isInfinite x0+ , not $ isInfinite x1+ ] ==> (abs (x1 - x0) < 1e-6) where x0 = quantile d (1 - p) x1 = complQuantile d p -- Quantile is inverse of CDF-quantileIsInvCDF :: (ContDistr d) => T d -> d -> Double01 -> Property+quantileIsInvCDF :: (Param d, ContDistr d) => T d -> d -> Double01 -> Property quantileIsInvCDF _ d (Double01 p) =- and [ p > 1e-250+ and [ p > m_tiny , p < 1 , x > m_tiny , dens > 0@@ -207,20 +224,23 @@ ( counterexample (printf "Quantile = %g" x ) $ counterexample (printf "Probability = %g" p ) $ counterexample (printf "Probability' = %g" p')- $ counterexample (printf "Expected err. = %g" err) $ counterexample (printf "Rel. error = %g" (relativeError p p')) $ counterexample (printf "Abs. error = %e" (abs $ p - p'))- $ eqRelErr err p p'+ $ counterexample (printf "Expected err. = %g" err)+ $ counterexample (printf "Distance = %i" (ulpDistance p p'))+ $ counterexample (printf "Err/est = %g" (fromIntegral (ulpDistance p p') / err))+ $ ulpDistance p p' <= round err ) where -- Algorithm for error estimation is taken from here -- -- http://sepulcarium.org/posts/2012-07-19-rounding_effect_on_inverse.html dens = density d x- err = 64 * m_epsilon * (1 + abs (x / p) * dens)+ err = eps + eps' * abs (x / p) * dens -- x = quantile d p p' = cumulative d x+ (eps,eps') = prec_quantile_CDF d -- Test that quantile fails if p<0 or p>1 quantileShouldFail :: (ContDistr d) => T d -> d -> Double -> Property@@ -261,36 +281,60 @@ $ counterexample (printf "eps = %g" (abs (logP - log p) / max (abs (log p)) (abs logP))) $ or [ p == 0 && logP == (-1/0) , p < 1e-308 && logP < 609- , eq 1e-14 (log p) logP+ -- To avoid problems with roundtripping error in case+ -- when density is computed as exponent of logDensity we+ -- accept either inequality+ , (ulpDistance (log p) logP <= 32)+ || (ulpDistance p (exp logP) <= 32) ] where p = probability d x logP = logProbability d x --- Parameters for distribution testing. Some distribution require--- relaxing parameters a bit+-- | Parameters for distribution testing. Some distribution require+-- relaxing parameters a bit class Param a where- -- Precision for quantileIsInvCDF- invQuantilePrec :: a -> Double- invQuantilePrec _ = 1e-14- -- Distribution is OK for testing limits- okForInfLimit :: a -> Bool- okForInfLimit _ = True---instance Param a+ -- | Whether quantileIsInvCDF is enabled+ quantileIsInvCDF_enabled :: T a -> Bool+ quantileIsInvCDF_enabled _ = True+ -- | Precision for 'quantileIsInvCDF' test+ prec_quantile_CDF :: a -> (Double,Double)+ prec_quantile_CDF _ = (16,16)+ -- |+ prec_discreteCDF :: a -> Double+ prec_discreteCDF _ = 32 * m_epsilon+ -- | Precision of CDF's complement+ prec_complementCDF :: a -> Double+ prec_complementCDF _ = 1e-14 instance Param StudentT where- invQuantilePrec _ = 1e-13- okForInfLimit d = studentTndf d > 0.75+ -- FIXME: disabled unless incompleteBeta troubles are sorted out+ quantileIsInvCDF_enabled _ = False+instance Param BetaDistribution where+ -- FIXME: See https://github.com/bos/statistics/issues/161 for details+ quantileIsInvCDF_enabled _ = False+instance Param FDistribution where+ -- FIXME: disabled unless incompleteBeta troubles are sorted out+ quantileIsInvCDF_enabled _ = False -instance Param (LinearTransform StudentT) where- invQuantilePrec _ = 1e-13- okForInfLimit d = (studentTndf . linTransDistr) d > 0.75+instance Param ChiSquared where+ prec_quantile_CDF _ = (32,32) -instance Param FDistribution where- invQuantilePrec _ = 1e-12+instance Param BinomialDistribution where+ prec_discreteCDF _ = 1e-13+instance Param CauchyDistribution+instance Param DiscreteUniform+instance Param ExponentialDistribution+instance Param GammaDistribution+instance Param GeometricDistribution+instance Param GeometricDistribution0+instance Param HypergeometricDistribution+instance Param LaplaceDistribution+instance Param NormalDistribution+instance Param PoissonDistribution+instance Param UniformDistribution+instance Param a => Param (LinearTransform a) @@ -298,7 +342,7 @@ -- Unit tests ---------------------------------------------------------------- -unitTests :: Test+unitTests :: TestTree unitTests = testGroup "Unit tests" [ testAssertion "density (gammaDistr 150 1/150) 1 == 4.883311" $ 4.883311418525483 =~ density (gammaDistr 150 (1/150)) 1
tests/Tests/Function.hs view
@@ -1,14 +1,14 @@ module Tests.Function ( tests ) where import Statistics.Function-import Test.Framework-import Test.Framework.Providers.QuickCheck2+import Test.Tasty+import Test.Tasty.QuickCheck import Test.QuickCheck import Tests.Helpers import qualified Data.Vector.Unboxed as U -tests :: Test+tests :: TestTree tests = testGroup "S.Function" [ testProperty "Sort is sort" p_sort , testAssertion "nextHighestPowerOfTwo is OK" p_nextHighestPowerOfTwo
tests/Tests/Helpers.hs view
@@ -21,11 +21,11 @@ import Data.Typeable import Numeric.MathFunctions.Constants (m_tiny)-import Test.Framework-import Test.Framework.Providers.HUnit+import Test.Tasty+import Test.Tasty.HUnit import Test.QuickCheck-import qualified Numeric.IEEE as IEEE-import qualified Test.HUnit as HU+import qualified Numeric.IEEE as IEEE+import qualified Test.Tasty.HUnit as HU -- | Phantom typed value used to select right instance in QC tests data T a = T@@ -75,10 +75,10 @@ -- HUnit helpers ---------------------------------------------------------------- -testAssertion :: String -> Bool -> Test+testAssertion :: String -> Bool -> TestTree testAssertion str cont = testCase str $ HU.assertBool str cont -testEquality :: (Show a, Eq a) => String -> a -> a -> Test+testEquality :: (Show a, Eq a) => String -> a -> a -> TestTree testEquality msg a b = testCase msg $ HU.assertEqual msg a b unsquare :: (Arbitrary a, Show a, Testable b) => (a -> b) -> Property
tests/Tests/KDE.hs view
@@ -3,17 +3,17 @@ tests )where -import Data.Vector.Unboxed ((!))-import Numeric.Sum (kbn, sumVector)+import Data.Vector.Unboxed ((!))+import Numeric.Sum (kbn, sumVector) import Statistics.Sample.KernelDensity-import Test.Framework (Test, testGroup)-import Test.Framework.Providers.QuickCheck2 (testProperty)-import Test.QuickCheck (Property, (==>), counterexample)-import Text.Printf (printf)+import Test.Tasty (TestTree, testGroup)+import Test.Tasty.QuickCheck (testProperty)+import Test.QuickCheck (Property, (==>), counterexample)+import Text.Printf (printf) import qualified Data.Vector.Unboxed as U -tests :: Test+tests :: TestTree tests = testGroup "KDE" [ testProperty "integral(PDF) == 1" t_densityIsPDF ]
tests/Tests/Matrix.hs view
@@ -2,8 +2,8 @@ import Statistics.Matrix hiding (map) import Statistics.Matrix.Algorithms-import Test.Framework (Test, testGroup)-import Test.Framework.Providers.QuickCheck2 (testProperty)+import Test.Tasty (TestTree, testGroup)+import Test.Tasty.QuickCheck (testProperty) import Test.QuickCheck import Tests.ApproxEq (ApproxEq(..)) import Tests.Matrix.Types@@ -31,9 +31,9 @@ t_qr a = hasNaN p .||. eql 1e-10 a p where p = uncurry multiply (qr a) -tests :: Test-tests = testGroup "Matrix" [- testProperty "t_row" t_row+tests :: TestTree+tests = testGroup "Matrix"+ [ testProperty "t_row" t_row , testProperty "t_column" t_column , testProperty "t_center" t_center , testProperty "t_transpose" t_transpose
tests/Tests/NonParametric.hs view
@@ -10,17 +10,16 @@ import Statistics.Test.WilcoxonT import Statistics.Types (PValue,pValue,mkPValue) -import Test.Framework (testGroup)-import Test.Framework.Providers.HUnit-import qualified Test.Framework as Tst-import Test.HUnit (assertEqual)-import Tests.ApproxEq (eq)-import Tests.Helpers (testAssertion, testEquality)+import Test.Tasty (testGroup)+import Test.Tasty.HUnit+import Tests.ApproxEq (eq)+import Tests.Helpers (testAssertion, testEquality) import Tests.NonParametric.Table (tableKSD, tableKS2D)+import qualified Test.Tasty as Tst import qualified Data.Vector.Unboxed as U -tests :: Tst.Test+tests :: Tst.TestTree tests = testGroup "Nonparametric tests" $ concat [ mannWhitneyTests , wilcoxonSumTests@@ -32,7 +31,7 @@ ---------------------------------------------------------------- -mannWhitneyTests :: [Tst.Test]+mannWhitneyTests :: [Tst.TestTree] mannWhitneyTests = zipWith test [(0::Int)..] testData ++ [ testEquality "Mann-Whitney U Critical Values, m=1" (replicate (20*3) Nothing)@@ -89,7 +88,7 @@ ) ] -wilcoxonSumTests :: [Tst.Test]+wilcoxonSumTests :: [Tst.TestTree] wilcoxonSumTests = zipWith test [(0::Int)..] testData where test n (a, b, c) = testCase "Wilcoxon Sum"@@ -106,7 +105,7 @@ ) ] -wilcoxonPairTests :: [Tst.Test]+wilcoxonPairTests :: [Tst.TestTree] wilcoxonPairTests = zipWith test [(0::Int)..] testData ++ -- Taken from the Mitic paper: [ testAssertion "Sig 16, 35" (to4dp 0.0467 $ wilcoxonMatchedPairSignificance 16 35)@@ -158,7 +157,7 @@ ---------------------------------------------------------------- -kruskalWallisRankTests :: [Tst.Test]+kruskalWallisRankTests :: [Tst.TestTree] kruskalWallisRankTests = zipWith test [(0::Int)..] testData where test n (a, b) = testCase "Kruskal-Wallis Ranking"@@ -177,7 +176,7 @@ ) ] -kruskalWallisTests :: [Tst.Test]+kruskalWallisTests :: [Tst.TestTree] kruskalWallisTests = zipWith test [(0::Int)..] testData where test n (a, b, c) = testCase "Kruskal-Wallis" $ do@@ -228,7 +227,7 @@ ---------------------------------------------------------------- -kolmogorovSmirnovDTest :: [Tst.Test]+kolmogorovSmirnovDTest :: [Tst.TestTree] kolmogorovSmirnovDTest = [ testAssertion "K-S D statistics" $ and [ eq 1e-6 (kolmogorovSmirnovD standard (toU sample)) reference
tests/Tests/Parametric.hs view
@@ -4,11 +4,11 @@ import Statistics.Test.StudentT import Statistics.Types import qualified Data.Vector.Unboxed as U-import Test.Framework (testGroup)+import Test.Tasty (testGroup) import Tests.Helpers (testEquality)-import qualified Test.Framework as Tst+import qualified Test.Tasty as Tst -tests :: Tst.Test+tests :: Tst.TestTree tests = testGroup "Parametric tests" studentTTests -- 2 samples x 20 obs data@@ -71,14 +71,14 @@ testTTest :: String -> PValue Double -> Test d- -> [Tst.Test]+ -> [Tst.TestTree] testTTest name pVal test = [ testEquality name (isSignificant pVal test) NotSignificant , testEquality name (isSignificant (mkPValue $ pValue pVal + 1e-5) test) Significant ] -studentTTests :: [Tst.Test]+studentTTests :: [Tst.TestTree] studentTTests = concat [ -- R: t.test(sample1, sample2, alt="two.sided", var.equal=T) testTTest "two-sample t-test SamplesDiffer Student"
tests/Tests/Quantile.hs view
@@ -5,15 +5,13 @@ import Control.Exception import qualified Data.Vector.Unboxed as U-import Test.Framework-import Test.Framework.Providers.HUnit-import Test.Framework.Providers.QuickCheck2-import Test.HUnit (Assertion,assertEqual,assertFailure)-import Test.QuickCheck hiding (sample)+import Test.Tasty+import Test.Tasty.HUnit+import Test.Tasty.QuickCheck hiding (sample) import Numeric.MathFunctions.Comparison (ulpDelta,ulpDistance) import Statistics.Quantile -tests :: Test+tests :: TestTree tests = testGroup "Quantiles" [ testCase "R alg. 4" $ compareWithR cadpw (0.00, 0.50, 2.50, 8.25, 10.00) , testCase "R alg. 5" $ compareWithR hazen (0.00, 1.00, 5.00, 9.00, 10.00)
tests/Tests/Serialization.hs view
@@ -23,15 +23,15 @@ import Statistics.Distribution.Uniform (UniformDistribution) import Statistics.Types -import Test.Framework (Test, testGroup)-import Test.Framework.Providers.QuickCheck2 (testProperty)+import Test.Tasty (TestTree, testGroup)+import Test.Tasty.QuickCheck (testProperty) import Test.QuickCheck as QC import Tests.Helpers import Tests.Orphanage () -tests :: Test+tests :: TestTree tests = testGroup "Test for data serialization" [ serializationTests (T :: T (CL Float)) , serializationTests (T :: T (CL Double))@@ -65,13 +65,13 @@ serializationTests :: (Eq a, Typeable a, Binary a, Show a, Read a, ToJSON a, FromJSON a, Arbitrary a)- => T a -> Test+ => T a -> TestTree serializationTests t = serializationTests' (typeName t) t -- Not all types are Typeable, unfortunately serializationTests' :: (Eq a, Binary a, Show a, Read a, ToJSON a, FromJSON a, Arbitrary a)- => String -> T a -> Test+ => String -> T a -> TestTree serializationTests' name t = testGroup ("Tests for: " ++ name) [ testProperty "show/read" (p_showRead t) , testProperty "binary" (p_binary t)
tests/Tests/Transform.hs view
@@ -12,8 +12,8 @@ import Numeric.Sum (kbn, sumVector) import Statistics.Function (within) import Statistics.Transform (CD, dct, fft, idct, ifft)-import Test.Framework (Test, testGroup)-import Test.Framework.Providers.QuickCheck2 (testProperty)+import Test.Tasty (TestTree, testGroup)+import Test.Tasty.QuickCheck (testProperty) import Test.QuickCheck ( Positive(..), Arbitrary(..), Blind(..), (==>), Gen , choose, vectorOf, counterexample, forAll) import Test.QuickCheck.Property (Property(..))@@ -23,7 +23,7 @@ import qualified Data.Vector.Unboxed as U -tests :: Test+tests :: TestTree tests = testGroup "fft" [ testProperty "t_impulse" t_impulse , testProperty "t_impulse_offset" t_impulse_offset@@ -103,13 +103,13 @@ $ nd <= 3e-14 * nx -- Test discrete cosine transform-testDCT :: [Double] -> [Double] -> Test+testDCT :: [Double] -> [Double] -> TestTree testDCT (U.fromList -> vec) (U.fromList -> res) = testAssertion ("DCT test for " ++ show vec) $ vecEqual 3e-14 (dct vec) res -- Test inverse discrete cosine transform-testIDCT :: [Double] -> [Double] -> Test+testIDCT :: [Double] -> [Double] -> TestTree testIDCT (U.fromList -> vec) (U.fromList -> res) = testAssertion ("IDCT test for " ++ show vec) $ vecEqual 3e-14 (idct vec) res
tests/tests.hs view
@@ -1,4 +1,4 @@-import Test.Framework (defaultMain)+import Test.Tasty (defaultMain,testGroup) import qualified Tests.Distribution import qualified Tests.Function@@ -12,14 +12,15 @@ import qualified Tests.Quantile main :: IO ()-main = defaultMain [ Tests.Distribution.tests- , Tests.Function.tests- , Tests.KDE.tests- , Tests.Matrix.tests- , Tests.NonParametric.tests- , Tests.Parametric.tests- , Tests.Transform.tests- , Tests.Correlation.tests- , Tests.Serialization.tests- , Tests.Quantile.tests- ]+main = defaultMain $ testGroup "statistics"+ [ Tests.Distribution.tests+ , Tests.Function.tests+ , Tests.KDE.tests+ , Tests.Matrix.tests+ , Tests.NonParametric.tests+ , Tests.Parametric.tests+ , Tests.Transform.tests+ , Tests.Correlation.tests+ , Tests.Serialization.tests+ , Tests.Quantile.tests+ ]