0

I am looking for a programming language to accelerate performance of my Markov Chain Monte Carlo code. The code is written in Python and does not use any special MCMC libraries (like PyMC or Stan) - what I need is basically:

  • sampling random numbers (at least integers and from interval $[0,1]$)
  • optimization/minimization of a univariate function
  • basic math (no special matrix library needed, as necessary matrix operations can be rather easily implemented.)
  • Optionally: accessible input/output for files (like pd.read_csv), since this seems to be a major hurdle when switching to many languages - but this is optional.

The code then loops million of times or so over the same operations.

I have tried Julia - which is very straightforward when switching from Python, and it boosts performance at least by a factor of 2. Surprisingly, I had less success with Rust - it is slightly better than Python, but still behind Julia (I naïvely believed that a compiled language is inherently faster than an interpreted one. I suppose that an expert Rust programmer could make it work faster... but I am not there yet.)

What could be a good "second language" with these requirements? C/C++ seem like an obvious choice... or perhaps even Fortran? Or would one do better by using a specialized library (like PyMC, Stan, TensorFlow Probability - but I fear that adapting my model for such a package might be a hurdle)?

Related:
What to consider before learning a new language for data analysis?
Best languages for scientific computing

Roger V.
  • 119
  • 6

0 Answers0