1

I would like to generate samples from a gamma distribution in c++. I am compiling my code on a supercomputer, which does not have an up-to-date version of g++ (nor can it be updated). I have written code which uses chrono and random to generate samples from a gamma distribution. Unfortunately, the version of g++ does not allow me to compile the code (I also cannot use the flags -std=c++11 or -std=c++0x). I also cannot use boost/TR1 as the compiler does not have it.

Other than going back to basics (generating gamma from a sum of exponentials etc.) is there another way that I can sample from this distribution? I am thinking of pure c++ rather than implementing MCMC.

Peter O.
  • 32,158
  • 14
  • 82
  • 96
ben18785
  • 356
  • 1
  • 5
  • 15
  • 3
    Can you use a text editor? Seriously, you're looking for library recommendations, and I can guarantee that you won't be satisfied with any answer, if you can't even Boost or TR1. I suppose you should just get cracking and come back if you get stuck with a concrete problem. – sehe Aug 26 '14 at 23:40
  • 3
    If you can generate a uniform sample you can generate a sample of any distribution with help of the [Inverse transform sampling](http://en.wikipedia.org/wiki/Inverse_transform_sampling) – CantTouchDis Aug 26 '14 at 23:50
  • 2
    You can have a look at http://luc.devroye.org/chapter_nine.pdf. It covers various rejection methods (in addition to special cases, and the basic sum of exponentials) – SleuthEye Aug 26 '14 at 23:55
  • Thanks. Yes, I suspect that I may have to use either inverse transform sampling or just go back to basics, starting with uniformly distributed pseudorandom numbers. If anyone has any other ideas though, they would be most appreciated! – ben18785 Aug 26 '14 at 23:58
  • Thanks SleuthEye by the way. That's a really nice link - I should be able to implement those easily! Thanks! – ben18785 Aug 27 '14 at 00:00
  • 1
    No problem. The whole book is available online if you need for future reference (http://luc.devroye.org/rnbookindex.html) – SleuthEye Aug 27 '14 at 00:04
  • Usually you can use the compiler available to you to compile a personal, more up-to-date version of the compiler and install it in your home directory. – T.C. Aug 27 '14 at 02:21
  • 1
    @CantTouchDis Not correct. If you think that's so, what is the inverse transform of the Gaussian distribution? The fact that it doesn't exist in closed form is why we use techniques such as Box-Muller, the polar method, or the ziggurat method to generate normals. – pjs Aug 27 '14 at 14:24
  • @pjs You are right and I should have mentioned that. But the article states that as well. – CantTouchDis Aug 27 '14 at 14:34

0 Answers0