Question

Has anyone used Passage, the PArallel SAmpler GEnerator?

Potentially it could be very useful to me, but the only documentation I found is the three line README on Github (https://github.com/cscherrer/passage), and the terse API on Hackage.

A simple example of how to run it would be great!

Was it helpful?

Solution

At a high level, Passage has two important monads to keep in mind: BayesianNetwork and BayesianSimulator.

First, you build a model in the 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)

This is specified as a generative model, so anything that is not random (here the number of data points n) must be passed as a parameter. Alternatively, we could have put a distribution on n.

Next, we build a simulator that calls the model:

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

Finally, take some data:

xs0 = [1, -1, 2, 2, 2, -2]

and run the simluator:

main = genSimulator "myExample" (mySim xs0)

This creates a new directory myExample with OpenMP code for the sampler.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top