Skip to content
Prev 201066 / 398502 Next

python

On Sat, Nov 21, 2009 at 2:29 PM, Jean Legeande <jean.legeande at gmail.com> wrote:
Have you done a profile of your MCMC code to see where the bottleneck
is? Without doing that first any effort could be a total waste of
time.

 R can do a lot of it's calculations at the same level as C, so if 80%
of your time is spent inverting matrices then converting to Python or
C (or even assembly language) isn't going to help much since R's
matrix inversion is done using C code (and quite possibly very
optimised C code with maybe some assembly language too).

 So do a profile (see ?Rprof) and work out the bottleneck. It might be
one of your functions, in which case just re-writing that in C and
linking to R (see programmers guide and a good C book) will do the
job.

 My hunch is that Python and R run at about the same speed, and both
use C libraries for speedups (Python primarily via the numpy package).

 You can call the GSL from Python, and there are probably tricks for
getting the distributions you want:

http://www.mailinglistarchive.com/help-gsl at gnu.org/msg00096.html

 describes how to get samples from a Wishart.

 However using the GSL from Python probably wont be much faster than
using R because again it's all at the C level already. Did I suggest
you profile your code?

Barry