template<class RealType = real>
class gmx::GammaDistribution< RealType >
Gamma distribution.
The C++ standard library does provide a gamma distribution, but when using libstdc++-4.4.7 with at least gcc-4.6 the headers produce errors. Even for newer compilers, libstdc++ and libc++ appear to use different algorithms to generate it, which means their values differ in contrast to the uniform and normal distributions where they are identical. To avoid both compiler bugs and make it easier to use GROMACS unit tests that depend on random numbers, we have our own implementation.
Be warned that the gamma distribution works like the standard normal distribution and keeps drawing values from the random engine in a loop, so you want to make sure you use a random stream with a very large margin to make sure you do not run out of random numbers in an unlucky case (which will lead to an exception with the GROMACS default random engine).
The gamma distribution is defined as
In this definition, the parameter α is the so-called shape, while θ is so-called scale. This distribution will have the expectation value αθ, and the variance αθθ.
- Note
- The gamma distribution is sometimes defined in terms of a parameter β that is the inverse of θ (i.e., a rate rather than scale), while in other cases the parameter in the definition above is simply called β. We can't do a lot about these different definitions, so make sure you look at the expectation value and variance unless you are certain you are using e.g. scale or rate for the second parameter - do not trust that it e.g. rate just because it is called β in your equations.
-
For now, we generate the gamma distribution using the algorithm from Marsaglia G, Tsang WW (2000). ACM Trans. Math. Softw. 26(3), 363-372. DOI:10.1145/358407.358414
- Template Parameters
-
RealType | Floating-point type, real by default in GROMACS. |