#63 Gamma RNG

closed
itpp (51)
5
2012-09-15
2008-03-13
vasek
No

Sampler of the Gamma distribution is not available in IT++. The following code is a combination of IT++ style of doing RNG (I hope) with sampling method from the R-language.

The files are not complete (yet). I just want to get feedback if I am on the right track.

h- file:

Discussion

  • vasek
    vasek
    2008-03-13

     
    Attachments
  • vasek
    vasek
    2008-03-13

     
    Attachments
  • vasek
    vasek
    2008-03-13

    Logged In: YES
    user_id=1169711
    Originator: YES

    File Added: GRNG.h

     
  • Logged In: YES
    user_id=1004597
    Originator: NO

    Hi Vasek,

    Thanks for your contribution. I think that there is no point in reusing exactly the same (copy/paste) code of the sample() function as is in the R package (I mean by providing hacks to call std:: functions, etc.), but if you think so, I have no objections to follow such way. I hope this code is quite stable in R package, so we won't propagate bugs to IT++ from R.

    So, I would like you to work on this as follows:
    1) Get rid of the #define ... macros. I guess we can employ "using std::log;", "using std::isfinite;" etc. for this purpose.
    3) Include itpp/base/math/misc.h file in the *.cpp file. It is required for std::isfinite() on platforms where this function is not available. We can do this later after integrating your codes in random.{cpp,h}
    4) Provide sample() as a public method, like other random generators do.
    5) Please write some short documentation in Doxygen format what this generator produces.
    6) Please beautify the code with astyle formater (http://astyle.sourceforge.net/) using the following configuration options:
    indent=spaces=2
    brackets=linux
    brackets=break-closing
    indent-namespaces
    indent-labels
    pad=oper
    unpad=paren
    You can find the above settings in a file in the IT++ SVN repository (trunk, file: "extras/astylerc").
    7) Do not forget about preparing a simple test program. I think we should just extend the existing random_test.

    BR,
    /Adam

     
  • vasek
    vasek
    2008-03-17

    Logged In: YES
    user_id=1169711
    Originator: YES

    Hi Adam,
    I tried to follow your advices. The attached patch implements most of your points.
    The exceptions are:
    4) sample() is now public. Originally I copied it from Exponential_RNG which has sample() as private. Actually, it seems that more RNGs have it private than public.
    6) I tried both the svn and your version of astylerc (they are not the same) and in both cases the patch made by astyle was bigger that my contribution (using astyle 1.21). I tried to play with a setting of astyle but I did not manage to find one which did not modify the svn code. So, I guess, I would just submit the patch as it is, since it is easier to spot what have really changed.

    One minor issue:
    The original code in R use function expm1. It is available on linux but my colleagues had trouble compiling it on Win. So, I have changed it to exp()-1. Do you have any idea how to make it work on windows?

    Best,
    Vasek
    File Added: gammRNG.dif

     
  • vasek
    vasek
    2008-03-17

     
    Attachments
  • Logged In: YES
    user_id=1004597
    Originator: NO

    Hi Vasek,

    Thanks for your patch. It is now a part of the trunk in IT++ SVN repository. I only had to add a couple of "std::" scope rules before exp, fabs, and log functions.
    As for the expm1() function, I plan to introduce an additional check for it in configure and if it is not available a workaround in the form of (exp() - 1.0) will be used. IT++ use more of such portability tricks.

    Sorry about the noise related to astyle. You are right. At the moment the sources in our SVN repository haven't been processed yet with this tool, so my request to use it before creating the patch was unnecessary. But the issue is currently discussed among other developers, so in future we might use some more strict coding style in IT++.

    BR,
    /Adam