Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

A big old style cleanup diff

This cleans up a number of small issues that are not consistent
with my normal coding style, mostly relating to import sorting and
whitespace.

--HG--
rename : tests/Tests/NonparametricTest.hs => tests/Tests/NonParametric.hs
rename : tests/Tests/NonparametricTest/Table.hs => tests/Tests/NonParametric/Table.hs
  • Loading branch information...
commit d948e0c6d7fe1b609919ee5b6b3c8ce0b8d87093 1 parent a06b3ca
Bryan O'Sullivan authored
Showing with 210 additions and 236 deletions.
  1. +2 −3 Statistics/Distribution.hs
  2. +2 −2 Statistics/Distribution/Beta.hs
  3. +1 −1  Statistics/Distribution/Binomial.hs
  4. +1 −1  Statistics/Distribution/CauchyLorentz.hs
  5. +3 −3 Statistics/Distribution/ChiSquared.hs
  6. +2 −2 Statistics/Distribution/FDistribution.hs
  7. +9 −10 Statistics/Distribution/Gamma.hs
  8. +8 −8 Statistics/Distribution/Geometric.hs
  9. +1 −1  Statistics/Distribution/Hypergeometric.hs
  10. +4 −5 Statistics/Distribution/Normal.hs
  11. +14 −14 Statistics/Distribution/Poisson/Internal.hs
  12. +1 −1  Statistics/Distribution/StudentT.hs
  13. +11 −10 Statistics/Distribution/Transform.hs
  14. +2 −2 Statistics/Function/Comparison.hs
  15. +1 −2  Statistics/Math.hs
  16. +6 −7 Statistics/Math/RootFinding.hs
  17. +3 −3 Statistics/Quantile.hs
  18. +4 −4 Statistics/Resampling/Bootstrap.hs
  19. +4 −5 Statistics/Sample/KernelDensity.hs
  20. +2 −2 Statistics/Sample/KernelDensity/Simple.hs
  21. +7 −7 Statistics/Sample/Powers.hs
  22. +8 −8 Statistics/Test/KolmogorovSmirnov.hs
  23. +8 −8 Statistics/Test/MannWhitneyU.hs
  24. +8 −7 Statistics/Test/WilcoxonT.hs
  25. +7 −7 Statistics/Transform.hs
  26. +3 −5 benchmark/bench.hs
  27. +2 −2 statistics.cabal
  28. +34 −45 tests/Tests/Distribution.hs
  29. +4 −8 tests/Tests/Function.hs
  30. +3 −3 tests/Tests/KDE.hs
  31. +19 −26 tests/Tests/{NonparametricTest.hs → NonParametric.hs}
  32. +7 −4 tests/Tests/{NonparametricTest → NonParametric}/Table.hs
  33. +8 −8 tests/Tests/Transform.hs
  34. +11 −12 tests/tests.hs
