commit ce29df3c8c5d600f5bd7decefd2ba10b8d01d060 parent ba51e4e625f4c04d5b8cb65b7c7b17502409e274 Author: Jared Tobin <jared@jtobin.ca> Date: Thu, 2 Apr 2015 18:24:31 +1000 Add standard collection of measures. Diffstat:
M | measurable.cabal | | | 1 | + |
A | src/Measurable/Measures.hs | | | 49 | +++++++++++++++++++++++++++++++++++++++++++++++++ |
2 files changed, 50 insertions(+), 0 deletions(-)
diff --git a/measurable.cabal b/measurable.cabal @@ -42,6 +42,7 @@ library default-language: Haskell2010 exposed-modules: Measurable.Core + , Measurable.Measures , Measurable.Util other-extensions: diff --git a/src/Measurable/Measures.hs b/src/Measurable/Measures.hs @@ -0,0 +1,49 @@ + +module Measurable.Measures where + +import Measurable.Core +import Statistics.Distribution +import qualified Statistics.Distribution.Beta as Statistics +import qualified Statistics.Distribution.Binomial as Statistics +import qualified Statistics.Distribution.ChiSquared as Statistics +import qualified Statistics.Distribution.Gamma as Statistics +import qualified Statistics.Distribution.Exponential as Statistics +import qualified Statistics.Distribution.Normal as Statistics + +standard :: Measure Double +standard = fromDensityFunction pdf where + pdf = density Statistics.standard + +normal :: Double -> Double -> Measure Double +normal m s = fromDensityFunction pdf where + pdf = density $ Statistics.normalDistr m s + +logNormal :: Double -> Double -> Measure Double +logNormal m s = fmap exp (normal m s) + +exponential :: Double -> Measure Double +exponential r = fromDensityFunction pdf where + pdf = density $ Statistics.exponential r + +gamma :: Double -> Double -> Measure Double +gamma a b = fromDensityFunction pdf where + pdf = density $ Statistics.gammaDistr a b + +inverseGamma :: Double -> Double -> Measure Double +inverseGamma a b = fmap recip (gamma a b) + +chiSquare :: Int -> Measure Double +chiSquare k = fromDensityFunction pdf where + pdf = density $ Statistics.chiSquared k + +beta :: Double -> Double -> Measure Double +beta a b = fromDensityFunction pdf where + pdf = density $ Statistics.betaDistr a b + +binomial :: Int -> Double -> Measure Int +binomial n p = fromMassFunction pmf [0..n] where + pmf = probability $ Statistics.binomial n p + +bernoulli :: Double -> Measure Int +bernoulli = binomial 1 +