Skip to content

mkleesiek/versatile-mcmc

Repository files navigation

versatile-mcmc

Build Status codecov

A lightweight and extensible Markov Chain Monte Carlo (MCMC) library written in modern C++.

Introduction

With this project I aim at building a modular and easy to integrate C++ framework for performing Bayesian inference and mathematical optimization tasks in high-dimensional models.

While there are several MCMC algorithms available for the software environment R, similar options for the C++ language, which often is the first choice in scientific high-performance computings, are limited (you should definitely have a look at BAT though).

In order to allow for a future proof and robust code base with intuitive extensibility and good integrability of the library into existing C++ projects, I'd like to meet the following design criteria:

  • Limited use of 3rd party libraries for better maintainability and control of dependencies.
    • The only mandatory requirement for now are the Boost C++ libraries. Most of them are peer-reviewed, well documented and follow decent style guidelines. Especially the numeric, linear algebra and statistical utilities are extremely helpful in the start of this project.
    • Although popular among nature scientists, I have ruled out to interface with ROOT. It is a huge dependency bringing a whole data analysis ecosystem along with it. Also, its API holds a rather questionable standing in terms of style and consistency.
  • Modern object-oriented C++11 style with dashes of functional programming and templating magic where justifiable.
  • Thread-safety to make way for multi-core parallelization.
  • Unit testing (Google Test) and code annotations (Doxygen).

Status

  • Build system, unit testing and continuous integration set up.
  • Numeric + logging utilities and random number generator interfaces implemented.
  • Basic classes and interfaces for proposal functions and samplers declared.
  • First running example for a simple Metropolis-Hastings (MH) algorithm.

Next items on my todo list

  • Automatic error control / step size adjustment for the MH algorithm.
  • More export / output options.
  • Hamiltonian / self-adjusting sampling algorithms.
  • Real-time visualization of chain evolutions might be neat:

Real-time chain evolution on GnuplotReal-time chain evolution on Gnuplot

Supported compilers and operating systems

Essentially, all C++11 compliant compilers should work. Currently the build is being tested on Travis CI using the following OS/compiler combinations:

  • Ubuntu Trusty (14.04)
    • g++ 4.8.4
    • g++ 5.3.0
    • g++ 6.1.1
    • clang++ 3.5
    • clang++ 3.9
  • OS X El Capitan (10.11.5)
    • Xcode (clang) 7.3
    • Xcode (clang) 8.0

Prerequisits

On Debian-based systems simply use apt-get:

sudo apt-get install meson ninja libboost-all-dev doxygen libtbb-dev libgtest-dev 

If meson is not provided by your package manager, you can use the python 3 installer:

pip3 install meson

Quick Installation

  • Setup meson in an out-of-source build directory (e.g. a subdirectory in the source root):
cd versatile-mcmc
mkdir build
cd build
meson .. [--prefix=/install/dir] [--buildtype=(plain|debug|debugoptimized|release)]
  • Use mesonconf to revise or modify your configuration:
mesonconf .
  • Both meson(.py) and mesonconf(.py) offer decent command-line help if executed with the option --help.
  • To compile the code, execute ninja in the build directory:
ninja [-v]
  • Install:
ninja install
  • Run unit tests:
ninja test
  • Generate source documentation (requires doxygen):
ninja doc

Getting Started

See the example in src/vmcmc-example.cpp on how to invoke a Metropolis-Hastings sampler on a custom likelihood function and write the sampled points to text files.

About

A modular Markov Chain Monte Carlo C++ library for Bayesian inference applications.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages