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

Updated


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 (new version), R, C++ (now independent of GSL), C (native stand alone), MatLab and NEW now also in Julia, 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: http://projecteuclid.org/euclid.ba/1340218339



The implementations:


NEW! R implementation:

After a while of being removed from the CRAN, with a very generous and clever contribution by Rodrigo Villa, from Rio Grande do Sul, Brasil, a new implementation of the twalk in R is now available: https://cran.r-project.org/web/packages/Rtwalk/index.html

Although it has the same name as before, Rtwalk, it is a brand new implementation that Rodrigo did from scratch, specially using modern R coding techniques. I am deeply grateful for this.









Python implementation:

The Python implementation is a standard Python package.  It is "pure" Python, therefore is platform independent.  It requires the numpy and scypy package and, optionally, the pylab package as well for some basic plotting methods.  
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 onwards
version is now for Python 3.

pytwalk for Python 3, the previous version in Python 2 will no longer be maintained. For the plotting auxiliary method PlotMarg (previously Hist, but still available) 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 matplotlib.pylab in Python 3 also.


From version 1.5 uses matplotlib.pylab instead of pylab, backward compatible and has a “silent” parameter, to silent all information messages.

In version 1.6 a bugg was found by Felipe Medina in the GHopU function of the Hop move. The hop move is now active again.

NEW!

From version 1.7, the plotting methods now are based on using an Axes instance (using subplots). Three new derived classes are included: pyPstwalk, Ind1Dsampl and BUQ. These help for Bayesian Posterior Sampling, including logprior, loglikelihood, new plotting aids, like using parameter names, a corner plot etc.

The new installation procedure is used, using pip. Download the .whl file below (WARNING! Some browsers, or browser settings, think a this file is potentially harmful and may block the download, maybe because it is a binary file. I created this file using pip, and installs the pytwalk program in your computer, it is not harmful at all!):

This is the standard Python wheel: pytwalk-2.0.1-py3-none-any.whl

And in a terminal install it with:

pip install pytwalk-2.0.1-py3-none-any.whl

If you have any previous twalk installation, you will need to do:

pip install --ignore-install pytwalk-2.0.1-py3-none-any.whl



See the new pytwalktutorial2.py new functionalities, new examples and easy to do Bayesian inference !!!!! But is the same algorithm.







C/C++ implementations:

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.

C++: cpptwalk.tar.gz 



The pure C implementation: Tony Begg <Tony.Begg at dataventures dot com> 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!

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



MatLab implementations:

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



Julia implementation:

Thanks to Nico Kuschinski we now have a Julia implementation of the twalk. From Julia directly install it from https://github.com/tuerda/JTwalk . See instructions within.





Updated: 05FEB2026.