-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters