Boost C++ Libraries: Ticket #1540: Poisson distribution very slow for large mean (and may also overflow). https://svn.boost.org/trac10/ticket/1540 <p> Joel Eidsath reports: </p> <p> The poisson_distribution code will fail for any mean larger than 750 or so (on my x86_64 machine). The problem is a comparison with exp(-_mean) which evaluates as zero right around there. </p> <p> The easiest fix is to operate with logs instead of exponents. I changed the operator() code to be something like this: </p> <p> <a class="missing wiki">RealType</a> product = <a class="missing wiki">RealType</a>(0); </p> <blockquote> <p> for(result_type m = 0; ; ++m) { </p> <blockquote> <p> product += log(eng()); if(product &lt;= -_mean) </p> <blockquote> <p> return m; </p> </blockquote> </blockquote> <p> } </p> </blockquote> <p> This also makes it possible to get rid of the init() function and the _exp_mean private member variable. </p> <p> A far better fix would be to use an algorithm other than Knuth's for this. Knuth's algorithm is simple, but O(n). </p> <p> References to better implementation methods include: </p> <ul><li>Numerical Recipes </li><li><a class="ext-link" href="http://statistik.wu-wien.ac.at/unuran"><span class="icon">​</span>http://statistik.wu-wien.ac.at/unuran</a> </li><li>"Non-Uniform Random Variate Generation" by Luc Devroye. Full text available for free at <a class="ext-link" href="http://cg.scs.carleton.ca/~luc/rnbookindex.html"><span class="icon">​</span>http://cg.scs.carleton.ca/~luc/rnbookindex.html</a> with Poisson covered in chapt 10 at <a class="ext-link" href="http://cg.scs.carleton.ca/~luc/chapter_ten.pdf"><span class="icon">​</span>http://cg.scs.carleton.ca/~luc/chapter_ten.pdf</a> starting p501. </li></ul> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/1540 Trac 1.4.3 John Maddock Thu, 27 Dec 2007 10:20:33 GMT <link>https://svn.boost.org/trac10/ticket/1540#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1540#comment:1</guid> <description> <p> And another reference: </p> <p> Ahrens, J.H. and Dieter, U. (1982). Computer generation of Poisson deviates from modified normal distributions. ACM Trans. Math. Software 8, 163-179. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Mon, 31 Dec 2007 09:39:18 GMT</pubDate> <title>cc changed https://svn.boost.org/trac10/ticket/1540#comment:2 https://svn.boost.org/trac10/ticket/1540#comment:2 <ul> <li><strong>cc</strong> <span class="trac-author">pbristow@…</span> added </li> </ul> <p> Similar overflow issues occur in the Boost.Math Poisson distribution PDF function: now fixed in SVN Trunk by calling gamma_p_derivative to do the hard work. </p> Ticket Steven Watanabe Sat, 30 May 2009 00:09:37 GMT component changed https://svn.boost.org/trac10/ticket/1540#comment:3 https://svn.boost.org/trac10/ticket/1540#comment:3 <ul> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">random</span> </li> </ul> Ticket Steven Watanabe Fri, 26 Mar 2010 23:08:44 GMT owner, status changed https://svn.boost.org/trac10/ticket/1540#comment:4 https://svn.boost.org/trac10/ticket/1540#comment:4 <ul> <li><strong>owner</strong> changed from <span class="trac-author">jsiek</span> to <span class="trac-author">Steven Watanabe</span> </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> <p> I'm working on new implementations of a couple distributions, but it's slow going. </p> Ticket Steven Watanabe Sun, 20 Jun 2010 03:31:31 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/1540#comment:5 https://svn.boost.org/trac10/ticket/1540#comment:5 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</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/63126" title="Better implementation of the poisson distribution. Fixes #1540.">[63126]</a>. </p> Ticket