Skip to content

Commit

Permalink
Gibbs: Add simple gibbs sampler
Browse files Browse the repository at this point in the history
  • Loading branch information
bgamari committed May 17, 2013
1 parent ecf4055 commit 0ce3855
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
24 changes: 24 additions & 0 deletions BayesStack/Gibbs/Simple.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{-# LANGUAGE TypeFamilies, FlexibleInstances, FlexibleContexts, GADTs, CPP #-}

module BayesStack.Gibbs.Concurrent ( gibbsUpdate
, module BayesStack.Gibbs
) where

import BayesStack.Gibbs
import Control.Monad.State hiding (lift)
import Control.DeepSeq
import Data.Random
import Data.Random.Lift
import System.Random.MWC

updateUnit :: WrappedUpdateUnit ms -> StateT ms RVar ()
updateUnit (WrappedUU unit) = do
ms <- get
let s = fetchSetting unit ms
s' <- lift $ evolveSetting ms unit
(s,s') `deepseq` return ()
put $ updateSetting unit s s' ms

gibbsUpdate :: ms -> [WrappedUpdateUnit ms] -> IO ms
gibbsUpdate modelState units = withSystemRandom $ asGenIO $ \mwc->
runRVar (execStateT (mapM_ updateUnit units) modelState) mwc
1 change: 1 addition & 0 deletions bayes-stack.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ source-repository head
Library
Exposed-modules: BayesStack.Types,
BayesStack.Gibbs, BayesStack.Gibbs.Concurrent,
BayesStack.Gibbs.Simple,
BayesStack.DirMulti, BayesStack.Dirichlet,
BayesStack.UniqueKey,
BayesStack.TupleEnum,
Expand Down

0 comments on commit 0ce3855

Please sign in to comment.