measurable

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

commit c33b02c0089e2b2a2c2bfddf249ec1d386c69b17
parent 2c683db9f2d791dc8bf3e9bf6107f65844704dc2
Author: Jared Tobin <jared@jtobin.ca>
Date:   Mon, 21 Oct 2013 18:43:48 +1300

Add bizarre measure example.

Diffstat:
Msrc/Examples.hs | 18+++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/src/Examples.hs b/src/Examples.hs @@ -123,7 +123,7 @@ binomMeasure -> MeasureT Double m Int binomMeasure n p = fromMassFunction (return . binom p n) [0..n] --- | Note that we can handle all sorts of things that are densities w/respect +-- | Note that we can handle all sorts of things that have densities w/respect -- to counting measure. They don't necessarily have to have integral -- domains (or even have Ordered domains, though that's the case here). data Group = A | B | C deriving (Enum, Eq, Ord, Show) @@ -167,6 +167,22 @@ gaussianMixtureModel n observed g = do fromObservations samples +-- | A bizarre measure. +weirdMeasure + :: Fractional r + => [Group] + -> [Bool] + -> MeasureT r IO Bool +weirdMeasure [] acc = fromObservations acc +weirdMeasure (m:ms) acc + | m == A = do + j <- lift $ withSystemRandom . asGenIO $ uniform + k <- lift $ withSystemRandom . asGenIO $ uniform + if j + then weirdMeasure ms (k : acc) + else weirdMeasure ms acc + | otherwise = weirdMeasure ms acc + main :: IO () main = do let nng = normalNormalGammaMeasure 30 2 6 1 0.5