DIY Markov Chains.
What is this
This package presents a simple combinator language for Markov transition operators that are useful in MCMC.
Any transition operators sharing the same stationary distribution and obeying the Markov and reversibility properties can be combined in a couple of ways, such that the resulting operator preserves the stationary distribution and desirable properties amenable for MCMC.
We can deterministically concatenate operators end-to-end, or sample from a collection of them according to some probability distribution. See Geyer, 2005 for details.
The result is a simple grammar for building composite, property-preserving transition operators from existing ones:
transition ::= primitive <transition> | concatT transition transition | sampleT transition transition
Markov chains can then be run over arbitrary
Targets using whatever
transition operator is desired.
import Numeric.MCMC import Data.Sampling.Types target :: [Double] -> Double target [x0, x1] = negate (5 *(x1 - x0 ^ 2) ^ 2 + 0.05 * (1 - x0) ^ 2) rosenbrock :: Target [Double] rosenbrock = Target target Nothing transition :: Transition IO (Chain [Double] b) transition = concatT (sampleT (metropolis 0.5) (metropolis 1.0)) (sampleT (slice 2.0) (slice 3.0)) main :: IO () main = withSystemRandom . asGenIO $ mcmc 10000 [0, 0] transition rosenbrock
Installing is best done via stack, which will pull down everything you might need (including GHC).
$ stack install declarative
If you want to grab the test suite/examples, grab the repo and build via
git clone email@example.com:jtobin/declarative.git cd declarative stack build
You can then run the test suite via
Documentation & Examples
Check out the haddock-generated docs on Hackage.
You can also peruse the introductory announce post.
PRs and issues welcome.