有人使用过Passage(并行采样器生成器)吗?
它对我来说可能非常有用,但我在Github上找到的唯一文档是三行的README(https://github.com/cscherrer/passage),以及Hackage上的简短API说明。
一个简单的运行示例将会非常有帮助!
回答:
从高层次来看,Passage有两个重要的单子需要注意:BayesianNetwork
和BayesianSimulator
。
首先,您在BayesianNetwork单子中构建模型:
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代码。