有人用过Passage ,并行采样器发生器?
它可能对我非常有用,但我找到的唯一文档是 Github 上的三行自述文件 (https://github.com/cscherrer/passage) 和 Hackage 上的简洁 API。
如果有一个关于如何运行它的简单示例就太好了!
最佳答案
在较高层面上,Passage 有两个重要的 monad 需要记住:BayesianNetwork
和 BayesianSimulator
。
首先,在 BayesianNetwork monad 中构建一个模型:
myModel :: Int -> BayesianNetwork (Node, Node, [Node])
myModel n = do
mu <- normal 0 0.001
tau <- improperScale
xs <- replicateM n $ normal mu tau
return (mu, tau, xs)
这被指定为生成模型,因此任何非随机的东西(此处为数据点的数量n
)都必须作为参数传递。或者,我们可以在 n
上进行分发。
接下来,我们构建一个调用模型的模拟器:
mySim :: [Double] -> BayesianSimulator ()
mySim xs0 = do
setThreadNum 4
let n = length xs0
(mu, tau, xs) <- model $ myModel n
forM (zip xs xs0) $ \(x, x0) -> observe x x0
monitor mu
monitor tau
最后,获取一些数据:
xs0 = [1, -1, 2, 2, 2, -2]
并运行模拟器:
main = genSimulator "myExample" (mySim xs0)
这将创建一个新目录 myExample
,其中包含采样器的 OpenMP 代码。
关于statistics - channel : usage example,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9785416/