Boost C++ Libraries: Ticket #3888: Generation of two-parameter Gamma variates https://svn.boost.org/trac10/ticket/3888 <p> Actually, the code used to generate random Gamma variates cannot be used to generate variates for two-parameters Gamma distributions, that is for Gamma distributions with both shape and scale parameters (e.g., see <a class="ext-link" href="http://en.wikipedia.org/wiki/Gamma_distribution"><span class="icon">​</span>http://en.wikipedia.org/wiki/Gamma_distribution</a> or <a class="ext-link" href="http://www.itl.nist.gov/div898/handbook/eda/section3/eda366b.htm"><span class="icon">​</span>http://www.itl.nist.gov/div898/handbook/eda/section3/eda366b.htm</a>). </p> <p> In principle this should be possible by means of the <em>scaling property</em>: <strong>Gamma(shape,scale) ~ scale*Gamma(shape,1)</strong> </p> <p> This would simply translate into </p> <pre class="wiki">boost::mt19937 rng; boost::gamma_distribution&lt;&gt; gamma(shape); // 1-parameter Gamma distribution boost::variate_generator&lt; boost::mt19937&amp;, boost::gamma_distribution&lt;&gt; &gt; rvg(rng, gamma); double r = scale*rvg(); </pre><p> However, when <em>shape == 1</em> the implementation uses the fact that <strong>Gamma(1) ~ Exp(1)</strong>. This is rigth when <em>scale==1</em> but not when <em>scale != 1</em> since the exact relation is <strong>Gamma(1,scale) ~ Exp(1/scale)</strong> </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/3888 Trac 1.4.3 Marco Guazzone <marco.guazzone@…> Tue, 02 Feb 2010 09:32:53 GMT <link>https://svn.boost.org/trac10/ticket/3888#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3888#comment:1</guid> <description> <p> R provides a possible implementation: </p> <p> <a class="ext-link" href="https://svn.r-project.org/R/trunk/src/nmath/rgamma.c"><span class="icon">​</span>https://svn.r-project.org/R/trunk/src/nmath/rgamma.c</a> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Steven Watanabe</dc:creator> <pubDate>Tue, 22 Jun 2010 16:12:30 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3888#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3888#comment:2</guid> <description> <p> Might I point out that <strong>Exp(1/scale) ~ scale*Exp(1)</strong>. In fact this is how Exp is implemented anyway. We probably lose slightly less accuracy by multiplying. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Steven Watanabe</dc:creator> <pubDate>Tue, 22 Jun 2010 20:31:13 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/3888#comment:3 https://svn.boost.org/trac10/ticket/3888#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Fixed in <a class="changeset" href="https://svn.boost.org/trac10/changeset/63247" title="Sync gamma_distribution with C++0x. Fixes #3888.">[63247]</a>. </p> Ticket