The t-walk software
J. Andres Christen and Colin Fox
CIMAT, Mexico, and U. of Otago, New Zealand.


The t-walk is a "A General Purpose Sampling Algorithm for Continuous Distributions" to sample from many objective functions (specially suited for posterior distributions using non-standard models that would make the use of common algorithms and software difficult); it is an MCMC that does not required tuning.  However, as mentioned in the paper, it may not perform well in some examples and fine tuned samplers to specific objective densities should perform better than the t-walk.

It is now implemented in Python, R, C++, C (native stand alone) and MatLab, see below.

Please cite the paper when you use the twalk:

Christen, J.A. and Fox, C. (2010), "A General Purpose Sampling Algorithm for
Continuous Distributions (the t-walk)",
Bayesian Analysis, 5(2), 263-282.

The paper is available online at:

The implementations:

The R version:

Thanks to the very generous help of Dr Alireza Mahani <alireza dot s dot mahani at gmail dot com>, correcting many errors and pitfalls in the design of the package, the R version is now in the CRAN (however, no modifications were done regarding the numerical algorithms, so in that respect it is exactly the same as in the previous version). Please use the CRAN to download the Rtwalk package.

The Rtwalk is now a standard R package and has been recompiled for R 3.+ . Version 3 of R is not backwards compatible and requires all packages to be recompiled.  Please install this new version.

The Python version is also a standard Python package.  It is "pure" Python, therefore is platform independent.  It requires the ScyPy package and, optionally, the PyLab package as well for some basic plotting methods.  Download the ziped file and follow the README instructions within. 
My students Diego Andrés Pérez and Mario Santana found a small mistake in the calculation of the IAT in the Python version.  Now this is corrected in the pytwalk version 1.2.

The 1.4 version is now for Python 3.

The C++ implementation has only been compiled in Linux and Mac OS, but most likely will compile in many other Unix flavor OS's.  It requires the GNU scientific library, gsl.  Download the ziped file and follow the README instructions within.  Tony Begg found two small buggs, which are corrected in this new version.

NEW: Now the C++ version does not need the GSL library anymore, as the pure C version. For backwards compatibility you can still used the gsl library if needed. I also changed the .c extensions to .cpp . 14 AGO 2019.

The pure C version Tony Begg has done a very handy, stand alone (does not require the gsl or any other special library), single file, Open Source, pure C version of the t-walk!

MatLab: The Matlab implementation of the twalk was coded by Colin Fox, with a bug correction by Andreas Nilsson. See instructions within the file. As opposed to the other implementations, this one needs log of the posterior (not minus log post) and should return -inf for a point outside the support (no “Supp” function is required): mtwalk.m

Oscar Alberto Rodríguez-Melendez created a new version without the parameter “p” to be passed to the logTarget. It also includes an example (commented inside the file). Therefore this new version is not backwards compatible, but is more user friendly: mtwalk2.m


Download and install the Rtwalk package from the CRAN, then start with:

> rm(list=ls(all=TRUE))

> library(Rtwalk) ## and follow the online help:

> help(Rtwalk) ## or with help.start() and look for the Rtwalk package in your browser

Also see the examples.R for more help.

Python: NEW Now I have pytwalk for Python 3, the previous version in Python 2 will no longer be maintained. For the plotting auxiliary method Hist the normed is depreciated in Python 3 and is no longer used, use density instead. The functionality is as in the hist function of pylab. Everything else is the same, only now for Python 3. Note, you need numpy, scipy and pylab in Python 3 also. It is Python 3.6.

This is a standard Python module: pytwalk-1.4.4.tar.gz

Download the for examples.  (21AGO2018)

The old Python 2 version is: pytwalk-1.3.2.tar.gz 

C++: cpptwalk.tar.gz 

C: Ctwalk.tar.gz See the main() function for an example.

If you have any troubles or comments please contact (me) Andres <jac at cimat dot mx> for the Python, R and C++ versions and Colin <fox at physics dot otago dot ac dot nz> for the MatLab version and Tony Begg <Tony.Begg at dataventures dot com> for the C example.

Updated: 14AGO2019.