summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryanOSullivan <>2010-10-11 03:58:29 (GMT)
committerLuite Stegeman <luite@luite.com>2010-10-11 03:58:29 (GMT)
commit36f7f3e079765544d8e64785350eaf64bac2c8cc (patch)
tree12421e78587807fd4c450e6aa0d75e6b8525f96e
parent97b8ffcd0711c75b27c76d5716e4a0f9f6690899 (diff)
version 0.8.0.30.8.0.3
-rw-r--r--README.markdown (renamed from README)37
-rw-r--r--Statistics/Distribution/Beta.hs51
-rw-r--r--Statistics/Distribution/LogNormal.hs81
-rw-r--r--Statistics/Distribution/Triangular.hs68
-rw-r--r--statistics.cabal9
5 files changed, 24 insertions, 222 deletions
diff --git a/README b/README.markdown
index db51ecf..c11bbb2 100644
--- a/README
+++ b/README.markdown
@@ -1,5 +1,4 @@
-Statistics: efficient, general purpose statistics
--------------------------------------------------
+# Statistics: efficient, general purpose statistics
This package provides the Statistics module, a Haskell library for
working with statistical data in a space- and time-efficient way.
@@ -8,8 +7,7 @@ Where possible, we give citations and computational complexity
estimates for the algorithms used.
-Performance
------------
+# Performance
This library has been carefully optimised for high performance. To
obtain the best runtime efficiency, it is imperative to compile
@@ -18,30 +16,37 @@ optimisation.
Suggested GHC options:
- -O -fvia-C -funbox-strict-fields
+ -O -funbox-strict-fields
To illustrate, here are the times (in seconds) to generate and sum 250
million random Word32 values, on a laptop with a 2.4GHz Core2 Duo
P8600 processor, running Fedora 11 and GHC 6.10.3:
- no flags 200+
- -O 1.249
- -O -fvia-C 0.991
+ no flags 200+
+ -O 1.249
+ -O -fvia-C 0.991
As the numbers above suggest, compiling without optimisation will
yield unacceptable performance.
-Get involved!
--------------
+# Get involved!
-Please feel welcome to contribute new code or bug fixes. You can
-fetch the source repository from here:
+Please report bugs via the
+[bitbucket issue tracker](http://bitbucket.org/bos/attoparsec/statistics).
-http://bitbucket.org/bos/statistics
+Master [Mercurial repository](http://bitbucket.org/bos/statistics):
+* `hg clone http://bitbucket.org/bos/statistics`
-Authors
--------
+There's also a [git mirror](http://github.com/bos/statistics):
-Bryan O'Sullivan <bos@serpentine.com>
+* `git clone git://github.com/bos/statistics.git`
+
+(You can create and contribute changes using either Mercurial or git.)
+
+
+# Authors
+
+This library is written and maintained by Bryan O'Sullivan,
+<bos@serpentine.com>.
diff --git a/Statistics/Distribution/Beta.hs b/Statistics/Distribution/Beta.hs
deleted file mode 100644
index b507357..0000000
--- a/Statistics/Distribution/Beta.hs
+++ /dev/null
@@ -1,51 +0,0 @@
-{-# LANGUAGE DeriveDataTypeable #-}
--- |
--- Module : Statistics.Distribution.Beta
--- Copyright : (c) 2010 Karamaan Group
---
--- The beta distribution.
-
-module Statistics.Distribution.Beta
- (
- BetaDistribution
- -- * Constructors
- , fromParams
- -- * Accessors
- , tridistA
- , tridistB
- , tridistC
- ) where
-
-import Control.Exception
-import Data.Generics
-import Foreign.C.Math.Double (gamma)
-import qualified Statistics.Distribution as D
-
-data BetaDistribution = BetaDist {
- alpha :: Double,
- beta :: Double
-} deriving (Eq, Read, Show, Typeable, Data)
-
-instance D.Distribution BetaDistribution where
- density (BetaDist a b) x = (gamma (a+b) / (gamma a * gamma b)) *
- (x**(a-1)) * ((1-x)**(b-1))
- {-# INLINE density #-}
- cumulative (BetaDist a b) x = undefined
- {-# INLINE cumulative #-}
- quantile (BetaDist a b) p = undefined
- {-# INLINE quantile #-}
-
-instance D.Variance BetaDistribution where
- variance (BetaDist a b) = (a * b) /
- ((a+b)^2 * (a + b + 1))
- {-# INLINE variance #-}
-
-instance D.Mean BetaDistribution where
- mean (BetaDist a b) = a / (a + b)
- {-# INLINE mean #-}
-
-fromParams :: Double -> Double -> BetaDistribution
-fromParams a b = assert (a > 0 && b > 0) (BetaDist a b)
-{-# INLINE fromParams #-}
-
-
diff --git a/Statistics/Distribution/LogNormal.hs b/Statistics/Distribution/LogNormal.hs
deleted file mode 100644
index 3b932a3..0000000
--- a/Statistics/Distribution/LogNormal.hs
+++ /dev/null
@@ -1,81 +0,0 @@
-{-# LANGUAGE DeriveDataTypeable #-}
--- |
--- Module : Statistics.Distribution.LogNormal
--- Copyright : (c) 2009 Karamaan Group
---
--- The lognormal distribution. This is the distribution of a random
--- variable whose logarithm is normally distributed.
-
-module Statistics.Distribution.LogNormal
- (
- LogNormalDistribution
- -- * Constructors
- , fromParams
- , standard
- ) where
-
-import Control.Exception (assert)
-import Data.Number.Erf (erf)
-import Data.Generics
-import Statistics.Constants (m_sqrt_2, m_sqrt_2_pi)
-import qualified Statistics.Distribution as D
-
--- | The lognormal distribution.
-data LogNormalDistribution = ND {
- mean :: {-# UNPACK #-} !Double
- , variance :: {-# UNPACK #-} !Double
- , ndPdfDenom :: {-# UNPACK #-} !Double
- , ndCdfDenom :: {-# UNPACK #-} !Double
- } deriving (Eq, Read, Show, Typeable, Data)
-
-instance D.Distribution LogNormalDistribution where
- density = density
- cumulative = cumulative
- quantile = quantile
-
-instance D.Variance LogNormalDistribution where
- variance = variance
-
-instance D.Mean LogNormalDistribution where
- mean = mean
-
-standard :: LogNormalDistribution
-standard = ND {
- mean = 0.0
- , variance = 1.0
- , ndPdfDenom = m_sqrt_2_pi
- , ndCdfDenom = m_sqrt_2
- }
-
-fromParams :: Double -> Double -> LogNormalDistribution
-fromParams m v = assert (v > 0)
- ND {
- mean = m
- , variance = v
- , ndPdfDenom = m_sqrt_2_pi * sv
- , ndCdfDenom = m_sqrt_2 * sv
- }
- where sv = sqrt v
-
-density :: LogNormalDistribution -> Double -> Double
-density d x = exp (-xm * xm / (2 * variance d)) / (x * ndPdfDenom d)
- where xm = log x - mean d
-
-cumulative :: LogNormalDistribution -> Double -> Double
-cumulative d x = (1 + erf ((log x-mean d) / ndCdfDenom d)) / 2
-
--- | This is the quantile function for the LogNormalDistribution.
-quantile :: LogNormalDistribution -> Double -> Double
-quantile d p = exp $ quantile' d p
-
--- | This is the quantile function for NormalDistribution.
-quantile' :: LogNormalDistribution -> Double -> Double
-quantile' d p
- | p < 0 || p > 1 = inf/inf
- | p == 0 = -inf
- | p == 1 = inf
- | p == 0.5 = mean d
- | otherwise = x * sqrt (variance d) + mean d
- where x = D.findRoot standard p 0 (-100) 100
- inf = 1/0
-
diff --git a/Statistics/Distribution/Triangular.hs b/Statistics/Distribution/Triangular.hs
deleted file mode 100644
index 0dd4f6b..0000000
--- a/Statistics/Distribution/Triangular.hs
+++ /dev/null
@@ -1,68 +0,0 @@
-{-# LANGUAGE DeriveDataTypeable #-}
--- |
--- Module : Statistics.Distribution.Triangular
--- Copyright : (c) 2010 Karamaan Group
---
--- The triangular distribution. This is the distribution of a random
--- variable with lower limit a, mode c and upper limit b.
-
-module Statistics.Distribution.Triangular
- (
- TriangularDistribution
- -- * Constructors
- , fromParams
- -- * Accessors
- , tridistA
- , tridistB
- , tridistC
- ) where
-
-import Data.Generics
-import qualified Statistics.Distribution as D
-
-data TriangularDistribution = TriDist {
- tridistA :: Double, -- min
- tridistB :: Double, -- max
- tridistC :: Double -- mode
-} deriving (Eq, Read, Show, Typeable, Data)
-
-instance D.Distribution TriangularDistribution where
- density (TriDist a b c) x
- | (a <= x) && (x <= c) = (2 * (x - a)) / ((b - a) * (c - a))
- | (c <= x) && (x <= b) = (2 * (b - x)) / ((b - a) * (b - c))
- | otherwise = 0
- {-# INLINE density #-}
-
- cumulative (TriDist a b c) x
- | a > x = 0
- | (a <= x) && (x <= c) = ((x - a) ^ 2) / ((b - a) * (c - a))
- | (c <= x) && (x <= b) = 1 - ((b - x) ^ 2) / ((b - a) * (b - c))
- | otherwise = 1
- {-# INLINE cumulative #-}
-
- quantile (TriDist a b c) p = calc ((c - a) / (b - a))
- where calc p0
- | p < p0 = sqrt ((b-a) * (c-a) * p) + a
- | p == p0 = c
- | otherwise = b - sqrt ((b-a) * (b-c) * (1-p))
- {-# INLINE quantile #-}
-
-instance D.Variance TriangularDistribution where
- variance (TriDist a b c) =
- (a^2 + b^2 + c^2 - (a*b) - (a*c) - (b*c)) / 18
- {-# INLINE variance #-}
-
-instance D.Mean TriangularDistribution where
- mean (TriDist a b c) = (a + b + c) / 3
- {-# INLINE mean #-}
-
-fromParams :: Double -> Double -> Double -> TriangularDistribution
-fromParams a b c
- | (c > b) || (c < a) = error $ "Triangular Distribution: Parameter " ++ (show c)
- ++ " is expected to be between the parameters "
- ++ (show a) ++ " and " ++ (show b) ++ "."
- | b < a = error $ "Triangular Distribution: Parameter " ++ (show b)
- ++ " is expected to be greater than parameter " ++ (show a) ++ "."
- | otherwise = TriDist a b c
-{-# INLINE fromParams #-}
-
diff --git a/statistics.cabal b/statistics.cabal
index 4d58d56..3d21647 100644
--- a/statistics.cabal
+++ b/statistics.cabal
@@ -1,5 +1,5 @@
name: statistics
-version: 0.8.0.2
+version: 0.8.0.3
synopsis: A library of statistical types, data, and functions
description:
This library provides a number of common functions and types useful
@@ -30,24 +30,21 @@ copyright: 2009, 2010 Bryan O'Sullivan
category: Math, Statistics
build-type: Simple
cabal-version: >= 1.6
-extra-source-files: README
+extra-source-files: README.markdown
library
exposed-modules:
Statistics.Autocorrelation
Statistics.Constants
Statistics.Distribution
- Statistics.Distribution.Beta
Statistics.Distribution.Binomial
Statistics.Distribution.ChiSquared
- Statistics.Distribution.Exponential
Statistics.Distribution.Gamma
Statistics.Distribution.Geometric
+ Statistics.Distribution.Exponential
Statistics.Distribution.Hypergeometric
- Statistics.Distribution.LogNormal
Statistics.Distribution.Normal
Statistics.Distribution.Poisson
- Statistics.Distribution.Triangular
Statistics.Function
Statistics.KernelDensity
Statistics.Math