2

有没有人用过Passage,并行采样器生成器?

它可能对我非常有用,但我发现的唯一文档是 Github (https://github.com/cscherrer/passage) 上的三行 README,以及 Hackage 上的简洁 API。

一个简单的例子来说明如何运行它会很棒!

4

1 回答 1

2

在高层次上,Passage 有两个重要的 monad 需要牢记:BayesianNetworkBayesianSimulator.

首先,您在 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 代码的新目录。

于 2012-05-23T17:04:16.257 回答