[ https://issues.apache.org/jira/browse/MATH294?page=com.atlassian.jira.plugin.system.issuetabpanels:alltabpanel
]
Luc Maisonobe updated MATH294:

Attachment: math294.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: MATH294
> URL: https://issues.apache.org/jira/browse/MATH294
> Project: Commons Math
> Issue Type: Bug
> Affects Versions: 1.2, 2.0
> Environment: Java 1.6 on mac osX
> Reporter: Jason McFall
> Attachments: math294.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.
