BayesReef: A Bayesian inference framework for pyReef-Core using MCMC methods

BayesReef: A Bayesian inference framework for pyReef-Core using MCMC methods

BayesReef: A Bayesian inference framework for pyReef-Core using MCMC methods


BayesReef is a framework for implementing Bayesian inference on the deterministic model, pyReef-Core. It simulates data from the pyReef-Core stratigraphic forward model (SFM) to generate samples which are used to approximate the posterior distribution parameters using a Markov Chain Monte Carlo (MCMC) method. BayesReef is used to quantify uncertainty in pyReef-Core predictions and estimate parameters in the form of a probability distribution.

BayesReef is capable of inference of reef core data from the perspective of the depth structure and the time structure of a core. Studies have shown that the software produces accurate parameter estimation and mean model prediction for two- and four-dimensional problems with pyReef-Core (Pall et al., unpublished).

MCMC methods

MCMC methods, when applied to numerical system models, are used to approximate the posterior distribution of a parameter of interest by randomly sampling in a probabilistic space via a random walk. The random walk generates a chain of samples that are dependent on the current step, but are independent of the previous steps in the chain. The MCMC random walk is designed to take adequately large samples in regions near the solutions of best fit in order to approximate the distribution of parameter values in a model. BayesReef uses the Metropolis-Hastings algorithm MCMC method, which allows for asymmetrical proposals.

MCMC methods are a trademark of a Bayesian inference approach, which is based on Bayes Rule:

Schematic representation of Bayes' rule by Stone, 2013

This formula encapsulates our prior beliefs about a parameter and the likelihood that a chosen parameter value explains the observed data. Combining the prior and likelihood distributions determine the posterior distribution, which tells us the parameter values that maximise the probability of the observed data.

To visualise the Metropolis-Hastings MCMC technique, an animation of an example is provided below (Huber, 2016).

Alt Text

Depth-based and time-based inference

BayesReef estimates the posterior distribution of parameters by comparing different forms of data extracted from pyReef-Core simulations. We have two methods of doing this.

Data about the depth structure or the time structure of a core can be used as a basis of comparison. The depth structure refers to which coralgal assemblage occurs at a given depth interval. The time structure of a core refers to which assemblage (or sediment) is deposited at each time interval over the course of the simulation time. Both perspectives on a reef drill core are presented in the title figure below.

Flowchart of BayesReef process. A fusion of multiple sources of data is used to create prior probability distributions on free parameters. Following this, BayesReef is initiated with a vector of free parameters are drawn from the prior. The MCMC sampler uses a Metropolis-Hastings (M-H) algorithm as a basis to accept or reject proposed samples. The sampler terminates when all the allocated samples have been assessed.


The code is available from our github page and can be obtained either from this page or using git clone

git clone

Download the prerequisite python packages provided in the installation.txt file.

Once donwloaded, navigate to the BayesReef folder and run the following command:

pip install -e /workspace/volume/pyReefCore/

Basic Usage

BayesReef is initiated from python scripts directly with Python 2.7.

To initiate BayesReef using either time-based or depth-based inference, navigate to the Testing folder.

cd BayesReef/Testing/

Within the Testing folder, there are two sub-directories: depth-based_likl which uses depth-based inferencea and time-based_likl which uses time-based inference. The main MCMC scripts within these folders are and

Set the number of iterates in main and initiate BayesReef using the command:


Tailored usage

The script offers parameterisation of 27 parameters, which include:

  • Population dynamics parameters
    • Malthusian parameter ε
    • The Assemblage Interaction Matrix (AIM) parameters αm and αs
  • Hydrodynamic flow exposure threshold parameters (for each assemblage)
    • fflow1
    • fflow2
    • fflow3
    • fflow4
  • Sediment imput exposure threshold parameters (for each assemblage)
    • fsed1
    • fsed2
    • fsed3
    • fsed4

The user may wish to run experiments with lesser free parameters. and are similar to the main MCMC scripts, but offer up to 4 parameters to allow for low-dimensional experiments with BayesReef.

With simple adjustments to, the user can parameterise any combination of those 27 parameters.

Other scripts in the BayesReef package include:

  • input_synth.xml defines the fixed parameters in pyReef-Core. For a greater discussion on pyReef-Core, visit the Github repository here.

  • creates a figure of marginal likelihood (1-D) of population dynamics parameters.

  • creates a figure of marginal likelihood (1-D) of environmental threshold parameters.

  • creates a figure of bivariate likelihood (3-D) of population dynamics parameters.

  • creates a figure of bivariate likelihood (3-D) of environmental threshold parameters.

  • simulates a iteration of pyReef-Core without the Bayesian inference framework.


This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this program. If not, see


If you come accross a bug or if you need some help compiling or using the code you can drop us a line at and


Dechnik, B. (2016) Evolution of the Great Barrier Reef over the last 130 ka: a multifaceted approach integrating palaeo ecological, palaeo environmental and chronological data from cores (Unpublished doctoral thesis). University of Sydney, Sydney, Australia 2006.

Huber, C. (2016). Introduction to Bayesian statistics, part 2: MCMC and the Metropolis–Hastings algorithm. [Blog] The Stata Blog. Available at: [Accessed 19 Jul. 2018].

Pall, J., Chandra, R., Azam, D., Salles, T., Webster, J.M. and Cripps, S. (unpublished). BayesReef: A Bayesian inference framework for modelling reef growth in response to environmental change and biological dynamics.

Stone, James. (2013). Bayes’ Rule: A Tutorial Introduction to Bayesian Analysis. 10.13140/2.1.1371.6801.