Markov chain Monte Carlo sampler

Sample from a posterior using Markov chain Monte Carlo (MCMC) algorithms.

At the moment, the following algorithms are available:

  • Metropolis-Hastings-Green 1;
  • Metropolis-coupled Markov chain Monte Carlo (also known as parallel tempering) 2 , 3.
  • Hamilton Monte Carlo proposal 4.


The source code contains detailed documentation about general concepts as well as specific functions.


Example MCMC analyses can be built with cabal-install or Stack and are attached to this repository.

git clone
cd mcmc
stack build

For example, estimate the accuracy of an archer with

stack exec archery

For a more involved example, have a look at the phylogenetic dating project.


1 Geyer, C. J., Introduction to Markov chain Monte Carlo, In Handbook of Markov Chain Monte Carlo (pp. 45) (2011). CRC press.

2 Geyer, C. J., Markov chain monte carlo maximum likelihood, Computing Science and Statistics, Proceedings of the 23rd Symposium on the Interface, (1991).

3 Altekar, G., Dwarkadas, S., Huelsenbeck, J. P., & Ronquist, F., Parallel metropolis coupled markov chain monte carlo for bayesian phylogenetic inference, Bioinformatics, 20(3), 407–415 (2004).

4 Neal, R. M., Mcmc Using Hamiltonian Dynamics, In S. Brooks, A. Gelman, G. Jones, & X. Meng (Eds.), Handbook of Markov Chain Monte Carlo (2011). CRC press.


Markov chain Monte Carlo sampling - ChangeLog

Unreleased changes

  • Remove dependency monad-parallel. Fix stackage build.

  • Improve logGammaG. The calculation of the gamma function involves vectors; the generalized version needs boxed vectors, and is slow. Using Typeable, we now check if the type is Double, and use the fast version in this case.

  • Improve leapfrog integrator.
  • Update tooling.
  • Cleanup proposals.

  • Revamp Hamiltonian proposal (storable vectors).
  • Use mass matrices; allow tuning of all masses (covariance estimation using specialized estimators).

  • Improve documentation.
  • Generalized priors allowing automatic differentiation.
  • Hamiltonian proposal.


  • Marginal likelihood estimation using thermodynamic integration or stepping stone sampling.
  • Various changes of function names (e.g., metropologis -> mhg).
  • Updated examples.
  • Proper but minimal logging framework.
  • Various other changes.

  • Greatly improve documentation.
  • Major design change: Introduction of the Algorithm type class; algorithms are data types. See MHG.
  • Metropolic-coupled Markov chain Monte Carlo algorithm (parallel chains).
  • Optimal acceptance rate depends on dimension of proposal.
  • Use a circular trace with constant memory usage (big change).
  • Therefore, batch monitors use vectors now.
  • Always save chain with complete trace (but with sensible length).
  • Determine necessary trace length at initialization.
  • Rename Item to Link.
  • Rename Status to Chain and separate Settings and Environment from the Chain.
  • Many bug fixes.


  • New shorter example/test for dating trees.
  • noData allows running a chain without likelihood function.
  • Give proposal parameters PName, PDescription, and PWeight newtype wrappers.
  • Give Tune a data type.
  • Allow periodical cleansing of state (Cleaner).
  • Add description string to proposals, so that they can be identified in an easier way.
  • Add simplices and proposals on simplices.
  • slideUniform renamed to slideUniformSymmetric.
  • Merge tools into internal.
  • Do not export internal modules.


  • Change order of arguments for proposals.
  • ’slideStem’ was renamed to ’slideBranch’.
  • Change ProposalSimple from newtype to type.
  • Contravariant instances of parameter and batch monitors. Use (>$<) instead of (@.) and (@#).
  • Add gammaDirichlet prior for partitioned dating analyses.


  • Contrary proposals.
  • Change how monitors are lifted (use normal function, not a lens).
  • Priors.
  • Remove concurrent monitors (was slow).
  • Improve MCMC sampler output.


  • Move away from hpack.


  • Consistently use ByteString instead of Text.
  • Verbosity levels.
  • Improved handling of proposals, moves, and monitors.
  • Bactrian moves.
  • Many small changes.


Many changes; notably it is now possible to continue a Markov chain run.