A Python implementation of EP-ABC for likelihood-free, probabilistic inference.
This implementation requires Python 3.
Clone the repository and use the Python setuptools to install
pyEPABC, e.g. in the created directory call:
python setup.py install
For the DDM-example below to work, installation is a bit more complicated, see the example for further details.
examples-folder contains two examples demonstrating the usage of
testDDM. Instructions for how to run these
Simple Gaussian example
This example compares EPABC to an analytic solution for the simplest case you can imagine: Estimating the mean of some data points. The simplicity of the problem allows that the posterior distribution and log marginal likelihood can be computed analytically so that the EP-ABC estimates can be compared to that.
I assume that you have downloaded (or cloned) the pyEPABC git-project into a
pyEPABC_git. To run this example open an ipython shell and navigate
import pyEPABC run testGauss
You can change parameters of EP-ABC, or the problem, e.g., the dimensionality of
the data points, in
testGauss.py to investigate the behaviour of EP-ABC.
This examples requires: numpy, scipy, pandas, matplotlib.
Drift-diffusion model example
This example fits a drift-diffusion model (DDM) to an example data set consisting of reaction times and choices recorded in a psychophysics experiment. The results are compared to the results produced by HDDM.
Additional to showing the working of EP-ABC on this kind of problem, this example also demonstrates how pyEPABC can be integrated with simulation functions implemented in C. The idea is that your simulation function is provided by an externally compiled shared library. This example shows how you can link this code for use in pyEPABC. Note that, if you are implementing a new model, i.e., simulation function, from scratch you may want to consider alternatives for this pure-C path. See the section on Binary Extensions in the Python Packaging User Guide for further information.
Before you can run the example you need to compile a few things. I'll only
explain how to do this in Linux. First, compile the 'external' library which
will provide super-fast simulations from a DDM. Do this by opening a shell and
navigating to the
pyEPABC_git/src folder. There run:
mkdir ../lib gcc -shared -fPIC -O3 -lc -o ../lib/libDDMsampler.so DDMsampler.c brownian_motion_simulation.c
which will place the resulting shared library into
compile the Python-C-interface:
python setup.py build_ext -i -useC
which will generate another shared library
depend on your python setup. This library can be directly imported into python
as a module, as done in
testDDM.py. To run the example open an ipython shell,
navigate to the
pyEPABC_git folder and execute:
import pyEPABC run examples/testDDM
This example requires: numpy, scipy, pandas, matplotlib, seaborn, cython, hddm.
EP-ABC sometimes produces too narrow posteriors. See
examples/narrow_posteriors.ipynb for an explanation, how to identify this
issue and how to prevent it.