deanie

An embedded probabilistic programming language.
git clone git://git.jtobin.io/deanie.git
Log | Files | Refs | README | LICENSE

MixtureImportance.hs (546B)


      1 
      2 module Main where
      3 
      4 import Control.Monad
      5 import Deanie
      6 import Model.Mixture as Model
      7 
      8 logDensity :: Bool -> Double -> Double
      9 logDensity accept x
     10   | accept    = logDensityGaussian (negate 2) 0.5 x
     11   | otherwise = logDensityGaussian 2 0.5 x
     12 
     13 posterior :: Program (Double, Bool)
     14 posterior = importance Model.observations (bernoulli 0.5) logDensity
     15 
     16 main :: IO ()
     17 main = do
     18   samples <- replicateM 1000 (sample (rvar posterior))
     19   mapM_ print samples
     20 
     21   putStrLn "\nestimate:"
     22   print (mcw (fmap (\(w, x) -> if x then (w, 1) else (w, 0)) samples))
     23