Return-Path: Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: (qmail 89222 invoked from network); 13 Sep 2009 14:47:23 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 13 Sep 2009 14:47:23 -0000 Received: (qmail 70269 invoked by uid 500); 13 Sep 2009 14:47:23 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 70145 invoked by uid 500); 13 Sep 2009 14:47:22 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 70135 invoked by uid 99); 13 Sep 2009 14:47:22 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 13 Sep 2009 14:47:22 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 13 Sep 2009 14:47:19 +0000 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 93DE7234C045 for ; Sun, 13 Sep 2009 07:46:57 -0700 (PDT) Message-ID: <2027008890.1252853217579.JavaMail.jira@brutus> Date: Sun, 13 Sep 2009 07:46:57 -0700 (PDT) From: "Luc Maisonobe (JIRA)" To: issues@commons.apache.org Subject: [jira] Updated: (MATH-294) RandomDataImpl.nextPoisson fails for means in range 6.0 - 19.99 In-Reply-To: <912278699.1252690497652.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/MATH-294?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Luc Maisonobe updated MATH-294: ------------------------------- Attachment: math-294.patch The failure seems to be related with a wrong detection of out of bound cases. In the example given the failure occurs at iteration 125 on my computer (Open JDK 1.6, Linux, 64bits). At the beginning of the loop, the u = nextUniform(0.0, c) random drawing leads to a value u smaller than c1. So the first branch of the if is taken and another random drawing is done : z = nextGaussian(0.0, 1.0) which leads to a value for x far below mu (x = -8, mu = 2). This is detected as w is set to positive infinity, but in fact this is not sufficient. The "accept" boolean is still computed despite it will always be false. The attached patch is an attempt to compute "accept" only in some cases and to force it to "false" in other cases without computation. I did *not* check this in subversion because I would like some other people to have a look at it. I am not sure it does work properly because when I compute for example the mean of 200, 100000, 1000000 or 10000000 calls to nextPoisson(6.0), I always get values between 14.7 and 15.2. I have seen the variance of a Poisson distribution is the same as its mean and so could expect a large value, but this still looked strange to me. > RandomDataImpl.nextPoisson fails for means in range 6.0 - 19.99 > --------------------------------------------------------------- > > Key: MATH-294 > URL: https://issues.apache.org/jira/browse/MATH-294 > Project: Commons Math > Issue Type: Bug > Affects Versions: 1.2, 2.0 > Environment: Java 1.6 on mac osX > Reporter: Jason McFall > Attachments: math-294.patch > > > math.random.RandomDataImpl.nextPoisson(double mean) fails frequently (but not always) for values of mean between 6.0 and 19.99 inclusive. For values below 6.0 (where I see there is a branch in the logic) and above 20.0 it seems to be okay (though I've only randomly sampled the space and run a million trials for the values I've tried) > When it fails, the exception is as follows (this for a mean of 6.0) > org.apache.commons.math.MathRuntimeException$4: must have n >= 0 for n!, got n = -2 > at org.apache.commons.math.MathRuntimeException.createIllegalArgumentException(MathRuntimeException.java:282) > at org.apache.commons.math.util.MathUtils.factorialLog(MathUtils.java:561) > at org.apache.commons.math.random.RandomDataImpl.nextPoisson(RandomDataImpl.java:434) > ie MathUtils.factorialLog is being called with a negative input > To reproduce: > JDKRandomGenerator random = new JDKRandomGenerator(); > random.setSeed(123456); > RandomData randomData = new RandomDataImpl(random); > for (int i=0; i< 1000000; i++){ > randomData.nextPoisson(6.0); > } -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.