measurable

A simple shallowly-embedded DSL for dealing with measures.
Log | Files | Refs | README | LICENSE

commit a7c1e1d51a04dc7662e3ab2a68782bcf28f099ff
parent 0cf141f5be8c12186bb4bb41ed8c36a1015a83a6
Author: Jared Tobin <jared@jtobin.ca>
Date:   Sun, 20 Oct 2013 00:17:55 +1300

Minor cleanup of examples.

Diffstat:
Mtests/Test.hs | 14+++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/tests/Test.hs b/tests/Test.hs @@ -1,6 +1,4 @@ -- Simple examples that demonstrate some measure-fu. --- --- These have become pretty thrown together. Need to clean them up. import Control.Applicative import Control.Monad @@ -21,16 +19,21 @@ betaBinomialConjugate a b n = do p <- betaMeasure a b binomMeasure n p +-- | Workhorse densities. standardNormal = density $ normalDistr 0 1 genLocationNormal m = density $ normalDistr m 1 basicBeta a b = density $ betaDistr a b + +-- | A beta measure. betaMeasure a b = fromDensity $ basicBeta a b +-- | A binomial mass function. binom p n k | n <= 0 = 0 | k < 0 = 0 | n < k = 0 | otherwise = n `choose` k * p ^ k * (1 - p) ^ (n - k) +-- | Binomial measure. binomMeasure n p = fromMassFunction (\x -> binom p n (truncate x)) (map fromIntegral [0..n] :: [Double]) @@ -53,10 +56,6 @@ main = do putStrLn $ "let X ~ N(0, 1), Y ~ observed. mean of exp(cos X + sin Y): " ++ show (expectation eta) - putStrLn "" - putStrLn "and now some 'woah, this actally seems to make sense' examples:" - putStrLn "" - -- Subtraction of measures? let iota = mu - mu @@ -100,7 +99,8 @@ main = do putStrLn "Creating from a mass function:" putStrLn "" - let kappa = fromMassFunction (\x -> binom 0.5 10 (truncate x)) [0..10] + + let kappa = binomMeasure 10 0.5 putStrLn $ "let X ~ binom(10, 0.5). mean of X (should be 5): " ++ show (expectation kappa)