You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Jason McFall (JIRA)" <ji...@apache.org> on 2009/09/11 19:34:57 UTC
[jira] Created: (MATH-294) RandomDataImpl.nextPoisson fails for
means in range 6.0 - 19.99
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: 2.0, 1.2
Environment: Java 1.6 on mac osX
Reporter: Jason McFall
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.
[jira] Updated: (MATH-294) RandomDataImpl.nextPoisson fails for
means in range 6.0 - 19.99
Posted by "Luc Maisonobe (JIRA)" <ji...@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.
[jira] Commented: (MATH-294) RandomDataImpl.nextPoisson fails for
means in range 6.0 - 19.99
Posted by "Phil Steitz (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/MATH-294?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12755314#action_12755314 ]
Phil Steitz commented on MATH-294:
----------------------------------
Lets hold on the patch for now. We need to understand why the rejection algorithm is failing. Based on a quick review of the reference in the javadoc (p. 511, X.3), it looks like the following line in the u < c_1 case should not be subtracting 1.0 at the end.
y = -Math.abs(z) * Math.sqrt(mu) - 1.0;
I have not tested the effect dropping the -1 here as I am still working through the algorithm.
> 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.
[jira] Closed: (MATH-294) RandomDataImpl.nextPoisson fails for
means in range 6.0 - 19.99
Posted by "Phil Steitz (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/MATH-294?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Phil Steitz closed MATH-294.
----------------------------
> 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
> Fix For: 2.1
>
> 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.
-
If you think it was sent incorrectly contact one of the administrators: https://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] Commented: (MATH-294) RandomDataImpl.nextPoisson fails for
means in range 6.0 - 19.99
Posted by "Phil Steitz (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/MATH-294?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12760210#action_12760210 ]
Phil Steitz commented on MATH-294:
----------------------------------
In r819492, I committed a goodness of fit test (testNextPoissionConistency) for the values generated by nextPoisson. Currently, it tests only values up to 5. When this issue is resolved, the upper bound in the test needs to be increased.
I have not been able to rectify the current code so that it succeeds for all values and passes the test. The implementation does not match the reference in the javadoc and the reference appears to contain errors. If someone does not beat me to it or supply a patch that passes the test, I will find and implement a different version of the rejection algorithm for means > 6.
> 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.
[jira] Updated: (MATH-294) RandomDataImpl.nextPoisson fails for
means in range 6.0 - 19.99
Posted by "Phil Steitz (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/MATH-294?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Phil Steitz updated MATH-294:
-----------------------------
Fix Version/s: 2.1
> 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
> Fix For: 2.1
>
> 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.
[jira] Resolved: (MATH-294) RandomDataImpl.nextPoisson fails for
means in range 6.0 - 19.99
Posted by "Phil Steitz (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/MATH-294?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Phil Steitz resolved MATH-294.
------------------------------
Resolution: Fixed
Fixed in r824214
> 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
> Fix For: 2.1
>
> 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.