5 Statistics/Distribution.hs
View
@@ -32,15 +32,14 @@ module Statistics.Distribution
, sumProbabilities
) where
-import Control.Applicative ((<$>), Applicative(..))
+import Control.Applicative ((<$>), Applicative(..))
import Control.Monad.Primitive (PrimMonad,PrimState)
import Prelude hiding (sum)
import Statistics.Sample.Internal (sum)
-import System.Random.MWC
+import System.Random.MWC (Gen, uniform)
import qualified Data.Vector.Unboxed as U
-
-- | Type class common to all distributions. Only c.d.f. could be
-- defined for both discrete and continous distributions.
class Distribution d where
4 Statistics/Distribution/Beta.hs
View
@@ -89,12 +89,12 @@ instance D.MaybeVariance BetaDistribution where
instance D.Entropy BetaDistribution where
entropy (BD a b) =
- logBeta a b
+ logBeta a b
- (a-1) * digamma a
- (b-1) * digamma b
+ (a+b-2) * digamma (a+b)
{-# INLINE entropy #-}
-
+
instance D.MaybeEntropy BetaDistribution where
maybeEntropy = Just . D.entropy
{-# INLINE maybeEntropy #-}
2  Statistics/Distribution/Binomial.hs
View
@@ -103,7 +103,7 @@ variance (BD n p) = fromIntegral n * p * (1 - p)
{-# INLINE variance #-}
directEntropy :: BinomialDistribution -> Double
-directEntropy d@(BD n _) =
+directEntropy d@(BD n _) =
negate . sum $
takeWhile (< negate m_epsilon) $
dropWhile (not . (< negate m_epsilon)) $
2  Statistics/Distribution/CauchyLorentz.hs
View
@@ -76,6 +76,6 @@ instance D.ContGen CauchyDistribution where
instance D.Entropy CauchyDistribution where
entropy (CD _ s) = log s + log (4*pi)
-
+
instance D.MaybeEntropy CauchyDistribution where
maybeEntropy = Just . D.entropy
6 Statistics/Distribution/ChiSquared.hs
View
@@ -72,12 +72,12 @@ instance D.MaybeMean ChiSquared where
instance D.MaybeVariance ChiSquared where
maybeStdDev = Just . D.stdDev
maybeVariance = Just . D.variance
-
+
instance D.Entropy ChiSquared where
entropy (ChiSquared ndf) =
let kHalf = 0.5 * fromIntegral ndf in
- kHalf
- + log 2
+ kHalf
+ + log 2
+ logGamma kHalf
+ (1-kHalf) * digamma kHalf
4 Statistics/Distribution/FDistribution.hs
View
@@ -93,9 +93,9 @@ instance D.Entropy FDistribution where
entropy (F n m _) =
let nHalf = 0.5 * n
mHalf = 0.5 * m in
- log (n/m)
+ log (n/m)
+ logBeta nHalf mHalf
- + (1 - nHalf) * digamma nHalf
+ + (1 - nHalf) * digamma nHalf
- (1 + mHalf) * digamma mHalf
+ (nHalf + mHalf) * digamma (nHalf + mHalf)
19 Statistics/Distribution/Gamma.hs
View
@@ -25,17 +25,16 @@ module Statistics.Distribution.Gamma
, gdScale
) where
+import Control.Applicative ((<$>), (<*>))
import Data.Binary (Binary)
+import Data.Binary (put, get)
import Data.Data (Data, Typeable)
import GHC.Generics (Generic)
import Numeric.MathFunctions.Constants (m_pos_inf, m_NaN, m_neg_inf)
-import Numeric.SpecFunctions (
- incompleteGamma, invIncompleteGamma, logGamma, digamma)
-import Statistics.Distribution.Poisson.Internal as Poisson
-import qualified Statistics.Distribution as D
+import Numeric.SpecFunctions (incompleteGamma, invIncompleteGamma, logGamma, digamma)
+import Statistics.Distribution.Poisson.Internal as Poisson
+import qualified Statistics.Distribution as D
import qualified System.Random.MWC.Distributions as MWC
-import Data.Binary (put, get)
-import Control.Applicative ((<$>), (<*>))
-- | The gamma distribution.
data GammaDistribution = GD {
@@ -94,11 +93,11 @@ instance D.MaybeVariance GammaDistribution where
instance D.MaybeEntropy GammaDistribution where
maybeEntropy (GD a l)
- | a > 0 && l > 0 =
+ | a > 0 && l > 0 =
Just $
- a
- + log l
- + logGamma a
+ a
+ + log l
+ + logGamma a
+ (1-a) * digamma a
| otherwise = Nothing
16 Statistics/Distribution/Geometric.hs
View
@@ -30,15 +30,15 @@ module Statistics.Distribution.Geometric
, gdSuccess0
) where
-import Control.Monad (liftM)
-import Data.Binary (Binary)
-import Data.Data (Data, Typeable)
-import GHC.Generics (Generic)
-import Numeric.MathFunctions.Constants(m_pos_inf,m_neg_inf)
-import qualified Statistics.Distribution as D
-import qualified System.Random.MWC.Distributions as MWC
-import Data.Binary (put, get)
import Control.Applicative ((<$>))
+import Control.Monad (liftM)
+import Data.Binary (Binary)
+import Data.Binary (put, get)
+import Data.Data (Data, Typeable)
+import GHC.Generics (Generic)
+import Numeric.MathFunctions.Constants (m_pos_inf, m_neg_inf)
+import qualified Statistics.Distribution as D
+import qualified System.Random.MWC.Distributions as MWC
----------------------------------------------------------------
-- Distribution over [1..]
2  Statistics/Distribution/Hypergeometric.hs
View
@@ -67,7 +67,7 @@ instance D.MaybeVariance HypergeometricDistribution where
instance D.Entropy HypergeometricDistribution where
entropy = directEntropy
-
+
instance D.MaybeEntropy HypergeometricDistribution where
maybeEntropy = Just . D.entropy
9 Statistics/Distribution/Normal.hs
View
@@ -20,17 +20,16 @@ module Statistics.Distribution.Normal
, standard
) where
+import Control.Applicative ((<$>), (<*>))
import Data.Binary (Binary)
+import Data.Binary (put, get)
import Data.Data (Data, Typeable)
import GHC.Generics (Generic)
import Numeric.MathFunctions.Constants (m_sqrt_2, m_sqrt_2_pi)
-import Numeric.SpecFunctions (erfc, invErfc)
+import Numeric.SpecFunctions (erfc, invErfc)
import qualified Statistics.Distribution as D
-import qualified Statistics.Sample as S
+import qualified Statistics.Sample as S
import qualified System.Random.MWC.Distributions as MWC
-import Data.Binary (put, get)
-import Control.Applicative ((<$>), (<*>))
-
-- | The normal distribution.
28 Statistics/Distribution/Poisson/Internal.hs
View
@@ -14,10 +14,10 @@ module Statistics.Distribution.Poisson.Internal
probability, poissonEntropy
) where
-import Data.List(unfoldr)
+import Data.List (unfoldr)
import Numeric.MathFunctions.Constants (m_sqrt_2_pi, m_tiny, m_epsilon)
import Numeric.SpecFunctions (logGamma, stirlingError, choose, logFactorial)
-import Numeric.SpecFunctions.Extra (bd0)
+import Numeric.SpecFunctions.Extra (bd0)
-- | An unchecked, non-integer-valued version of Loader's saddle point
-- algorithm.
@@ -50,7 +50,7 @@ alyc k =
where parity j
| even (k-j) = -1
| otherwise = 1
-
+
-- | Returns [x, x^2, x^3, x^4, ...]
powers :: Double -> [Double]
powers x = unfoldr (\y -> Just (y*x,y*x)) 1
@@ -68,7 +68,7 @@ alyThm2 :: Double -> [Double] -> [Double] -> Double
alyThm2 lambda upper lower =
alyThm2Upper lambda upper + 0.5 * (zipCoefficients lambda lower)
-zipCoefficients :: Double -> [Double] -> Double
+zipCoefficients :: Double -> [Double] -> Double
zipCoefficients lambda coefficients =
(sum $ map (uncurry (*)) (zip (powers $ recip lambda) coefficients))
@@ -76,12 +76,12 @@ zipCoefficients lambda coefficients =
--
-- poissonMoment[0, s_] := 1
-- poissonMoment[1, s_] := 0
--- poissonMoment[k_, s_] :=
+-- poissonMoment[k_, s_] :=
-- Sum[s * Binomial[k - 1, j] * poissonMoment[j, s], {j, 0, k - 2}]
--
-- upperSeries[m_] :=
-- Distribute[Integrate[
--- Sum[(-1)^(j - 1) *
+-- Sum[(-1)^(j - 1) *
-- poissonMoment[j, \[Lambda]] / (j * (j - 1)* \[Lambda]^j),
-- {j, 3, 2 m - 1}],
-- \[Lambda]]]
@@ -89,10 +89,10 @@ zipCoefficients lambda coefficients =
-- lowerSeries[m_] :=
-- Distribute[Integrate[
-- poissonMoment[
--- 2 m + 2, \[Lambda]] / ((2 m +
+-- 2 m + 2, \[Lambda]] / ((2 m +
-- 1)*\[Lambda]^(2 m + 2)), \[Lambda]]]
--
--- upperBound[m_] := upperSeries[m] + (Log[2*Pi*\[Lambda]] + 1)/2
+-- upperBound[m_] := upperSeries[m] + (Log[2*Pi*\[Lambda]] + 1)/2
--
-- lowerBound[m_] := upperBound[m] + lowerSeries[m]
@@ -120,7 +120,7 @@ lowerCoefficients8 :: [Double]
lowerCoefficients8 = [0,0,0,0,0,0,0, -2027025/8, -15315300, -105252147,
-178127950, -343908565/4, -10929270, -3721149/14,
-7709/15, -1/272]
-
+
upperCoefficients10 :: [Double]
upperCoefficients10 = [1/12, 1/24, 19/360, 9,80, 863/2520, 1375/1008,
33953/5040, 57281/1440, -2271071617/11880,
@@ -128,13 +128,13 @@ upperCoefficients10 = [1/12, 1/24, 19/360, 9,80, 863/2520, 1375/1008,
-7531072742237/131040, -1405507544003/65520,
-21001919627/10080, -1365808297/36720,
-26059/544, -1/5814]
-
+
lowerCoefficients10 :: [Double]
lowerCoefficients10 = [0,0,0,0,0,0,0,0,0,-130945815/2, -7638505875,
-438256243425/4, -435477637540, -3552526473925/6,
-857611717105/3, -545654955967/12, -5794690528/3,
-578334559/42, -699043/133, -1/420]
-
+
upperCoefficients12 :: [Double]
upperCoefficients12 = [1/12, 1/24, 19/360, 863/2520, 1375/1008,
33953/5040, 57281/1440, 3250433/11880,
@@ -153,13 +153,13 @@ lowerCoefficients12 = [0,0,0,0,0,0,0,0,0,0,0,
-347362037754732, -2205885452434521/100,
-12237195698286/35, -16926981721/22,
-6710881/155, -1/600]
-
+
-- | Compute entropy directly from its definition. This is just as accurate
-- as 'alyThm1' for lambda <= 1 and is faster, but is slow for large lambda,
-- and produces some underestimation due to accumulation of floating point
-- error.
directEntropy :: Double -> Double
-directEntropy lambda =
+directEntropy lambda =
negate . sum $
takeWhile (< negate m_epsilon * lambda) $
dropWhile (not . (< negate m_epsilon * lambda)) $
@@ -175,4 +175,4 @@ poissonEntropy lambda
| lambda <= 18 = alyThm2 lambda upperCoefficients6 lowerCoefficients6
| lambda <= 24 = alyThm2 lambda upperCoefficients8 lowerCoefficients8
| lambda <= 30 = alyThm2 lambda upperCoefficients10 lowerCoefficients10
- | otherwise = alyThm2 lambda upperCoefficients12 lowerCoefficients12
+ | otherwise = alyThm2 lambda upperCoefficients12 lowerCoefficients12
2  Statistics/Distribution/StudentT.hs
View
@@ -79,7 +79,7 @@ instance D.MaybeVariance StudentT where
instance D.Entropy StudentT where
entropy (StudentT ndf) =
0.5 * (ndf+1) * (digamma ((1+ndf)/2) - digamma(ndf/2))
- + log (sqrt ndf)
+ + log (sqrt ndf)
+ logBeta (ndf/2) 0.5
instance D.MaybeEntropy StudentT where
21 Statistics/Distribution/Transform.hs
View
@@ -10,19 +10,20 @@
-- Portability : portable
--
-- Transformations over distributions
-module Statistics.Distribution.Transform (
- LinearTransform (..)
- , linTransFixedPoint
- , scaleAround
- ) where
+module Statistics.Distribution.Transform
+ (
+ LinearTransform (..)
+ , linTransFixedPoint
+ , scaleAround
+ ) where
+import Control.Applicative ((<*>))
import Data.Binary (Binary)
+import Data.Binary (put, get)
import Data.Data (Data, Typeable)
+import Data.Functor ((<$>))
import GHC.Generics (Generic)
-import Data.Functor ((<$>))
import qualified Statistics.Distribution as D
-import Data.Binary (put, get)
-import Control.Applicative ((<*>))
-- | Linear transformation applied to distribution.
--
@@ -77,11 +78,11 @@ instance (D.Variance d) => D.Variance (LinearTransform d) where
variance (LinearTransform _ sc dist) = sc * sc * D.variance dist
stdDev (LinearTransform _ sc dist) = sc * D.stdDev dist
-instance (D.MaybeEntropy d, D.DiscreteDistr d)
+instance (D.MaybeEntropy d, D.DiscreteDistr d)
=> D.MaybeEntropy (LinearTransform d) where
maybeEntropy (LinearTransform _ _ dist) = D.maybeEntropy dist
-instance (D.Entropy d, D.DiscreteDistr d)
+instance (D.Entropy d, D.DiscreteDistr d)
=> D.Entropy (LinearTransform d) where
entropy (LinearTransform _ _ dist) = D.entropy dist
4 Statistics/Function/Comparison.hs
View
@@ -16,9 +16,9 @@ module Statistics.Function.Comparison
within
) where
-import Control.Monad.ST (runST)
+import Control.Monad.ST (runST)
+import Data.Int (Int64)
import Data.Primitive.ByteArray (newByteArray, readByteArray, writeByteArray)
-import Data.Int (Int64)
-- | Compare two 'Double' values for approximate equality, using
-- Dawson's method.
3  Statistics/Math.hs
View
@@ -15,7 +15,7 @@
-- 'Numeric.SpecFunctions.Extra' and 'Numeric.Polynomial.Chebyshev'.
module Statistics.Math
-{-# DEPRECATED "Use package math-function" #-}
+{-# DEPRECATED "Use package math-function" #-}
( module Numeric.Polynomial.Chebyshev
, module Numeric.SpecFunctions
, module Numeric.SpecFunctions.Extra
@@ -24,4 +24,3 @@ module Statistics.Math
import Numeric.Polynomial.Chebyshev
import Numeric.SpecFunctions
import Numeric.SpecFunctions.Extra
-
13 Statistics/Math/RootFinding.hs
View
@@ -20,16 +20,15 @@ module Statistics.Math.RootFinding
-- $references
) where
-import Statistics.Function.Comparison
-
+import Control.Applicative (Alternative(..), Applicative(..))
+import Control.Monad (MonadPlus(..), ap)
import Data.Binary (Binary)
-import Control.Applicative
-import Control.Monad (MonadPlus(..), ap)
-import Data.Data (Data, Typeable)
-import GHC.Generics (Generic)
import Data.Binary (put, get)
-import Data.Binary.Put (putWord8)
import Data.Binary.Get (getWord8)
+import Data.Binary.Put (putWord8)
+import Data.Data (Data, Typeable)
+import GHC.Generics (Generic)
+import Statistics.Function.Comparison (within)
-- | The result of searching for a root of a mathematical function.
6 Statistics/Quantile.hs
View
@@ -37,14 +37,14 @@ module Statistics.Quantile
-- $references
) where
-import Data.Vector.Generic ((!))
+import Data.Vector.Generic ((!))
import Numeric.MathFunctions.Constants (m_epsilon)
-import Statistics.Function (partialSort)
+import Statistics.Function (partialSort)
import qualified Data.Vector.Generic as G
-- | O(/n/ log /n/). Estimate the /k/th /q/-quantile of a sample,
-- using the weighted average method.
-weightedAvg :: G.Vector v Double =>
+weightedAvg :: G.Vector v Double =>
Int -- ^ /k/, the desired quantile.
-> Int -- ^ /q/, the number of quantiles.
-> v Double -- ^ /x/, the sample data.
8 Statistics/Resampling/Bootstrap.hs
View
@@ -21,14 +21,16 @@ module Statistics.Resampling.Bootstrap
-- $references
) where
+import Control.Applicative ((<$>), (<*>))
import Control.DeepSeq (NFData)
import Control.Exception (assert)
-import Control.Monad.Par (parMap,runPar)
+import Control.Monad.Par (parMap, runPar)
import Data.Binary (Binary)
+import Data.Binary (put, get)
import Data.Data (Data)
import Data.Typeable (Typeable)
import Data.Vector.Unboxed ((!))
-import GHC.Generics
+import GHC.Generics (Generic)
import Statistics.Distribution (cumulative, quantile)
import Statistics.Distribution.Normal
import Statistics.Resampling (Resample(..), jackknife)
@@ -36,8 +38,6 @@ import Statistics.Sample (mean)
import Statistics.Types (Estimator, Sample)
import qualified Data.Vector.Unboxed as U
import qualified Statistics.Resampling as R
-import Data.Binary (put, get)
-import Control.Applicative ((<$>), (<*>))
-- | A point and interval estimate computed via an 'Estimator'.
data Estimate = Estimate {
9 Statistics/Sample/KernelDensity.hs
View
@@ -27,16 +27,15 @@ module Statistics.Sample.KernelDensity
import Numeric.MathFunctions.Constants (m_sqrt_2_pi)
import Prelude hiding (const, min, max, sum)
-import Statistics.Function (minMax, nextHighestPowerOfTwo)
-import Statistics.Math.RootFinding (fromRoot, ridders)
-import Statistics.Sample.Histogram (histogram_)
+import Statistics.Function (minMax, nextHighestPowerOfTwo)
+import Statistics.Math.RootFinding (fromRoot, ridders)
+import Statistics.Sample.Histogram (histogram_)
import Statistics.Sample.Internal (sum)
-import Statistics.Transform (dct, idct)
+import Statistics.Transform (dct, idct)
import qualified Data.Vector.Generic as G
import qualified Data.Vector.Unboxed as U
-
-- | Gaussian kernel density estimator for one-dimensional data, using
-- the method of Botev et al.
--
4 Statistics/Sample/KernelDensity/Simple.hs
View
@@ -53,10 +53,10 @@ import GHC.Generics (Generic)
import Numeric.MathFunctions.Constants (m_1_sqrt_2, m_2_sqrt_pi)
import Prelude hiding (sum)
import Statistics.Function (minMax)
-import Statistics.Sample (stdDev)
+import Statistics.Sample (stdDev)
import Statistics.Sample.Internal (sum)
-import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Generic as G
+import qualified Data.Vector.Unboxed as U
-- | Points from the range of a 'Sample'.
newtype Points = Points {
14 Statistics/Sample/Powers.hs
View
@@ -50,16 +50,16 @@ module Statistics.Sample.Powers
import Data.Binary (Binary(..))
import Data.Data (Data, Typeable)
import Data.Vector.Binary ()
-import Data.Vector.Generic (unsafeFreeze)
-import Data.Vector.Unboxed ((!))
+import Data.Vector.Generic (unsafeFreeze)
+import Data.Vector.Unboxed ((!))
import GHC.Generics (Generic)
-import Prelude hiding (sum)
-import Statistics.Function (indexed)
-import Statistics.Internal (inlinePerformIO)
import Numeric.SpecFunctions (choose)
-import System.IO.Unsafe (unsafePerformIO)
-import qualified Data.Vector.Unboxed as U
+import Prelude hiding (sum)
+import Statistics.Function (indexed)
+import Statistics.Internal (inlinePerformIO)
+import System.IO.Unsafe (unsafePerformIO)
import qualified Data.Vector.Generic as G
+import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as MU
import qualified Statistics.Sample.Internal as S
16 Statistics/Test/KolmogorovSmirnov.hs
View
@@ -29,16 +29,16 @@ module Statistics.Test.KolmogorovSmirnov (
-- $references
) where
-import Control.Monad
-import Control.Monad.ST (ST)
+import Control.Monad (when)
+import Control.Monad.ST (ST)
import Prelude hiding (sum)
-import Statistics.Distribution (Distribution(..))
-import Statistics.Function (sort)
+import Statistics.Distribution (Distribution(..))
+import Statistics.Function (sort)
import Statistics.Sample.Internal (sum)
-import Statistics.Test.Types
-import Statistics.Types (Sample)
-import Text.Printf
-import qualified Data.Vector.Unboxed as U
+import Statistics.Test.Types (TestResult(..), TestType(..), significant)
+import Statistics.Types (Sample)
+import Text.Printf (printf)
+import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as M
16 Statistics/Test/MannWhitneyU.hs
View
@@ -27,17 +27,17 @@ module Statistics.Test.MannWhitneyU (
) where
import Control.Applicative ((<$>))
-import Data.List (findIndex)
-import Data.Ord (comparing)
-import Numeric.SpecFunctions (choose)
+import Data.List (findIndex)
+import Data.Ord (comparing)
+import Numeric.SpecFunctions (choose)
import Prelude hiding (sum)
-import Statistics.Distribution (quantile)
+import Statistics.Distribution (quantile)
import Statistics.Distribution.Normal (standard)
-import Statistics.Function (sortBy)
+import Statistics.Function (sortBy)
import Statistics.Sample.Internal (sum)
-import Statistics.Test.Internal
-import Statistics.Test.Types
-import Statistics.Types (Sample)
+import Statistics.Test.Internal (rank, splitByTags)
+import Statistics.Test.Types (TestResult(..), TestType(..), significant)
+import Statistics.Types (Sample)
import qualified Data.Vector.Unboxed as U
-- | The Wilcoxon Rank Sums Test.
15 Statistics/Test/WilcoxonT.hs
View
@@ -40,16 +40,17 @@ module Statistics.Test.WilcoxonT (
-- to the the length of the shorter sample.
import Control.Applicative ((<$>))
-import Data.Function (on)
-import Data.List (findIndex)
-import Data.Ord (comparing)
+import Data.Function (on)
+import Data.List (findIndex)
+import Data.Ord (comparing)
import Prelude hiding (sum)
-import Statistics.Function (sortBy)
+import Statistics.Function (sortBy)
import Statistics.Sample.Internal (sum)
-import Statistics.Test.Internal
-import Statistics.Test.Types
-import Statistics.Types (Sample)
+import Statistics.Test.Internal (rank, splitByTags)
+import Statistics.Test.Types (TestResult(..), TestType(..), significant)
+import Statistics.Types (Sample)
import qualified Data.Vector.Unboxed as U
+
wilcoxonMatchedPairSignedRank :: Sample -> Sample -> (Double, Double)
wilcoxonMatchedPairSignedRank a b = (sum ranks1, negate (sum ranks2))
where
14 Statistics/Transform.hs
View
@@ -29,14 +29,14 @@ module Statistics.Transform
, ifft
) where
-import Control.Monad (when)
-import Control.Monad.ST (ST)
-import Data.Bits (shiftL, shiftR)
-import Data.Complex (Complex(..), conjugate, realPart)
+import Control.Monad (when)
+import Control.Monad.ST (ST)
+import Data.Bits (shiftL, shiftR)
+import Data.Complex (Complex(..), conjugate, realPart)
import Numeric.SpecFunctions (log2)
-import qualified Data.Vector.Generic as G
+import qualified Data.Vector.Generic as G
import qualified Data.Vector.Generic.Mutable as M
-import qualified Data.Vector.Unboxed as U
+import qualified Data.Vector.Unboxed as U
type CD = Complex Double
@@ -90,7 +90,7 @@ idctWorker xs
interleave z | even z = vals `G.unsafeIndex` halve z
| otherwise = vals `G.unsafeIndex` (len - halve z - 1)
vals = G.map realPart . ifft $ G.zipWith (*) weights xs
- weights
+ weights
= G.cons n
$ G.generate (len - 1) $ \x -> 2 * n * exp ((0:+1) * fi (x+1) * pi/(2*n))
where n = fi len
8 benchmark/bench.hs
View
@@ -1,12 +1,10 @@
import Control.Monad.ST (runST)
-import Data.Complex
-import qualified Data.Vector.Unboxed as U
-
-import System.Random.MWC
import Criterion.Main
-
+import Data.Complex
import Statistics.Sample
import Statistics.Transform
+import System.Random.MWC
+import qualified Data.Vector.Unboxed as U
-- Test sample
4 statistics.cabal
View
@@ -123,8 +123,8 @@ test-suite tests
Tests.Distribution
Tests.Helpers
Tests.Function
- Tests.NonparametricTest
- Tests.NonparametricTest.Table
+ Tests.NonParametric
+ Tests.NonParametric.Table
Tests.Transform
Tests.KDE
79 tests/Tests/Distribution.hs
View
@@ -1,52 +1,41 @@
{-# OPTIONS_GHC -fno-warn-orphans #-}
-{-# LANGUAGE ScopedTypeVariables #-}
--- Required for Param
-{-# LANGUAGE FlexibleInstances #-}
-{-# LANGUAGE OverlappingInstances #-}
-{-# LANGUAGE ViewPatterns #-}
-module Tests.Distribution (
- distributionTests
- ) where
-
-import Control.Applicative
-import Control.Exception
-
-import Data.List (find)
-import Data.Typeable (Typeable)
-import Data.Binary
-
-import qualified Numeric.IEEE as IEEE
-
-import Test.Framework (Test,testGroup)
-import Test.Framework.Providers.QuickCheck2 (testProperty)
-import Test.QuickCheck as QC
-import Test.QuickCheck.Monadic as QC
-import Text.Printf
+{-# LANGUAGE FlexibleInstances, OverlappingInstances, ScopedTypeVariables,
+ ViewPatterns #-}
+module Tests.Distribution (tests) where
+import Control.Applicative ((<$>), (<*>))
+import Data.Binary (Binary, decode, encode)
+import Data.List (find)
+import Data.Typeable (Typeable)
import Statistics.Distribution
-import Statistics.Distribution.Beta
-import Statistics.Distribution.Binomial
-import Statistics.Distribution.ChiSquared
+import Statistics.Distribution.Beta (BetaDistribution, betaDistr)
+import Statistics.Distribution.Binomial (BinomialDistribution, binomial)
import Statistics.Distribution.CauchyLorentz
-import Statistics.Distribution.Exponential
-import Statistics.Distribution.FDistribution
-import Statistics.Distribution.Gamma
+import Statistics.Distribution.ChiSquared (ChiSquared, chiSquared)
+import Statistics.Distribution.Exponential (ExponentialDistribution, exponential)
+import Statistics.Distribution.FDistribution (FDistribution, fDistribution)
+import Statistics.Distribution.Gamma (GammaDistribution, gammaDistr)
import Statistics.Distribution.Geometric
import Statistics.Distribution.Hypergeometric
-import Statistics.Distribution.Normal
-import Statistics.Distribution.Poisson
+import Statistics.Distribution.Normal (NormalDistribution, normalDistr)
+import Statistics.Distribution.Poisson (PoissonDistribution, poisson)
import Statistics.Distribution.StudentT
-import Statistics.Distribution.Transform
-import Statistics.Distribution.Uniform
-
-import Prelude hiding (catch)
-
-import Tests.Helpers
+import Statistics.Distribution.Transform (LinearTransform, linTransDistr)
+import Statistics.Distribution.Uniform (UniformDistribution, uniformDistr)
+import Test.Framework (Test, testGroup)
+import Test.Framework.Providers.QuickCheck2 (testProperty)
+import Test.QuickCheck as QC
+import Test.QuickCheck.Monadic as QC
+import Tests.Helpers (T(..), (=~), eq, testAssertion, typeName)
+import Tests.Helpers (monotonicallyIncreasesIEEE)
+import Text.Printf (printf)
+import qualified Control.Exception as E
+import qualified Numeric.IEEE as IEEE
-- | Tests for all distributions
-distributionTests :: Test
-distributionTests = testGroup "Tests for all distributions"
+tests :: Test
+tests = testGroup "Tests for all distributions"
[ contDistrTests (T :: T BetaDistribution )
, contDistrTests (T :: T CauchyDistribution )
, contDistrTests (T :: T ChiSquared )
@@ -109,7 +98,7 @@ cdfTests t =
-- CDF is in [0,1] range
cdfSanityCheck :: (Distribution d) => T d -> d -> Double -> Bool
-cdfSanityCheck _ d x = c >= 0 && c <= 1
+cdfSanityCheck _ d x = c >= 0 && c <= 1
where c = cumulative d x
-- CDF never decreases
@@ -152,7 +141,7 @@ cdfComplementIsCorrect _ d x = (eq 1e-14) 1 (cumulative d x + complCumulative d
cdfDiscreteIsCorrect :: (DiscreteDistr d) => T d -> d -> Property
cdfDiscreteIsCorrect _ d
= printTestCase (unlines badN)
- $ null badN
+ $ null badN
where
-- We are checking that:
--
@@ -206,15 +195,15 @@ quantileIsInvCDF _ d (snd . properFraction -> p) =
-- Test that quantile fails if p<0 or p>1
quantileShouldFail :: (ContDistr d) => T d -> d -> Double -> Property
quantileShouldFail _ d p =
- p < 0 || p > 1 ==> QC.monadicIO $ do r <- QC.run $ catch
+ p < 0 || p > 1 ==> QC.monadicIO $ do r <- QC.run $ E.catch
(do { return $! quantile d p; return False })
- (\(e :: SomeException) -> return True)
+ (\(_ :: E.SomeException) -> return True)
QC.assert r
-- Probability is in [0,1] range
probSanityCheck :: (DiscreteDistr d) => T d -> d -> Int -> Bool
-probSanityCheck _ d x = p >= 0 && p <= 1
+probSanityCheck _ d x = p >= 0 && p <= 1
where p = probability d x
-- Check that discrete CDF is correct
@@ -297,7 +286,7 @@ instance QC.Arbitrary (LinearTransform StudentT) where
<*> ((abs <$> arbitrary))
<*> ((abs <$> arbitrary) `suchThat` (>0))
instance QC.Arbitrary FDistribution where
- arbitrary = fDistribution
+ arbitrary = fDistribution
<$> ((abs <$> arbitrary) `suchThat` (>0))
<*> ((abs <$> arbitrary) `suchThat` (>0))
12 tests/Tests/Function.hs
View
@@ -1,15 +1,11 @@
module Tests.Function ( tests ) where
-import qualified Data.Vector.Unboxed as U
-import Data.Vector.Unboxed ((!))
-
-import Test.QuickCheck
+import Statistics.Function
import Test.Framework
import Test.Framework.Providers.QuickCheck2
-
+import Test.QuickCheck
import Tests.Helpers
-import Statistics.Function
-
+import qualified Data.Vector.Unboxed as U
tests :: Test
@@ -29,5 +25,5 @@ p_nextHighestPowerOfTwo :: Bool
p_nextHighestPowerOfTwo
= all (\(good, is) -> all ((==good) . nextHighestPowerOfTwo) is) lists
where
- pows = [1 .. 17]
+ pows = [1 .. 17 :: Int]
lists = [ (2^m, [2^n+1 .. 2^m]) | (n,m) <- pows `zip` tail pows ]
6 tests/Tests/KDE.hs
View
@@ -6,10 +6,10 @@ module Tests.KDE (
import Data.Vector.Unboxed ((!))
import Numeric.Sum (kbn, sumVector)
import Statistics.Sample.KernelDensity
-import Test.Framework (Test, testGroup)
+import Test.Framework (Test, testGroup)
import Test.Framework.Providers.QuickCheck2 (testProperty)
-import Test.QuickCheck
-import Text.Printf
+import Test.QuickCheck (Property, (==>), printTestCase)
+import Text.Printf (printf)
import qualified Data.Vector.Unboxed as U
45 tests/Tests/NonparametricTest.hs → tests/Tests/NonParametric.hs
View
@@ -1,32 +1,25 @@
-- Tests for Statistics.Test.NonParametric
-module Tests.NonparametricTest (
- nonparametricTests
- ) where
-
-
-import qualified Data.Vector.Unboxed as U
-import Test.HUnit (assertEqual)
-import Test.Framework
-import Test.Framework.Providers.HUnit
+module Tests.NonParametric (tests) where
+import Statistics.Distribution.Normal (standard)
+import Statistics.Test.KolmogorovSmirnov
import Statistics.Test.MannWhitneyU
import Statistics.Test.WilcoxonT
-
-import Tests.Helpers
-import Tests.NonparametricTest.Table
-
-import Statistics.Test.KolmogorovSmirnov
-import Statistics.Distribution.Normal (standard)
-
+import Test.Framework (Test, testGroup)
+import Test.Framework.Providers.HUnit
+import Test.HUnit (assertEqual)
+import Tests.Helpers (eq, testAssertion, testEquality)
+import Tests.NonParametric.Table (tableKSD, tableKS2D)
+import qualified Data.Vector.Unboxed as U
-nonparametricTests :: Test
-nonparametricTests = testGroup "Nonparametric tests"
- $ concat [ mannWhitneyTests
- , wilcoxonSumTests
- , wilcoxonPairTests
- , kolmogorovSmirnovDTest
- ]
+tests :: Test
+tests = testGroup "Nonparametric tests"
+ $ concat [ mannWhitneyTests
+ , wilcoxonSumTests
+ , wilcoxonPairTests
+ , kolmogorovSmirnovDTest
+ ]
----------------------------------------------------------------
@@ -177,14 +170,14 @@ kolmogorovSmirnovDTest =
]
where
toU = U.fromList
- -- Test data for the calculation of cumulative probability
+ -- Test data for the calculation of cumulative probability
-- P(D[n] < d).
- --
+ --
-- Test data is:
-- (D[n], n, p)
-- Table is generated using sample program from paper
testData :: [(Double,Int,Double)]
- testData =
+ testData =
[ (0.09 , 3, 0 )
, (0.2 , 3, 0.00177777777777778 )
, (0.301 , 3, 0.116357025777778 )
11 tests/Tests/NonparametricTest/Table.hs → tests/Tests/NonParametric/Table.hs
View
@@ -1,12 +1,15 @@
-module Tests.NonparametricTest.Table where
+module Tests.NonParametric.Table (
+ tableKSD
+ , tableKS2D
+ ) where
-- Table for Kolmogorov-Smirnov statistics for standard normal
-- distribution. Generated using R.
--
-- First element of tuple is D second is sample for which it was
--- calculated.
+-- calculated.
tableKSD :: [(Double,[Double])]
-tableKSD =
+tableKSD =
[ (0.2012078,[1.360645,-0.3151904,-1.245443,0.1741977,-0.1421206,-1.798246,1.171594,-1.335844,-5.050093e-2,1.030063,-1.849005,0.6491455,-0.7028004])
, (0.2569956,[0.3884734,-1.227821,-0.4166262,0.429118,-0.9280124,0.8025867,-0.6703089,-0.2124872,0.1224496,0.1087734,-4.285284e-2,-1.039936,-0.7071956])
, (0.1960356,[-1.814745,-0.6327167,0.7082493,0.6264716,1.02061,-0.4094635,0.821026,-0.4255047,-0.4820728,-0.2239833,0.648517,1.114283,0.3610216])
@@ -33,4 +36,4 @@ tableKS2D =
, (0.1833333,[1.376196,9.926384e-2,2.199292,-2.04993,0.5585353,-0.4812132,0.1041527,2.084774,0.71194,-1.398245,-4.458574e-2,1.484945,-1.473182,1.020076,-0.7019646,0.2182066,-1.702963,-0.3522622,-0.8129267,-0.6338972],[-1.020371,0.3323861,1.513288,0.1958708,-1.0723,5.323446e-2,-0.9993713,-0.7046356,-0.6781067,-0.4471603,1.512042,-0.2650665,-4.765228e-2,-1.501205,1.228664,0.5332935,-0.2960315,-0.1509683])
, (0.5666667,[0.7145305,0.1255674,2.001531,0.1419216],[2.113474,-0.3352839,-0.4962429,-1.386079,0.6404667,-0.7145304,0.1084008,-0.9821421,-2.270472,-1.003846,-0.5644588,2.699695,-1.296494,-0.1538839,1.319094,-1.127544,0.3568889,0.2004726,-1.313291,0.3581084,0.3313498,0.9336278,0.9850203,-1.309506,1.170459,-0.7517466,-1.771269,0.7156381,-1.129691,0.877729])
, (0.5,[0.6950626,0.1643805,-0.3102472,0.4810762,0.1844602,1.338836,-0.8083386,-0.5482141,0.9532421,-0.2644837],[7.527945,-1.95654,1.513725,-1.318431,2.453895,0.2078194,0.7371092,2.834245,-2.134794,3.938259])
- ]
+ ]
16 tests/Tests/Transform.hs
View
@@ -6,17 +6,17 @@ module Tests.Transform
tests
) where
-import Data.Bits ((.&.), shiftL)
-import Data.Complex (Complex((:+)))
-import Data.Functor ((<$>))
+import Data.Bits ((.&.), shiftL)
+import Data.Complex (Complex((:+)))
+import Data.Functor ((<$>))
import Numeric.Sum (kbn, sumVector)
-import Statistics.Function (within)
-import Statistics.Transform
-import Test.Framework (Test, testGroup)
+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.QuickCheck (Positive(..), Property, Arbitrary(..), Gen, choose, vectorOf, printTestCase)
-import Tests.Helpers
-import Text.Printf
+import Tests.Helpers (testAssertion)
+import Text.Printf (printf)
import qualified Data.Vector.Generic as G
import qualified Data.Vector.Unboxed as U
23 tests/tests.hs
View
@@ -1,15 +1,14 @@
-import Test.Framework (defaultMain)
-
-import Tests.Distribution
-import Tests.NonparametricTest
-import qualified Tests.Transform
-import qualified Tests.Function
-import qualified Tests.KDE
+import Test.Framework (defaultMain)
+import qualified Tests.Distribution as Distribution
+import qualified Tests.Function as Function
+import qualified Tests.KDE as KDE
+import qualified Tests.NonParametric as NonParametric
+import qualified Tests.Transform as Transform
main :: IO ()
-main = defaultMain [ distributionTests
- , nonparametricTests
- , Tests.Transform.tests
- , Tests.Function.tests
- , Tests.KDE.tests
+main = defaultMain [ Distribution.tests
+ , Function.tests
+ , KDE.tests
+ , NonParametric.tests
+ , Transform.tests
]
Please sign in to comment.
Something went wrong with that request. Please try again.